From e4cc6b2f147cfac9913523e59e5b04b557337cba Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Fri, 15 Aug 2025 11:35:58 +1000 Subject: [PATCH] Fix critical bug, further functions --- docs/syntax.md | 8 +------- src/main.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index accfdf2..ba12a10 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -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 diff --git a/src/main.cpp b/src/main.cpp index 23891b4..d198867 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include using namespace std; @@ -254,12 +255,17 @@ struct Function { */ map functions; +/* + fnArgs vector + Containst the arguments to be passed to a function +*/ +vector fnArgs; /* - funargs vector - Contains the arguments to be passed to a function + localArgStack stack + Contains the variables in a scope */ -vector args; +stack> localArgStack; /* error function @@ -380,6 +386,8 @@ Types getType(string in) { bool processingFunction = false; string procFnName = ""; +bool inFunction = false; + Literal exec(vector in) { for (int i = 0; i < in.size(); i++) { Instruction l = in[i]; @@ -513,7 +521,6 @@ Literal exec(vector 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 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(l.args[0])) { + fnArgs.push_back(get(l.args[0])); + } else { + error("First argument of pusharg must be a literal"); + } break; case Instructions::Local: break; @@ -1611,7 +1626,7 @@ vector parser(vector> 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;