Fix critical bug, further functions

This commit is contained in:
2025-08-15 11:35:58 +10:00
parent bb753e97d4
commit e4cc6b2f14
2 changed files with 21 additions and 12 deletions

View File

@@ -234,13 +234,7 @@ Defines a function. All code between `fun` and `endfun` will be included in the
Usage: `fun -type !functionname -type &var -type &var -type &var # and so on...`
Usage note: The first type specified before the function name must be the return type. The type displayed before all vars
#### local
Defines a variable. The variable will be destroyed when the function is finished.
Usage: `local &var $value`
Usage note: The first type specified before the function name must be the return type. The type displayed before all vars shows what type that variable must be.
#### return

View File

@@ -39,6 +39,7 @@
#include <variant>
#include <vector>
#include <map>
#include <stack>
#include <fstream>
using namespace std;
@@ -254,12 +255,17 @@ struct Function {
*/
map<string, Function> functions;
/*
fnArgs vector
Containst the arguments to be passed to a function
*/
vector<Literal> fnArgs;
/*
funargs vector
Contains the arguments to be passed to a function
localArgStack stack
Contains the variables in a scope
*/
vector<Literal> args;
stack<vector<Literal>> localArgStack;
/*
error function
@@ -380,6 +386,8 @@ Types getType(string in) {
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];
@@ -513,7 +521,6 @@ Literal exec(vector<Instruction> in) {
} else {
error("Second argument of set must be a value (literal or value reference)");
}
variables[varName] = varContents;
}
break;
@@ -1502,6 +1509,14 @@ Literal exec(vector<Instruction> in) {
error("No function is being defined. Cannot end function declaration here");
break;
case Instructions::Pusharg:
if (l.args.size() < 1) {
error("Could not find all arguments required for Endfun inbuilt");
}
if (holds_alternative<Literal>(l.args[0])) {
fnArgs.push_back(get<Literal>(l.args[0]));
} else {
error("First argument of pusharg must be a literal");
}
break;
case Instructions::Local:
break;
@@ -1611,7 +1626,7 @@ vector<Instruction> parser(vector<vector<string>> in) {
firstInst = false;
if (isLabel(i)) {
labels[i.substr(1)] = lineNum;
out.push_back(newInst);
//out.push_back(newInst);
continue;
}
else if (i == "stdin") newInst.inst = Instructions::Stdin;