visualqub
The visualqub shows how a stack machine works. You can write a program and watch the execution step by step.
Contents
1. Screen layout
1.1. Display
Top: program text.
Bottom left: output stack, data stack.
1.2. Controls
Bottom right: numeric panel / control panel.
Left: program panel.
2. Numeric panel
2.1. General
| [.] dot | n — | { output = n } |
| [<] backspace | { erase } |
2.2. Numbers
| button | effect | description |
|---|---|---|
| 0..9 | { buffer += digit } |
|
| [ ] space | — n | { n = int(buffer) } |
2.3. Arithmetic
| button | effect | description |
|---|---|---|
| + | x y — n | { n = x + y } |
| - | x y — n | { n = x - y } |
| * | x y — n | { n = x * y } |
| / | x y — r q | { (quotient, remainder) = x / y } |
2.4. Memory
| button | effect | description |
|---|---|---|
| X! | x — | { X = n } |
| X? | — x | { n = X } |
| Y! | x — | { Y = n } |
| Y? | — x | { n = Y } |
3. Control panel
3.1. Logical operators
| operator | effect | description |
|---|---|---|
| AND | x y — n | if (x==0 || y==0) { n = 0 } else { n = -1 } |
| OR | x y — n | if (x<>0 && y<>0) { n = 0 } else { n = -1 } |
| NOT | x — n | if (x==0) { n = -1 } else { n = 0 } |
3.2. Relational operators
| operator | effect | description |
|---|---|---|
| < | x y — b | if (x<y) { b = -1 } else { b= 0 } |
| > | x y — b | if (x>y) { b = -1 } else { b = 0 } |
| = | x y — b | if (x==y) { b = -1 } else { b = 0 } |
3.3. Control flow
| operator | effect | description |
|---|---|---|
| BEGIN ... WHILE | x — | do { ... } while (x<>0) |
| IF ... THEN | x — | if (x<>0) { ... } |
3.4. Stack operators
| operator | effect | description |
|---|---|---|
| DUP | x y — x y y | duplicate top of data stack |
| OVER | x y — x y x | duplicate second of data stack |
| DROP | x y — x | remove top of data stack |
| SWAP | x y — y x | { x, y = y, x } |
4. Program panel
| button | effect | description |
|---|---|---|
| CLEAR | clear the program text |
|
| EMPTY | xxx — | empty the data and output stacks |
| ABORT | abort execution, rewind the cursor, clear variables and messages |
|
| STEP | execute the word under the cursor |
|
| RUN | step every second |
5. Source code
5.1. Graphical interface
Image. ImageList
Button. Image, Hit test, Handler.
Panel.
Font.
String. stralign
5.2. Virtual machine
Stack. Data, Output, Control
Word.
Exception.
Message.
Automation.