From 6e428f97e54c4ebff1d5c3d4ba7e1122a15e0ea8 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Wed, 5 Jul 2023 21:37:44 +0300 Subject: [PATCH 1/5] fix grammar in expr17 --- crypto/func/parse-func.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index 15794c425..a47773931 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -852,7 +852,7 @@ Expr* parse_expr20(Lexer& lex, CodeBlob& code, bool nv) { return res; } -// parse E { ( << | >> | >>~ | >>^ ) E } +// parse E { ( << | >> | ~>> | ^>> ) E } Expr* parse_expr17(Lexer& lex, CodeBlob& code, bool nv) { Expr* res = parse_expr20(lex, code, nv); while (lex.tp() == _Lshift || lex.tp() == _Rshift || lex.tp() == _RshiftC || lex.tp() == _RshiftR) { From fdbf7defa5ce4834eccc8ac4a11bcaf4ce0c1c91 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Sat, 2 Dec 2023 17:05:35 +0700 Subject: [PATCH 2/5] Fix ``& ^ |` priority --- crypto/func/parse-func.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index a47773931..be36bf551 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -797,7 +797,7 @@ Expr* parse_expr75(Lexer& lex, CodeBlob& code, bool nv) { Expr* parse_expr30(Lexer& lex, CodeBlob& code, bool nv) { Expr* res = parse_expr75(lex, code, nv); while (lex.tp() == '*' || lex.tp() == '/' || lex.tp() == '%' || lex.tp() == _DivMod || lex.tp() == _DivC || - lex.tp() == _DivR || lex.tp() == _ModC || lex.tp() == _ModR || lex.tp() == '&') { + lex.tp() == _DivR || lex.tp() == _ModC || lex.tp() == _ModR) { res->chk_rvalue(lex.cur()); int t = lex.tp(); sym_idx_t name = symbols.lookup_add(std::string{"_"} + lex.cur().str + "_"); @@ -815,7 +815,7 @@ Expr* parse_expr30(Lexer& lex, CodeBlob& code, bool nv) { return res; } -// parse [-] E { (+ | - | `|` | ^) E } +// parse [-] E { ( + | - ) E } Expr* parse_expr20(Lexer& lex, CodeBlob& code, bool nv) { Expr* res; int t = lex.tp(); @@ -834,7 +834,7 @@ Expr* parse_expr20(Lexer& lex, CodeBlob& code, bool nv) { } else { res = parse_expr30(lex, code, nv); } - while (lex.tp() == '-' || lex.tp() == '+' || lex.tp() == '|' || lex.tp() == '^') { + while (lex.tp() == '-' || lex.tp() == '+') { res->chk_rvalue(lex.cur()); t = lex.tp(); sym_idx_t name = symbols.lookup_add(std::string{"_"} + lex.cur().str + "_"); @@ -852,7 +852,7 @@ Expr* parse_expr20(Lexer& lex, CodeBlob& code, bool nv) { return res; } -// parse E { ( << | >> | ~>> | ^>> ) E } +// parse E { ( << | >> | >>~ | >>^ ) E } Expr* parse_expr17(Lexer& lex, CodeBlob& code, bool nv) { Expr* res = parse_expr20(lex, code, nv); while (lex.tp() == _Lshift || lex.tp() == _Rshift || lex.tp() == _RshiftC || lex.tp() == _RshiftR) { @@ -895,9 +895,30 @@ Expr* parse_expr15(Lexer& lex, CodeBlob& code, bool nv) { return res; } +// parse E [ ( & | ^ | '|' ) E ] +Expr* parse_expr14(Lexer& lex, CodeBlob& code, bool nv) { + Expr* res = parse_expr15(lex, code, nv); + if (lex.tp() == '&' || lex.tp() == '^' || lex.tp() == '|') { + res->chk_rvalue(lex.cur()); + int t = lex.tp(); + sym_idx_t name = symbols.lookup_add(std::string{"_"} + lex.cur().str + "_"); + check_global_func(lex.cur(), name); + SrcLocation loc{lex.cur().loc}; + lex.next(); + auto x = parse_expr15(lex, code, false); + x->chk_rvalue(lex.cur()); + res = new Expr{Expr::_Apply, name, {res, x}}; + res->here = loc; + res->set_val(t); + res->flags = Expr::_IsRvalue; + res->deduce_type(lex.cur()); + } + return res; +} + // parse E [ ? E : E ] Expr* parse_expr13(Lexer& lex, CodeBlob& code, bool nv) { - Expr* res = parse_expr15(lex, code, nv); + Expr* res = parse_expr14(lex, code, nv); if (lex.tp() == '?') { res->chk_rvalue(lex.cur()); SrcLocation loc{lex.cur().loc}; @@ -905,7 +926,7 @@ Expr* parse_expr13(Lexer& lex, CodeBlob& code, bool nv) { auto x = parse_expr(lex, code, false); x->chk_rvalue(lex.cur()); lex.expect(':'); - auto y = parse_expr13(lex, code, false); + auto y = parse_expr14(lex, code, false); y->chk_rvalue(lex.cur()); res = new Expr{Expr::_CondExpr, {res, x, y}}; res->here = loc; From d73f80c4ca6e8c59bcb24e45b8718c58a710a523 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Sat, 2 Dec 2023 17:09:21 +0700 Subject: [PATCH 3/5] fix formatting --- crypto/func/parse-func.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index be36bf551..2f97701ea 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -912,7 +912,7 @@ Expr* parse_expr14(Lexer& lex, CodeBlob& code, bool nv) { res->set_val(t); res->flags = Expr::_IsRvalue; res->deduce_type(lex.cur()); - } + } return res; } From 5368287d5f0b689cfaf7d033fc1717e9b6acdbc4 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Tue, 5 Dec 2023 18:18:22 +0700 Subject: [PATCH 4/5] fix legacy test --- crypto/func/parse-func.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index 2f97701ea..8c4d16f35 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -905,7 +905,7 @@ Expr* parse_expr14(Lexer& lex, CodeBlob& code, bool nv) { check_global_func(lex.cur(), name); SrcLocation loc{lex.cur().loc}; lex.next(); - auto x = parse_expr15(lex, code, false); + auto x = parse_expr14(lex, code, false); x->chk_rvalue(lex.cur()); res = new Expr{Expr::_Apply, name, {res, x}}; res->here = loc; From 7a407c4fe3b2ff5b2041e976088ebec5f0a6d057 Mon Sep 17 00:00:00 2001 From: Andrey Pfau Date: Wed, 6 Dec 2023 06:16:35 +0700 Subject: [PATCH 5/5] Fix Whales' nominator case --- .../whales-nominators/modules/model.fc | 4 ++-- crypto/func/parse-func.cpp | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crypto/func/auto-tests/legacy_tests/whales-nominators/modules/model.fc b/crypto/func/auto-tests/legacy_tests/whales-nominators/modules/model.fc index 9c28b42a1..9c2fb6f74 100644 --- a/crypto/func/auto-tests/legacy_tests/whales-nominators/modules/model.fc +++ b/crypto/func/auto-tests/legacy_tests/whales-nominators/modules/model.fc @@ -137,7 +137,7 @@ int apply_profit(int value, int value_profit, int profit) { } ;; Try to withdraw from withdraw balance - if ((remaining > 0) & ctx_member_withdraw > 0) { + if (((remaining > 0) & ctx_member_withdraw) > 0) { int delta = min(ctx_member_withdraw, remaining); ctx_member_withdraw = ctx_member_withdraw - delta; ctx_balance_withdraw = ctx_balance_withdraw - delta; @@ -294,4 +294,4 @@ int owned_balance() { ;; Reset sent amount ctx_balance_sent = 0; -} \ No newline at end of file +} diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index 8c4d16f35..d21fa266a 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -793,7 +793,7 @@ Expr* parse_expr75(Lexer& lex, CodeBlob& code, bool nv) { } } -// parse E { (* | / | % | /% ) E } +// parse E { ( * | / | % | /% ) E } Expr* parse_expr30(Lexer& lex, CodeBlob& code, bool nv) { Expr* res = parse_expr75(lex, code, nv); while (lex.tp() == '*' || lex.tp() == '/' || lex.tp() == '%' || lex.tp() == _DivMod || lex.tp() == _DivC || @@ -852,7 +852,7 @@ Expr* parse_expr20(Lexer& lex, CodeBlob& code, bool nv) { return res; } -// parse E { ( << | >> | >>~ | >>^ ) E } +// parse E { ( << | >> | ~>> | ^>> ) E } Expr* parse_expr17(Lexer& lex, CodeBlob& code, bool nv) { Expr* res = parse_expr20(lex, code, nv); while (lex.tp() == _Lshift || lex.tp() == _Rshift || lex.tp() == _RshiftC || lex.tp() == _RshiftR) { @@ -895,17 +895,17 @@ Expr* parse_expr15(Lexer& lex, CodeBlob& code, bool nv) { return res; } -// parse E [ ( & | ^ | '|' ) E ] -Expr* parse_expr14(Lexer& lex, CodeBlob& code, bool nv) { +// parse E { ( '|' | & | ^ ) E } +Expr* parse_expr14(Lexer& lex, CodeBlob& code, const bool nv) { Expr* res = parse_expr15(lex, code, nv); - if (lex.tp() == '&' || lex.tp() == '^' || lex.tp() == '|') { + while (lex.tp() == '|' || lex.tp() == '&' || lex.tp() == '^') { res->chk_rvalue(lex.cur()); int t = lex.tp(); - sym_idx_t name = symbols.lookup_add(std::string{"_"} + lex.cur().str + "_"); + const sym_idx_t name = symbols.lookup_add(std::string{"_"} + lex.cur().str + "_"); check_global_func(lex.cur(), name); - SrcLocation loc{lex.cur().loc}; + const SrcLocation loc{lex.cur().loc}; lex.next(); - auto x = parse_expr14(lex, code, false); + auto x = parse_expr15(lex, code, false); x->chk_rvalue(lex.cur()); res = new Expr{Expr::_Apply, name, {res, x}}; res->here = loc; @@ -926,7 +926,7 @@ Expr* parse_expr13(Lexer& lex, CodeBlob& code, bool nv) { auto x = parse_expr(lex, code, false); x->chk_rvalue(lex.cur()); lex.expect(':'); - auto y = parse_expr14(lex, code, false); + auto y = parse_expr13(lex, code, false); y->chk_rvalue(lex.cur()); res = new Expr{Expr::_CondExpr, {res, x, y}}; res->here = loc;