Currently, we are attaching globals tables to codeobjects (KrkCodeObject), as a pointer to an instance object (KrkInstance*). Thus far, this has been fine, as functions (KrkClosure) are only ever built from codeobjects in places where the difference is not visible, but if we want to be able to instantiate functions from codeobjects as one can do in Python, then the ownership of the global context needs to move to the function.
Further, the use of a pointer to an instance is not the best approach here, as it does not allow us to meaningfully use a dict as the globals of a function - all of the current global reference code assumes we are using an instance's fields, but the value table in a dict is not its fields - it is a separate table. We could use a pointer to the relevant table, but this would pose challenges for garbage collection. More investigation should be done here.
Currently, we are attaching globals tables to
codeobject
s (KrkCodeObject
), as a pointer to an instance object (KrkInstance*
). Thus far, this has been fine, asfunction
s (KrkClosure
) are only ever built fromcodeobject
s in places where the difference is not visible, but if we want to be able to instantiatefunction
s fromcodeobject
s as one can do in Python, then the ownership of the global context needs to move to thefunction
.Further, the use of a pointer to an instance is not the best approach here, as it does not allow us to meaningfully use a
dict
as the globals of afunction
- all of the current global reference code assumes we are using an instance's fields, but the value table in adict
is not its fields - it is a separate table. We could use a pointer to the relevant table, but this would pose challenges for garbage collection. More investigation should be done here.