Klip icon indicating copy to clipboard operation
Klip copied to clipboard

Local variables for function are empty after any call

Open blapaz opened this issue 5 years ago • 0 comments

file.txt

import system

function Main()
{
    name = "test"
    PrintLine(name)  // Prints "test"
    PrintLine(name)  // Prints 0
}

When the call block is run, it stores the list items into Call to retrieve later. However, a couple lines later, vars.Clear() is called which also clears the var list and the list in the new Call object.

file.krt

:Main
pushString "test"
setVar name
pushVar name

 // Prints "test" but vars in main call object are being cleared when this is run
call PrintLine
// Variable "name" is not found as far and gets pushed with default value "0"
pushVar name 
// Prints "0"
call PrintLine  

ret

Changing this line to the following will preserve the list when Clear is called: Call c = new Call(currentFunc, code.pos, new List<Var>(vars));

I know this is meant to be a learning tool and not everything complete, but this would make the variables work the way they were intended to.

blapaz avatar Aug 16 '19 14:08 blapaz