(updatable) or ”n” (not updatable) Our language is lazy, so after evaluation of suspended computation, we should update something, to not evaluate the same code again but maybe already during compilation we can deduce, that we won’t have to update some closures? functions with non-empty argument list - they don’t need updating partial applications - the same ( vs \n {} -> f {x1, ..., xm} ) saturated constructor - the same thunks - these are rather updatable Rafal Lasocha Haskell compiler
stack, update stack, heap, global environment value, on the argument stack are either heap addresses or primitive integers 4 possible states of compiler Eval e p - evaluate expression e in environemnt p Enter a - apply the closure at address a to the arguments on the argument stack ReturnCon c ws - Return the constructor c applied to values ws to the continuation on the return stack ReturnInt k - Return the primitive integer k to the continuation on the return stack Rafal Lasocha Haskell compiler
is an address of the updatable closure we try to Enter (Enter a) clean argument and return stacks, and save triple (”update frame”) (as, rs, a) to the update frames stack now just evaluate and wait until our program ”crash” because lack of values in either return stack or argument stack Rafal Lasocha Haskell compiler
be C it’s not perfect, it’s not very efficient, but it works mapping haskell functions to C functions doesn’t work each closure becomes C function, but without arguments stacks will be managed by us but subsequently entering functions will cause our stack to grow... while (TRUE) { cont = (*cont)(); } Rafal Lasocha Haskell compiler
evacuating code handles moving specific closure from 1st space to 2nd it also overrides in 1st space with forwarding pointer ... and returns new closure address to the caller scavenging code knows how to iterate evacuating code on each pointer in closure it also replace old pointers with new ones forwarding pointers - simple return of associated pointer Rafal Lasocha Haskell compiler
STG has two stack pointers - one for integers, and one for pointers. # apply3 = {} \n {f,x} -> f {x,x,x} Node = SpA[0] t = SpA[1] SpA[0] = t SpA[-1] = t SpA = SpA - 1 ENTER( Node ) # Node is a closure, not code ptr Rafal Lasocha Haskell compiler