Closed tomv42 closed 4 months ago
Hi Tom, great work; I will try the code tomorrow, but I already have some requests:
Thank you for your feedback.
test_int.py
to test the exponentiation (**
) operator.mul
could not multiply operands of different sizes (e.g., a ** 3
resulted in a * a * a
where intermediate results have different sizes).
Description:
This PR addresses the issue of implementing the
ast.Pow
operator (**
) between a variable and an integer constant. The goal is to rewrite the exponentiation operation as a series of multiplication operations. The following changes have been made:visit_BinOp
method to handleast.Pow
nodes:a ** n
asa * a * ... * a
(n times).visit_Pow
becauseast.Pow
is not visited directly but as part ofast.BinOp
.Testing:
a ** n
is correctly transformed intoa * a * ... * a
for positive integer constants.visit_BinOp
method.Explanation:
I focused on overriding the
visit_BinOp
method to handle theast.Pow
operator. My understanding is thatvisit_Pow
is not applicable here becauseast.Pow
is an operator within aBinOp
node rather than a standalone node. Thus,visit_BinOp
seemed to be the appropriate place to implement this transformation. I'm not entirely sure if this is the best approach, but it appears to work based on my testing.Related Issue:
This PR resolves issue #23
Please review these changes and provide feedback :smile: