Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Local variables for function are empty after any call #5

@blapaz

Description

@blapaz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions