-
Notifications
You must be signed in to change notification settings - Fork 2
ClosureRec
jean-dao edited this page Mar 3, 2012
·
3 revisions
The closurerec
intsruction constructs nested closures.
closurerec nfuncs nvars ofs...
with:
nfuncs: number of code offset to be given.
nvars: number of value to add to the environment. The first is in the accu, the rest on the stack.
ofs: several offsets may be given. Code offset to all functions involved.
- If
nvars > 0
the accu is pushed onto the stack, thus all vars are on the stack. - Some space is allocated for the closure. A pointer to this space is put in the accu.
- The variables are stored in the closure and then removed from the stack.
- The first offset is stored as the closure's code pointer.
- The closure's pointer, still in the accu, is pushed onto the stack.
- For all remaining code offsets:
- A closure is created with it. The following closure (if any) will be view as a (special) variable.
- A pointer to this closure is pushed onto the stack.
A nested closure fills 2 words: a header and the code pointer. It is directly stored in the parent closure, so the main closure contains all others, memory space speaking.
Since each variable takes up 1 field (= 1 word), nested closure are not accessed like regular variables with ENVACC
, which stores the value of a field in the accu, but with OFFSETCLOSURE
, which stores a pointer to the requested closure in the accu.