Inline ground

This commit is contained in:
2026-01-12 15:24:37 +11:00
parent c5b67bff72
commit 6bc483b1db
5 changed files with 46 additions and 2 deletions

5
.project.fish Normal file
View File

@@ -0,0 +1,5 @@
# source .project.fish
alias run "make && ./solstice"
alias clean "make clean"
alias cleanrun "make clean && make && ./solstice"

View File

@@ -58,6 +58,11 @@ int main(int argc, char** argv) {
outputFile.close(); outputFile.close();
exit(0); exit(0);
} else { } else {
groundRunProgram(&program); GroundValue gv = groundRunProgram(&program);
if (gv.type == INT) {
return gv.data.intVal;
} else {
return 0;
}
} }
} }

View File

@@ -747,6 +747,15 @@ namespace Solstice {
} }
break; 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: {} default: {}
} }
return code; return code;
@@ -883,6 +892,9 @@ namespace Solstice {
if (in == "return") { if (in == "return") {
return SolNodeType::Return; return SolNodeType::Return;
} }
if (in == "ground") {
return SolNodeType::InlineGround;
}
if (in == "{") { if (in == "{") {
return SolNodeType::CodeBlockStart; return SolNodeType::CodeBlockStart;
} }
@@ -1428,6 +1440,20 @@ namespace Solstice {
rootNode.addNode(returnNode); rootNode.addNode(returnNode);
break; 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; return rootNode;

View File

@@ -57,7 +57,7 @@ namespace Solstice {
enum class SolNodeType { 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 { enum class SolDataType {
@@ -114,6 +114,7 @@ namespace Solstice {
std::string outputId; std::string outputId;
int line = 0; int line = 0;
std::string lineContent = ""; std::string lineContent = "";
std::string ground = "";
SolNode(SolNodeType nodeType); SolNode(SolNodeType nodeType);
SolNode(SolNodeType nodeType, SolData data); SolNode(SolNodeType nodeType, SolData data);

7
tests/inlineground.sols Normal file
View File

@@ -0,0 +1,7 @@
result = 0
ground {
println "dingus"
add 3 2 &result
}
puts result