G-Machine State Transition Rules¶
Core Transition Rules¶
Lookup a global by name and push its value onto the stack
Allocate an int node on the heap, and push the address of the newly created node onto the stack
Allocate an application node on the heap, applying the top of the stack to the address directly below it. The address of the application node is pushed onto the stack.
Push a function’s argument onto the stack
Tidy up the stack after instantiating a supercombinator
If a number is on top of the stack,
Unwindleaves the machine in a halt state
If an application is on top of the stack,
Unwindcontinues unwinding
When a supercombinator is on top of the stack (and the correct number of arguments have been provided),
Unwindsets up the stack and jumps to the supercombinator’s code (-reduction)
Pop the stack, and update the nth node to point to the popped address
Pop the stack.
Follow indirections while unwinding
Allocate uninitialised heap space
When unwinding, if the top of the stack is in WHNF, pop the dump
Evaluate the top of the stack to WHNF
Extension Rules¶
A sneaky trick to enable sharing of
NNumnodes. We note that the global environment is a mapping ofNameobjects (i.e. identifiers) to heap addresses. Strings of digits are not considered valid identifiers! We abuse this by modifying Core Rule 2 to update the global environment with the new node’s address. Consider how this rule might impact garbage collection (remember that the environment is intended for globals).
In order for Extension Rule 1. to be effective, we are also required to take action when a number already exists in the environment: