The old runtime environment representation is a variant of SECD machine.
Although there is an optimization that the local variable is optimized to not allocate in Env (heap), the env object itself is still there.
After this commit, the runtime representation is just like the C language -- no Environment!
I use closure convert to collect the free variable in the Closure struct.
In the calling protocol, args[0] is the closure object itself, so the free variable is accessible through args[0]->parent->parent->freeVars[n]
The Closure struct will record the it closed free variable, and also the parent closure within which it's created.
This runtime representation is much efficient than before, it avoid the allocating of Environment object in every call.
Run shen-go test:
Continue with https://github.com/tiancaiamao/shen-go/pull/32/
The old runtime environment representation is a variant of SECD machine. Although there is an optimization that the local variable is optimized to not allocate in Env (heap), the env object itself is still there.
After this commit, the runtime representation is just like the C language -- no Environment! I use closure convert to collect the free variable in the Closure struct. In the calling protocol, args[0] is the closure object itself, so the free variable is accessible through
args[0]->parent->parent->freeVars[n]
The Closure struct will record the it closed free variable, and also the parent closure within which it's created.This runtime representation is much efficient than before, it avoid the allocating of Environment object in every call. Run shen-go test: