diff --git a/DMS/DMS.cpp b/DMS/DMS.cpp index df5b934..32845ea 100644 --- a/DMS/DMS.cpp +++ b/DMS/DMS.cpp @@ -46,10 +46,11 @@ int main() enviroment* envio = new enviroment; LineParser parser = LineParser("test.dms"); dms_state* state = parser.Parse(); + state->dump(); envio->registerFunction("print", print); state->invoker.registerFunction("print", print); state->injectEnv("io",envio); - state->dump(); + state->run(); diff --git a/DMS/LineParser.h b/DMS/LineParser.h index dc7b13a..5395482 100644 --- a/DMS/LineParser.h +++ b/DMS/LineParser.h @@ -93,6 +93,7 @@ namespace dms { bool match_process_for(tokenstream* stream); bool match_process_number(tokenstream* stream, value& v); bool match_process_asm(tokenstream* stream); + bool match_process_1afunc(tokenstream* stream, value& v); // Build void buildGoto(std::string g, bool v = false); diff --git a/DMS/LineParserMatchProcess.cpp b/DMS/LineParserMatchProcess.cpp index a1cb41a..c422570 100644 --- a/DMS/LineParserMatchProcess.cpp +++ b/DMS/LineParserMatchProcess.cpp @@ -73,6 +73,10 @@ namespace dms { } return true; } + if (match_process_1afunc(stream, v)) { + match_process_condition(stream, v); + return true; + } if (match_process_expression(stream, v)) { match_process_condition(stream,v); return true; @@ -330,8 +334,46 @@ namespace dms { } return false; } + bool LineParser::match_process_1afunc(tokenstream* stream, value& v ) { + if (stream->match(tokens::name,tokens::string) || stream->match(tokens::name,tokens::number) || stream->match(tokens::name,tokens::minus)) { + cmd* c = new cmd; + c->opcode = codes::FUNC; + c->args.push(value(stream->next().name,variable)); + c->args.push(v); + value num; + if (stream->match(tokens::string)) { + c->args.push(value(stream->next().name)); + } else if (match_process_number(stream,num)) { + c->args.push(num); + } + current_chunk->addCmd(c); + return true; + } + return false; + } bool LineParser::match_process_disp(tokenstream* stream) { - if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) { + if (stream->match(tokens::name,tokens::colon)) { + std::string name = stream->next().name; + stream->next(); + cmd* c = new cmd; + 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 }); + } + else { + badSymbol(stream); + return false; + } + return true; + } + else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) { stream->next(); // Standard consumption cmd* c = new cmd; c->opcode = codes::DISP; @@ -874,6 +916,8 @@ namespace dms { c->args.push(v); c->args.push(value(name,datatypes::block)); c->args.push(tempval); + current_chunk->addCmd(c); + return true; } else if (nlcount) { state->push_error(errors::error{ errors::badtoken,concat("Unexpected symbol '",tempstream.last().toString(),"' Expected ']' to close list (line: ",tempstream.last().line_num,") Indexing must be done on one line?"),true,tempstream.last().line_num,current_chunk }); @@ -888,9 +932,6 @@ namespace dms { return false; } } - - current_chunk->addCmd(c); - return true; } return false; } @@ -1171,8 +1212,6 @@ namespace dms { o = codes::CHOI; else if (cmd == "blck") o = codes::BLCK; - else if (cmd == "fore") - o = codes::FORE; else if (cmd == "whle") o = codes::WHLE; else if (cmd == "func") @@ -1578,6 +1617,19 @@ namespace dms { return false; } } + else if (stream->match(tokens::name, tokens::bracketo)) { + value tmpvalue = value(datatypes::variable); + if (match_process_index(stream, tmpvalue)) { + if (left.isNil()) + left = tmpvalue; + else if (right.isNil()) + right = tmpvalue; + else { + badSymbol(stream); + return false; + } + } + } 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! if (left.isNil()) diff --git a/DMS/LineParserParse.cpp b/DMS/LineParserParse.cpp index 10846df..30c2a6a 100644 --- a/DMS/LineParserParse.cpp +++ b/DMS/LineParserParse.cpp @@ -519,6 +519,7 @@ namespace dms { manageCount(match_process_wait(stream), count, current_count); //utils::print("[jump]"); manageCount(match_process_jump(stream), count, current_count); + manageCount(match_process_1afunc(stream, nil),count,current_count); manageCount(match_process_asm(stream), count, current_count); if (count != 0 && current_count == count) { return true; // We got what we came for, we exit and consume no more! diff --git a/DMS/character.cpp b/DMS/character.cpp index ac87602..bc1c214 100644 --- a/DMS/character.cpp +++ b/DMS/character.cpp @@ -2,7 +2,7 @@ #include "utils.h" namespace dms { value character_setName(void* self, dms_state* state, dms_args* args) { - if(utils::typeassert(*args, datatypes::string)) { + if(args->args[0].type == datatypes::string){ character* me = (character*)self; me->set("fname", args->args[0]); } diff --git a/DMS/codes.cpp b/DMS/codes.cpp index 57ce06d..6d1fe32 100644 --- a/DMS/codes.cpp +++ b/DMS/codes.cpp @@ -14,7 +14,7 @@ const std::string dms::codes::list[] = { "LABL", "CHOI", "BLCK", - "FORE", + "CHAR", "WHLE", "FUNC", "IFFF", diff --git a/DMS/codes.h b/DMS/codes.h index b4ef9c4..45152d6 100644 --- a/DMS/codes.h +++ b/DMS/codes.h @@ -15,8 +15,8 @@ namespace dms::codes { ASGN, // Done LABL, // Done CHOI, // Done - BLCK, - FORE, + BLCK, // + CHAR, // Done WHLE, FUNC, // Done IFFF, // Done diff --git a/DMS/dms_state.cpp b/DMS/dms_state.cpp index 7164d13..c9aa62a 100644 --- a/DMS/dms_state.cpp +++ b/DMS/dms_state.cpp @@ -43,6 +43,12 @@ namespace dms { c->args.push(value(key, datatypes::variable)); c->args.push(value(key, datatypes::block)); chunks["$INIT"]->addCmd(c); + if (val->type == bt_character) { + c = new cmd; + c->opcode = codes::CHAR; + c->args.push(value(key)); + chunks["$INIT"]->addCmd(c); + } c = new cmd; } else if (val->type == bt_method) { @@ -141,7 +147,7 @@ namespace dms { bool dms_state::injectEnv(std::string name, enviroment* env) { - std::string ename = std::string("$ENV_") + name; + std::string ename = name; assign(value(name, datatypes::variable), value(ename, datatypes::block)); environments.insert_or_assign(ename, env); chunk* c = new chunk; @@ -160,8 +166,8 @@ namespace dms { push_error(errors::error{ errors::unknown ,val.s }); return false; } - if(val.state==nullptr) - val.state = this; + val.state = this; + var.state = this; (*getMem())[var.getPrintable()] = val; return true; } diff --git a/DMS/dms_state_interpret.cpp b/DMS/dms_state_interpret.cpp index f5c7dfe..8b89985 100644 --- a/DMS/dms_state_interpret.cpp +++ b/DMS/dms_state_interpret.cpp @@ -254,7 +254,7 @@ namespace dms { break; case OFUN: { - std::string obj = c->args.args[0].resolve(this).getPrintable(); + std::string obj = c->args.args[0].getPrintable(); if (obj=="nil") { obj = c->args.args[0].getPrintable(); } @@ -410,13 +410,13 @@ namespace dms { value assn = c->args.args[0]; value env = c->args.args[1]; value indx = c->args.args[2].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]; } if(!assign( assn, e->values[indx.getPrintable()])) { return false; @@ -540,15 +540,18 @@ namespace dms { } break; case APND: - //FIX STRING STER - if (!handler->handleMessageAppend(this, c->args.args[0].s)) + if (!handler->handleMessageAppend(this, c->args.args[0].resolve(this).getPrintable())) return false; break; + case CHAR: + { + std::string cha = c->args.args[0].s; + getCharacter(cha); + break; + } case DISP: { - //FIX STRING STER - value disp = c->args.args[0].resolve(this).getPrintable(); - if (!handler->handleMessageDisplay(this, c->args.args[0].s)) + if (!handler->handleMessageDisplay(this, c->args.args[0].resolve(this).getPrintable())) return false; } break; diff --git a/DMS/dump.bin b/DMS/dump.bin index 1c3a6e8..8a92921 100644 Binary files a/DMS/dump.bin and b/DMS/dump.bin differ diff --git a/DMS/dump.txt b/DMS/dump.txt index 111713f..42f9823 100644 --- a/DMS/dump.txt +++ b/DMS/dump.txt @@ -21,9 +21,6 @@ Line <6> name savestate Line <6> newline Line <6> newline Line <7> newline -Line <8> flag -Line <8> name debugging -Line <8> newline Line <8> newline Line <9> newline Line <10> flag @@ -41,110 +38,149 @@ Line <12> newline Line <12> newline Line <13> name Ryan Line <13> colon : -Line <13> string I am good +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 John -Line <14> colon : -Line <14> string Hi -Line <14> plus + -Line <14> name Ryan -Line <14> plus + -Line <14> string how are you? +Line <14> name Bob +Line <14> dot . +Line <14> name setName +Line <14> parao ( +Line <14> string Rob +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> newline Line <15> newline Line <16> newline -Line <16> newline Line <17> newline Line <17> newline -Line <18> bracketo [ -Line <18> name John -Line <18> colon : -Line <18> name char -Line <18> bracketc ] Line <18> newline -Line <18> newline -Line <19> name lname -Line <19> equal = -Line <19> string Johnson Line <19> newline -Line <19> newline -Line <20> name age -Line <20> equal = -Line <20> number 16 Line <20> newline -Line <20> newline -Line <21> name money -Line <21> equal = -Line <21> number 100000 Line <21> newline -Line <21> newline -Line <22> name known -Line <22> equal = -Line <22> true true 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> bracketo [ -Line <24> name Ryan -Line <24> colon : -Line <24> name char -Line <24> bracketc ] +Line <24> ret +Line <24> name n +Line <24> plus + +Line <24> number 1 Line <24> newline Line <24> newline -Line <25> name lname -Line <25> equal = -Line <25> string Ward Line <25> newline Line <25> newline -Line <26> name age -Line <26> equal = -Line <26> number 24 +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 known +Line <27> name lname Line <27> equal = -Line <27> true true +Line <27> string Ward Line <27> newline Line <27> newline -Line <28> name money +Line <28> name age Line <28> equal = -Line <28> number 0 +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> bracketo [ -Line <30> name Bob -Line <30> colon : -Line <30> name char -Line <30> bracketc ] +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 <34> name unknown +Line <33> newline +Line <34> name age Line <34> equal = -Line <34> string Some Random Guy +Line <34> number 16 Line <34> newline Line <34> newline -Line <35> name age +Line <35> name money Line <35> equal = -Line <35> number 24 +Line <35> number 100000 Line <35> newline Line <35> newline -Line <36> name money +Line <36> name known Line <36> equal = -Line <36> number 100 +Line <36> true true Line <36> newline Line <36> newline -Line <37> name excited -Line <37> colon : -Line <37> string path/to/file Line <37> newline Line <37> newline -Line <37> eof +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> newline +Line <44> newline +Line <45> name excited +Line <45> colon : +Line <45> string path/to/file +Line <45> newline +Line <45> newline +Line <45> eof diff --git a/DMS/test.dms b/DMS/test.dms index 420f60a..e38b898 100644 --- a/DMS/test.dms +++ b/DMS/test.dms @@ -1,25 +1,27 @@ entry main // Will either start the first block seen or the block supplied by you! //enable warnings disable omniscient -enable fullname +disable fullname enable forwardlabels // Do most of your labels exist ahead? enable savestate //enable leaking -enable debugging +//enable debugging //loadfile "loadtest.dms" version 0.2 using extendedDefine [main] - Ryan: "I am good" - John: "Hi " + Ryan + " how are you?" + 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 - -[John:char] - lname = "Johnson" - age = 16 - money = 100000 - known = true +[test:function(n)] + return n + 1 [Ryan:char] lname = "Ward" @@ -27,10 +29,16 @@ using extendedDefine known = true money = 0 +[John:char] + lname = "Johnson" + age = 16 + money = 100000 + known = true + [Bob:char] //fname = "Bob" //known = true // defaults to false - //lname = "Johnson" // defaults to "" + lname = "Johnson" // defaults to "" unknown = "Some Random Guy" age = 24 money = 100 diff --git a/DMS/value.cpp b/DMS/value.cpp index 4bc3092..acf524b 100644 --- a/DMS/value.cpp +++ b/DMS/value.cpp @@ -55,6 +55,7 @@ namespace dms { value::value(const value& other) { if (this != &other) { type = other.type; + state = other.state; switch (other.type) { case datatypes::block: s = other.s; @@ -97,6 +98,7 @@ namespace dms { if (this != &other) { nuke(); // Delete it all type = other.type; + state = other.state; switch (other.type) { case datatypes::block: s = other.s; @@ -145,6 +147,7 @@ namespace dms { if (this != &other) { nuke(); type = other.type; + state = other.state; switch (other.type) { case datatypes::block: s = other.s; @@ -344,9 +347,9 @@ namespace dms { } return false; } - value value::resolve(dms_state* state) { - if (type == datatypes::variable && (*this)!=(*state->getMem())[getPrintable()]) { - return (*state->getMem())[getPrintable()].resolve(state); + value value::resolve(dms_state* _state) { + if (type == datatypes::variable && (*this)!=(*_state->getMem())[s]) { + return (*_state->getMem())[s].resolve(_state); } return *this; }