Skip to content

Commit

Permalink
Make it work for integers
Browse files Browse the repository at this point in the history
  • Loading branch information
namannimmo10 authored and certik committed Jun 21, 2022
1 parent 63dc43e commit c40f41e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,24 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
case (ASR::binopType::Mul): { result = left_value * right_value; break; }
case (ASR::binopType::Div): { result = left_value / right_value; break; }
case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; }
case (ASR::binopType::Mod): { result = left_value % right_value; break; }
case (ASR::binopType::BitAnd): { result = left_value & right_value; break; }
case (ASR::binopType::BitOr): { result = left_value | right_value; break; }
case (ASR::binopType::BitXor): { result = left_value ^ right_value; break; }
case (ASR::binopType::BitLShift): {
if (right_value < 0) {
throw SemanticError("Negative shift count not allowed.", loc);
}
result = left_value << right_value;
break;
}
case (ASR::binopType::BitRShift): {
if (right_value < 0) {
throw SemanticError("Negative shift count not allowed.", loc);
}
result = left_value >> right_value;
break;
}
default: { LFORTRAN_ASSERT(false); } // should never happen
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_IntegerConstant_t(
Expand Down

0 comments on commit c40f41e

Please sign in to comment.