From 6bc483b1db12b41eacf34de0fede2ad188c93756 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Mon, 12 Jan 2026 15:24:37 +1100 Subject: [PATCH] Inline ground --- .project.fish | 5 +++++ src/main.cpp | 7 ++++++- src/parser.cpp | 26 ++++++++++++++++++++++++++ src/parser.h | 3 ++- tests/inlineground.sols | 7 +++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .project.fish create mode 100644 tests/inlineground.sols diff --git a/.project.fish b/.project.fish new file mode 100644 index 0000000..71c73b8 --- /dev/null +++ b/.project.fish @@ -0,0 +1,5 @@ +# source .project.fish + +alias run "make && ./solstice" +alias clean "make clean" +alias cleanrun "make clean && make && ./solstice" diff --git a/src/main.cpp b/src/main.cpp index 99358e2..5cc8a52 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,11 @@ int main(int argc, char** argv) { outputFile.close(); exit(0); } else { - groundRunProgram(&program); + GroundValue gv = groundRunProgram(&program); + if (gv.type == INT) { + return gv.data.intVal; + } else { + return 0; + } } } diff --git a/src/parser.cpp b/src/parser.cpp index 25146cc..8fac2c8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -747,6 +747,15 @@ namespace Solstice { } break; } + case SolNodeType::InlineGround: { + GroundProgram program = groundParseFile(ground.c_str()); + SolGroundCodeBlock codeBlock; + for (size_t i = 0; i < program.size; i++) { + codeBlock.code.push_back(program.instructions[i]); + } + code.push_back(codeBlock); + break; + } default: {} } return code; @@ -883,6 +892,9 @@ namespace Solstice { if (in == "return") { return SolNodeType::Return; } + if (in == "ground") { + return SolNodeType::InlineGround; + } if (in == "{") { return SolNodeType::CodeBlockStart; } @@ -1428,6 +1440,20 @@ namespace Solstice { rootNode.addNode(returnNode); break; } + case SolNodeType::InlineGround: { + SolNode groundNode(SolNodeType::InlineGround); + consume(); // some funny token + consume(); // { + consume(); // new line token + while (auto tokenopt = consume()) { + if (tokenopt.value().value == "}") { + break; + } + groundNode.ground += tokenopt.value().value + " "; + } + rootNode.addNode(groundNode); + break; + } } } return rootNode; diff --git a/src/parser.h b/src/parser.h index 2ab65d3..99e8369 100644 --- a/src/parser.h +++ b/src/parser.h @@ -57,7 +57,7 @@ namespace Solstice { enum class SolNodeType { - Add, Subtract, Multiply, Divide, Equal, Inequal, Greater, Lesser, EqGreater, EqLesser, Set, While, If, Value, Identifier, None, Root, CodeBlock, CodeBlockStart, CodeBlockEnd, FunctionDef, FunctionCall, Expression, BracketStart, BracketEnd, Puts, Return + Add, Subtract, Multiply, Divide, Equal, Inequal, Greater, Lesser, EqGreater, EqLesser, Set, While, If, Value, Identifier, None, Root, CodeBlock, CodeBlockStart, CodeBlockEnd, FunctionDef, FunctionCall, Expression, BracketStart, BracketEnd, Puts, Return, InlineGround }; enum class SolDataType { @@ -114,6 +114,7 @@ namespace Solstice { std::string outputId; int line = 0; std::string lineContent = ""; + std::string ground = ""; SolNode(SolNodeType nodeType); SolNode(SolNodeType nodeType, SolData data); diff --git a/tests/inlineground.sols b/tests/inlineground.sols new file mode 100644 index 0000000..53463b9 --- /dev/null +++ b/tests/inlineground.sols @@ -0,0 +1,7 @@ +result = 0 +ground { + println "dingus" + add 3 2 &result +} + +puts result