Constructor
new FishStack(program, initialStackopt)
Creates a new FishStack
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
program |
FishProgram | The program this stack is part of | |
initialStack |
Array.<Number> |
<optional> |
Initial stack of the program. Defaults to an empty stack |
- Source:
Members
(readonly) length :Integer
Number of elements in the stack
Type:
- Integer
- Source:
(readonly) register :Number
The program's register
Type:
- Number
- Source:
(readonly) snapshot :Array.<Number>
A snapshot of the stack
Type:
- Array.<Number>
- Source:
Methods
$()
Swaps the two top elements of the stack
- Source:
Throws:
-
If the stack does not contain at least two elements
- Type
- Error
&()
Manipulates the register. If it is empty, pops the top value and puts it in the registry. Otherwise, take the registry value and push it to the stack, leaving a `null` in the registry
- Source:
:()
Duplicates the top element of the stack, making the two top elements equal
- Source:
Throws:
-
If the stack is empty
- Type
- Error
@()
Swaps the three top elements, shifting them rightwards (e.g. if your stack is 1,2,3,4, calling @ results in 1,4,2,3)
- Source:
Throws:
-
If the stack does not contain at least three elements
- Type
- Error
[()
Pop x off the stack and create a new stack, moving x values from the old stack onto the new one
- Source:
Throws:
-
If the stack is empty or does not contain x+1 values
- Type
- Error
]()
Removes the current stack, putting its values onto the one below it. If there is no stack below, the stack and register is emptied
- Source:
l()
Pushes the length of the stack onto the stack
- Source:
pop()
Pops the top value off the stack
- Source:
Throws:
-
If the stack is empty
- Type
- Error
push(number)
Pushes a number onto the stack
Parameters:
| Name | Type | Description |
|---|---|---|
number |
Number | The number to push |
- Source:
Throws:
-
If anything but a number was given
- Type
- Error
r()
Reverses the entire stack
- Source:
{()
Shifts the entire stack left. 1,2,3,4 -> 2,3,4,1
- Source:
Throws:
-
If the stack is empty
- Type
- Error
}()
Shifts the entire stack right. 1,2,3,4 -> 4,1,2,3
- Source:
Throws:
-
If the stack is empty
- Type
- Error
~()
Removes the top element from the stack
- Source:
Throws:
-
If the stack is empty
- Type
- Error