Next: 2.4 Standard I/O Up: 2. Onyx Language Reference Previous: 2.2 Syntax Contents Index

# 2.3 Stacks

Stacks in Onyx are the core data structure that programs act on. Stacks store objects in a last in, first out (LIFO) order. Onyx includes a number of operators that manipulate stacks.

Each Onyx thread has five program-visible stacks associated with it:

Operand stack (ostack):
  Most direct object manipulations are done using the operand stack. Operators use the operand stack for inputs and outputs, and code generally uses the operand stack for a place to store objects as they are being manipulated.
Dictionary stack (dstack):
  The dictionary stack is used for looking up names. Each thread starts with with four dictionaries on its dictionary stack, which are, from top to bottom:
  - userdict
  - globaldict
  - systemdict
  - threaddict
  The dictionary stack is normally manipulated via the begin and end operators. The initial dictionaries on the dictionary stack should not generally be removed, since doing so can cause interpreter crashes.
Context stack (cstack):
  The context stack supports Onyx's object-oriented programming facilities. The topmost object on the context stack (either a class or an instance) is used by the Onyx interpreter to look up methods and data. That object is known as ``this'' in object-oriented programming parlance, and can be quickly accessed via the this operator.
Execution stack (estack):
  The interpreter uses the execution stack to store objects that are being executed. The application generally does not need to explicitly manipulate the execution stack, but its contents are accessible, mainly for debugging purposes.
Index stack (istack):
  The interpreter uses the index stack to store execution offsets for arrays that are being executed. There is a one to one correspondence of the elements of the execution stack to the elements of the index stack, even though the elements of the index stack that do not correspond to arrays have no meaning. The index stack does not affect execution, and exists purely to allow useful execution stack traces when errors occur.

The application can also create additional stacks and manipulate them in much the same way as the operand stack can be manipulated.

Next: 2.4 Standard I/O Up: 2. Onyx Language Reference Previous: 2.2 Syntax Contents Index