diff --git a/src/main.cpp b/src/main.cpp index a73f1fd..23891b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -254,6 +254,13 @@ struct Function { */ map functions; + +/* + funargs vector + Contains the arguments to be passed to a function +*/ +vector args; + /* error function Takes a string (which is a debug message) and prints it to the console, letting the @@ -373,7 +380,7 @@ Types getType(string in) { bool processingFunction = false; string procFnName = ""; -void exec(vector in) { +Literal exec(vector in) { for (int i = 0; i < in.size(); i++) { Instruction l = in[i]; if (processingFunction) { @@ -1478,6 +1485,14 @@ void exec(vector in) { Exits a function. */ case Instructions::Return: + if (l.args.size() < 1) { + error("Could not find all arguments required for Return inbuilt"); + } + if (holds_alternative(l.args[0])) { + return get(l.args[0]); + } else { + error("First argument of return must be a literal value/value reference"); + } break; /* endfun instruction @@ -1501,6 +1516,8 @@ void exec(vector in) { break; } } + Literal retLiteral; + return retLiteral; } /* @@ -1754,6 +1771,11 @@ int main(int argc, char** argv) { while (getline(file, lns)) { in += lns += "\n"; } - exec(parser(lexer(in))); + Literal ret = exec(parser(lexer(in))); + if (holds_alternative(ret.val)) { + return get(ret.val); + } else { + return 0; + } return 0; }