From 8fe543b2914a99d3dcd3cb79cd1698f6bd53c312 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Tue, 13 May 2025 09:07:35 +1000 Subject: [PATCH] `args` variable allows access to command line args --- examples/args.io | 1 + src/Interpreter.cpp | 22 +++++++--------------- src/common.h | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) create mode 100644 examples/args.io diff --git a/examples/args.io b/examples/args.io new file mode 100644 index 0000000..491de73 --- /dev/null +++ b/examples/args.io @@ -0,0 +1 @@ +printlist args; diff --git a/src/Interpreter.cpp b/src/Interpreter.cpp index 65929f0..e5efa0f 100644 --- a/src/Interpreter.cpp +++ b/src/Interpreter.cpp @@ -78,25 +78,17 @@ void Interpreter::interpret(vector tokenList) { if (varIt != variables.end()) { // This is pretty crappy code but it exists for now. Lists are gonna break this so much it's not even gonna be funny - if (varIt->second.type == valtype::LIST) { - if (peek()->keyword == keywords::OSQUA) { - if (peek(2)->keyword == keywords::VALUE && peek(2)->type == valtype::INT && peek(2)->type == valtype::INT && peek(3)->keyword == keywords::CSQUA) { - Token newToken; - Value tokenVal = get(varIt->second.value).value[get(peek(2)->value.value)]; - newToken.keyword = keywords::VALUE; - newToken.type = tokenVal.type; - newToken.value.value = tokenVal.value; - // Do this later - } - } - } else { + //if (varIt->second.type == valtype::LIST) { + + //} else { // Replace the token with the variable's value Token newToken; newToken.keyword = keywords::VALUE; + if (varIt->second.type == valtype::LIST) newToken.keyword = keywords::LISTOBJ; newToken.type = varIt->second.type; newToken.value = varIt->second; currentInstruction[i] = newToken; - } + //} } } else if (currentInstruction[i].keyword == keywords::INPUT) { Token newToken; @@ -273,7 +265,7 @@ void Interpreter::interpret(vector tokenList) { newToken.type = valtype::LIST; newToken.value.type = valtype::LIST; newToken.value.value = buf; - newToken.keyword = keywords::LIST; + newToken.keyword = keywords::LISTOBJ; currentInstruction.insert(currentInstruction.begin() + startIndex, newToken); } } @@ -368,7 +360,7 @@ void Interpreter::executeCode(vector tokens) { if (tokens.size() <= i) syntaxError.fnNotSufficientArgs("printlist", 1, 1, 0); Token nextToken = tokens[i]; log.debug("Printing a list. Type of next token is " + log.getTypeString(nextToken.value.type)); - if (nextToken.keyword == keywords::LIST && nextToken.type == valtype::LIST) { + if (nextToken.keyword == keywords::LISTOBJ && nextToken.type == valtype::LIST) { List list = get(nextToken.value.value); log.debug("List obtained"); if (list.value[0].type == valtype::INT) { diff --git a/src/common.h b/src/common.h index 7a222ba..b8398a0 100644 --- a/src/common.h +++ b/src/common.h @@ -39,7 +39,7 @@ enum class keywords { EQUAL, INEQUAL, LESS, GREATER, EQLESS, EQGREATER, INCREMENT, DECREMENT, PRINT, PRINTLN, PRINTLIST, LET, INPUT, EXIT, - VALUE, LIST, SEMICOLON, VARIABLE, + VALUE, LISTOBJ, SEMICOLON, VARIABLE, COMMENT };