forked from jamesbowman/camelforth-z80
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglosshi.txt
184 lines (175 loc) · 8.51 KB
/
glosshi.txt
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
TABLE 1. GLOSSARY OF "HIGH LEVEL" WORDS
(files CAMEL80D.AZM and CAMEL80H.AZM)
NAME stack in -- stack out description
Guide to stack diagrams: R: = return stack,
c = 8-bit character, flag = boolean (0 or -1),
n = signed 16-bit, u = unsigned 16-bit,
d = signed 32-bit, ud = unsigned 32-bit,
+n = unsigned 15-bit, x = any cell value,
i*x j*x = any number of cell values,
a-addr = aligned adrs, c-addr = character adrs
p-addr = I/O port adrs, sys = system-specific.
Refer to ANS Forth document for more details.
ANS Forth Core words
These are required words whose definitions are
specified by the ANS Forth document.
# ud1 -- ud2 convert 1 digit of output
#S ud1 -- ud2 convert remaining digits
#> ud1 -- c-addr u end conv., get string
' -- xt find word in dictionary
( -- skip input until )
* n1 n2 -- n3 signed multiply
*/ n1 n2 n3 -- n4 n1*n2/n3
*/MOD n1 n2 n3 -- n4 n5 n1*n2/n3, rem & quot
+LOOP adrs -- L: 0 a1 a2 .. aN --
, x -- append cell to dict
/ n1 n2 -- n3 signed divide
/MOD n1 n2 -- n3 n4 signed divide, rem & quot
: -- begin a colon definition
; end a colon definition
<# -- begin numeric conversion
>BODY xt -- a-addr adrs of param field
>IN -- a-addr holds offset into TIB
>NUMBER ud adr u -- ud' adr' u'
convert string to number
2DROP x1 x2 -- drop 2 cells
2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 per diag
2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2 per diagram
2! x1 x2 a-addr -- store 2 cells
2@ a-addr -- x1 x2 fetch 2 cells
ABORT i*x -- R: j*x -- clear stack & QUIT
ABORT" i*x 0 -- i*x R: j*x -- j*x print msg &
i*x x1 -- R: j*x -- abort,x1<>0
ABS n1 -- +n2 absolute value
ACCEPT c-addr +n -- +n' get line from terminal
ALIGN -- align HERE
ALIGNED addr -- a-addr align given addr
ALLOT n -- allocate n bytes in dict
BASE -- a-addr holds conversion radix
BEGIN -- adrs target for backward branch
BL -- char an ASCII space
C, char -- append char to dict
CELLS n1 -- n2 cells->adrs units
CELL+ a-addr1 -- a-addr2 add cell size to adrs
CHAR -- char parse ASCII character
CHARS n1 -- n2 chars->adrs units
CHAR+ c-addr1 -- c-addr2 add char size to adrs
COUNT c-addr1 -- c-addr2 u counted->adr/len
CR -- output newline
CREATE -- create an empty definition
DECIMAL -- set number base to decimal
DEPTH -- +n number of items on stack
DO -- adrs L: -- 0 start of DO..LOOP
DOES> -- change action of latest def'n
ELSE adrs1 -- adrs2 branch for IF..ELSE
ENVIRONMENT? c-addr u -- false system query
EVALUATE i*x c-addr u -- j*x interpret string
FIND c-addr -- c-addr 0 ..if name not found
xt 1 ..if immediate
xt -1 ..if "normal"
FM/MOD d1 n1 -- n2 n3 floored signed division
HERE -- addr returns dictionary pointer
HOLD char -- add char to output string
IF -- adrs conditional forward branch
IMMEDIATE -- make last def'n immediate
LEAVE -- L: -- adrs exit DO..LOOP
LITERAL x -- append numeric literal to dict.
LOOP adrs -- L: 0 a1 a2 .. aN --
MAX n1 n2 -- n3 signed maximum
MIN n1 n2 -- n3 signed minimum
MOD n1 n2 -- n3 signed remainder
MOVE addr1 addr2 u -- smart move
M* n1 n2 -- d signed 16*16->32 multiply
POSTPONE -- postpone compile action of word
QUIT -- R: i*x -- interpret from keyboard
RECURSE -- recurse current definition
REPEAT adrs1 adrs2 -- resolve WHILE loop
SIGN n -- add minus sign if n<0
SM/REM d1 n1 -- n2 n3 symmetric signed division
SOURCE -- adr n current input buffer
SPACE -- output a space
SPACES n -- output n spaces
STATE -- a-addr holds compiler state
S" -- compile in-line string
." -- compile string to print
S>D n -- d single -> double precision
THEN adrs -- resolve forward branch
TYPE c-addr +n -- type line to terminal
UNTIL adrs -- conditional backward branch
U. u -- display u unsigned
. n -- display n signed
WHILE -- adrs branch for WHILE loop
WORD char -- c-addr n parse word delim by char
[ -- enter interpretive state
[CHAR] -- compile character literal
['] -- find word & compile as literal
] -- enter compiling state
ANS Forth Extensions
These are optional words whose definitions are
specified by the ANS Forth document.
.S -- print stack contents
/STRING a u n -- a+n u-n trim string
AGAIN adrs -- uncond'l backward branch
COMPILE, xt -- append execution token
DABS d1 -- +d2 absolute value, dbl.prec.
DNEGATE d1 -- d2 negate, double precision
HEX -- set number base to hex
PAD -- a-addr user PAD buffer
TIB -- a-addr Terminal Input Buffer
WITHIN n1|u1 n2|u2 n3|u3 -- f test n2<=n1<n3?
WORDS -- list all words in dict.
Private Extensions
These are words which are unique to CamelForth.
Many of these are necessary to implement ANS
Forth words, but are not specified by the ANS
document. Others are functions I find useful.
!CF adrs cfa -- set code action of a word
!COLON -- change code field to docolon
!DEST dest adrs -- change a branch dest'n
#INIT -- n #bytes of user area init data
'SOURCE -- a-addr two cells: len, adrs
(DOES>) -- run-time action of DOES>
(S") -- c-addr u run-time code for S"
,BRANCH xt -- append a branch instruction
,CF adrs -- append a code field
,DEST dest -- append a branch address
,EXIT -- append hi-level EXIT action
>COUNTED src n dst -- copy to counted str
>DIGIT n -- c convert to 0..9A..Z
>L x -- L: -- x move to Leave stack
?ABORT f c-addr u -- abort & print msg
?DNEGATE d1 n -- d2 negate d1 if n negative
?NEGATE n1 n2 -- n3 negate n1 if n2 negative
?NUMBER c-addr -- n -1 convert string->number
-- c-addr 0 if convert error
?SIGN adr n -- adr' n' f get optional sign
advance adr/n if sign; return NZ if negative
CELL -- n size of one cell
COLD -- cold start Forth system
COMPILE -- append inline execution token
DIGIT? c -- n -1 ..if c is a valid digit
-- x 0 ..otherwise
DP -- a-addr holds dictionary ptr
ENDLOOP adrs xt -- L: 0 a1 a2 .. aN --
HIDE -- "hide" latest definition
HP -- a-addr HOLD pointer
IMMED? nfa -- f fetch immediate flag
INTERPRET i*x c-addr u -- j*x
interpret given buffer
L0 -- a-addr bottom of Leave stack
LATEST -- a-addr last word in dictionary
LP -- a-addr Leave-stack pointer
L> -- x L: x -- move from Leave stack
NFA>CFA nfa -- cfa name adr -> code field
NFA>LFA nfa -- lfa name adr -> link field
R0 -- a-addr end of return stack
REVEAL -- "reveal" latest definition
S0 -- a-addr end of parameter stack
TIBSIZE -- n size of TIB
U0 -- a-addr current user area adrs
UD* ud1 d2 -- ud3 32*16->32 multiply
UD/MOD ud1 u2 -- u3 ud4 32/16->32 divide
UINIT -- addr initial values for user area
UMAX u1 u2 -- u unsigned maximum
UMIN u1 u2 -- u unsigned minimum