diff --git a/examples/args.io b/examples/args.io new file mode 100644 index 0000000..c38f1b2 --- /dev/null +++ b/examples/args.io @@ -0,0 +1 @@ +println args; diff --git a/src/ArgParser.cpp b/src/ArgParser.cpp index 5ee57c1..3648ef9 100644 --- a/src/ArgParser.cpp +++ b/src/ArgParser.cpp @@ -54,3 +54,7 @@ string ArgParser::getArg(int index) { } return ""; } + +vector ArgParser::getAllArgs() { + return args; +} diff --git a/src/ArgParser.h b/src/ArgParser.h index ae0341d..cdec6ca 100644 --- a/src/ArgParser.h +++ b/src/ArgParser.h @@ -26,4 +26,5 @@ private: public: ArgParser(int argc, char* argv[]); string getArg(int index); + vector getAllArgs(); }; diff --git a/src/Interpreter.cpp b/src/Interpreter.cpp index e39703c..a318963 100644 --- a/src/Interpreter.cpp +++ b/src/Interpreter.cpp @@ -31,7 +31,21 @@ optional Interpreter::peek(int offset) { return {}; } -void Interpreter::convertToTokens(vector tokenList) { +void Interpreter::initInterpreter(vector args) { + List arguments; + for (int i = 0; i < args.size(); i++) { + Value buf; + buf.type = valtype::STR; + buf.value = args[i]; + arguments.value.push_back(buf); + } + Value buf; + buf.type = valtype::LIST; + buf.value = arguments; + variables["args"] = buf; +} + +void Interpreter::interpret(vector tokenList) { if (debugMode) log.toggleDebugPrint(); tokens = tokenList; log.debug("Alright we got " + to_string(tokens.size()) + " tokens"); diff --git a/src/Interpreter.h b/src/Interpreter.h index 82cd0e1..37ca035 100644 --- a/src/Interpreter.h +++ b/src/Interpreter.h @@ -36,8 +36,9 @@ private: int tokenIndex = -1; optional consume(); optional peek(int offset = 1); + void executeCode(vector tokens); public: - void convertToTokens(vector tokenList); - void executeCode(vector tokens); + void initInterpreter(vector args); + void interpret(vector tokenList); }; diff --git a/src/main.cpp b/src/main.cpp index 95c9ba9..96251fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,6 +50,7 @@ int main(int argc, char* argv[]) { // Initialise the interpreter Interpreter interpreter; // Convert to tokens and run the code - interpreter.convertToTokens(parser.getTokens()); + interpreter.initInterpreter(args.getAllArgs()); + interpreter.interpret(parser.getTokens()); return 0; }