-
Notifications
You must be signed in to change notification settings - Fork 94
Portal: Stack
A total of 11 stacks is used in Clojush to run the Push programs. Most of them are used to store different types of data. This portal brings information about stack-based languages and stacks in Clojush.
Stack is a data structure. The feature of a stack could be described with the word LIFO (Last In First Out). Generally, 2 operations are widely used on stacks. push
would add an item on the top of a stack while pop
would get the top item out from a stack. So the item which is pushed into the stack last would be on the top and it would be the first item when we are popping the stack.
A typical stack-based programming language is postscript
. A very basic postscript
code is:
1 2 +
1
and 2
would be pushed into the stack. When the instruction +
is being executed, 2 items would be popped and the result would be pushed back to the stack. Thus in this example, 1
and 2
would be popped and the result is calculated to be 3
, which would be pushed to the stack.
The stack system in Clojush is more complex than the one in postscript
. A Push program contains only instructions. When Clojush is executing an instruction, it would find the inputs from the related stack and after calculating the result would be pushed into the target stack.
For example integer_lt
compares 2 integers and decide whether the first one is lesser than the second one or not. This instruction takes 2 integers as inputs and outputs a boolean value. Thus when it is executed, Clojush would gets the inputs from the :integer
stack and pushes the result into the :boolean
stack.
If there isn’t enough items in the inputing stack, it would be regarded as a no_op
, which stands for "no options". And nothing would be done.