- Execution Stack
- Object Heap
- Message Queue
When a context is to be executed an execution context is created on the stack. If the executing code makes a call to function then an execution context for the called function is created and pushed onto the the stack. Once the currently executing context completes its execution context is popped of the stack.
There are three types of context:
- Global - code outside of any function.
- Function - code that is defined in a function.
- Eval - code from an eval statement.
This is a stack frame that conceptually contains three things:
- Variable object - the functions vars, function definitions, and function arguments
- Scope chain - a structure that references the functions ancestors “Variable objects”
- this object reference
Note - it is the Scope chain that makes clojures work.
When an identifier is references the Variable object is checked first then it uses the Scope chain checking the most recent ancestor first.
All objects are allocated in a heap which is just a name to denote a large mostly unstructured region of memory.
This is a list of messages to be processed, each message has a function associated with it. When the execution stack is empty a message is taken of the queue and processed. The processing consists of executing the messages associated function.