-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_ops.bscript
More file actions
119 lines (105 loc) Β· 2.79 KB
/
stack_ops.bscript
File metadata and controls
119 lines (105 loc) Β· 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Stack
OP_TOALTSTACK β
// - Puts the input onto the top of the alt stack. Removes it from the main stack.
// => OP_TOALTSTACK
// => STACK = [ 0x10 ]
// => ALT_STACK = []
// ...
// STACK = []
// ALT_STACK = [ 0x10 ]
OP_FROMALTSTACK β
// - Puts the input onto the top of the main stack. Removes it from the alt stack.
// => OP_TOALTSTACK
// => STACK = []
// => ALT_STACK = [ 0x10 ]
// ...
// STACK = [ 0x10 ]
// ALT_STACK = []
OP_IFDUP β
// - If the top stack value is not 0, duplicate it.
// => OP_IFDUP
// => STACK = [ 0x10 ]
// ...
// STACK = [ 0x10 0x10 ]
OP_DEPTH β
// - Puts the number of stack items onto the stack.
// => OP_DEPTH
// => STACK = [ 0x10 0x20 0x30 ]
// ...
// STACK = [ 0x03 0x10 0x20 0x30 ]
OP_DROP / [OP_2DROP] β
// - Removes the top stack item.
// - [Removes the top two stack items.]
// => OP_DROP
// => STACK = [ 0x10 0x20 ]
// ...
// STACK = [ 0x20 ]
OP_DUP / [OP_2DUP] / [[OP_3DUP]] β
// - Duplicates the top stack item.
// - [Duplicates the top two stack items (in same order)]
// - [[Duplicates the top three stack items (in same order)]]
// => OP_DUP
// => STACK = [ 0x10 0x20 ]
// ...
// STACK = [ 0x10 0x10 0x20 ]
OP_NIP β
// - Removes the second-to-top stack item.
// => OP_NIP
// => STACK = [ 0x20 0x10 0x30 ]
// ...
// STACK = [ 0x20 0x30 ]
OP_OVER / [OP_2OVER] β
// - Copies the second-to-top stack item to the top.
// - [Copies the pair of items two spaces back in the stack to the front.]
// => OP_OVER
// => STACK = [ 0x30 0x20 0x10 ]
// ...
// STACK = [ 0x20 0x30 0x20 0x10 ]
OP_PICK β
// - The item n back in the stack is copied to the top.
// => 1 2 3 4 2 OP_PICK
// => STACK = []
// ...
// => 2 OP_PICK
// => STACK = [ 4 3 2 1 ]
// numbering 1 2 3 4
// => copies the 2nd item from the top of the stack to the top of the stack
// ...
// STACK = [ 3 4 3 2 1 ]
OP_ROLL β
// - The item n back in the stack is moved to the top.
// => 1 2 3 4 2 OP_ROLL
// => STACK = []
// ...
// => 2 OP_ROLL
// => STACK = [ 4 3 2 1 ]
// numbering 1 2 3 4
// => moves the second element [3] to the top of the stack
// ...
// STACK = [ 3 4 2 1 ]
OP_ROT / [OP_2ROT] β
// - The 3rd item down the stack is moved to the top.
// - [The fifth and sixth items back are moved to the top of the stack.]
// => OP_ROT
// => STACK = [ 3 2 1 ]
// ...
// STACK = [ 1 3 2 ]
OP_SWAP / [OP_2SWAP] β
// - The top two items on the stack are swapped.
// - [Swaps the top two pairs of items.]
// => OP_SWAP
// => STACK = [ 1 2 3 4 ]
// ...
// STACK = [ 2 1 3 4 ]
OP_TUCK β
// - The item at the top of the stack is copied and inserted before the second-to-top item.
// => OP_TUCK
// => STACK = [ 1 2 3 4 ]
// ...
// STACK = [ 1 2 1 3 4 ]
OP_SIZE β
// - Pushes the string length of the top element of the stack (without popping it).
// => OP_SIZE
// => STACK = [ "fruit" ]
// ...
// STACK = [ 0x05 "fruit" ]