Calling a function within itself will use and may rewrite the same memory previously
Closed this issue · 2 comments
This is due to functions and scopes using global memory instead of their own stack (which was a lazy thing I did 8 months ago.)
Example:
Function f() has variable Y declared inside it.
f() calls itself twice, in the first call Y is unmodified.
In the second call, Y is set to x.
Y will be set to x to all instances of f()
To fix this, I'll be adding two new instructions to the virtual machine: LSTORE and LLOAD, which'll store memory in each function's stack frame, which will be popped once the function ends (which'll save memory as global memory never gets deleted).
This'll introduce a new problem when returning a value from a function, but I'm sure I'll figure it out.
Fixed, but instructions not implemented to compiler yet.