-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumentation.frt
245 lines (189 loc) · 4.56 KB
/
documentation.frt
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
' drop g"
( a -- )
Drop the topmost element of the stack.
" doc-word
' swap g"
( a b -- b a )
Swap two topmost elements of the stack.
" doc-word
' dup g"
( a - a a )
Duplicate the cell on top of the stack.
" doc-word
' rot g"
( a b c -- b c a )
Rotate three topmost elements of the stack. The 3rd element goes to TOS.
" doc-word
( Arithmetic )
' + g"
( x y -- [ x + y ] )
Add two topmost elements of the stack and place the result on TOS.
" doc-word
' * g"
( y x -- [ x * y ] )
Multiply two topmost elements of the stack and place the result on TOS.
" doc-word
' / g"
( x y -- [ x / y ] )
Divide the 2nd element of the stack by the 1st one and place the quotient on TOS.
" doc-word
' % g"
( x y -- [ x mod y ] )
Divide the 2nd element of the stack by the 1st one and place the remainder on TOS.
" doc-word
' - g"
( x y -- [x - y] )
Subtract the 2nd element of the stack from the 1st one and place the result on TOS.
" doc-word
' < g"
( x y -- [x < y] )
Compare two topmost elements of the stack and place the result on TOS.
The result is 1 if the 2nd element is less than the 1st one. Otherwise, the result is 0.
" doc-word
( Logic )
' not "g
( a -- a' )
Invert the topmost element of the stack. If it's 0, replace TOS with 1, otherwise with 0.
" doc-word
' = g"
( a b -- c )
Compare two topmost elements of the stack and place the result on TOS.
The result is 1 if elements are equal. Otherwise, the result is 0.
" doc-word
' land g"
( a b -- a && b )
Place the result of logical AND operation on two topmost elements of the stack on TOS.
The result is 0 if at least one of the elements is 0.
" doc-word
' lor g"
( a b -- a || b )
Place the result of logical OR operation on two topmost elements of the stack on TOS.
The result is 0 if both of the elements is 0.
" doc-word
( Bitwise )
' and g"
( a b -- a & b )
Place the result of bitwise AND operation on two topmost elements of the stack on TOS.
" doc-word
' or g"
( a b -- a | b )
Place the result of bitwise OR operation on two topmost elements of the stack on TOS.
" doc-word
' ' g"
Read word, find its XT and place on stack (place zero if no such word).
" doc-word
' count g"
( str -- len )
Calculate length of a null-terminated string.
" doc-word
' printc g"
( str cnt -- )
Print a certain amount of characters from string.
" doc-word
' . g"
Drop element from stack and send it to stdout.
" doc-word
' or g"
; .S Shows stack contents. Does not pop elements.
native ".S", show_stack
" doc-word
' init g"
Store the data stack base.
" doc-word
' docol g"
This is the implementation of any colon-word.
" doc-word
' exit g"
Exit from colon word.
" doc-word
' r> g"
Push from return stack into data stack.
" doc-word
' >r g"
Pop from data stack into return stack.
" doc-word
' r@ g"
Non-destructive copy from the top of return stack to the top of data stack.
" doc-word
' find g"
( str_ptr -- header_addr )
Get pointer to the word header in dictionary.
" doc-word
' cfa g"
( word_addr -- xt )
Convert word header start address to the execution token.
" doc-word
' emit g"
( c -- )
Output a single character to stdout.
" doc-word
' word g"
( addr -- len )
Read word from stdin and store it starting at address addr.
Word length is pushed into stack.
" doc-word
' number g"
( str -- num len )
Parse an integer from string.
" doc-word
' prints g"
( addr -- )
Print a null-terminated string.
" doc-word
' bye g"
Exit Forthress.
" doc-word
' syscall g"
( call_num a1 a2 a3 a4 a5 a6 -- new_rax new_rdx)
Execute syscall. According to ABI, the following registers store arguments:
rdi , rsi , rdx , r10 , r8 and r9.
" doc-word
' branch g"
Jump to a location. Location is absolute.
Branch is a compile-only word.
" doc-word
' branch0 g"
Jump to a location if topmost element is 0. Location is absolute.
Branch0 is a compile-only word.
" doc-word
' lit g"
Pushe a value immediately following this XT.
" doc-word
' execute g"
( xt -- )
Execute word with this execution token on TOS.
" doc-word
' lit g"
; @ ( addr -- value ) Fetch value from memory.
" doc-word
' ! g"
( val addr -- )
Store value by address.
" doc-word
' c! g"
( char addr -- )
Store one byte by address.
" doc-word
' c@ g"
( addr -- char )
Read one byte starting at addr.
" doc-word
' , g"
( x -- )
Add x to the word being defined.
" doc-word
' c, g"
( c -- )
Add a single byte to the word being defined.
" doc-word
' create g"
( flags name -- )
Create an entry in the dictionary with the given name.
Only immediate flag is implemented ATM.
" doc-word
' : g"
Read word from current input stream and start defining it.
" doc-word
' ; g"
End the current word definition
" doc-word