forked from solstice/solstice
Inline ground
This commit is contained in:
5
.project.fish
Normal file
5
.project.fish
Normal file
@@ -0,0 +1,5 @@
|
||||
# source .project.fish
|
||||
|
||||
alias run "make && ./solstice"
|
||||
alias clean "make clean"
|
||||
alias cleanrun "make clean && make && ./solstice"
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
7
tests/inlineground.sols
Normal file
7
tests/inlineground.sols
Normal file
@@ -0,0 +1,7 @@
|
||||
result = 0
|
||||
ground {
|
||||
println "dingus"
|
||||
add 3 2 &result
|
||||
}
|
||||
|
||||
puts result
|
||||
Reference in New Issue
Block a user