From 76205a613d84a0050db794fbd60c54bf37427433 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Sun, 31 Aug 2025 15:04:27 +1000 Subject: [PATCH] Rewrite label system --- src/main.cpp | 126 ++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 57 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 80b7e6a..a4479db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,6 +168,31 @@ struct FunctionRef { string fnName; }; +/* + Label struct + Contains information needed to register labels +*/ +struct Label { + string id; + int lineNum = -1; +}; + +/* + Line struct + Contains information needed to jump to lines +*/ +struct Line { + int lineNum = -1; + bool isLabel = false; + string label; +}; + +/* + labelStack stack + Allows each function to hold it's own set of labels +*/ +stack> labelStack; + /* ListRef struct Contains the name of a list referenced by the program. For example, if the @@ -188,12 +213,6 @@ struct ListRef { */ map variables; -/* - labels map - Contains all labels made in the program, for ease of jumping around the code. -*/ -map labels; - /* ValueRef struct If the program being executed makes a value reference, it is stored in a ValueRef @@ -208,22 +227,6 @@ struct ValueRef { string varName; }; -/* - Line struct - If the program being executed makes a line reference, it is stored in a Line - struct. For example, if the following line was written: - jump %10 - The Line struct in the instruction should look like this: - { - lineNum = 10; - } -*/ -struct Line { - int lineNum; - bool isLabel = false; - string label; -}; - /* Instruction struct An instruction usually corresponds to a line in the program being interpreted. @@ -249,9 +252,13 @@ struct Line { See also: Instructions enum class, Literal struct, ValueRef struct, Direct struct, Line struct, exec function, parser function */ + +typedef variant argument; struct Instruction { Instructions inst = Instructions::Empty; - vector> args; + vector args; + bool isLabel = false; + Label label; }; struct FnArg { @@ -267,7 +274,7 @@ struct Function { Types returnType; vector args; vector instructions; - map localLabels; + vector