patterns: Fixed offset being incorrectly incremented when calling functions

This commit is contained in:
WerWolv
2022-03-01 09:40:08 +01:00
parent 6b2423cdce
commit 540f468e8a
2 changed files with 5 additions and 0 deletions

View File

@@ -41,6 +41,9 @@ namespace hex::pl {
}
[[nodiscard]] std::unique_ptr<ASTNode> evaluate(Evaluator *evaluator) const override {
auto startOffset = evaluator->dataOffset();
ON_SCOPE_EXIT { evaluator->dataOffset() = startOffset; };
std::vector<Token::Literal> evaluatedParams;
for (auto &param : this->m_params) {
const auto expression = param->evaluate(evaluator)->evaluate(evaluator);

View File

@@ -48,9 +48,11 @@ namespace hex::pl {
evaluator->addCustomFunction(this->m_name, paramCount, [this](Evaluator *ctx, const std::vector<Token::Literal> &params) -> std::optional<Token::Literal> {
std::vector<std::shared_ptr<Pattern>> variables;
auto startOffset = ctx->dataOffset();
ctx->pushScope(nullptr, variables);
ON_SCOPE_EXIT {
ctx->popScope();
ctx->dataOffset() = startOffset;
};
if (this->m_parameterPack.has_value()) {