Skip to content

Commit

Permalink
Update AST->ASR
Browse files Browse the repository at this point in the history
  • Loading branch information
namannimmo10 authored and certik committed Jun 21, 2022
1 parent 9ebb732 commit 63dc43e
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,41 +1559,26 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
this->visit_expr(*x.m_right);
ASR::expr_t *right = ASRUtils::EXPR(tmp);
ASR::binopType op;
std::string op_name = "";
switch (x.m_op) {
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
case (AST::operatorType::Sub) : { op = ASR::binopType::Sub; break; }
case (AST::operatorType::Mult) : { op = ASR::binopType::Mul; break; }
case (AST::operatorType::Div) : { op = ASR::binopType::Div; break; }
case (AST::operatorType::FloorDiv) : {op = ASR::binopType::Div; break;}
case (AST::operatorType::Pow) : { op = ASR::binopType::Pow; break; }
case (AST::operatorType::Mod) : { op_name = "_mod"; break; }
case (AST::operatorType::BitOr) : { op_name = "_bitwise_or"; break; }
case (AST::operatorType::BitAnd) : { op_name = "_bitwise_and"; break; }
case (AST::operatorType::BitXor) : { op_name = "_bitwise_xor"; break; }
case (AST::operatorType::LShift) : { op_name = "_bitwise_lshift"; break; }
case (AST::operatorType::RShift) : { op_name = "_bitwise_rshift"; break; }
case (AST::operatorType::Mod) : { op = ASR::binopType::Mod; break; }
case (AST::operatorType::BitOr) : { op = ASR::binopType::BitOr; break; }
case (AST::operatorType::BitAnd) : { op = ASR::binopType::BitAnd; break; }
case (AST::operatorType::BitXor) : { op = ASR::binopType::BitXor; break; }
case (AST::operatorType::LShift) : { op = ASR::binopType::BitLShift; break; }
case (AST::operatorType::RShift) : { op = ASR::binopType::BitRShift; break; }
default : {
throw SemanticError("Binary operator type not supported",
x.base.base.loc);
}
}
left = cast_helper(ASRUtils::expr_type(right), left);
right = cast_helper(ASRUtils::expr_type(left), right);
Vec<ASR::call_arg_t> args;
args.reserve(al, 2);
ASR::call_arg_t arg1, arg2;
arg1.loc = left->base.loc;
arg1.m_value = left;
args.push_back(al, arg1);
arg2.loc = right->base.loc;
arg2.m_value = right;
args.push_back(al, arg2);
if (op_name != "") {
ASR::symbol_t *fn_mod = resolve_intrinsic_function(x.base.base.loc, op_name);
tmp = make_call_helper(al, fn_mod, current_scope, args, op_name, x.base.base.loc);
return;
}
bool floordiv = (x.m_op == AST::operatorType::FloorDiv);
make_BinOp_helper(left, right, op, x.base.base.loc, floordiv);
}
Expand Down

0 comments on commit 63dc43e

Please sign in to comment.