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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Ruby code generator #206

Merged
merged 2 commits into from May 13, 2020
Merged

added Ruby code generator #206

merged 2 commits into from May 13, 2020

Conversation

StrikerRUS
Copy link
Member

Ruby is in top15 TIOBE latest rating: https://www.tiobe.com/tiobe-index/. 馃檪

image

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.

@coveralls
Copy link

coveralls commented May 7, 2020

Coverage Status

Coverage increased (+0.04%) to 95.641% when pulling b39ee53 on ruby into 7626a60 on master.

Copy link
Member

@izeigerman izeigerman left a 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
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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 +
Copy link
Member

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

Copy link
Member

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?

Copy link
Member Author

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:

tpl_infix_expression = CodeTemplate("(${left}) ${op} (${right})")

Note parentheses around left and right operands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, makes perfect sense 馃憤

@izeigerman izeigerman merged commit e4eccc5 into master May 13, 2020
@izeigerman izeigerman deleted the ruby branch May 13, 2020 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants