From f8ccf5eedb60435b7fac66521554beab582c0b00 Mon Sep 17 00:00:00 2001 From: alexvitkov <44268717+alexvitkov@users.noreply.github.com> Date: Sat, 24 Oct 2020 17:58:54 +0300 Subject: JSImpl: Implemented ASTInterpreter::Visit for unary + and - (#87) * JSImpl: Implemented ASTInterpreter::Visit for unary + and - * JSImpl: Added tests for unary + and - * JSImpl: fixed appveyor ubuntu build Co-authored-by: Martin Dobrev --- JSImpl/src/ASTInterpreter.cpp | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'JSImpl/src/ASTInterpreter.cpp') diff --git a/JSImpl/src/ASTInterpreter.cpp b/JSImpl/src/ASTInterpreter.cpp index 25f5c02..9874a4d 100644 --- a/JSImpl/src/ASTInterpreter.cpp +++ b/JSImpl/src/ASTInterpreter.cpp @@ -216,27 +216,41 @@ void ASTInterpreter::Visit(BinaryExpression* e) { } void ASTInterpreter::Visit(UnaryExpression* e) { - LValueExtractor extractor(this); - auto lvalue = extractor.Run(e->GetExpr().get()); - if (e->GetSuffix()) - { - m_Evaluation.push_back(*lvalue); - } switch (e->GetOperator()) { - case TokenType::PlusPlus: - ++(*lvalue); - break; - case TokenType::MinusMinus: - --(*lvalue); - break; - default: - NOT_IMPLEMENTED; - } - if (!e->GetSuffix()) - { - m_Evaluation.push_back(*lvalue); + case TokenType::Minus: + { + e->GetExpr()->Accept(*this); + m_Evaluation.back() *= -1; + break; + } + case TokenType::Plus: + { + e->GetExpr()->Accept(*this); + break; + } + case TokenType::PlusPlus: // FALLTHROUGH + case TokenType::MinusMinus: + { + LValueExtractor extractor(this); + auto lvalue = extractor.Run(e->GetExpr().get()); + if (e->GetSuffix()) + { + m_Evaluation.push_back(*lvalue); + } + *lvalue += e->GetOperator() == TokenType::PlusPlus ? 1 : -1; + if (!e->GetSuffix()) + { + m_Evaluation.push_back(*lvalue); + } + break; + } + default: + { + NOT_IMPLEMENTED; + } } + } void ASTInterpreter::Visit(IdentifierExpression* e) { -- cgit v1.3.1-23-gd82d