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

There is a case that the bytecode does not be outputted. #258

Closed
Kray-G opened this issue Mar 31, 2021 · 0 comments
Closed

There is a case that the bytecode does not be outputted. #258

Kray-G opened this issue Mar 31, 2021 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Kray-G
Copy link
Owner

Kray-G commented Mar 31, 2021

Problem

In the following conditions, the bytecode does not be outputted unfortunately.

  • It is const declaration
  • It has an initializer which is not constant.
  • By a constant folding after analyzing AST, it has been fold to constant such as integer.

Then, the code generator will remove the code because it is a constant and it assumed to be propagated.

Cause

A constant folding is done first before analyzing AST.
After that, analyzing AST will propagate a constant to variables referencing it.
The problem is that a constant folding is done again after analyzing AST.

If the const variable becomes a constant value in the 2nd constant folding phase, the code generator will omit to generate a code even though it has not been propagated.

Code To Reproduce

In the following code, N can be removed because a variable which references it will use directly 3 as a constant. On the other hand, R will be removed but it is a problem because the number 9 has not been correctly propagated yet.

const X = 10;
const Y = X + X;
System.println(Y);

It displays nothing.

Workaround

  1. Replace const by var, or
  2. Write const Y = 20; directly, or
  3. Write it like var YY = X + X; const Y = YY;, if you want Y to be const and to calculate Y by X.
@Kray-G Kray-G self-assigned this Mar 31, 2021
@Kray-G Kray-G added the bug Something isn't working label Mar 31, 2021
@Kray-G Kray-G added this to the v1.1.0 milestone Mar 31, 2021
@Kray-G Kray-G closed this as completed in 9a10e8b Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant