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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we need to change how shecc evaluate expression? #28

Closed
eecheng87 opened this issue Nov 5, 2020 · 4 comments
Closed

Do we need to change how shecc evaluate expression? #28

eecheng87 opened this issue Nov 5, 2020 · 4 comments
Assignees

Comments

@eecheng87
Copy link
Collaborator

eecheng87 commented Nov 5, 2020

The way recent shecc evaluating local expression is generating relative arithmetic instruction and calculating in run-time. I think we can change the scheme into evaluating in compile time.

Although it will increase compile time, there're still lots of benefits:

  • we can do more tricks(optimization) on expression because we know the characteristic(value) of the operand before run-time. e.g. quick modulo
  • no operand limit because we use stack. Also we can pass relative test bench in driver.sh(expr 210 "1 + (2 + (3 + (4 + (5 + (6 + (7 + (8 + (9 + (10 + (11 + (12 + (13 + (14 + (15 + (16 + (17 + (18 + (19 + 20))))))))))))))))))")
@eecheng87 eecheng87 changed the title Do we need to change how shecc evaluate expression Do we need to change how shecc evaluate expression? Nov 5, 2020
@sysprog21 sysprog21 deleted a comment from eecheng87 Nov 5, 2020
@jserv
Copy link
Collaborator

jserv commented Nov 5, 2020

The idea is generally making sense. However, we should take the lazy evaluation way. By using eager evaluation, the cfront aggressively computes all the expressions, that would cause unexpected work. Instead, once we keep the operands (and expressions) in the stack, we can then evaluate right before code generation.

@eecheng87
Copy link
Collaborator Author

eecheng87 commented Nov 5, 2020

once we keep the operands (and expressions) in the stack, we can then evaluate right before code generation.

I think stack using in read_expr is for generating proper order to evaluate right expression and I don't think it now can be determined before code generation. Also, in some test case, register will run out when code is generating.

And I am curious about why eager evaluation cause unexpected work? We need to evaluate it anyway, what is difference to do it in advance?

@jserv
Copy link
Collaborator

jserv commented Nov 5, 2020

And I am curious about why eager evaluation cause unexpected work? We need to evaluate it anyway, what is difference to do it in advance?

Lazy evaluation (or call-by-need) delays evaluating an expression until it is actually needed; when it is evaluated, the result is saved so repeated evaluation is not needed. This technique can make some algorithms easier to express compactly or much more efficiently, or both. The binary of shecc might be bootstrapped, which implies less efficient evaluations (and sometimes, buggy).

@jserv
Copy link
Collaborator

jserv commented Dec 7, 2023

Drop this issue in favor of #84

@jserv jserv closed this as completed Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants