diff --git a/DMS/Character.h b/DMS/Character.h index e79aa72..06cccc9 100644 --- a/DMS/Character.h +++ b/DMS/Character.h @@ -1,6 +1,5 @@ #pragma once -#include -#include +#include "pch.h" #include "value.h" #include "enviroment.h" namespace dms { diff --git a/DMS/DMS.cpp b/DMS/DMS.cpp index 32845ea..02b1da4 100644 --- a/DMS/DMS.cpp +++ b/DMS/DMS.cpp @@ -1,11 +1,6 @@ +#include "pch.h" #include "dms.h" -#include "memory.h" -#include -#include "utils.h" -#include -#include "value.h" -#include "enviroment.h" -#include "wrapper.h" + //#include using namespace dms; //typedef void(*FNPTR)(); @@ -14,26 +9,21 @@ using namespace dms; // utils::print(args->args[0].getPrintable()); // return "I work!"; //} -value print(void* self, dms_state* state, dms_args* args) { - std::string str = ""; - for (size_t i = 0; i < args->args.size(); i++) { - str += args->args[i].getPrintable() + "\t"; - } - printf((str + "\n").c_str()); - return NULL; -} -value type(void* self, dms_state* state, dms_args* args) { - if (args->size() > 0) { - return datatype[args->args[0].type]; - } - return "nil"; -} //value concat(void* self, dms_state* state, dms_args* args) { // std::stringstream str; // for (size_t i = 0; i < args->size() - 1; i++) // str << args->args[i].getPrintable(); // return value(str.str()); //} +//void draw(sf::RenderWindow& window) { +// sf::CircleShape shape(60.f); +// shape.setFillColor(sf::Color(150, 50, 250)); +// +// // set a 10-pixel wide orange outline +// shape.setOutlineThickness(10.f); +// shape.setOutlineColor(sf::Color(250, 150, 100)); +// window.draw(shape); +//} int main() { // TODO fix disp cmd to handle the standard @@ -43,17 +33,38 @@ int main() system_clock::now().time_since_epoch() ); utils::print(ms.count());*/ - enviroment* envio = new enviroment; + LineParser parser = LineParser("test.dms"); dms_state* state = parser.Parse(); + // Load audio stuff + dms::audio::init(state); state->dump(); - envio->registerFunction("print", print); - state->invoker.registerFunction("print", print); - state->injectEnv("io",envio); - state->run(); + + // create the window + //sf::RenderWindow window(sf::VideoMode(800, 600), "My window"); + //// run the program as long as the window is open + //while (window.isOpen()) + //{ + // // check all the window's events that were triggered since the last iteration of the loop + // sf::Event event; + // while (window.pollEvent(event)) + // { + // // "close requested" event: we close the window + // if (event.type == sf::Event::Closed) + // window.close(); + // } + // // clear the window with black color + // window.clear(sf::Color::Black); + + // // draw everything here... + // draw(window); + + // // end the current frame + // window.display(); + //} /*HINSTANCE hInst = LoadLibrary(L"C:\\Users\\rayam\\Desktop\\test.dll"); if (!hInst) { diff --git a/DMS/DMS.vcxproj b/DMS/DMS.vcxproj index 69bf1f6..74f1dd9 100644 --- a/DMS/DMS.vcxproj +++ b/DMS/DMS.vcxproj @@ -89,10 +89,13 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 + C:\SFML\include;%(AdditionalIncludeDirectories) Console true + sfml-audio-d.lib;sfml-system-d.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + C:\SFML\lib;%(AdditionalLibraryDirectories) @@ -104,12 +107,15 @@ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 + C:\SFML\include;%(AdditionalIncludeDirectories) Console true true true + C:\SFML\lib;%(AdditionalLibraryDirectories) + sfml-audio.lib;%(AdditionalDependencies) @@ -121,16 +127,19 @@ stdcpp17 Default Default - NotUsing + Use false Default false + C:\SFML\include;%(AdditionalIncludeDirectories) + pch.h Console true - C:\includes\include;%(AdditionalLibraryDirectories) + C:\SFML\lib;C:\includes\include;%(AdditionalLibraryDirectories) 4194304 + sfml-audio-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-network-d.lib;sfml-system-d.lib;%(AdditionalDependencies) @@ -143,16 +152,20 @@ true stdcpp17 MinSpace + C:\SFML\include;%(AdditionalIncludeDirectories) Console true true true + C:\SFML\lib; + sfml-audio.lib;sfml-graphics.lib;sfml-window.lib;sfml-network.lib;sfml-system.lib;%(AdditionalDependencies) + @@ -169,13 +182,19 @@ - + + Create + + + + + @@ -189,6 +208,9 @@ + + + diff --git a/DMS/DMS.vcxproj.filters b/DMS/DMS.vcxproj.filters index 542dac8..ac3e0c8 100644 --- a/DMS/DMS.vcxproj.filters +++ b/DMS/DMS.vcxproj.filters @@ -19,18 +19,36 @@ {e3410a7b-6408-4022-b606-2c14cfaac52c} - - {978b41cd-27e4-4b8c-874e-3b6e927b3d4d} - - - {4c0bb4c5-388c-4f15-abb7-143cb6d6232f} - {f71964f6-66b3-4d8c-a8da-56d703ad1c2a} {32abbbfd-6359-488c-83be-f61da8fd8f4d} + + {10d9f698-b08c-40c5-b6b1-e6d903f4b279} + + + {4757b859-2680-4c9a-83e8-be3bf06f192e} + + + {be440a96-7b07-48b3-a84e-64b10775c979} + + + {9490aa5b-7d9d-415c-a263-ef1ecd8dd188} + + + {4c0bb4c5-388c-4f15-abb7-143cb6d6232f} + + + {978b41cd-27e4-4b8c-874e-3b6e927b3d4d} + + + {39dc0943-16ca-48a6-b04e-04ba994cfb8d} + + + {ef57bfaf-35f9-4b3e-8642-7ee96fb82139} + @@ -42,9 +60,6 @@ Source Files\DMS - - Source Files\DMS - Source Files\DMS @@ -54,43 +69,52 @@ Source Files - - Source Files\DMS - Source Files\DMS - - Source Files\DMS - - - Source Files\DMS - - - Source Files\DMS - - - Source Files\DMS - - - Source Files\DMS - Source Files\DMS - Source Files\DMS\blocks + Source Files\DMS\objects - Source Files\DMS\blocks + Source Files\DMS\objects Source Files\DMS - + Source Files\DMS - + + Source Files\DMS\standardMethods + + + Source Files\DMS\parser + + + Source Files\DMS\parser + + + Source Files\DMS\parser + + + Source Files\DMS\parser + + + Source Files\DMS\state + + + Source Files\DMS\state + + + Source Files\DMS\objects + + + Source Files\DMS\standardMethods + + Source Files\DMS @@ -132,13 +156,10 @@ Header Files\DMS - Header Files\DMS\blocks + Header Files\DMS\objects - Header Files\DMS\blocks - - - Header Files\DMS + Header Files\DMS\objects Header Files\DMS @@ -152,5 +173,20 @@ Header Files\DMS\C-API + + Header Files\DMS\objects + + + Header Files\DMS\standardMethods + + + Header Files\DMS\C-API + + + Header Files\DMS\standardMethods + + + Header Files\DMS + \ No newline at end of file diff --git a/DMS/Handlers.cpp b/DMS/Handlers.cpp index e0563ce..bc339e6 100644 --- a/DMS/Handlers.cpp +++ b/DMS/Handlers.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "Handlers.h" namespace dms { uint8_t Handler::handleChoice(dms_state* state, std::string prompt, std::vector args) const { diff --git a/DMS/Handlers.h b/DMS/Handlers.h index 877b063..3330a23 100644 --- a/DMS/Handlers.h +++ b/DMS/Handlers.h @@ -1,8 +1,8 @@ #pragma once +#include "pch.h" #include "value.h" #include "utils.h" #include "character.h" -#include namespace dms { struct Handler { diff --git a/DMS/Invoker.cpp b/DMS/Invoker.cpp index dbda6f9..daef6d3 100644 --- a/DMS/Invoker.cpp +++ b/DMS/Invoker.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "Invoker.h" #include "dms_state.h" #include "utils.h" @@ -21,11 +22,23 @@ namespace dms { if(args->size()) for (int i = 0; i < args->args.size() - 1; i++) args->args[i] = args->args[i].resolve(state); + return funcs[str](self, state, args); } state->push_error(errors::error{ errors::non_existing_function, utils::concat("Attempt to call '",str,"' a nil value!") }); return value(datatypes::error); } + value Invoker::Invoke(std::string str,void* ref, dms_state* state, dms_args* args) { + if (funcs.count(str)) { + if (args->size()) + for (int i = 0; i < args->args.size() - 1; i++) + args->args[i] = args->args[i].resolve(state); + + return funcs[str](ref, state, args); + } + state->push_error(errors::error{ errors::non_existing_function, utils::concat("Attempt to call '",str,"' a nil value!") }); + return value(datatypes::error); + } std::unordered_map Invoker::Export() { return funcs; } diff --git a/DMS/Invoker.h b/DMS/Invoker.h index 47d9ab0..f5e620b 100644 --- a/DMS/Invoker.h +++ b/DMS/Invoker.h @@ -1,6 +1,6 @@ #pragma once +#include "pch.h" #include "errors.h" -#include namespace dms { struct dms_state; class Invoker { @@ -12,6 +12,7 @@ namespace dms { bool registerFunction(std::string str, value (*f)(void*, dms_state*, dms_args*), bool preventoverride); void _init(void* ref); value Invoke(std::string str, dms_state* state, dms_args* args); + value Invoke(std::string str, void* ref, dms_state* state, dms_args* args); // Exports the methods from an Invoker object std::unordered_map Export(); // Imports methods from another Invoker, this will add and overwrite any method with the same name diff --git a/DMS/LineParser.h b/DMS/LineParser.h index 5395482..ca61237 100644 --- a/DMS/LineParser.h +++ b/DMS/LineParser.h @@ -1,12 +1,7 @@ #pragma once #include #include -#include -#include -#include -#include -#include -#include +#include "pch.h" #include "codes.h" #include "cmd.h" #include "dms_state.h" @@ -94,6 +89,7 @@ namespace dms { bool match_process_number(tokenstream* stream, value& v); bool match_process_asm(tokenstream* stream); bool match_process_1afunc(tokenstream* stream, value& v); + bool match_process_ooxoo(tokenstream* stream, value& v); // Build void buildGoto(std::string g, bool v = false); diff --git a/DMS/LineParserBuilds.cpp b/DMS/LineParserBuilds.cpp index a6db31f..1da2296 100644 --- a/DMS/LineParserBuilds.cpp +++ b/DMS/LineParserBuilds.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "LineParser.h" namespace dms { void LineParser::buildGoto(std::string g, bool v) { diff --git a/DMS/LineParserMatchProcess.cpp b/DMS/LineParserMatchProcess.cpp index c422570..01fd70b 100644 --- a/DMS/LineParserMatchProcess.cpp +++ b/DMS/LineParserMatchProcess.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "LineParser.h" using namespace dms::tokens; using namespace dms::utils; @@ -73,11 +74,15 @@ namespace dms { } return true; } - if (match_process_1afunc(stream, v)) { + if (match_process_ooxoo(stream,v)) { match_process_condition(stream, v); return true; } - if (match_process_expression(stream, v)) { + else if (match_process_1afunc(stream, v)) { + match_process_condition(stream, v); + return true; + } + else if (match_process_expression(stream, v)) { match_process_condition(stream,v); return true; } @@ -144,6 +149,21 @@ namespace dms { } return false; } + bool LineParser::match_process_ooxoo(tokenstream* stream, value& v) { + if (stream->match(name, plus, plus)) { + + } + else if (stream->match(name, minus, minus)) { + + } + else if (stream->match(plus, plus, name)) { + + } + else if (stream->match(minus, minus, name)) { + + } + return false; + } bool LineParser::match_process_andor(tokenstream* stream, value& v) { codes::op code = codes::MUL; if (stream->match(tokens::Or)) { @@ -356,16 +376,35 @@ namespace dms { std::string name = stream->next().name; stream->next(); cmd* c = new cmd; - c->opcode = codes::SSPK; - c->args.push(value(name, datatypes::variable)); + if (isBlock(bt_character)) { + c->opcode = codes::STAT; + c->args.push(value(name, datatypes::variable)); + } + else { + c->opcode = codes::SSPK; + c->args.push(value(name, datatypes::variable)); + } current_chunk->addCmd(c); value msg(variable); - if (match_process_standard(stream, msg)) { - c = new cmd; - c->opcode = codes::DISP; - c->args.push(msg); - current_chunk->addCmd(c); // Add the cmd to the current chunk - current_chunk->addCmd(new cmd{ codes::HALT }); + if (stream->match(tokens::cbracketo)) { + if (match_process_scope(stream)) { + return true; + } + else { + badSymbol(stream); + return false; + } + } else if (match_process_standard(stream, msg)) { + if (isBlock(bt_character)) { + c->args.push(value(msg)); + } + else { + c = new cmd; + c->opcode = codes::DISP; + c->args.push(msg); + current_chunk->addCmd(c); // Add the cmd to the current chunk + current_chunk->addCmd(new cmd{ codes::HALT }); + } } else { badSymbol(stream); @@ -373,14 +412,21 @@ namespace dms { } return true; } - else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) { + else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string)) { stream->next(); // Standard consumption - cmd* c = new cmd; - c->opcode = codes::DISP; - c->args.push(value(stream->next().name)); - current_chunk->addCmd(c); // Add the cmd to the current chunk - current_chunk->addCmd(new cmd{ codes::HALT }); - return true; + value temp(variable); + if (match_process_standard(stream, temp)) { + cmd* c = new cmd; + c->opcode = codes::DISP; + c->args.push(temp); + current_chunk->addCmd(c); // Add the cmd to the current chunk + current_chunk->addCmd(new cmd{ codes::HALT }); + return true; + } + else { + badSymbol(stream); + return false; + } } else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline,tokens::pipe ,tokens::string, tokens::newline)) { stream->next(); // Standard consumption @@ -396,105 +442,6 @@ namespace dms { current_chunk->addCmd(new cmd{ codes::HALT }); return true; } - else if (isBlock(bt_character) && stream->match(tokens::newline, tokens::name, tokens::colon, tokens::string, tokens::newline)) { - stream->next(); // Standard consumption - std::string name = stream->next().name; - stream->next(); // That colon - std::string msg = stream->next().name; - cmd* c = new cmd; - c->opcode = codes::STAT; - c->args.push(value(name,datatypes::variable)); - c->args.push(value(msg)); - current_chunk->addCmd(c); // Add the cmd to the current chunk - } - else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::name, tokens::colon, tokens::string, tokens::newline)) { - // We might have to handle scope here - // Here we match 'Ryan: "This guy said this!"' Note the colon is needed! - stream->next(); // Standard consumption - std::string name = stream->next().name; - stream->next(); // That colon - std::string msg = stream->next().name; - cmd* c = new cmd; - c->opcode = codes::SSPK; - c->args.push(value(name, datatypes::variable)); - current_chunk->addCmd(c); - c = new cmd; - c->opcode = codes::DISP; - c->args.push(value(msg)); - current_chunk->addCmd(c); // Add the cmd to the current chunk - current_chunk->addCmd(new cmd{ codes::HALT }); - return true; - } - else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::name,tokens::colon,tokens::cbracketo)) { - std::string name = stream->next().name; - // Command to set the speaker - cmd* c = new cmd; - c->opcode = codes::SSPK; - c->args.push(value(name,datatypes::variable)); - current_chunk->addCmd(c); - stream->next(); - stream->next(); - while (stream->peek().type != tokens::cbracketc) { - debugInvoker(stream); - if (stream->match(tokens::name)) { - std::string mode = stream->next().name; - if (mode == "speed") { - if (stream->match(tokens::number)) { - buildSpeed(std::stod(stream->next().name)); - } - else { - badSymbol(stream); - return false; - } - } - else if (mode == "wait") { - if (stream->match(tokens::number)) { - buildWait(std::stod(stream->next().name)); - } - else { - badSymbol(errors::disp_unknown, stream); - } - } - else { - // Assume we have a dact - if (stream->match(tokens::string) || stream->match(tokens::colon,tokens::string)) { - if (stream->match(tokens::colon)) { - stream->next(); - } - cmd* c = new cmd; - c->opcode = codes::DACT; - c->args.push(value(mode)); - current_chunk->addCmd(c); - // Now build the apnd msg cmd - c = new cmd; - c->opcode = codes::APND; - c->args.push(value(stream->next().name)); - current_chunk->addCmd(c); - } - else { - badSymbol(stream); - return false; - } - } - } - else if (stream->match(tokens::string)) { - cmd* c = new cmd; - c->opcode = codes::APND; - c->args.push(value(stream->next().name)); - current_chunk->addCmd(c); - } - else if (stream->match(tokens::newline)) { - stream->next(); - } - else { - badSymbol(stream); - return false; - } - } - stream->next(); - current_chunk->addCmd(new cmd{ codes::HALT }); - return true; - } return false; } bool LineParser::match_process_return(tokenstream* stream) { @@ -896,7 +843,24 @@ namespace dms { return false; } bool LineParser::match_process_index(tokenstream* stream, value& v, bool leftside) { - if (stream->match(tokens::name,tokens::bracketo)) { + if (stream->match(tokens::name,tokens::dot,tokens::name)) { + std::string name = stream->next().name; + stream->next(); + std::string key = stream->next().name; + cmd* c = new cmd; + if (leftside) { + c->opcode = codes::ASID; + } + else { + c->opcode = codes::INDX; + } + c->args.push(v); + c->args.push(value(name, datatypes::block)); + c->args.push(value(key)); + current_chunk->addCmd(c); + return true; + } + else if (stream->match(tokens::name,tokens::bracketo)) { std::string name = stream->next().name; std::vector toks = stream->next(tokens::bracketo, tokens::bracketc); toks.pop_back(); // Remove the last element since its a ']' @@ -1151,11 +1115,11 @@ namespace dms { temp.push_back(value(ts.next().name)); } else if (ts.match(tokens::number)) { - temp.push_back(stov(stream->next().name)); + temp.push_back(stov(ts.next().name)); } else if (ts.match(tokens::minus,tokens::number)) { ts.next(); - temp.push_back(stov(stream->next().name)); + temp.push_back(stov(ts.next().name)); } else if (ts.match(tokens::True)) { temp.push_back(value(true)); @@ -1287,6 +1251,8 @@ namespace dms { } } if (temp.size() >= 1) { + if(o == codes::FUNC || o == codes::OFUN) + temp.push_back(escape); buildCmd(o, temp); } return true; @@ -1583,6 +1549,7 @@ namespace dms { //Function template ^^^ If we encounter an issue the method should push an error, incase it misses something we will! value tmpvalue = value(datatypes::variable); if (match_process_function(stream,tmpvalue)) { + hasOP = false; if (left.isNil()) left = tmpvalue; else if (right.isNil()) @@ -1598,6 +1565,7 @@ namespace dms { } } else if (stream->match(tokens::number)) { + hasOP = false; if (left.isNil()) left = stov(stream->next().name); else if (right.isNil()) @@ -1608,6 +1576,7 @@ namespace dms { } } else if (stream->match(tokens::string)) { + hasOP = false; if (left.isNil()) left = value(stream->next().name,string); else if (right.isNil()) @@ -1620,6 +1589,7 @@ namespace dms { else if (stream->match(tokens::name, tokens::bracketo)) { value tmpvalue = value(datatypes::variable); if (match_process_index(stream, tmpvalue)) { + hasOP = false; if (left.isNil()) left = tmpvalue; else if (right.isNil()) @@ -1632,6 +1602,7 @@ namespace dms { } else if (stream->match(tokens::name)) { // We tested functions already! So if that fails and we have a name then... we have a variable lets handle this! + hasOP = false; if (left.isNil()) left = value(stream->next().name,datatypes::variable); else if (right.isNil()) @@ -1641,7 +1612,7 @@ namespace dms { return false; } } - else if (stream->match(tokens::newline) || stream->match(tokens::parac) || stream->match(tokens::seperator)) { + else if ((stream->match(tokens::newline) && !hasOP) || stream->match(tokens::parac) || stream->match(tokens::seperator)) { if (wv.isNil()) return stream->restore(lastcmd, current_chunk); // Always return false and restores the position in stream! cmd* cc = new cmd; diff --git a/DMS/LineParserParse.cpp b/DMS/LineParserParse.cpp index 30c2a6a..d97a25c 100644 --- a/DMS/LineParserParse.cpp +++ b/DMS/LineParserParse.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "LineParser.h" using namespace dms::tokens; using namespace dms::utils; @@ -239,12 +240,12 @@ namespace dms { doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); t_vec.push_back(token{ tokens::anglebracketO,codes::NOOP,"<",line }); } - else if (data == '\t') { + /*else if (data == '\t') { doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); t_vec.push_back(token{ tokens::tab,codes::NOOP,"\t",line }); - } + }*/ - if ((data == ' ' || data == '(') && !isStr) { // tokens end with a space + if ((data == ' ' || data == '(' || data == '\t') && !isStr) { // tokens end with a space std::string str = stream.processBuffer(buffer); tolower(str); if (str == "enable") { @@ -531,8 +532,8 @@ namespace dms { if (stream->match(newline) || stream->match(eof)) { current = stream->next(); } - } + return true; } void LineParser::_Parse(tokenstream* stream) { if (stop) return; diff --git a/DMS/LineParserUtils.cpp b/DMS/LineParserUtils.cpp index 57a09ad..f763fdd 100644 --- a/DMS/LineParserUtils.cpp +++ b/DMS/LineParserUtils.cpp @@ -1,5 +1,5 @@ +#include "pch.h" #include "LineParser.h" -#include using namespace dms::tokens; using namespace dms::utils; namespace dms { @@ -249,6 +249,15 @@ namespace dms { buffer->clear(); hasDec = false; } + else if (str.find('.')!=std::string::npos) { + auto s = utils::split(str, "."); + t_vec->push_back(token{ tokens::name,codes::NOOP,s[0],line }); + t_vec->push_back(token{ tokens::dot,codes::NOOP,"dot",line }); + t_vec->push_back(token{ tokens::name,codes::NOOP,s[1],line }); + buffer->clear(); + isNum = false; + hasDec = false; + } else { t_vec->push_back(token{ tokens::name,codes::ERRO,"Invalid variable name!",line }); } diff --git a/DMS/Ryan.dms b/DMS/Ryan.dms new file mode 100644 index 0000000..541c0d5 --- /dev/null +++ b/DMS/Ryan.dms @@ -0,0 +1,5 @@ +filetype char // Define this file as a char, the default makes all all blocks "block" +// This definition allows us to do some cool things, like adding our own methods into the base character object +[setNickname:function(name)] + nickname = name + \ No newline at end of file diff --git a/DMS/character.cpp b/DMS/character.cpp index bc1c214..4753dbe 100644 --- a/DMS/character.cpp +++ b/DMS/character.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "character.h" #include "utils.h" namespace dms { diff --git a/DMS/chunk.cpp b/DMS/chunk.cpp index 48a6bb5..cef4e9e 100644 --- a/DMS/chunk.cpp +++ b/DMS/chunk.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "chunk.h" namespace dms { std::string getBlockType(const blocktype b) { diff --git a/DMS/chunk.h b/DMS/chunk.h index 6a5bf07..fbeb01c 100644 --- a/DMS/chunk.h +++ b/DMS/chunk.h @@ -1,8 +1,6 @@ #pragma once +#include "pch.h" #include "cmd.h" -#include -#include -#include namespace dms { enum blocktype { bt_block, diff --git a/DMS/cmd.cpp b/DMS/cmd.cpp index a5bfb36..613243f 100644 --- a/DMS/cmd.cpp +++ b/DMS/cmd.cpp @@ -1 +1,2 @@ +#include "pch.h" #include "cmd.h" diff --git a/DMS/cmd.h b/DMS/cmd.h index f405fe3..cfb0a08 100644 --- a/DMS/cmd.h +++ b/DMS/cmd.h @@ -1,8 +1,7 @@ #pragma once +#include "pch.h" #include "value.h" #include "codes.h" -#include -#include namespace dms { struct cmd { diff --git a/DMS/codes.cpp b/DMS/codes.cpp index 6d1fe32..3b6b3ac 100644 --- a/DMS/codes.cpp +++ b/DMS/codes.cpp @@ -1,4 +1,5 @@ #pragma once +#include "pch.h" #include "Codes.h" const std::string dms::codes::list[] = { "NOOP", diff --git a/DMS/codes.h b/DMS/codes.h index 45152d6..10977de 100644 --- a/DMS/codes.h +++ b/DMS/codes.h @@ -1,57 +1,58 @@ #pragma once -#include -#include -namespace dms::codes { - enum op { - NOOP, // Done - ENTR, // Done - ENAB, // Done - DISA, // Done - LOAD, // Done - VERN, // Done - USIN, // TODO - STAT, - DISP, // Done - ASGN, // Done - LABL, // Done - CHOI, // Done - BLCK, // - CHAR, // Done - WHLE, - FUNC, // Done - IFFF, // Done - KNOT, // Done - ELSE, // Scraped - DEFN, - SKIP, - COMP, // Done - INDX, // Done - JMPZ, // Scraped see [COMP] - INST, // Done - ERRO, - GOTO, - JUMP, // Done - RETN, - EXIT, // Done - DEBG, - DSPD, // Todo - DACT, - WAIT, // Done - APND, // Done - SSPK, // Done - ADD, // Done - SUB, // Done - MUL, // Done - DIV, // Done - POW, // Done - MOD, // Done - LIST, // Done - LINE, // Done - HALT, // Todo - FILE, - GC, - ASID, // Done - OFUN // Done - }; - extern const std::string list[]; +#include "pch.h" +namespace dms { + namespace codes { + enum op { + NOOP, // Done + ENTR, // Done + ENAB, // Done + DISA, // Done + LOAD, // Done + VERN, // Done + USIN, // TODO + STAT, + DISP, // Done + ASGN, // Done + LABL, // Done + CHOI, // Done + BLCK, // + CHAR, // Done + WHLE, + FUNC, // Done + IFFF, // Done + KNOT, // Done + ELSE, // Scraped + DEFN, + SKIP, + COMP, // Done + INDX, // Done + JMPZ, // Scraped see [COMP] + INST, // Done + ERRO, + GOTO, + JUMP, // Done + RETN, + EXIT, // Done + DEBG, + DSPD, // Todo + DACT, + WAIT, // Done + APND, // Done + SSPK, // Done + ADD, // Done + SUB, // Done + MUL, // Done + DIV, // Done + POW, // Done + MOD, // Done + LIST, // Done + LINE, // Done + HALT, // Todo + FILE, + GC, + ASID, // Done + OFUN // Done + }; + extern const std::string list[]; + } } \ No newline at end of file diff --git a/DMS/core.cpp b/DMS/core.cpp new file mode 100644 index 0000000..0f3a8cc --- /dev/null +++ b/DMS/core.cpp @@ -0,0 +1,30 @@ +#pragma once +#include "pch.h" +#include "core.h" +#include "utils.h" +namespace dms { + namespace core { + value print(void* self, dms_state* state, dms_args* args) { + std::string str = ""; + for (size_t i = 0; i < args->args.size(); i++) { + str += args->args[i].getPrintable() + "\t"; + } + printf((str + "\n").c_str()); + return NULL; + } + value type(void* self, dms_state* state, dms_args* args) { + if (args->size() > 0) { + value temp = args->args[0]; + if (temp.type == datatypes::custom && temp.ctype != "") + return temp.ctype; + else + return datatype[args->args[0].type]; + } + return "nil"; + } + void init(dms_state* state) { + state->invoker.registerFunction("print", print); + state->invoker.registerFunction("type", type); + } + } +} \ No newline at end of file diff --git a/DMS/core.h b/DMS/core.h new file mode 100644 index 0000000..c0a3f80 --- /dev/null +++ b/DMS/core.h @@ -0,0 +1,9 @@ +#pragma once +#include "dms_state.h" +namespace dms { + namespace core { + void init(dms_state* state); + value print(void* self, dms_state* state, dms_args* args); + value type(void* self, dms_state* state, dms_args* args); + } +} \ No newline at end of file diff --git a/DMS/dms.h b/DMS/dms.h index ad92d65..70f64ad 100644 --- a/DMS/dms.h +++ b/DMS/dms.h @@ -14,4 +14,8 @@ #include "Invoker.h" #include "memory.h" #include "dms_list.h" +#include "s_value.h" +#include "wrapper.h" +#include "sound.h" +#include "comparisons.h" diff --git a/DMS/dms_custom.cpp b/DMS/dms_custom.cpp index 649e2c4..fc9ef6e 100644 --- a/DMS/dms_custom.cpp +++ b/DMS/dms_custom.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "value.h" #include "utils.h" //Implement the defaults diff --git a/DMS/dms_exceptions.cpp b/DMS/dms_exceptions.cpp index 657d2fa..8adcf46 100644 --- a/DMS/dms_exceptions.cpp +++ b/DMS/dms_exceptions.cpp @@ -1 +1,2 @@ +#include "pch.h" #include "dms_exceptions.h" diff --git a/DMS/dms_exceptions.h b/DMS/dms_exceptions.h index b1930b1..db10de2 100644 --- a/DMS/dms_exceptions.h +++ b/DMS/dms_exceptions.h @@ -1,20 +1,21 @@ #pragma once -#include -namespace dms::exceptions { - struct StringBoundsException : public std::exception { - const char* what() const throw () { - return "Attempt to sub outside of the bounds of the string!"; - } - }; - struct BadChoiceHandlerException : public std::exception { - const char* what() const throw () { - return "ChoiceHandler Expected got ???"; - } - }; - struct InvalidChoice : public std::exception { - const char* what() const throw () { - return "Invalid Choice!"; - } - }; -} - +#include "pch.h" +namespace dms { + namespace exceptions { + struct StringBoundsException : public std::exception { + const char* what() const throw () { + return "Attempt to sub outside of the bounds of the string!"; + } + }; + struct BadChoiceHandlerException : public std::exception { + const char* what() const throw () { + return "ChoiceHandler Expected got ???"; + } + }; + struct InvalidChoice : public std::exception { + const char* what() const throw () { + return "Invalid Choice!"; + } + }; + } +} \ No newline at end of file diff --git a/DMS/dms_state.cpp b/DMS/dms_state.cpp index c9aa62a..7bce8aa 100644 --- a/DMS/dms_state.cpp +++ b/DMS/dms_state.cpp @@ -1,5 +1,8 @@ +#include "pch.h" #include "dms_state.h" #include "Handlers.h" +#include "core.h" +#include "sound.h" namespace dms { value dms::blockInvoke(void* self, dms_state* state, dms_args* args) { std::string func = state->call_stack.top(); @@ -35,6 +38,7 @@ namespace dms { void dms_state::init() { if (init_init || stop) return; + init_init = true; cmd* c = new cmd; for (const auto& [key, val] : chunks) { @@ -65,6 +69,7 @@ namespace dms { else c->args.push(value(chunks.begin()->first)); chunks["$INIT"]->addCmd(c); + dms::core::init(this); if (!handler->OnStateInit(this)) stop = true; } @@ -72,7 +77,12 @@ namespace dms { return &mem_stack.top(); } void dms_state::pushMem() { - mem_stack.push(memory()); + memory mem = memory(); + if (!mem_stack.empty()) { + + mem.parent = getMem(); + } + mem_stack.push(mem); } void dms_state::pushMem(memory &mem) { mem_stack.push(mem); @@ -145,6 +155,15 @@ namespace dms { return false; } + bool dms_state::assoiateType(std::string type, Invoker* inv) + { + if(inv_map.count(type)) // Already exists! + return false; + + inv_map.insert_or_assign(type,inv); // Create it + return true; + } + bool dms_state::injectEnv(std::string name, enviroment* env) { std::string ename = name; diff --git a/DMS/dms_state.h b/DMS/dms_state.h index 5a221f2..c6654b6 100644 --- a/DMS/dms_state.h +++ b/DMS/dms_state.h @@ -1,8 +1,5 @@ #pragma once -#include -#include -#include -#include +#include "pch.h" #include "Invoker.h" #include "errors.h" #include "chunk.h" @@ -10,7 +7,6 @@ #include "Character.h" #include "enviroment.h" #include "memory.h" -#include #include "dms_list.h" #include "comparisons.h" namespace dms { @@ -30,6 +26,7 @@ namespace dms { std::unordered_map characters; std::unordered_map environments; std::unordered_map labels; + std::unordered_map inv_map; std::string entry = "$undefined"; std::unordered_map enables; std::size_t cur_line=0; @@ -38,6 +35,7 @@ namespace dms { const double Iversion = 1.0; double Sversion; // The version of errors::error err; + character* speaker = nullptr; dms_state(); void dump(std::string fn = "dump.bin"); @@ -57,6 +55,7 @@ namespace dms { character* getCharacter(std::string c); enviroment* getEnvironment(std::string c); + bool assoiateType(std::string type, Invoker* inv); bool injectEnv(std::string, enviroment*); bool assign(value var, value val); size_t seek(std::string label,std::vector cmds ,codes::op code, size_t pos); @@ -71,6 +70,7 @@ namespace dms { bool run(); bool run(std::string ent,memory* mem); bool run(std::string instance); + bool error(std::string); // This is called once and once only. Dynamically loading code is not a thing! void init(); bool hasError(); diff --git a/DMS/dms_state_interpret.cpp b/DMS/dms_state_interpret.cpp index 8b89985..02689cf 100644 --- a/DMS/dms_state_interpret.cpp +++ b/DMS/dms_state_interpret.cpp @@ -1,8 +1,7 @@ +#include "pch.h" #include "dms_state.h" #include "utils.h" #include "Handlers.h" -#include -#include using namespace dms::utils; using namespace dms::exceptions; using namespace dms::codes; @@ -113,6 +112,11 @@ namespace dms { //Spawn thread and run return true; } + bool dms_state::error(std::string err) + { + push_error(errors::error{ errors::unknown ,err }); + return false; + } bool dms_state::run() { if (stop) return false; @@ -138,7 +142,6 @@ namespace dms { //TODO: parse the cmds and do stuff // If this is running in a thread then stop will force this loop to stop size_t ln = 0; - character* speaker = nullptr; std::string temp; while (!stop || !halt) { c = cmds[pos++]; @@ -216,7 +219,7 @@ namespace dms { if (!cmp.b || cmp.isNil()) { pos = seek(gt.getPrintable(), cmds, LABL, pos); } - } + } break; } case GOTO: @@ -254,30 +257,54 @@ namespace dms { break; case OFUN: { - std::string obj = c->args.args[0].getPrintable(); - if (obj=="nil") { - obj = c->args.args[0].getPrintable(); - } - std::string funcname = c->args.args[1].getPrintable(); - value assn = c->args.args[2]; - dms_args args; + if (c->args.args[0].resolve(this).type == datatypes::custom) { + auto cust = c->args.args[0].resolve(this); + auto fname = c->args.args[1].s; + auto assn = c->args.args[2]; + dms_args args; - for (int i = 3; i < c->args.args.size(); i++) { - args.push(c->args.args[i]); + for (int i = 3; i < c->args.args.size(); i++) { + args.push(c->args.args[i]); + } + if (inv_map.count(cust.ctype)) { + Invoker* inv = inv_map[cust.ctype]; + auto ret = inv->Invoke(fname, cust.c, this, &args); + if (assn.type != datatypes::nil) { + if (!assign(assn, ret)) { + return false; + } + } + } + else { + error("Custom object not assoiated with any functions!"); + } } - - value ret; - if (characterExists(obj)) { - ret = getCharacter(obj)->Invoke(funcname, this, &args); - } - else if (environmentExists(obj)) { - ret = getEnvironment(obj)->Invoke(funcname, this, &args); - } - if (ret.type == datatypes::error) - return false; - if (assn.type != datatypes::nil) { - if(!assign(assn, ret)) { + else { + std::string obj = c->args.args[0].getPrintable(); + if (obj == "nil") { + obj = c->args.args[0].getPrintable(); + } + std::string funcname = c->args.args[1].getPrintable(); + value assn = c->args.args[2]; + dms_args args; + + for (int i = 3; i < c->args.args.size(); i++) { + args.push(c->args.args[i]); + } + + value ret; + if (characterExists(obj)) { + ret = getCharacter(obj)->Invoke(funcname, this, &args); + } + else if (environmentExists(obj)) { + ret = getEnvironment(obj)->Invoke(funcname, this, &args); + } + if (ret.type == datatypes::error) return false; + if (assn.type != datatypes::nil) { + if (!assign(assn, ret)) { + return false; + } } } } @@ -313,15 +340,15 @@ namespace dms { value env = c->args.args[1]; value indx = c->args.args[2].resolve(this); value assn = c->args.args[3].resolve(this); - if (env.type == datatypes::block && blockExists(env.getPrintable())) { // If this is a block let's handle this + if (env.type == datatypes::block && blockExists(env.s)) { // If this is a block let's handle this enviroment* e = nullptr; - if (environments.count(env.getPrintable())) { - e = environments[env.getPrintable()]; + if (environments.count(env.s)) { + e = environments[env.s]; } - else if (characters.count(env.getPrintable())) { - e = characters[env.getPrintable()]; + else if (characters.count(env.s)) { + e = characters[env.s]; } - e->values[indx.getPrintable()] = assn; + e->values[indx.s] = assn; } else if (env.type == datatypes::env) { if (indx.type == datatypes::number) { @@ -333,7 +360,7 @@ namespace dms { } } else if (env.type == datatypes::custom) { - env.c->NewIndex(indx, assn); + //env.c->NewIndex(indx, assn); //if(!assign( assn, env->c->Index(indx)); // Call the method within the custom data } @@ -434,9 +461,9 @@ namespace dms { } } else if (env.type == datatypes::custom) { - if(!assign( assn, env.c->Index(indx))) { - return false; - } + //if(!assign( assn, env.c->Index(indx))) { + // return false; + //} // Call the method within the custom data } } diff --git a/DMS/dump.bin b/DMS/dump.bin index 8a92921..0a8f1b9 100644 Binary files a/DMS/dump.bin and b/DMS/dump.bin differ diff --git a/DMS/dump.txt b/DMS/dump.txt index 42f9823..74e064f 100644 --- a/DMS/dump.txt +++ b/DMS/dump.txt @@ -23,164 +23,343 @@ Line <6> newline Line <7> newline Line <8> newline Line <9> newline -Line <10> flag -Line <10> number 0.2 -Line <10> newline Line <10> newline Line <11> flag -Line <11> name extendedDefine +Line <11> number 0.2 Line <11> newline Line <11> newline -Line <12> bracketo [ -Line <12> name main -Line <12> bracketc ] +Line <12> flag +Line <12> name extendedDefine Line <12> newline Line <12> newline -Line <13> name Ryan -Line <13> colon : -Line <13> string Hello Mr. -Line <13> plus + -Line <13> name Bob -Line <13> bracketo [ -Line <13> string lname -Line <13> bracketc ] -Line <13> plus + -Line <13> string ! How are you doing? Line <13> newline -Line <13> newline -Line <14> name Bob -Line <14> dot . -Line <14> name setName +Line <14> name music +Line <14> equal = +Line <14> name loadMusic Line <14> parao ( -Line <14> string Rob +Line <14> string test2.ogg Line <14> parac ) Line <14> newline Line <14> newline -Line <15> name Ryan -Line <15> colon : -Line <15> string Hello -Line <15> plus + -Line <15> name Bob -Line <15> plus + -Line <15> string ! How are you doing? +Line <15> name music2 +Line <15> equal = +Line <15> name loadMusic +Line <15> parao ( +Line <15> string test.ogg +Line <15> parac ) Line <15> newline Line <15> newline +Line <16> bracketo [ +Line <16> name main +Line <16> bracketc ] Line <16> newline +Line <16> newline +Line <17> name a +Line <17> equal = +Line <17> number 10 Line <17> newline Line <17> newline +Line <18> name tester +Line <18> parao ( +Line <18> parac ) Line <18> newline +Line <18> newline +Line <19> name print +Line <19> parao ( +Line <19> string a = +Line <19> plus + +Line <19> name a +Line <19> parac ) +Line <19> newline Line <19> newline Line <20> newline Line <21> newline Line <22> newline -Line <22> newline -Line <23> bracketo [ -Line <23> name test -Line <23> colon : -Line <23> name function -Line <23> parao ( -Line <23> name n -Line <23> parac ) -Line <23> bracketc ] Line <23> newline -Line <23> newline -Line <24> ret -Line <24> name n -Line <24> plus + -Line <24> number 1 -Line <24> newline Line <24> newline Line <25> newline -Line <25> newline -Line <26> bracketo [ -Line <26> name Ryan -Line <26> colon : -Line <26> name char -Line <26> bracketc ] Line <26> newline -Line <26> newline -Line <27> name lname -Line <27> equal = -Line <27> string Ward Line <27> newline -Line <27> newline -Line <28> name age -Line <28> equal = -Line <28> number 24 Line <28> newline -Line <28> newline -Line <29> name known -Line <29> equal = -Line <29> true true Line <29> newline -Line <29> newline -Line <30> name money -Line <30> equal = -Line <30> number 0 -Line <30> newline Line <30> newline Line <31> newline -Line <31> newline -Line <32> bracketo [ -Line <32> name John -Line <32> colon : -Line <32> name char -Line <32> bracketc ] Line <32> newline -Line <32> newline -Line <33> name lname -Line <33> equal = -Line <33> string Johnson Line <33> newline -Line <33> newline -Line <34> name age -Line <34> equal = -Line <34> number 16 Line <34> newline -Line <34> newline -Line <35> name money -Line <35> equal = -Line <35> number 100000 Line <35> newline -Line <35> newline -Line <36> name known -Line <36> equal = -Line <36> true true -Line <36> newline Line <36> newline Line <37> newline -Line <37> newline -Line <38> bracketo [ -Line <38> name Bob -Line <38> colon : -Line <38> name char -Line <38> bracketc ] -Line <38> newline Line <38> newline Line <39> newline Line <40> newline -Line <41> name lname -Line <41> equal = -Line <41> string Johnson Line <41> newline -Line <42> name unknown -Line <42> equal = -Line <42> string Some Random Guy Line <42> newline -Line <42> newline -Line <43> name age -Line <43> equal = -Line <43> number 24 Line <43> newline Line <43> newline -Line <44> name money -Line <44> equal = -Line <44> number 100 +Line <44> bracketo [ +Line <44> name tester +Line <44> colon : +Line <44> name function +Line <44> parao ( +Line <44> parac ) +Line <44> bracketc ] Line <44> newline Line <44> newline -Line <45> name excited -Line <45> colon : -Line <45> string path/to/file +Line <45> name print +Line <45> parao ( +Line <45> name a +Line <45> parac ) Line <45> newline Line <45> newline -Line <45> eof +Line <46> newline +Line <46> newline +Line <47> bracketo [ +Line <47> name SelectSong +Line <47> colon : +Line <47> name function +Line <47> parao ( +Line <47> parac ) +Line <47> bracketc ] +Line <47> newline +Line <47> newline +Line <48> control +Line <48> string Pick song: +Line <48> cbracketo { +Line <48> newline +Line <48> newline +Line <49> string Music 1 +Line <49> cbracketo { +Line <49> newline +Line <49> newline +Line <50> ret +Line <50> name music +Line <50> newline +Line <50> newline +Line <51> cbracketc } +Line <51> newline +Line <51> newline +Line <52> string Music 2 +Line <52> cbracketo { +Line <52> newline +Line <52> newline +Line <53> ret +Line <53> name music2 +Line <53> newline +Line <53> newline +Line <54> cbracketc } +Line <54> newline +Line <54> newline +Line <55> cbracketc } +Line <55> newline +Line <55> newline +Line <56> newline +Line <56> newline +Line <57> bracketo [ +Line <57> name player +Line <57> colon : +Line <57> name function +Line <57> parao ( +Line <57> name song +Line <57> parac ) +Line <57> bracketc ] +Line <57> newline +Line <57> newline +Line <58> control +Line <58> string What you wanna do? +Line <58> cbracketo { +Line <58> newline +Line <58> newline +Line <59> string play/resume +Line <59> cbracketo { +Line <59> newline +Line <59> newline +Line <60> name song +Line <60> dot dot +Line <60> name play +Line <60> parao ( +Line <60> parac ) +Line <60> newline +Line <60> newline +Line <61> name player +Line <61> parao ( +Line <61> name song +Line <61> parac ) +Line <61> newline +Line <61> newline +Line <62> cbracketc } +Line <62> newline +Line <62> newline +Line <63> string pause +Line <63> cbracketo { +Line <63> newline +Line <63> newline +Line <64> name song +Line <64> dot . +Line <64> name pause +Line <64> parao ( +Line <64> parac ) +Line <64> newline +Line <64> newline +Line <65> name player +Line <65> parao ( +Line <65> name song +Line <65> parac ) +Line <65> newline +Line <65> newline +Line <66> cbracketc } +Line <66> newline +Line <66> newline +Line <67> string stop +Line <67> cbracketo { +Line <67> newline +Line <67> newline +Line <68> name song +Line <68> dot . +Line <68> name stop +Line <68> parao ( +Line <68> parac ) +Line <68> newline +Line <68> newline +Line <69> name player +Line <69> parao ( +Line <69> name song +Line <69> parac ) +Line <69> newline +Line <69> newline +Line <70> cbracketc } +Line <70> newline +Line <70> newline +Line <71> string newSong +Line <71> cbracketo { +Line <71> newline +Line <71> newline +Line <72> name song +Line <72> dot . +Line <72> name stop +Line <72> parao ( +Line <72> parac ) +Line <72> newline +Line <72> newline +Line <73> name player +Line <73> parao ( +Line <73> name song +Line <73> parac ) +Line <73> newline +Line <73> newline +Line <74> cbracketc } +Line <74> newline +Line <74> newline +Line <75> string quit +Line <75> exit +Line <75> number 0 +Line <75> newline +Line <75> newline +Line <76> cbracketc } +Line <76> newline +Line <76> newline +Line <77> newline +Line <77> newline +Line <78> bracketo [ +Line <78> name Ryan +Line <78> colon : +Line <78> name char +Line <78> bracketc ] +Line <78> newline +Line <78> newline +Line <79> name age +Line <79> equal = +Line <79> number 21 +Line <79> newline +Line <79> newline +Line <80> name money +Line <80> equal = +Line <80> number 1000 +Line <80> newline +Line <80> newline +Line <81> name lname +Line <81> equal = +Line <81> string Ward +Line <81> newline +Line <81> newline +Line <82> name known +Line <82> equal = +Line <82> true true +Line <82> newline +Line <82> newline +Line <83> newline +Line <84> name calm +Line <84> colon : +Line <84> string ./path/to/file +Line <84> newline +Line <84> newline +Line <85> name excited +Line <85> colon : +Line <85> string ./path/to/file +Line <85> newline +Line <85> newline +Line <86> newline +Line <86> newline +Line <87> bracketo [ +Line <87> name John +Line <87> colon : +Line <87> name char +Line <87> bracketc ] +Line <87> newline +Line <87> newline +Line <88> name lname +Line <88> equal = +Line <88> string Johnson +Line <88> newline +Line <88> newline +Line <89> name age +Line <89> equal = +Line <89> number 16 +Line <89> newline +Line <89> newline +Line <90> name money +Line <90> equal = +Line <90> number 100000 +Line <90> newline +Line <90> newline +Line <91> name known +Line <91> equal = +Line <91> true true +Line <91> newline +Line <91> newline +Line <92> newline +Line <92> newline +Line <93> bracketo [ +Line <93> name Bob +Line <93> colon : +Line <93> name char +Line <93> bracketc ] +Line <93> newline +Line <93> newline +Line <94> newline +Line <95> newline +Line <96> name lname +Line <96> equal = +Line <96> string Johnson +Line <96> newline +Line <97> name unknown +Line <97> equal = +Line <97> string Some Random Guy +Line <97> newline +Line <97> newline +Line <98> name age +Line <98> equal = +Line <98> number 24 +Line <98> newline +Line <98> newline +Line <99> name money +Line <99> equal = +Line <99> number 100 +Line <99> newline +Line <99> newline +Line <100> name excited +Line <100> colon : +Line <100> string path/to/file +Line <100> newline +Line <100> newline +Line <100> eof diff --git a/DMS/enviroment.cpp b/DMS/enviroment.cpp index 72ae945..cd30eef 100644 --- a/DMS/enviroment.cpp +++ b/DMS/enviroment.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "enviroment.h" namespace dms { bool enviroment::has(std::string index) { diff --git a/DMS/enviroment.h b/DMS/enviroment.h index 325460a..8f62d38 100644 --- a/DMS/enviroment.h +++ b/DMS/enviroment.h @@ -1,6 +1,5 @@ #pragma once -#include -#include +#include "pch.h" #include "value.h" #include "memory.h" #include "Invoker.h" diff --git a/DMS/errors.h b/DMS/errors.h index 5929814..564d31c 100644 --- a/DMS/errors.h +++ b/DMS/errors.h @@ -1,27 +1,29 @@ #pragma once -#include +#include "pch.h" #include "chunk.h" -namespace dms::errors { - enum errortype { - unknown, - string_out_of_bounds, - invalid_arguments, - invalid_type, - array_out_of_bounds, - badtoken, - block_already_defined, - choice_unknown, - nested_function, - disp_unknown, - non_existing_block, - incompatible_version, - non_existing_function - }; - struct error { - errortype code=unknown; - std::string err_msg; - bool crash = true; // Set if you would like the state to exit - size_t linenum = 0; - chunk* current_chunk = nullptr; - }; +namespace dms { + namespace errors { + enum errortype { + unknown, + string_out_of_bounds, + invalid_arguments, + invalid_type, + array_out_of_bounds, + badtoken, + block_already_defined, + choice_unknown, + nested_function, + disp_unknown, + non_existing_block, + incompatible_version, + non_existing_function + }; + struct error { + errortype code = unknown; + std::string err_msg; + bool crash = true; // Set if you would like the state to exit + size_t linenum = 0; + chunk* current_chunk = nullptr; + }; + } } \ No newline at end of file diff --git a/DMS/loadtest.dms b/DMS/loadtest.dms index d17cddc..0d86e8e 100644 --- a/DMS/loadtest.dms +++ b/DMS/loadtest.dms @@ -3,15 +3,6 @@ money = 0 test = nil -[Ryan:char] - age = 21 - money = 1000 - lname = "Ward" - known = true - // Inside a character block this syntax defines animation/image file for an emotion - calm: "./path/to/file" - excited: "./path/to/file" - [step:function(a,b,c)] "Testing..." // testing //d = (100 + b) / c diff --git a/DMS/memory.cpp b/DMS/memory.cpp index d136427..3245885 100644 --- a/DMS/memory.cpp +++ b/DMS/memory.cpp @@ -1,9 +1,13 @@ +#include "pch.h" #include "memory.h" -#include -#include #include "utils.h" namespace dms { value& memory::operator[](std::string str) { + /*if (!mem[str].isNil()) + return mem[str]; + else if (parent != nullptr && parent->count(str)) { + return parent->mem[str]; + }*/ return mem[str]; } std::vector memory::examine(datatypes dt) @@ -23,4 +27,9 @@ namespace dms { void memory::erase(std::string str) { mem.erase(str); } + memory::memory(const memory& other) { + mem = other.mem; + parent = other.parent; + } + memory::memory(){} } \ No newline at end of file diff --git a/DMS/memory.h b/DMS/memory.h index a02c1f1..74b5329 100644 --- a/DMS/memory.h +++ b/DMS/memory.h @@ -1,7 +1,5 @@ #pragma once -#include -#include -#include +#include "pch.h" #include "value.h" namespace dms { struct memory @@ -10,6 +8,9 @@ namespace dms { void erase(std::string); value& operator[](std::string); std::vector examine(datatypes dt); + memory* parent = nullptr; + memory(const memory& other); + memory(); private: std::unordered_map mem; }; diff --git a/DMS/number_utils.cpp b/DMS/number_utils.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/DMS/pch.cpp b/DMS/pch.cpp new file mode 100644 index 0000000..1730571 --- /dev/null +++ b/DMS/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" \ No newline at end of file diff --git a/DMS/pch.h b/DMS/pch.h new file mode 100644 index 0000000..fa1d0cb --- /dev/null +++ b/DMS/pch.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/DMS/s_value.h b/DMS/s_value.h new file mode 100644 index 0000000..8ee0e75 --- /dev/null +++ b/DMS/s_value.h @@ -0,0 +1,31 @@ +#pragma once +extern "C" { + // All structs types in this file will have an s_typename infront of it + // All methods will have an sf_methodname infron of it as well + const char sv_escape = 0x00; + const char sv_nil = 0x01; + const char sv_number = 0x02; + const char sv_int = 0x03; + const char sv_boolean = 0x04; + const char sv_env = 0x05; + const char sv_string = 0x06; + const char sv_custom = 0x07; + const char sv_variable = 0x08; + const char sv_block = 0x09; + const char sv_error = 0x10; + + struct s_value { + char type = sv_nil; // The type of the value + const char* s; // Contains the string part. + long long int i; // The int portion of the code + long double n; + }; + + void sm_value_setEscape(s_value& sv) { sv.type = sv_escape; } // An escape type, used at the end of an array of values. + void sm_value_setInt(s_value& sv, int n) { sv.type = sv_int; sv.i = n; } // Define value as an int + void sm_value_setDouble(s_value& sv, long double d) { sv.type = sv_number; sv.n = d; } // Define value as a double + void sm_value_setString(s_value& sv, const char* str) { sv.type = sv_string; sv.s = str; } // Define value as a string + void sm_value_setBlock(s_value& sv, const char* str) { sv.type = sv_block; sv.s = str; } // Define value as a block + void sm_value_setVariable(s_value& sv, const char* str) { sv.type = sv_variable; sv.s = str; } // Define value as a variable + void sm_value_setNil(s_value& sv) { sv.type = sv_nil; } // Define value as nil +} \ No newline at end of file diff --git a/DMS/sound.cpp b/DMS/sound.cpp new file mode 100644 index 0000000..4f98a77 --- /dev/null +++ b/DMS/sound.cpp @@ -0,0 +1,92 @@ +#include "pch.h" +#include "sound.h" + +//sf::Music music; +//if (!music.openFromFile("test2.ogg")) +//return -1; // error +//music.setPitch(.6); +//music.setLoop(true); +//music.play(); + +namespace dms::audio { + value play(void* self, dms_state* state, dms_args* args) { + // Self, since it is a custom object will be equal to whatever we declared to the c pointer! + sf::Music* music = (sf::Music*)self; + music->play(); + return value(); + } + value pause(void* self, dms_state* state, dms_args* args) { + sf::Music* music = (sf::Music*)self; + music->pause(); + return value(); + } + value stop(void* self, dms_state* state, dms_args* args) { + sf::Music* music = (sf::Music*)self; + music->stop(); + return value(); + } + value setLoop(void* self, dms_state* state, dms_args* args) { + if (args->size() || args->args[0].resolve(state).type == datatypes::boolean) { + sf::Music* music = (sf::Music*)self; + music->setLoop(args->args[0].resolve(state).b); + return NULL; + } + } + value setPitch(void* self, dms_state* state, dms_args* args) { + if (args->size() || args->args[0].resolve(state).isNum()) { + sf::Music* music = (sf::Music*)self; + music->setPitch(args->args[0].resolve(state).getDouble()); + return NULL; + } + } + value setVolume(void* self, dms_state* state, dms_args* args) { + if (args->size() || args->args[0].resolve(state).isNum()) { + sf::Music* music = (sf::Music*)self; + music->setVolume(args->args[0].resolve(state).getDouble()); + return NULL; + } + } + value getStatus(void* self, dms_state* state, dms_args* args) { + sf::Music* music = (sf::Music*)self; + if (music->getStatus() == sf::Music::Status::Paused) { + return "paused"; + } + else if (music->getStatus() == sf::Music::Status::Playing) { + return "playing"; + } + else { + return "stopped"; + } + } + // The customtype will be "sound" + // We need to assoiate the sound type with an invoker so the interperter knows how to handle it + + Invoker* inv = new Invoker; + + void init(dms_state* state) { + inv->registerFunction("play",play); + inv->registerFunction("resume",play); + inv->registerFunction("pause", pause); + inv->registerFunction("stop", stop); + inv->registerFunction("setLoop",setLoop); + inv->registerFunction("setPitch", setPitch); + inv->registerFunction("setVolume", setVolume); + inv->registerFunction("getStatus", getStatus); + + state->assoiateType("audiostream",inv); + state->invoker.registerFunction("loadMusic", loadMusic); + } + + value loadMusic(void* self, dms_state* state, dms_args* args) + { + if (args->size() || args->args[0].resolve(state).type == datatypes::string) { + + sf::Music* music = new sf::Music; + if (!music->openFromFile(args->args[0].s)) { + return value("Cannot open audio stream!", datatypes::error); + } + return value(music, "audiostream"); + } + return value("First argument must be a string!",datatypes::error); + } +} \ No newline at end of file diff --git a/DMS/sound.h b/DMS/sound.h new file mode 100644 index 0000000..ab9c75f --- /dev/null +++ b/DMS/sound.h @@ -0,0 +1,9 @@ +#pragma once +#include "pch.h" +#include +#include "dms_state.h" +namespace dms::audio { + void init(dms_state*); + value loadMusic(void*, dms_state*, dms_args*); + // I want to do more with this, like effects and stuff. For now only simple things are implemented +} \ No newline at end of file diff --git a/DMS/test.dms b/DMS/test.dms index e38b898..1553cdc 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -4,30 +4,85 @@ disable omniscient disable fullname enable forwardlabels // Do most of your labels exist ahead? enable savestate +//loadfile "Ryan.dms" //enable leaking //enable debugging //loadfile "loadtest.dms" version 0.2 using extendedDefine +// this code will reside within +music = loadMusic("test2.ogg") +music2 = loadMusic("test.ogg") [main] - Ryan: "Hello Mr. " + Bob["lname"] + "! How are you doing?" - Bob.setName("Rob") - Ryan: "Hello " + Bob + "! How are you doing?" - //io.print(test 122 + 7) - - // Ryan: "I am good" - // John: "Hi " + Ryan + " how are you?" - // sqrt 144 + 10 - // speed + a = 10 + tester() + print("a = " + a) + // music.setPitch(.7) + // print(music.getStatus()) + // music.play() + // print(music.getStatus()) + // print("Type: " + type(music2)) + // while(music.getStatus()!="stopped"){ + // wait 1 + // } + // print("Done") + // a = 0 + // while (true){ + // asm { + // add %a %a 1 + // add %p "a = " %a + // func %print nil %p + // } + // a = a + 1 + // print("a = " + a) + // } + // while(true){ + // song = SelectSong() + // player(song) + // } -[test:function(n)] - return n + 1 +[tester:function()] + print(a) + +[SelectSong:function()] + choice "Pick song:" { + "Music 1" { + return music + } + "Music 2" { + return music2 + } + } + +[player:function(song)] + choice "What you wanna do?" { + "play/resume" { + song.play() + player(song) + } + "pause" { + song.pause() + player(song) + } + "stop" { + song.stop() + player(song) + } + "newSong" { + song.stop() + player(song) + } + "quit" exit 0 + } [Ryan:char] + age = 21 + money = 1000 lname = "Ward" - age = 24 known = true - money = 0 + // Inside a character block this syntax defines animation/image file for an emotion + calm: "./path/to/file" + excited: "./path/to/file" [John:char] lname = "Johnson" diff --git a/DMS/test.ogg b/DMS/test.ogg new file mode 100644 index 0000000..430d946 Binary files /dev/null and b/DMS/test.ogg differ diff --git a/DMS/test2.ogg b/DMS/test2.ogg new file mode 100644 index 0000000..bddd6f1 Binary files /dev/null and b/DMS/test2.ogg differ diff --git a/DMS/token.h b/DMS/token.h index e39c60f..f62a3e7 100644 --- a/DMS/token.h +++ b/DMS/token.h @@ -1,136 +1,138 @@ #pragma once -#include +#include "pch.h" #include "codes.h" #include "utils.h" -namespace dms::tokens { - enum tokentype { - none, - noop, - flag, - name, - number, - string, - parao, - parac, - bracketo, - bracketc, - seperator, - dot, - cbracketo, - cbracketc, - plus, - minus, - multiply, - divide, - caret, - percent, - equal, - colon, - control, - True, - False, - Or, - And, - exclamation, - For, - label, - newline, - tab, - eof, - ret, - gotoo, - jump, - exit, - debug, - tilde, - backtick, - at, - pound, - dollar, - ampersand, - nil, - pipe, - anglebracketO, - anglebracketC, - escape, - };//stream, t_vec, line, isNum, buffer - struct token { - tokentype type = noop; - codes::op raw = codes::op::NOOP; - std::string name=""; - size_t line_num=0; - void build(tokentype tt, codes::op o) { - type = tt; - raw = o; - } - void build(tokentype tt, std::string s) { - type = tt; - name = s; - } - void build(tokentype tt, codes::op o, std::string s) { - type = tt; - raw = o; - name = s; - } - std::string toString() { - std::stringstream str; - str << name; - return str.str(); - } - friend std::ostream& operator << (std::ostream& out, const token& c) { - const std::string tokenlist[] = { - "none", - "noop", - "flag", - "name", - "number", - "string", - "parao", - "parac", - "bracketo", - "bracketc", - "seperator", - "dot", - "cbracketo", - "cbracketc", - "plus", - "minus", - "multiply", - "divide", - "pow", - "mod", - "equal", - "colon", - "control", - "true", - "false", - "or", - "and", - "not", - "for", - "label", - "newline", - "tab", - "eof", - "ret", - "gotoo", - "jump", - "exit", - "debug", - "tilde", - "backtick", - "at", - "pound", - "dollar", - "ampersand", - "nil", - "pipe", - "anglebracketO", - "anglebracketC", - "escape" - }; - out << "Line <" << c.line_num << "> " << tokenlist[c.type] << " \t\t " << c.name; - return out; - } - }; +namespace dms { + namespace tokens { + enum tokentype { + none, + noop, + flag, + name, + number, + string, + parao, + parac, + bracketo, + bracketc, + seperator, + dot, + cbracketo, + cbracketc, + plus, + minus, + multiply, + divide, + caret, + percent, + equal, + colon, + control, + True, + False, + Or, + And, + exclamation, + For, + label, + newline, + tab, + eof, + ret, + gotoo, + jump, + exit, + debug, + tilde, + backtick, + at, + pound, + dollar, + ampersand, + nil, + pipe, + anglebracketO, + anglebracketC, + escape, + };//stream, t_vec, line, isNum, buffer + struct token { + tokentype type = noop; + codes::op raw = codes::op::NOOP; + std::string name = ""; + size_t line_num = 0; + void build(tokentype tt, codes::op o) { + type = tt; + raw = o; + } + void build(tokentype tt, std::string s) { + type = tt; + name = s; + } + void build(tokentype tt, codes::op o, std::string s) { + type = tt; + raw = o; + name = s; + } + std::string toString() { + std::stringstream str; + str << name; + return str.str(); + } + friend std::ostream& operator << (std::ostream& out, const token& c) { + const std::string tokenlist[] = { + "none", + "noop", + "flag", + "name", + "number", + "string", + "parao", + "parac", + "bracketo", + "bracketc", + "seperator", + "dot", + "cbracketo", + "cbracketc", + "plus", + "minus", + "multiply", + "divide", + "pow", + "mod", + "equal", + "colon", + "control", + "true", + "false", + "or", + "and", + "not", + "for", + "label", + "newline", + "tab", + "eof", + "ret", + "gotoo", + "jump", + "exit", + "debug", + "tilde", + "backtick", + "at", + "pound", + "dollar", + "ampersand", + "nil", + "pipe", + "anglebracketO", + "anglebracketC", + "escape" + }; + out << "Line <" << c.line_num << "> " << tokenlist[c.type] << " \t\t " << c.name; + return out; + } + }; + } } \ No newline at end of file diff --git a/DMS/utils.cpp b/DMS/utils.cpp index 43b871d..19d5fea 100644 --- a/DMS/utils.cpp +++ b/DMS/utils.cpp @@ -1,8 +1,23 @@ +#include "pch.h" #include "utils.h" namespace dms::utils { void print(const value val) { printf(val.getPrintable().c_str()); } + std::vector split(const std::string& str, const std::string& delim) + { + std::vector tokens; + size_t prev = 0, pos = 0; + do + { + pos = str.find(delim, prev); + if (pos == std::string::npos) pos = str.length(); + std::string token = str.substr(prev, pos - prev); + if (!token.empty()) tokens.push_back(token); + prev = pos + delim.length(); + } while (pos < str.length() && prev < str.length()); + return tokens; + } std::string concat(value& v1, value& v2, value& v3, value& v4, value& v5, value& v7, value& v8, value& v9, value& v10, value& v11, value& v12) { std::vector list{v1,v2,v3,v4,v5,v7,v8,v9,v10,v11,v12}; std::string str=""; diff --git a/DMS/utils.h b/DMS/utils.h index 72458b9..084f8de 100644 --- a/DMS/utils.h +++ b/DMS/utils.h @@ -1,39 +1,36 @@ #pragma once -#include -#include -#include -#include -#include +#include "pch.h" #include "value.h" -#include #include "dms_state.h" -#include -namespace dms::utils { - template - void debug(const Args... args) { - (std::cout << ... << args) << std::endl; +namespace dms { + namespace utils { + template + void debug(const Args... args) { + (std::cout << ... << args) << std::endl; + } + template + void write(const Args... args) { + (std::cout << ... << args); + } + void print(const value values...); + template + std::string concat(Args... args) { + std::stringstream str; + (str << ... << args); + return str.str(); + } + std::vector split(const std::string& str, const std::string& delim); + void sleep(unsigned int mseconds); + std::string random_string(size_t length); + bool typeassert(dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code! + bool typeassert(dms_state* state, dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); + bool valueassert(dms_args args, dms_state* state, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); + bool valueassertall(dms_args args, dms_state* state, datatypes t1); + std::string resolveTypes(datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); + bool isalphanum(std::string str); + bool isalpha(std::string str); + bool isNum(std::string str); + void trim(std::string& s); + void wait(); } - template - void write(const Args... args) { - (std::cout << ... << args); - } - void print(const value values...); - template - std::string concat(Args... args) { - std::stringstream str; - (str << ... << args); - return str.str(); - } - void sleep(unsigned int mseconds); - std::string random_string(size_t length); - bool typeassert(dms_args args, datatypes t1=nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code! - bool typeassert(dms_state* state, dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); - bool valueassert(dms_args args, dms_state* state, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); - bool valueassertall(dms_args args, dms_state* state, datatypes t1); - std::string resolveTypes(datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); - bool isalphanum(std::string str); - bool isalpha(std::string str); - bool isNum(std::string str); - void trim(std::string& s); - void wait(); } \ No newline at end of file diff --git a/DMS/value.cpp b/DMS/value.cpp index acf524b..4d32d3f 100644 --- a/DMS/value.cpp +++ b/DMS/value.cpp @@ -1,3 +1,4 @@ +#include "pch.h" #include "value.h" #include "dms_state.h" #include "utils.h" @@ -6,6 +7,12 @@ namespace dms { value::value() { // Nothing to do here! } + value::value(void* cdata, std::string t) + { + type = datatypes::custom; + c = cdata; + ctype = t; + } value::value(char const* str, datatypes t) { type = t; s = str; @@ -65,6 +72,8 @@ namespace dms { break; case datatypes::custom: // Handle this later + c = other.c; + ctype = other.ctype; break; case datatypes::env: // Handle this later @@ -107,7 +116,8 @@ namespace dms { b = other.b; break; case datatypes::custom: - // Handle this later + c = other.c; + ctype = other.ctype; break; case datatypes::env: // Handle this later @@ -156,7 +166,8 @@ namespace dms { b = other.b; break; case datatypes::custom: - // Handle this later + c = other.c; + ctype = other.ctype; break; case datatypes::env: // Handle this later @@ -357,7 +368,13 @@ namespace dms { return resolve(state); } void dms_args::push(value val) { - args.push_back(val); + args.emplace_back(val); + } + dms_args::dms_args(int n) { + args.reserve(n); + } + dms_args::dms_args() { + args.reserve(5); } size_t dms_args::size() { return args.size(); @@ -415,12 +432,28 @@ namespace dms { std::string value::toString() const { return getPrintable(); } + double value::getDouble() const + { + if (type == datatypes::int64) + return (double)i; + else if (type == datatypes::number) + return n; + else + return nan(""); + } + int64_t value::getInt() const + { + if (type == datatypes::int64) + return i; + else if (type == datatypes::number) + return (int64_t)n; + else + return INT_MIN; + } // Compile time void value::nuke() { delete e; - delete c; e = nullptr; - c = nullptr; } std::ostream& operator << (std::ostream& out, const value& c) { if (c.type == string) { @@ -491,10 +524,9 @@ namespace dms { e = en; type = env; } - void dms::value::set(dms_custom* cus) { + void dms::value::set(void* cus) { nuke(); c = cus; - c->_set(this); type = custom; } void value::set() { diff --git a/DMS/value.h b/DMS/value.h index 25c3172..6c0cb4b 100644 --- a/DMS/value.h +++ b/DMS/value.h @@ -1,9 +1,5 @@ #pragma once -#include -#include -#include -#include -#include +#include "pch.h" namespace dms { struct dms_list; @@ -41,9 +37,11 @@ namespace dms { int64_t i=0; std::string s; dms_list* e = nullptr; - dms_custom* c = nullptr; + void* c = nullptr; // A custom link to void data. Must be void* for compatiablity with c-API + std::string ctype; // The type of the custom data dms_state* state = nullptr; value(); + value(void* cdata,std::string t); value(datatypes); value(char const*,datatypes); value(std::string, datatypes); @@ -79,15 +77,19 @@ namespace dms { void set(bool bo); void set(double num); void set(dms_list* en); - void set(dms_custom* cus); + void set(void* cus); void set(); bool typeMatch(const value* o) const; std::string getPrintable() const; std::string toString() const; + double getDouble() const; + int64_t getInt() const; friend std::ostream& operator << (std::ostream& out, const value& c); }; struct dms_args { + dms_args(int n); + dms_args(); std::vector args; void push(value val); size_t size(); diff --git a/DMS/wrapper.h b/DMS/wrapper.h index 879b194..9640526 100644 --- a/DMS/wrapper.h +++ b/DMS/wrapper.h @@ -1,23 +1,3 @@ #pragma once #include "enviroment.h" // This file converts the c++ objects into a form that c is happy with -extern "C" { - using namespace dms; - // All structs types in this file will have an s_typename infront of it - // All methods will have an sf_methodname infron of it as well - struct s_value { - datatypes type = nil; // The type of the value - const char* s; // Contains the string part. - uint64_t i; // The int portion of the code - double n; - }; - void s_value_setInt(s_value& sv, int n) { sv.type = int64; sv.i = n; } // Define value as an int - void s_value_setDouble(s_value& sv, double d) { sv.type = number; sv.n = d; } // Define value as a double - void s_value_setString(s_value& sv, const char* str) { sv.type = string; sv.s = str; } // Define value as a string - void s_value_setBlock(s_value& sv, const char* str) { sv.type = block; sv.s = str; } // Define value as a block - void s_value_setVariable(s_value& sv, const char* str) { sv.type = variable; sv.s = str; } // Define value as a variable - void s_value_setNil(s_value& sv) { sv.type = nil; } // Define value as nil - struct s_enviroment { - - }; -} \ No newline at end of file