1
0
mirror of synced 2025-01-29 19:17:28 +01:00

pattern: Added dollar operator assignment

This commit is contained in:
WerWolv 2022-01-29 03:06:34 +01:00
parent 48de158d7c
commit a0a39f1c04
2 changed files with 14 additions and 1 deletions

View File

@ -2115,11 +2115,20 @@ namespace hex::pl {
return this->m_rvalue;
}
[[nodiscard]] std::vector<PatternData *> createPatterns(Evaluator *evaluator) const override {
this->execute(evaluator);
return { };
}
FunctionResult execute(Evaluator *evaluator) const override {
auto literal = dynamic_cast<ASTNodeLiteral *>(this->getRValue()->evaluate(evaluator));
ON_SCOPE_EXIT { delete literal; };
evaluator->setVariable(this->getLValueName(), literal->getValue());
if (this->getLValueName() == "$")
evaluator->dataOffset() = Token::literalToUnsigned(literal->getValue());
else
evaluator->setVariable(this->getLValueName(), literal->getValue());
return {};
}

View File

@ -491,6 +491,8 @@ namespace hex::pl {
if (MATCHES(sequence(IDENTIFIER, OPERATOR_ASSIGNMENT)))
statement = parseFunctionVariableAssignment();
else if (MATCHES(sequence(OPERATOR_DOLLAR, OPERATOR_ASSIGNMENT)))
statement = create(new ASTNodeAssignment("$", parseMathematicalExpression()));
else if (MATCHES(oneOf(KEYWORD_RETURN, KEYWORD_BREAK, KEYWORD_CONTINUE)))
statement = parseFunctionControlFlowStatement();
else if (MATCHES(sequence(KEYWORD_IF, SEPARATOR_ROUNDBRACKETOPEN))) {
@ -877,6 +879,8 @@ namespace hex::pl {
member = new ASTNodeControlFlowStatement(ControlFlowStatement::Break, nullptr);
else if (MATCHES(sequence(KEYWORD_CONTINUE)))
member = new ASTNodeControlFlowStatement(ControlFlowStatement::Continue, nullptr);
else if (MATCHES(sequence(OPERATOR_DOLLAR, OPERATOR_ASSIGNMENT)))
member = create(new ASTNodeAssignment("$", parseMathematicalExpression()));
else
throwParseError("invalid struct member", 0);