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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
added Ruby code generator #206
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 馃憤 Left a few points for your consideration.
|
||
def interpret_bin_num_expr(self, expr, **kwargs): | ||
if expr.op == ast.BinNumOpType.DIV: | ||
# Always force float result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A brief explanation why would be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find using fdiv
less polluting code than explicit converting every number to float with .to_f
method.
self.add_block_termination() | ||
|
||
def method_invocation(self, method_name, obj, args): | ||
return ("(" + str(obj) + ")." + method_name + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these parentheses (the ones in code not in string)? It makes the code a bit harder to digest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, while I'm on it, why do we need parentheses around the object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my initial mistake to not use these parentheses 馃槂 . It was caught by one of our e2e tests. Then I realized that
1.0 + 2.0.fdiv(3)
is not the same as (1.0 + 2.0).fdiv(3)
.
UPD:
We use the same in other interpreters:
m2cgen/m2cgen/interpreters/code_generator.py
Line 160 in c3426aa
tpl_infix_expression = CodeTemplate("(${left}) ${op} (${right})") |
Note parentheses around
left
and right
operands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, makes perfect sense 馃憤
Ruby is in top15 TIOBE latest rating: https://www.tiobe.com/tiobe-index/. 馃檪
I expect that adding Ruby support will be demanded not only in pure Ruby itself, but in Ruby on Rails web framework which is among popular frameworks: 1, 2.