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

[bug] Variables modified inside expressions don't behave correctly #180

Open
JeanJPNM opened this issue Jun 6, 2023 · 0 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@JeanJPNM
Copy link
Collaborator

JeanJPNM commented Jun 6, 2023

I watched this youtube video and noticed that the bug also affects mlogjs.

If we compile the following code and compare its output to the equivalent code in a browser, we see that they diverge:

let a = 1
print(a + ++a);
printFlush();

Generated code:

set a:1:4 1
op add a:1:4 a:1:4 1
op add &t0 a:1:4 a:1:4
print &t0
printflush message1

If we run the equivalent code on the browser, the answer we get is 3, but when running the generated code the answer is 4.

One way to fix this is to make mlogjs create a "security copy" of each value that goes into an expression and remove unused copies.
The first part is trivial (look at #115 and #116) but removing the unused ones requires a rework on the compiler to perform optimizations on an intermediate representation.

@JeanJPNM JeanJPNM changed the title [bug [bug] Variables modified inside expressions don't behave correctly Jun 6, 2023
@JeanJPNM JeanJPNM added the bug Something isn't working label Jun 6, 2023
@JeanJPNM JeanJPNM added this to the v0.7 milestone Jul 7, 2023
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