Add const variables

This commit is contained in:
2025-11-15 22:17:40 -06:00
parent 06e19150e8
commit 48e409f6d0
10 changed files with 380 additions and 9 deletions
+23
View File
@@ -1257,6 +1257,29 @@ namespace Tesses::CrossLang
}
}
else if(varNode.nodeName == ConstExpression && varNode.nodes.size() == 1 && std::holds_alternative<std::string>(varNode.nodes[0]))
{
GenNode(instructions,varNode.nodes[0],scope,contscope,brkscope,contI,brkI);
GenNode(instructions,adv.nodes[1],scope,contscope,brkscope,contI,brkI);
instructions.push_back(new SimpleInstruction(DECLARECONSTVARIABLE));
}
else if(varNode.nodeName == ConstExpression && varNode.nodes.size() == 1 && std::holds_alternative<AdvancedSyntaxNode>(varNode.nodes[0]))
{
auto adv2 = std::get<AdvancedSyntaxNode>(varNode.nodes[0]);
if(adv2.nodeName == ArrayExpression && adv2.nodes.size() == 1)
{
auto vars= StringifyListOfVars(adv2.nodes[0]);
auto nArray = AdvancedSyntaxNode::Create(ArrayExpression,true,{vars});
this->GenNode(instructions,nArray ,scope ,contscope ,brkscope ,contI , brkI);
GenNode(instructions,adv.nodes[1],scope,contscope,brkscope,contI,brkI);
instructions.push_back(new SimpleInstruction(DECLARECONSTVARIABLE));
}
}
else if(varNode.nodeName == GetFieldExpression && varNode.nodes.size() == 2)
{
GenNode(instructions,varNode.nodes[0],scope,contscope,brkscope,contI,brkI);
+27
View File
@@ -730,6 +730,33 @@ namespace Tesses::CrossLang
node = AdvancedSyntaxNode::Create(DeclareExpression,true,{variable.text});
}
}
else if(IsIdentifier("const"))
{
if(i >= tokens.size()) throw std::out_of_range("End of file");
auto variable = tokens[i];
i++;
if(variable.type == LexTokenType::Symbol && variable.text == ".")
{
EnsureSymbol("[");
node = AdvancedSyntaxNode::Create(ConstExpression,true,{
AdvancedSyntaxNode::Create(GetVariableExpression ,true,{ParseExpression()})
});
EnsureSymbol("]");
}
else if(variable.type == LexTokenType::Symbol && variable.text == "[")
{
node = AdvancedSyntaxNode::Create(ConstExpression,true,{
AdvancedSyntaxNode::Create(ArrayExpression ,true,{ParseExpression()})
});
EnsureSymbol("]");
}
else if(variable.type != LexTokenType::Identifier) throw SyntaxException(variable.lineInfo, "Expected an identifier got a " + LexTokenType_ToString(variable.type) + " \"" + variable.text + "\"");
else
{
node = AdvancedSyntaxNode::Create(ConstExpression,true,{variable.text});
}
}
else if(IsIdentifier("comptime"))
{
SyntaxNode n = nullptr;