Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix & ^ | priority in parsing #817

Open
wants to merge 6 commits into
base: testnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -294,4 +294,4 @@ int owned_balance() {

;; Reset sent amount
ctx_balance_sent = 0;
}
}
33 changes: 27 additions & 6 deletions crypto/func/parse-func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,11 @@ 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 ||
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 + "_");
Expand All @@ -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();
Expand All @@ -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 + "_");
Expand All @@ -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) {
Expand Down Expand Up @@ -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, const bool nv) {
Expr* res = parse_expr15(lex, code, nv);
while (lex.tp() == '|' || lex.tp() == '&' || lex.tp() == '^') {
res->chk_rvalue(lex.cur());
int t = lex.tp();
const sym_idx_t name = symbols.lookup_add(std::string{"_"} + lex.cur().str + "_");
check_global_func(lex.cur(), name);
const 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};
Expand Down