diff --git a/DMS/DMS.vcxproj b/DMS/DMS.vcxproj
index 3e89888..ecd5f34 100644
--- a/DMS/DMS.vcxproj
+++ b/DMS/DMS.vcxproj
@@ -147,6 +147,7 @@
+
diff --git a/DMS/DMS.vcxproj.filters b/DMS/DMS.vcxproj.filters
index 77fbc07..9fa0696 100644
--- a/DMS/DMS.vcxproj.filters
+++ b/DMS/DMS.vcxproj.filters
@@ -63,6 +63,9 @@
Source Files\DMS
+
+ Source Files\DMS
+
diff --git a/DMS/Debug/DMS.log b/DMS/Debug/DMS.log
index d1bfc24..e51610b 100644
--- a/DMS/Debug/DMS.log
+++ b/DMS/Debug/DMS.log
@@ -1,3 +1,21 @@
- LineParserMatchProcess.cpp
-F:\VSCWorkspace\DMS\DMS\LineParserMatchProcess.cpp(803): warning C4715: 'dms::LineParser::match_process_expression': not all control paths return a value
+ DMS.cpp
+ dms_state.cpp
+ dms_state_interpret.cpp
+ LineParserBuilds.cpp
+ LineParserMatchProcess.cpp
+ LineParserParse.cpp
+ string_utils.cpp
+F:\VSCWorkspace\DMS\DMS\string_utils.cpp(9,45): warning C4244: 'initializing': conversion from 'double' to 'unsigned int', possible loss of data
+F:\VSCWorkspace\DMS\DMS\string_utils.cpp(36,17): warning C4244: 'initializing': conversion from 'double' to 'size_t', possible loss of data
+F:\VSCWorkspace\DMS\DMS\string_utils.cpp(37,16): warning C4244: 'initializing': conversion from 'double' to 'size_t', possible loss of data
+F:\VSCWorkspace\DMS\DMS\string_utils.cpp(93,22): warning C4018: '<': signed/unsigned mismatch
+F:\VSCWorkspace\DMS\DMS\string_utils.cpp(134,22): warning C4018: '<': signed/unsigned mismatch
+F:\VSCWorkspace\DMS\DMS\string_utils.cpp(135,25): warning C4018: '<': signed/unsigned mismatch
+ LineParserUtils.cpp
+ number_utils.cpp
+F:\VSCWorkspace\DMS\DMS\number_utils.cpp(21,21): warning C4018: '<': signed/unsigned mismatch
+ utils.cpp
+ value.cpp
+ Generating Code...
+F:\VSCWorkspace\DMS\DMS\LineParserMatchProcess.cpp(773): warning C4715: 'dms::LineParser::match_process_expression': not all control paths return a value
DMS.vcxproj -> F:\VSCWorkspace\DMS\Debug\DMS.exe
diff --git a/DMS/Debug/DMS.obj b/DMS/Debug/DMS.obj
index 9be45ad..4dbb9f8 100644
Binary files a/DMS/Debug/DMS.obj and b/DMS/Debug/DMS.obj differ
diff --git a/DMS/Debug/DMS.tlog/CL.command.1.tlog b/DMS/Debug/DMS.tlog/CL.command.1.tlog
index b382e40..a716d14 100644
Binary files a/DMS/Debug/DMS.tlog/CL.command.1.tlog and b/DMS/Debug/DMS.tlog/CL.command.1.tlog differ
diff --git a/DMS/Debug/DMS.tlog/CL.read.1.tlog b/DMS/Debug/DMS.tlog/CL.read.1.tlog
index c8a12bd..50a43da 100644
Binary files a/DMS/Debug/DMS.tlog/CL.read.1.tlog and b/DMS/Debug/DMS.tlog/CL.read.1.tlog differ
diff --git a/DMS/Debug/DMS.tlog/CL.write.1.tlog b/DMS/Debug/DMS.tlog/CL.write.1.tlog
index 3aefb09..3e047c0 100644
Binary files a/DMS/Debug/DMS.tlog/CL.write.1.tlog and b/DMS/Debug/DMS.tlog/CL.write.1.tlog differ
diff --git a/DMS/Debug/DMS.tlog/link.command.1.tlog b/DMS/Debug/DMS.tlog/link.command.1.tlog
index 7c5dc1f..1a07c58 100644
Binary files a/DMS/Debug/DMS.tlog/link.command.1.tlog and b/DMS/Debug/DMS.tlog/link.command.1.tlog differ
diff --git a/DMS/Debug/DMS.tlog/link.read.1.tlog b/DMS/Debug/DMS.tlog/link.read.1.tlog
index 28ae491..0f501b7 100644
Binary files a/DMS/Debug/DMS.tlog/link.read.1.tlog and b/DMS/Debug/DMS.tlog/link.read.1.tlog differ
diff --git a/DMS/Debug/DMS.tlog/link.write.1.tlog b/DMS/Debug/DMS.tlog/link.write.1.tlog
index 20782c6..c5e2b02 100644
Binary files a/DMS/Debug/DMS.tlog/link.write.1.tlog and b/DMS/Debug/DMS.tlog/link.write.1.tlog differ
diff --git a/DMS/Debug/cmd.obj b/DMS/Debug/cmd.obj
index b108d4f..52b893a 100644
Binary files a/DMS/Debug/cmd.obj and b/DMS/Debug/cmd.obj differ
diff --git a/DMS/Debug/codes.obj b/DMS/Debug/codes.obj
index f4f07d6..2608965 100644
Binary files a/DMS/Debug/codes.obj and b/DMS/Debug/codes.obj differ
diff --git a/DMS/Debug/number_utils.obj b/DMS/Debug/number_utils.obj
index 7204779..211d4d6 100644
Binary files a/DMS/Debug/number_utils.obj and b/DMS/Debug/number_utils.obj differ
diff --git a/DMS/Debug/utils.obj b/DMS/Debug/utils.obj
index b1353af..df07d91 100644
Binary files a/DMS/Debug/utils.obj and b/DMS/Debug/utils.obj differ
diff --git a/DMS/Debug/value.obj b/DMS/Debug/value.obj
index 7326999..cc9429d 100644
Binary files a/DMS/Debug/value.obj and b/DMS/Debug/value.obj differ
diff --git a/DMS/Debug/vc142.idb b/DMS/Debug/vc142.idb
index 8c6185f..d7a7dd4 100644
Binary files a/DMS/Debug/vc142.idb and b/DMS/Debug/vc142.idb differ
diff --git a/DMS/Debug/vc142.pdb b/DMS/Debug/vc142.pdb
index adab8cb..f5afd00 100644
Binary files a/DMS/Debug/vc142.pdb and b/DMS/Debug/vc142.pdb differ
diff --git a/DMS/LineParserMatchProcess.cpp b/DMS/LineParserMatchProcess.cpp
index 78c105e..0b214b1 100644
--- a/DMS/LineParserMatchProcess.cpp
+++ b/DMS/LineParserMatchProcess.cpp
@@ -1,13 +1,14 @@
#include "LineParser.h"
using namespace dms::tokens;
using namespace dms::utils;
+// TODO: process if elseif else statements, for loops and while loops
namespace dms {
bool LineParser::match_process_standard(tokenstream* stream, value* v) {
if (match_process_expression(stream,v)) {
- return true; // Nothing todo
+ return true;
}
else if (match_process_function(stream, v)) {
- return true; // Nothing todo
+ return true;
}
else if (match_process_list(stream, v)) {
return true;
@@ -56,51 +57,66 @@ namespace dms {
bool LineParser::match_process_list(tokenstream* stream, value* v) {
if (stream->match(tokens::cbracketo)) {
token start = stream->peek();
+ token ancor = start;
std::vector t = stream->next(tokens::cbracketo, tokens::cbracketc);
tokenstream tempstream;
tempstream.init(&t);
value* ref = buildVariable();
value* length = new value;
+ value* dict = nullptr;
size_t count = 0;
cmd* c = new cmd;
c->opcode = codes::LIST;
c->args.push(v);
c->args.push(length);
current_chunk->addCmd(c);
+ bool ready = true;
while (tempstream.peek().type != tokens::none) {
- print(tempstream.peek());
if (tempstream.match(tokens::cbracketc)) {
+ ready = true;
c = new cmd;
c->opcode = codes::INST;
c->args.push(v);
c->args.push(ref);
+ if (dict != nullptr) {
+ c->args.push(dict);
+ dict = nullptr;
+ }
current_chunk->addCmd(c);
break;
}
+ // Match Dict
+ else if (tempstream.match(tokens::name,tokens::colon)) {
+ dict = buildVariable(tempstream.next().name);
+ tempstream.next();
+ if (!match_process_standard(&tempstream,ref)) {
+ badSymbol();
+ }
+ }
// This will modify the ref!!!
else if (match_process_standard(&tempstream, ref)) {
count++;
- print(">>",tempstream.peek());
-
- // TODO: make sure each statement is properly seperated by a comma n such
-
- /*if (tempstream.match(tokens::seperator) || tempstream.match(tokens::newline,tokens::seperator)) {
- print("Good!");
- }*/
- /*if (!(tempstream.match(tokens::seperator) || tempstream.match(tokens::cbracketc) || tempstream.match(tokens::newline))) {
- state->push_error(errors::error{ errors::badtoken,concat("Unexpected symbol '",tempstream.next().toString(),"' Expected '}' to close list at ",start.line_num),true,tempstream.peek().line_num,current_chunk });
- return false;
- }*/
+ if (ready) {
+ ancor = tempstream.last();
+ ready = false;
+ }
+ else
+ state->push_error(errors::error{ errors::badtoken,concat("Unexpected symbol '",ancor.toString(),"' Expected '}' to close list (line: ",start.line_num,") Did you forget a comma?"),true,ancor.line_num,current_chunk });
}
else if (tempstream.match(tokens::newline)) {
tempstream.next(); // this is fine
}
else if (tempstream.match(tokens::seperator)) {
// Handle the next piece
+ ready = true;
c = new cmd;
c->opcode = codes::INST;
c->args.push(v);
c->args.push(ref);
+ if (dict != nullptr) {
+ c->args.push(dict);
+ dict = nullptr;
+ }
current_chunk->addCmd(c);
// Build new value
ref = buildVariable();
@@ -120,22 +136,13 @@ namespace dms {
return false;
}
bool LineParser::match_process_disp(tokenstream* stream) {
- /*
- DISP, "msg"
- DISP, "msg" speaker
-
- Compound DISP
- */
- //lastCall.push("MP_disp");
if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) {
stream->next(); // Standard consumption
std::string msg = stream->next().name;
cmd* c = new cmd;
c->opcode = codes::DISP;
- //c->args.push(buildValue());
c->args.push(buildValue(msg));
current_chunk->addCmd(c); // Add the cmd to the current chunk
- //lastCall.pop();
return true;
}
else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::name, tokens::colon, tokens::string, tokens::newline)) {
@@ -151,26 +158,18 @@ namespace dms {
current_chunk->addCmd(c);
c = new cmd;
c->opcode = codes::DISP;
- //c->args.push(buildValue());
c->args.push(buildValue(msg));
current_chunk->addCmd(c); // Add the cmd to the current chunk
// We might have to consume a newline... Depends on what's next
- //lastCall.pop();
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(buildVariable(name));
current_chunk->addCmd(c);
- // Reset the display for the new speaker. Append can be used!
- //c = new cmd;
- //c->opcode = codes::DISP;
- //c->args.push(buildValue());
- //c->args.push(buildValue(std::string("")));
- //current_chunk->addCmd(c);
- // Command to set the speaker
stream->next();
stream->next();
while (stream->peek().type != tokens::cbracketc) {
@@ -235,74 +234,21 @@ namespace dms {
// emotion: "path"
// looks like a simple disp command
else if (isBlock(bt_character) && stream->match(tokens::tab, tokens::name, tokens::colon, tokens::string, tokens::newline)) {
- //lastCall.pop();
return true;
}
-
- // TODO: We still have to implement the compound disp
- //lastCall.pop();
return false;
}
bool LineParser::match_process_assignment(tokenstream* stream) {
- // something equals something else lets go
- //lastCall.push("MP_assignment");
if (stream->match(tokens::name,tokens::equal)) {
value* var = buildVariable(stream->next().name); // The variable that we will be setting stuff to
stream->next(); // Consume the equal
cmd* c = new cmd;
c->opcode = codes::ASGN;
c->args.push(var);
- if (match_process_list(stream, var)) {
- return true;
- }
- else if (match_process_expression(stream, var)) {
- // Expressions can internally set variables
- // We actually need to clean up our cmds
- return true;
- }
- else if (match_process_function(stream, var)) {
- // Functions can internally set variables
- // We actually need to clean up our cmds
- return true;
- }
- else if (stream->match(tokens::True)) {
- stream->next();
- c->args.push(buildValue(true));
- current_chunk->addCmd(c);
- return true;
- }
- else if (stream->match(tokens::False)) {
- stream->next();
- c->args.push(buildValue(false));
- current_chunk->addCmd(c);
- return true;
- }
- else if (stream->match(tokens::string)) {
- c->args.push(buildValue(stream->next().name));
- current_chunk->addCmd(c);
- return true;
- }
- else if (stream->match(tokens::nil)) {
- stream->next();
- c->args.push(buildValue());
- current_chunk->addCmd(c);
- return true;
- }
- else if (stream->match(tokens::number)) {
- c->args.push(buildValue(std::stod(stream->next().name)));
- current_chunk->addCmd(c);
- return true;
- }
- else if (stream->match(tokens::bracketo, tokens::name, tokens::bracketc)) {
- // We are assigning a block as a variable
- stream->next();
- c->args.push(buildBlock(stream->next().name));
- current_chunk->addCmd(c);
- stream->next();
- return true;
- }
- else if (stream->match(tokens::name)) {
- c->args.push(buildVariable(stream->next().name));
+ value* ref = buildVariable();
+ print(stream->peek());
+ if (match_process_standard(stream,ref)) {
+ c->args.push(ref);
current_chunk->addCmd(c);
return true;
}
@@ -336,7 +282,6 @@ namespace dms {
return false;
}
bool LineParser::match_process_choice(tokenstream* stream) {
- //lastCall.push("MP_choice");
token temp = stream->peek();
if (temp.raw == codes::CHOI && stream->match(tokens::control,tokens::string)) {
// Let's parse choice blocks.
@@ -383,7 +328,6 @@ namespace dms {
The NOOP ensures the pattern stays.
If we are provided with a number greater than 3 then we can push an execption.
*/
- std::string str = concat("$",stream->peek().line_num);
while (!stream->match(tokens::cbracketc)) {
if (stream->match(tokens::cbracketo) && !start) {
start = true;
@@ -400,7 +344,7 @@ namespace dms {
if (match_process_function(stream,nullptr,false)) { // No returns and also no nesting of functions!
// We cannot have a nested function here, but if we dont have that then we add our goto
hasfunc = true;
- buildGoto(str);
+ buildGoto(choicelabel);
}
else if (match_process_goto(stream)) {
buildNoop(); // Add noop to post-goto command
@@ -424,11 +368,9 @@ namespace dms {
current_chunk->cmds.pop_back();
delete cc;
if (hasfunc)
- buildLabel(str);
- //lastCall.pop();
+ buildLabel(choicelabel);
return true;
}
- //lastCall.pop();
return false;
}
@@ -437,7 +379,6 @@ namespace dms {
delete[] v; // We didn't need it, lets clean it up!
}
bool LineParser::match_process_function(tokenstream* stream, value* v, bool nested) {
- //lastCall.push("MP_function");
/*
Functions should be able to handle function calls as arguments,
HOWEVER functions cannot be passed as values since they aren't values like they are in other languages!
@@ -504,9 +445,9 @@ namespace dms {
tempstream.init(&t); // Turn tokens we consumed into a tokenstream
value* tempval;
token tok;
+ value* ref = buildVariable();
// This part we add values to the opcodes for the bytecode FUNC val a1 a2 a3 ... an
while (tempstream.peek().type != tokens::none) { // End of stream
- print("> ", tempstream.peek());
tempval = buildVariable();
tok = tempstream.peek();
if (tempstream.match(tokens::seperator)) {
@@ -576,7 +517,6 @@ namespace dms {
}
}
}
- //lastCall.pop();
return false;
}
bool LineParser::match_process_goto(tokenstream* stream) {
@@ -637,21 +577,10 @@ namespace dms {
// I will have to consume for this to work so we need to keep track of what was incase we return false!
stream->store(current_chunk);
cmd* lastcmd = nullptr;
- /*if(!current_chunk->cmds.empty())
- lastcmd = current_chunk->cmds.back();*/
// It has to start with one of these 3 to even be considered an expression
if (stream->match(tokens::number) || stream->match(tokens::name) || stream->match(tokens::parao)) {
// What do we know, math expressions can only be on a single line. We know where to stop looking if we have to
cmd* c = new cmd;
- /*
- * We have a few built-in methods we will have to handle
- * ADD val v1 v2
- * SUB val v1 v2
- * MUL val v1 v2
- * DIV val v1 v2
- * POW val v1 v2
- * MOD val v1 v2
- */
value* wv = nullptr;
value* left; // lefthand
codes::op op; // opperator
@@ -761,7 +690,7 @@ namespace dms {
else
badSymbol(stream);
}
- else if (/*stream->match(tokens::newline) || */stream->match(tokens::parac) || stream->match(tokens::seperator)) {
+ else if (stream->match(tokens::newline) || stream->match(tokens::parac) || stream->match(tokens::seperator)) {
if (wv == nullptr)
return stream->restore(lastcmd, current_chunk); // Always return false and restores the position in stream!
cmd* cc = new cmd;
@@ -769,7 +698,8 @@ namespace dms {
cc->args.push(v);
cc->args.push(wv);
current_chunk->addCmd(cc);
- stream->next();
+ if(stream->match(tokens::parac))
+ stream->next();
// We done!
int t=0;
return true;
diff --git a/DMS/LineParserParse.cpp b/DMS/LineParserParse.cpp
index d4203d6..e41306e 100644
--- a/DMS/LineParserParse.cpp
+++ b/DMS/LineParserParse.cpp
@@ -131,8 +131,17 @@ namespace dms {
t_vec.push_back(token{ tokens::seperator,codes::NOOP,",",line });
}
else if (data == '.') {
- //doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
- t_vec.push_back(token{ tokens::dot,codes::NOOP,".",line });
+ // If a number starts with a .## then we need to ensure that we create the value properly
+ if (std::isdigit(stream.peek()) && buffer.size()==0) {
+ // If the buffer has data then something isn't right
+ isNum = true;
+ buffer.push_back('0');
+ buffer.push_back('.');
+ }
+ else {
+ doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
+ t_vec.push_back(token{ tokens::dot,codes::NOOP,".",line });
+ }
}
else if (data == '{') {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
@@ -296,7 +305,6 @@ namespace dms {
}
t_vec.push_back(token{ tokens::eof,codes::NOOP,"",line - 1 });
tokenDump(&t_vec);
- print("Running tokenizer");
// Tokens build let's parse
tokenizer(state, t_vec);
return state;
@@ -321,8 +329,9 @@ namespace dms {
}
void LineParser::_Parse(tokenstream* stream) {
token current = stream->next();
+ createBlock("$INIT", blocktype::bt_block);
+ cmd* flagcmd = new cmd;
while (stream->peek().type != tokens::eof) {
- print(current);
if (current.type == tokens::flag) {
temp = stream->next(tokens::newline);
stream->prev(); // Unconsume the newline piece
@@ -333,33 +342,51 @@ namespace dms {
tokens::tokentype tok = temp[0].type;
if (code == codes::ENAB && tok == tokens::name) {
tolower(temp[0].name);
- state->enables.insert_or_assign(temp[0].name, true);
+ state->enable(temp[0].name);
+ flagcmd->opcode = code;
+ flagcmd->args.push(buildValue(temp[0].name));
+ current_chunk->addCmd(flagcmd);
+ flagcmd = new cmd;
}
else if (code == codes::ENTR && tok == tokens::name) {
state->entry = temp[0].name;
+ flagcmd->opcode = code;
+ flagcmd->args.push(buildValue(temp[0].name));
+ current_chunk->addCmd(flagcmd);
+ flagcmd = new cmd;
}
else if (code == codes::DISA && tok == tokens::name) {
tolower(temp[0].name);
- state->enables.insert_or_assign(temp[0].name, false);
+ state->disable(temp[0].name);
+ flagcmd->opcode = code;
+ flagcmd->args.push(buildValue(temp[0].name));
+ current_chunk->addCmd(flagcmd);
+ flagcmd = new cmd;
}
else if (code == codes::VERN && tok == tokens::number) {
state->version = std::stod(temp[0].name);
+ flagcmd->opcode = code;
+ flagcmd->args.push(buildValue(std::stod(temp[0].name)));
+ current_chunk->addCmd(flagcmd);
+ flagcmd = new cmd;
}
else if (code == codes::USIN && tok == tokens::name) {
// TODO add usings, kinda useless atm since everything will be packed in. Perhaps extensions?
}
else if (code == codes::LOAD && tok == tokens::string) {
+ flagcmd->opcode = code;
+ flagcmd->args.push(buildValue(temp[0].name));
+ current_chunk->addCmd(flagcmd);
+ flagcmd = new cmd;
LineParser parser = LineParser();
parser.Parse(state, temp[0].name);// Load another file
}
else {
- std::stringstream str;
- str << "Expected " << " got: " << current << temp[0];
- state->push_error(errors::error{ errors::badtoken,str.str(),true,line,current_chunk });
+ state->push_error(errors::error{ errors::badtoken,concat("Expected got: ", current, temp[0]),true,line,current_chunk });
}
}
// Default block
- if (stream->match(tokens::newline,tokens::bracketo, tokens::name, tokens::bracketc)) {
+ if (stream->match(tokens::newline,tokens::bracketo, tokens::name, tokens::bracketc,tokens::newline)) {
stream->next();
stream->next();
std::string name = stream->next().name;
@@ -449,6 +476,6 @@ namespace dms {
match_process_function(stream); // Naked Function
current = stream->next();
}
- createBlock("$END$", bt_block);
+ createBlock("$END", blocktype::bt_block);// Runs code that ensures that last user block is processed into the chunks array. Yes, I could have simply added in the lines of code at the end, but I didn't want to rewrite code again!
}
}
\ No newline at end of file
diff --git a/DMS/LineParserUtils.cpp b/DMS/LineParserUtils.cpp
index 1061d97..ffacf4c 100644
--- a/DMS/LineParserUtils.cpp
+++ b/DMS/LineParserUtils.cpp
@@ -217,21 +217,59 @@ namespace dms {
}
bool LineParser::createBlock(std::string bk_name, blocktype bk_type) {
if (current_chunk != nullptr) {
- if (!state->chunks.count(current_chunk->name))
+ if (state->chunks.count(bk_name)==0 && bk_name!="$END")
state->push_chunk(current_chunk->name, current_chunk);
else
{
- std::stringstream str;
- str << "Block <" << current_chunk->name << "> already defined!";
- state->push_error(errors::error{ errors::block_already_defined,str.str(),true,line,current_chunk });
- return false;
+ if (bk_name == "$INIT") {
+ current_chunk = state->chunks["$INIT"];
+ return true;
+ }
+ else if (bk_name == "$END") {
+ cmd* c = new cmd;
+ c->opcode = codes::JUMP;
+ c->args.push(buildVariable("$END"));
+ current_chunk->addCmd(c);
+ state->push_chunk(current_chunk->name, current_chunk);
+ current_chunk = state->chunks["$END"];
+ return true;
+ }
+ else {
+ std::stringstream str;
+ str << "Block <" << current_chunk->name << "> already defined!";
+ state->push_error(errors::error{ errors::block_already_defined,str.str(),true,line,current_chunk });
+ return false;
+ }
}
}
+ if (state->isEnabled("leaking") && (current_chunk != nullptr && current_chunk->name != "$INIT")) {
+ cmd* c = new cmd;
+ c->opcode = codes::JUMP;
+ c->args.push(buildVariable(bk_name));
+ current_chunk->addCmd(c);
+ }
+ if (current_chunk!= nullptr && current_chunk->name == "$INIT") {
+ cmd* c = new cmd;
+ c->opcode = codes::JUMP;
+ if(state->entry!="$undefined")
+ c->args.push(buildVariable(state->entry));
+ else
+ c->args.push(buildVariable(bk_name));
+ current_chunk->addCmd(c);
+ }
+ if (current_chunk != nullptr && current_chunk->name == "$END") {
+ cmd* c = new cmd;
+ c->opcode = codes::EXIT;
+ if (state->entry != "$undefined")
+ c->args.push(buildValue(0));
+ else
+ c->args.push(buildVariable(bk_name));
+ current_chunk->addCmd(c);
+ }
current_chunk = new chunk;
current_chunk->name = bk_name;
chunk_type = bk_type;
current_chunk->type = bk_type;
-
return true;
}
void LineParser::tokenizer(dms_state* state,std::vector &toks) {
diff --git a/DMS/codes.h b/DMS/codes.h
index 9f1210c..4631b1b 100644
--- a/DMS/codes.h
+++ b/DMS/codes.h
@@ -45,7 +45,7 @@ namespace dms::codes {
DIV,
POW,
MOD,
- LIST
+ LIST,
};
extern const std::string list[];
static bool isControl(const op code) {
diff --git a/DMS/dms_state.cpp b/DMS/dms_state.cpp
index aff0898..e37226d 100644
--- a/DMS/dms_state.cpp
+++ b/DMS/dms_state.cpp
@@ -7,6 +7,20 @@ namespace dms {
enables.insert_or_assign("warnings",false); //
enables.insert_or_assign("statesave",true); // Allows you to save state
enables.insert_or_assign("omniscient",true); // Allows you to know who's who when you first meet them
+ chunk* c = new chunk;
+ c->name = "$END";
+ c->type = blocktype::bt_block;
+ cmd* cc = new cmd;
+ cc->opcode = codes::EXIT;
+ cc->args.push(buildValue(0));
+ c->addCmd(cc);
+ push_chunk("$END", c);
+ }
+ void dms_state::enable(std::string flag) {
+ enables[flag] = true;
+ }
+ void dms_state::disable(std::string flag) {
+ enables[flag] = false;
}
bool dms_state::isEnabled(std::string flag) {
if (enables.count(flag)) {
@@ -41,12 +55,13 @@ namespace dms {
}
void dms_state::push_error(errors::error err) {
std::cout << err.err_msg << " On Line <" << err.linenum << ">" << std::endl;
+ this->err = err;
if (err.crash)
- std::exit(err.code);
+ stop = true;
}
void dms_state::push_warning(errors::error err) {
err.crash = false; // Force code to not crash then push the error
- if(enables.count("warnings"))
+ if(isEnabled("warnings"))
push_error(err);
}
}
\ No newline at end of file
diff --git a/DMS/dms_state.h b/DMS/dms_state.h
index ea8dcae..4b998a2 100644
--- a/DMS/dms_state.h
+++ b/DMS/dms_state.h
@@ -5,20 +5,27 @@
#include
#include
#include