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

Block expressions in binary operations are wonky and cause errors #1

Closed
sand-head opened this issue Jul 4, 2021 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@sand-head
Copy link
Owner

the following code throws a type error at runtime:

let test = "1" + {
  let test2 = 15;
  test2 / 3
};

this is the debug result:

== code ==
0000 #0001 Constant 0001 "1"
0001 #0002 Constant 0002 15 
0002 #0003 GetLocal(0)      
0003 #0003 Constant 0003 3  
0004 #0003 Divide
0005 #0004 Pop
0006 #0004 Add
0007 #0004 DefineGlobal(0)
0008 #0004 Return

0001 #0001 Constant 0001 "1"
        ["1"]
0002 #0002 Constant 0002 15
        ["1"][15]
0003 #0003 GetLocal(0)
        ["1"][15]["1"]
0004 #0003 Constant 0003 3
        ["1"][15]["1"][3]
0005 #0003 Divide
[!] Runtime error: Type error: expected value of type "number", found "1".

resolving locals doesn't work when there are other values in the stack, as it recognizes 15 as the value of the first local and assumes it to be at stack index 0, when it isn't. this is probably covered in the book during the function chapter but I haven't read it yet

@sand-head sand-head added the bug Something isn't working label Jul 4, 2021
@sand-head
Copy link
Owner Author

ok I fixed this by compiling literally all block expressions as functions. this is probably overkill but I can tweak it later down the line

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