Compare commits
2 Commits
e4cc6b2f14
...
b19b4123d8
Author | SHA1 | Date | |
---|---|---|---|
b19b4123d8 | |||
28a9e389fa |
62
src/main.cpp
62
src/main.cpp
@@ -376,18 +376,20 @@ Types getType(string in) {
|
||||
return Types::Int;
|
||||
}
|
||||
|
||||
bool processingFunction = false;
|
||||
string procFnName = "";
|
||||
|
||||
bool inFunction = false;
|
||||
|
||||
// Forward declaration for the call instruction
|
||||
Literal exec(vector<Instruction> in);
|
||||
|
||||
/*
|
||||
exec function
|
||||
This function takes a list of instructions (see Instruction struct above and parser
|
||||
function below) and acts upon their properties. This is the main interpreter
|
||||
function for the program.
|
||||
*/
|
||||
|
||||
bool processingFunction = false;
|
||||
string procFnName = "";
|
||||
|
||||
bool inFunction = false;
|
||||
|
||||
Literal exec(vector<Instruction> in) {
|
||||
for (int i = 0; i < in.size(); i++) {
|
||||
Instruction l = in[i];
|
||||
@@ -1508,6 +1510,10 @@ Literal exec(vector<Instruction> in) {
|
||||
case Instructions::Endfun:
|
||||
error("No function is being defined. Cannot end function declaration here");
|
||||
break;
|
||||
/*
|
||||
pusharg instruction
|
||||
This instruction makes new arguments avaliable for functions.
|
||||
*/
|
||||
case Instructions::Pusharg:
|
||||
if (l.args.size() < 1) {
|
||||
error("Could not find all arguments required for Endfun inbuilt");
|
||||
@@ -1518,9 +1524,33 @@ Literal exec(vector<Instruction> in) {
|
||||
error("First argument of pusharg must be a literal");
|
||||
}
|
||||
break;
|
||||
case Instructions::Local:
|
||||
break;
|
||||
/*
|
||||
call instruction
|
||||
This instruction calls a function, and makes the arguments avaliable for it.
|
||||
*/
|
||||
case Instructions::Call:
|
||||
{
|
||||
if (l.args.size() < 2) {
|
||||
error("Could not find all arguments required for Call inbuilt");
|
||||
}
|
||||
|
||||
FunctionRef ref;
|
||||
Direct returnRef;
|
||||
|
||||
if (holds_alternative<FunctionRef>(l.args[0])) {
|
||||
ref = get<FunctionRef>(l.args[0]);
|
||||
} else {
|
||||
error("First argument of call must be a function reference");
|
||||
}
|
||||
|
||||
if (holds_alternative<Direct>(l.args[1])) {
|
||||
returnRef = get<Direct>(l.args[1]);
|
||||
} else {
|
||||
error("Second argument of call must be a direct reference");
|
||||
}
|
||||
|
||||
variables[returnRef.varName] = exec(functions[ref.fnName].instructions);
|
||||
}
|
||||
break;
|
||||
case Instructions::Use:
|
||||
break;
|
||||
@@ -1553,14 +1583,22 @@ vector<vector<string>> lexer(string in) {
|
||||
switch (i) {
|
||||
case '"':
|
||||
if (!isComment) {
|
||||
procString = !procString;
|
||||
buf.push_back(i);
|
||||
if (procChar) {
|
||||
buf.push_back(i);
|
||||
} else {
|
||||
procString = !procString;
|
||||
buf.push_back(i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '\'':
|
||||
if (!isComment) {
|
||||
procChar = !procChar;
|
||||
buf.push_back(i);
|
||||
if (procString) {
|
||||
buf.push_back(i);
|
||||
} else {
|
||||
procChar = !procChar;
|
||||
buf.push_back(i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
|
@@ -1,6 +1,10 @@
|
||||
fun -int !dingle -string &silly
|
||||
stdlnout &silly
|
||||
stdlnout "This is inside the function"
|
||||
return 10
|
||||
endfun
|
||||
|
||||
stdlnout "This is outside the function"
|
||||
|
||||
call !dingle &var
|
||||
|
||||
stdlnout $var
|
||||
|
Reference in New Issue
Block a user