| 1 : |
pazsan
|
1.1
|
\ compiler definitions 14sep97jaw |
| 2 : |
|
|
|
| 3 : |
anton
|
1.74
|
\ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005 Free Software Foundation, Inc. |
| 4 : |
anton
|
1.6
|
|
| 5 : |
|
|
\ This file is part of Gforth. |
| 6 : |
|
|
|
| 7 : |
|
|
\ Gforth is free software; you can redistribute it and/or |
| 8 : |
|
|
\ modify it under the terms of the GNU General Public License |
| 9 : |
|
|
\ as published by the Free Software Foundation; either version 2 |
| 10 : |
|
|
\ of the License, or (at your option) any later version. |
| 11 : |
|
|
|
| 12 : |
|
|
\ This program is distributed in the hope that it will be useful, |
| 13 : |
|
|
\ but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 : |
|
|
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 : |
|
|
\ GNU General Public License for more details. |
| 16 : |
|
|
|
| 17 : |
|
|
\ You should have received a copy of the GNU General Public License |
| 18 : |
|
|
\ along with this program; if not, write to the Free Software |
| 19 : |
anton
|
1.29
|
\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
| 20 : |
anton
|
1.6
|
|
| 21 : |
pazsan
|
1.1
|
\ \ Revisions-Log |
| 22 : |
|
|
|
| 23 : |
|
|
\ put in seperate file 14sep97jaw |
| 24 : |
|
|
|
| 25 : |
|
|
\ \ here allot , c, A, 17dec92py |
| 26 : |
|
|
|
| 27 : |
jwilke
|
1.14
|
[IFUNDEF] allot |
| 28 : |
|
|
[IFUNDEF] forthstart |
| 29 : |
|
|
: allot ( n -- ) \ core |
| 30 : |
|
|
dup unused u> -8 and throw |
| 31 : |
|
|
dp +! ; |
| 32 : |
|
|
[THEN] |
| 33 : |
|
|
[THEN] |
| 34 : |
|
|
|
| 35 : |
|
|
\ we default to this version if we have nothing else 05May99jaw |
| 36 : |
|
|
[IFUNDEF] allot |
| 37 : |
pazsan
|
1.1
|
: allot ( n -- ) \ core |
| 38 : |
anton
|
1.23
|
\G Reserve @i{n} address units of data space without |
| 39 : |
|
|
\G initialization. @i{n} is a signed number, passing a negative |
| 40 : |
|
|
\G @i{n} releases memory. In ANS Forth you can only deallocate |
| 41 : |
|
|
\G memory from the current contiguous region in this way. In |
| 42 : |
|
|
\G Gforth you can deallocate anything in this way but named words. |
| 43 : |
|
|
\G The system does not check this restriction. |
| 44 : |
anton
|
1.12
|
here + |
| 45 : |
|
|
dup 1- usable-dictionary-end forthstart within -8 and throw |
| 46 : |
|
|
dp ! ; |
| 47 : |
jwilke
|
1.14
|
[THEN] |
| 48 : |
pazsan
|
1.1
|
|
| 49 : |
crook
|
1.22
|
: c, ( c -- ) \ core c-comma |
| 50 : |
crook
|
1.15
|
\G Reserve data space for one char and store @i{c} in the space. |
| 51 : |
pazsan
|
1.1
|
here 1 chars allot c! ; |
| 52 : |
|
|
|
| 53 : |
crook
|
1.22
|
: , ( w -- ) \ core comma |
| 54 : |
crook
|
1.15
|
\G Reserve data space for one cell and store @i{w} in the space. |
| 55 : |
pazsan
|
1.1
|
here cell allot ! ; |
| 56 : |
|
|
|
| 57 : |
|
|
: 2, ( w1 w2 -- ) \ gforth |
| 58 : |
crook
|
1.15
|
\G Reserve data space for two cells and store the double @i{w1 |
| 59 : |
anton
|
1.24
|
\G w2} there, @i{w2} first (lower address). |
| 60 : |
pazsan
|
1.1
|
here 2 cells allot 2! ; |
| 61 : |
|
|
|
| 62 : |
|
|
\ : aligned ( addr -- addr' ) \ core |
| 63 : |
|
|
\ [ cell 1- ] Literal + [ -1 cells ] Literal and ; |
| 64 : |
|
|
|
| 65 : |
|
|
: align ( -- ) \ core |
| 66 : |
crook
|
1.15
|
\G If the data-space pointer is not aligned, reserve enough space to align it. |
| 67 : |
pazsan
|
1.1
|
here dup aligned swap ?DO bl c, LOOP ; |
| 68 : |
|
|
|
| 69 : |
crook
|
1.22
|
\ : faligned ( addr -- f-addr ) \ float f-aligned |
| 70 : |
pazsan
|
1.1
|
\ [ 1 floats 1- ] Literal + [ -1 floats ] Literal and ; |
| 71 : |
|
|
|
| 72 : |
crook
|
1.22
|
: falign ( -- ) \ float f-align |
| 73 : |
crook
|
1.15
|
\G If the data-space pointer is not float-aligned, reserve |
| 74 : |
|
|
\G enough space to align it. |
| 75 : |
pazsan
|
1.1
|
here dup faligned swap |
| 76 : |
|
|
?DO |
| 77 : |
|
|
bl c, |
| 78 : |
|
|
LOOP ; |
| 79 : |
|
|
|
| 80 : |
anton
|
1.9
|
: maxalign ( -- ) \ gforth |
| 81 : |
anton
|
1.23
|
\G Align data-space pointer for all alignment requirements. |
| 82 : |
pazsan
|
1.1
|
here dup maxaligned swap |
| 83 : |
|
|
?DO |
| 84 : |
|
|
bl c, |
| 85 : |
|
|
LOOP ; |
| 86 : |
|
|
|
| 87 : |
|
|
\ the code field is aligned if its body is maxaligned |
| 88 : |
|
|
' maxalign Alias cfalign ( -- ) \ gforth |
| 89 : |
anton
|
1.24
|
\G Align data-space pointer for code field requirements (i.e., such |
| 90 : |
|
|
\G that the corresponding body is maxaligned). |
| 91 : |
pazsan
|
1.1
|
|
| 92 : |
|
|
' , alias A, ( addr -- ) \ gforth |
| 93 : |
|
|
|
| 94 : |
|
|
' NOOP ALIAS const |
| 95 : |
|
|
|
| 96 : |
|
|
\ \ Header 23feb93py |
| 97 : |
|
|
|
| 98 : |
|
|
\ input-stream, nextname and noname are quite ugly (passing |
| 99 : |
|
|
\ information through global variables), but they are useful for dealing |
| 100 : |
|
|
\ with existing/independent defining words |
| 101 : |
|
|
|
| 102 : |
|
|
defer (header) |
| 103 : |
|
|
defer header ( -- ) \ gforth |
| 104 : |
|
|
' (header) IS header |
| 105 : |
|
|
|
| 106 : |
|
|
: string, ( c-addr u -- ) \ gforth |
| 107 : |
|
|
\G puts down string as cstring |
| 108 : |
|
|
dup c, here swap chars dup allot move ; |
| 109 : |
|
|
|
| 110 : |
anton
|
1.30
|
: longstring, ( c-addr u -- ) \ gforth |
| 111 : |
anton
|
1.55
|
\G puts down string as longcstring |
| 112 : |
anton
|
1.30
|
dup , here swap chars dup allot move ; |
| 113 : |
|
|
|
| 114 : |
pazsan
|
1.1
|
: header, ( c-addr u -- ) \ gforth |
| 115 : |
|
|
name-too-long? |
| 116 : |
anton
|
1.53
|
dup max-name-length @ max max-name-length ! |
| 117 : |
pazsan
|
1.1
|
align here last ! |
| 118 : |
|
|
current @ 1 or A, \ link field; before revealing, it contains the |
| 119 : |
|
|
\ tagged reveal-into wordlist |
| 120 : |
pazsan
|
1.78
|
[ has? f83headerstring [IF] ] |
| 121 : |
|
|
string, |
| 122 : |
|
|
[ [ELSE] ] |
| 123 : |
pazsan
|
1.79
|
longstring, |
| 124 : |
pazsan
|
1.78
|
[ [THEN] ] |
| 125 : |
pazsan
|
1.79
|
cfalign alias-mask lastflags cset ; |
| 126 : |
pazsan
|
1.1
|
|
| 127 : |
|
|
: input-stream-header ( "name" -- ) |
| 128 : |
pazsan
|
1.80
|
parse-name name-too-short? header, ; |
| 129 : |
pazsan
|
1.1
|
|
| 130 : |
|
|
: input-stream ( -- ) \ general |
| 131 : |
|
|
\G switches back to getting the name from the input stream ; |
| 132 : |
|
|
['] input-stream-header IS (header) ; |
| 133 : |
|
|
|
| 134 : |
|
|
' input-stream-header IS (header) |
| 135 : |
|
|
|
| 136 : |
anton
|
1.32
|
2variable nextname-string |
| 137 : |
pazsan
|
1.1
|
|
| 138 : |
pazsan
|
1.33
|
has? OS [IF] |
| 139 : |
pazsan
|
1.1
|
: nextname-header ( -- ) |
| 140 : |
anton
|
1.32
|
nextname-string 2@ header, |
| 141 : |
|
|
nextname-string free-mem-var |
| 142 : |
pazsan
|
1.1
|
input-stream ; |
| 143 : |
pazsan
|
1.33
|
[THEN] |
| 144 : |
pazsan
|
1.1
|
|
| 145 : |
|
|
\ the next name is given in the string |
| 146 : |
|
|
|
| 147 : |
pazsan
|
1.33
|
has? OS [IF] |
| 148 : |
pazsan
|
1.1
|
: nextname ( c-addr u -- ) \ gforth |
| 149 : |
anton
|
1.19
|
\g The next defined word will have the name @var{c-addr u}; the |
| 150 : |
|
|
\g defining word will leave the input stream alone. |
| 151 : |
pazsan
|
1.1
|
name-too-long? |
| 152 : |
anton
|
1.32
|
nextname-string free-mem-var |
| 153 : |
|
|
save-mem nextname-string 2! |
| 154 : |
pazsan
|
1.1
|
['] nextname-header IS (header) ; |
| 155 : |
pazsan
|
1.33
|
[THEN] |
| 156 : |
pazsan
|
1.1
|
|
| 157 : |
|
|
: noname-header ( -- ) |
| 158 : |
|
|
0 last ! cfalign |
| 159 : |
|
|
input-stream ; |
| 160 : |
|
|
|
| 161 : |
|
|
: noname ( -- ) \ gforth |
| 162 : |
anton
|
1.19
|
\g The next defined word will be anonymous. The defining word will |
| 163 : |
|
|
\g leave the input stream alone. The xt of the defined word will |
| 164 : |
anton
|
1.56
|
\g be given by @code{latestxt}. |
| 165 : |
pazsan
|
1.1
|
['] noname-header IS (header) ; |
| 166 : |
|
|
|
| 167 : |
anton
|
1.56
|
: latestxt ( -- xt ) \ gforth |
| 168 : |
crook
|
1.15
|
\G @i{xt} is the execution token of the last word defined. |
| 169 : |
crook
|
1.13
|
\ The main purpose of this word is to get the xt of words defined using noname |
| 170 : |
pazsan
|
1.1
|
lastcfa @ ; |
| 171 : |
|
|
|
| 172 : |
anton
|
1.56
|
' latestxt alias lastxt \ gforth-obsolete |
| 173 : |
|
|
\G old name for @code{latestxt}. |
| 174 : |
|
|
|
| 175 : |
|
|
: latest ( -- nt ) \ gforth |
| 176 : |
|
|
\G @var{nt} is the name token of the last word defined; it is 0 if the |
| 177 : |
|
|
\G last word has no name. |
| 178 : |
|
|
last @ ; |
| 179 : |
|
|
|
| 180 : |
pazsan
|
1.1
|
\ \ literals 17dec92py |
| 181 : |
|
|
|
| 182 : |
|
|
: Literal ( compilation n -- ; run-time -- n ) \ core |
| 183 : |
anton
|
1.27
|
\G Compilation semantics: compile the run-time semantics.@* |
| 184 : |
|
|
\G Run-time Semantics: push @i{n}.@* |
| 185 : |
|
|
\G Interpretation semantics: undefined. |
| 186 : |
jwilke
|
1.14
|
[ [IFDEF] lit, ] |
| 187 : |
|
|
lit, |
| 188 : |
|
|
[ [ELSE] ] |
| 189 : |
anton
|
1.27
|
postpone lit , |
| 190 : |
jwilke
|
1.14
|
[ [THEN] ] ; immediate restrict |
| 191 : |
pazsan
|
1.1
|
|
| 192 : |
anton
|
1.72
|
: 2Literal ( compilation w1 w2 -- ; run-time -- w1 w2 ) \ double two-literal |
| 193 : |
|
|
\G Compile appropriate code such that, at run-time, @i{w1 w2} are |
| 194 : |
|
|
\G placed on the stack. Interpretation semantics are undefined. |
| 195 : |
|
|
swap postpone Literal postpone Literal ; immediate restrict |
| 196 : |
|
|
|
| 197 : |
pazsan
|
1.1
|
: ALiteral ( compilation addr -- ; run-time -- addr ) \ gforth |
| 198 : |
jwilke
|
1.14
|
[ [IFDEF] alit, ] |
| 199 : |
|
|
alit, |
| 200 : |
|
|
[ [ELSE] ] |
| 201 : |
|
|
postpone lit A, |
| 202 : |
|
|
[ [THEN] ] ; immediate restrict |
| 203 : |
pazsan
|
1.1
|
|
| 204 : |
pazsan
|
1.70
|
Defer char@ ( addr u -- char addr' u' ) |
| 205 : |
|
|
:noname over c@ -rot 1 /string ; IS char@ |
| 206 : |
|
|
|
| 207 : |
crook
|
1.8
|
: char ( '<spaces>ccc' -- c ) \ core |
| 208 : |
crook
|
1.15
|
\G Skip leading spaces. Parse the string @i{ccc} and return @i{c}, the |
| 209 : |
|
|
\G display code representing the first character of @i{ccc}. |
| 210 : |
pazsan
|
1.70
|
bl word count char@ 2drop ; |
| 211 : |
pazsan
|
1.1
|
|
| 212 : |
crook
|
1.8
|
: [char] ( compilation '<spaces>ccc' -- ; run-time -- c ) \ core bracket-char |
| 213 : |
crook
|
1.10
|
\G Compilation: skip leading spaces. Parse the string |
| 214 : |
crook
|
1.15
|
\G @i{ccc}. Run-time: return @i{c}, the display code |
| 215 : |
|
|
\G representing the first character of @i{ccc}. Interpretation |
| 216 : |
crook
|
1.10
|
\G semantics for this word are undefined. |
| 217 : |
pazsan
|
1.1
|
char postpone Literal ; immediate restrict |
| 218 : |
|
|
|
| 219 : |
|
|
\ \ threading 17mar93py |
| 220 : |
|
|
|
| 221 : |
|
|
: cfa, ( code-address -- ) \ gforth cfa-comma |
| 222 : |
|
|
here |
| 223 : |
|
|
dup lastcfa ! |
| 224 : |
|
|
0 A, 0 , code-address! ; |
| 225 : |
|
|
|
| 226 : |
jwilke
|
1.14
|
[IFUNDEF] compile, |
| 227 : |
anton
|
1.34
|
defer compile, ( xt -- ) \ core-ext compile-comma |
| 228 : |
|
|
\G Compile the word represented by the execution token @i{xt} |
| 229 : |
|
|
\G into the current definition. |
| 230 : |
|
|
|
| 231 : |
|
|
' , is compile, |
| 232 : |
jwilke
|
1.14
|
[THEN] |
| 233 : |
pazsan
|
1.1
|
|
| 234 : |
pazsan
|
1.80
|
has? ec 0= [IF] |
| 235 : |
anton
|
1.40
|
defer basic-block-end ( -- ) |
| 236 : |
|
|
|
| 237 : |
anton
|
1.60
|
:noname ( -- ) |
| 238 : |
|
|
0 compile-prim1 ; |
| 239 : |
|
|
is basic-block-end |
| 240 : |
pazsan
|
1.80
|
[THEN] |
| 241 : |
anton
|
1.40
|
|
| 242 : |
pazsan
|
1.36
|
has? peephole [IF] |
| 243 : |
anton
|
1.40
|
|
| 244 : |
|
|
\ dynamic only |
| 245 : |
anton
|
1.49
|
: peephole-compile, ( xt -- ) |
| 246 : |
|
|
\ compile xt, appending its code to the current dynamic superinstruction |
| 247 : |
|
|
here swap , compile-prim1 ; |
| 248 : |
anton
|
1.38
|
|
| 249 : |
anton
|
1.35
|
: compile-to-prims, ( xt -- ) |
| 250 : |
|
|
\G compile xt to use primitives (and their peephole optimization) |
| 251 : |
|
|
\G instead of ","-ing the xt. |
| 252 : |
|
|
\ !! all POSTPONEs here postpone primitives; this can be optimized |
| 253 : |
pazsan
|
1.39
|
dup >does-code if |
| 254 : |
anton
|
1.66
|
['] does-exec peephole-compile, , EXIT |
| 255 : |
|
|
\ dup >body POSTPONE literal ['] call peephole-compile, >does-code , EXIT |
| 256 : |
anton
|
1.35
|
then |
| 257 : |
|
|
dup >code-address CASE |
| 258 : |
anton
|
1.66
|
docon: OF >body ['] lit@ peephole-compile, , EXIT ENDOF |
| 259 : |
|
|
\ docon: OF >body POSTPONE literal ['] @ peephole-compile, EXIT ENDOF |
| 260 : |
anton
|
1.42
|
\ docon is also used by VALUEs, so don't @ at compile time |
| 261 : |
anton
|
1.66
|
docol: OF >body ['] call peephole-compile, , EXIT ENDOF |
| 262 : |
|
|
dovar: OF >body ['] lit peephole-compile, , EXIT ENDOF |
| 263 : |
|
|
douser: OF >body @ ['] useraddr peephole-compile, , EXIT ENDOF |
| 264 : |
|
|
dodefer: OF >body ['] lit-perform peephole-compile, , EXIT ENDOF |
| 265 : |
|
|
dofield: OF >body @ ['] lit+ peephole-compile, , EXIT ENDOF |
| 266 : |
|
|
\ dofield: OF >body @ POSTPONE literal ['] + peephole-compile, EXIT ENDOF |
| 267 : |
anton
|
1.48
|
\ code words and ;code-defined words (code words could be optimized): |
| 268 : |
anton
|
1.66
|
dup in-dictionary? IF drop POSTPONE literal ['] execute peephole-compile, EXIT THEN |
| 269 : |
anton
|
1.35
|
ENDCASE |
| 270 : |
anton
|
1.49
|
peephole-compile, ; |
| 271 : |
anton
|
1.35
|
|
| 272 : |
|
|
' compile-to-prims, IS compile, |
| 273 : |
pazsan
|
1.36
|
[ELSE] |
| 274 : |
|
|
' , is compile, |
| 275 : |
|
|
[THEN] |
| 276 : |
anton
|
1.34
|
|
| 277 : |
pazsan
|
1.1
|
: !does ( addr -- ) \ gforth store-does |
| 278 : |
anton
|
1.56
|
latestxt does-code! ; |
| 279 : |
pazsan
|
1.1
|
|
| 280 : |
anton
|
1.65
|
\ !! unused, but ifdefed/gosted in some places |
| 281 : |
pazsan
|
1.1
|
: (does>) ( R: addr -- ) |
| 282 : |
anton
|
1.62
|
r> cfaligned /does-handler + !does ; \ !! no gforth-native |
| 283 : |
pazsan
|
1.1
|
|
| 284 : |
anton
|
1.64
|
: (does>2) ( addr -- ) |
| 285 : |
|
|
cfaligned /does-handler + !does ; |
| 286 : |
|
|
|
| 287 : |
pazsan
|
1.1
|
: dodoes, ( -- ) |
| 288 : |
|
|
cfalign here /does-handler allot does-handler! ; |
| 289 : |
|
|
|
| 290 : |
pazsan
|
1.61
|
: (compile) ( -- ) \ gforth-obsolete: dummy |
| 291 : |
anton
|
1.63
|
true abort" (compile) doesn't work, use POSTPONE instead" ; |
| 292 : |
pazsan
|
1.1
|
|
| 293 : |
|
|
\ \ ticks |
| 294 : |
|
|
|
| 295 : |
|
|
: name>comp ( nt -- w xt ) \ gforth |
| 296 : |
crook
|
1.15
|
\G @i{w xt} is the compilation token for the word @i{nt}. |
| 297 : |
pazsan
|
1.1
|
(name>comp) |
| 298 : |
|
|
1 = if |
| 299 : |
|
|
['] execute |
| 300 : |
|
|
else |
| 301 : |
|
|
['] compile, |
| 302 : |
|
|
then ; |
| 303 : |
|
|
|
| 304 : |
|
|
: [(')] ( compilation "name" -- ; run-time -- nt ) \ gforth bracket-paren-tick |
| 305 : |
|
|
(') postpone ALiteral ; immediate restrict |
| 306 : |
|
|
|
| 307 : |
|
|
: ['] ( compilation. "name" -- ; run-time. -- xt ) \ core bracket-tick |
| 308 : |
crook
|
1.15
|
\g @i{xt} represents @i{name}'s interpretation |
| 309 : |
|
|
\g semantics. Perform @code{-14 throw} if the word has no |
| 310 : |
pazsan
|
1.1
|
\g interpretation semantics. |
| 311 : |
|
|
' postpone ALiteral ; immediate restrict |
| 312 : |
|
|
|
| 313 : |
anton
|
1.5
|
: COMP' ( "name" -- w xt ) \ gforth comp-tick |
| 314 : |
crook
|
1.15
|
\g Compilation token @i{w xt} represents @i{name}'s compilation semantics. |
| 315 : |
pazsan
|
1.1
|
(') name>comp ; |
| 316 : |
|
|
|
| 317 : |
|
|
: [COMP'] ( compilation "name" -- ; run-time -- w xt ) \ gforth bracket-comp-tick |
| 318 : |
crook
|
1.15
|
\g Compilation token @i{w xt} represents @i{name}'s compilation semantics. |
| 319 : |
pazsan
|
1.1
|
COMP' swap POSTPONE Aliteral POSTPONE ALiteral ; immediate restrict |
| 320 : |
|
|
|
| 321 : |
jwilke
|
1.18
|
: postpone, ( w xt -- ) \ gforth postpone-comma |
| 322 : |
anton
|
1.26
|
\g Compile the compilation semantics represented by the |
| 323 : |
|
|
\g compilation token @i{w xt}. |
| 324 : |
jwilke
|
1.18
|
dup ['] execute = |
| 325 : |
|
|
if |
| 326 : |
|
|
drop compile, |
| 327 : |
|
|
else |
| 328 : |
pazsan
|
1.61
|
swap POSTPONE aliteral compile, |
| 329 : |
jwilke
|
1.18
|
then ; |
| 330 : |
|
|
|
| 331 : |
|
|
: POSTPONE ( "name" -- ) \ core |
| 332 : |
|
|
\g Compiles the compilation semantics of @i{name}. |
| 333 : |
anton
|
1.48
|
COMP' postpone, ; immediate |
| 334 : |
jwilke
|
1.18
|
|
| 335 : |
pazsan
|
1.1
|
\ \ recurse 17may93jaw |
| 336 : |
|
|
|
| 337 : |
|
|
: recurse ( compilation -- ; run-time ?? -- ?? ) \ core |
| 338 : |
crook
|
1.10
|
\g Call the current definition. |
| 339 : |
anton
|
1.56
|
latestxt compile, ; immediate restrict |
| 340 : |
pazsan
|
1.1
|
|
| 341 : |
|
|
\ \ compiler loop |
| 342 : |
|
|
|
| 343 : |
anton
|
1.72
|
: compiler1 ( c-addr u -- ... xt ) |
| 344 : |
pazsan
|
1.1
|
2dup find-name dup |
| 345 : |
|
|
if ( c-addr u nt ) |
| 346 : |
anton
|
1.72
|
nip nip name>comp |
| 347 : |
pazsan
|
1.1
|
else |
| 348 : |
|
|
drop |
| 349 : |
anton
|
1.72
|
2dup 2>r snumber? dup |
| 350 : |
pazsan
|
1.1
|
IF |
| 351 : |
|
|
0> |
| 352 : |
|
|
IF |
| 353 : |
anton
|
1.72
|
['] 2literal |
| 354 : |
|
|
ELSE |
| 355 : |
|
|
['] literal |
| 356 : |
pazsan
|
1.1
|
THEN |
| 357 : |
anton
|
1.72
|
2rdrop |
| 358 : |
pazsan
|
1.1
|
ELSE |
| 359 : |
anton
|
1.72
|
drop 2r> compiler-notfound1 |
| 360 : |
pazsan
|
1.1
|
THEN |
| 361 : |
|
|
then ; |
| 362 : |
|
|
|
| 363 : |
crook
|
1.22
|
: [ ( -- ) \ core left-bracket |
| 364 : |
crook
|
1.8
|
\G Enter interpretation state. Immediate word. |
| 365 : |
anton
|
1.72
|
['] interpreter1 IS parser1 state off ; immediate |
| 366 : |
pazsan
|
1.1
|
|
| 367 : |
|
|
: ] ( -- ) \ core right-bracket |
| 368 : |
crook
|
1.8
|
\G Enter compilation state. |
| 369 : |
anton
|
1.72
|
['] compiler1 IS parser1 state on ; |
| 370 : |
pazsan
|
1.1
|
|
| 371 : |
|
|
\ \ Strings 22feb93py |
| 372 : |
|
|
|
| 373 : |
anton
|
1.44
|
: S, ( addr u -- ) |
| 374 : |
anton
|
1.45
|
\ allot string as counted string |
| 375 : |
anton
|
1.44
|
here over char+ allot place align ; |
| 376 : |
anton
|
1.45
|
|
| 377 : |
|
|
: mem, ( addr u -- ) |
| 378 : |
|
|
\ allot the memory block HERE (do alignment yourself) |
| 379 : |
|
|
here over allot swap move ; |
| 380 : |
pazsan
|
1.1
|
|
| 381 : |
anton
|
1.44
|
: ," ( "string"<"> -- ) |
| 382 : |
|
|
[char] " parse s, ; |
| 383 : |
pazsan
|
1.1
|
|
| 384 : |
|
|
\ \ Header states 23feb93py |
| 385 : |
|
|
|
| 386 : |
|
|
: cset ( bmask c-addr -- ) |
| 387 : |
anton
|
1.30
|
tuck @ or swap ! ; |
| 388 : |
pazsan
|
1.1
|
|
| 389 : |
|
|
: creset ( bmask c-addr -- ) |
| 390 : |
anton
|
1.30
|
tuck @ swap invert and swap ! ; |
| 391 : |
pazsan
|
1.1
|
|
| 392 : |
|
|
: ctoggle ( bmask c-addr -- ) |
| 393 : |
anton
|
1.30
|
tuck @ xor swap ! ; |
| 394 : |
pazsan
|
1.1
|
|
| 395 : |
|
|
: lastflags ( -- c-addr ) |
| 396 : |
|
|
\ the address of the flags byte in the last header |
| 397 : |
|
|
\ aborts if the last defined word was headerless |
| 398 : |
anton
|
1.56
|
latest dup 0= abort" last word was headerless" cell+ ; |
| 399 : |
pazsan
|
1.1
|
|
| 400 : |
|
|
: immediate ( -- ) \ core |
| 401 : |
crook
|
1.10
|
\G Make the compilation semantics of a word be to @code{execute} |
| 402 : |
|
|
\G the execution semantics. |
| 403 : |
pazsan
|
1.1
|
immediate-mask lastflags cset ; |
| 404 : |
|
|
|
| 405 : |
|
|
: restrict ( -- ) \ gforth |
| 406 : |
crook
|
1.10
|
\G A synonym for @code{compile-only} |
| 407 : |
pazsan
|
1.1
|
restrict-mask lastflags cset ; |
| 408 : |
jwilke
|
1.18
|
|
| 409 : |
pazsan
|
1.1
|
' restrict alias compile-only ( -- ) \ gforth |
| 410 : |
crook
|
1.10
|
\G Remove the interpretation semantics of a word. |
| 411 : |
pazsan
|
1.1
|
|
| 412 : |
|
|
\ \ Create Variable User Constant 17mar93py |
| 413 : |
|
|
|
| 414 : |
crook
|
1.15
|
: Alias ( xt "name" -- ) \ gforth |
| 415 : |
pazsan
|
1.1
|
Header reveal |
| 416 : |
|
|
alias-mask lastflags creset |
| 417 : |
|
|
dup A, lastcfa ! ; |
| 418 : |
|
|
|
| 419 : |
|
|
doer? :dovar [IF] |
| 420 : |
|
|
|
| 421 : |
|
|
: Create ( "name" -- ) \ core |
| 422 : |
|
|
Header reveal dovar: cfa, ; |
| 423 : |
|
|
[ELSE] |
| 424 : |
|
|
|
| 425 : |
|
|
: Create ( "name" -- ) \ core |
| 426 : |
|
|
Header reveal here lastcfa ! 0 A, 0 , DOES> ; |
| 427 : |
|
|
[THEN] |
| 428 : |
|
|
|
| 429 : |
|
|
: Variable ( "name" -- ) \ core |
| 430 : |
|
|
Create 0 , ; |
| 431 : |
|
|
|
| 432 : |
|
|
: AVariable ( "name" -- ) \ gforth |
| 433 : |
|
|
Create 0 A, ; |
| 434 : |
|
|
|
| 435 : |
crook
|
1.22
|
: 2Variable ( "name" -- ) \ double two-variable |
| 436 : |
pazsan
|
1.1
|
create 0 , 0 , ; |
| 437 : |
|
|
|
| 438 : |
pazsan
|
1.75
|
has? no-userspace 0= [IF] |
| 439 : |
crook
|
1.21
|
: uallot ( n -- ) \ gforth |
| 440 : |
|
|
udp @ swap udp +! ; |
| 441 : |
pazsan
|
1.1
|
|
| 442 : |
|
|
doer? :douser [IF] |
| 443 : |
|
|
|
| 444 : |
|
|
: User ( "name" -- ) \ gforth |
| 445 : |
|
|
Header reveal douser: cfa, cell uallot , ; |
| 446 : |
|
|
|
| 447 : |
|
|
: AUser ( "name" -- ) \ gforth |
| 448 : |
|
|
User ; |
| 449 : |
|
|
[ELSE] |
| 450 : |
|
|
|
| 451 : |
|
|
: User Create cell uallot , DOES> @ up @ + ; |
| 452 : |
|
|
|
| 453 : |
|
|
: AUser User ; |
| 454 : |
pazsan
|
1.75
|
[THEN] |
| 455 : |
pazsan
|
1.1
|
[THEN] |
| 456 : |
|
|
|
| 457 : |
|
|
doer? :docon [IF] |
| 458 : |
|
|
: (Constant) Header reveal docon: cfa, ; |
| 459 : |
|
|
[ELSE] |
| 460 : |
|
|
: (Constant) Create DOES> @ ; |
| 461 : |
|
|
[THEN] |
| 462 : |
|
|
|
| 463 : |
pazsan
|
1.76
|
doer? :dovalue [IF] |
| 464 : |
|
|
: (Value) Header reveal dovalue: cfa, ; |
| 465 : |
|
|
[ELSE] |
| 466 : |
|
|
has? rom [IF] |
| 467 : |
|
|
: (Value) Create DOES> @ @ ; |
| 468 : |
|
|
[ELSE] |
| 469 : |
|
|
: (Value) Create DOES> @ ; |
| 470 : |
|
|
[THEN] |
| 471 : |
|
|
[THEN] |
| 472 : |
|
|
|
| 473 : |
pazsan
|
1.1
|
: Constant ( w "name" -- ) \ core |
| 474 : |
crook
|
1.15
|
\G Define a constant @i{name} with value @i{w}. |
| 475 : |
pazsan
|
1.1
|
\G |
| 476 : |
crook
|
1.15
|
\G @i{name} execution: @i{-- w} |
| 477 : |
pazsan
|
1.1
|
(Constant) , ; |
| 478 : |
|
|
|
| 479 : |
|
|
: AConstant ( addr "name" -- ) \ gforth |
| 480 : |
|
|
(Constant) A, ; |
| 481 : |
|
|
|
| 482 : |
|
|
: Value ( w "name" -- ) \ core-ext |
| 483 : |
pazsan
|
1.76
|
(Value) , ; |
| 484 : |
pazsan
|
1.1
|
|
| 485 : |
jwilke
|
1.37
|
: AValue ( w "name" -- ) \ core-ext |
| 486 : |
pazsan
|
1.76
|
(Value) A, ; |
| 487 : |
jwilke
|
1.37
|
|
| 488 : |
crook
|
1.22
|
: 2Constant ( w1 w2 "name" -- ) \ double two-constant |
| 489 : |
pazsan
|
1.1
|
Create ( w1 w2 "name" -- ) |
| 490 : |
|
|
2, |
| 491 : |
|
|
DOES> ( -- w1 w2 ) |
| 492 : |
|
|
2@ ; |
| 493 : |
|
|
|
| 494 : |
|
|
doer? :dofield [IF] |
| 495 : |
|
|
: (Field) Header reveal dofield: cfa, ; |
| 496 : |
|
|
[ELSE] |
| 497 : |
|
|
: (Field) Create DOES> @ + ; |
| 498 : |
|
|
[THEN] |
| 499 : |
pazsan
|
1.39
|
|
| 500 : |
|
|
\ \ interpret/compile: |
| 501 : |
|
|
|
| 502 : |
|
|
struct |
| 503 : |
|
|
>body |
| 504 : |
|
|
cell% field interpret/compile-int |
| 505 : |
|
|
cell% field interpret/compile-comp |
| 506 : |
|
|
end-struct interpret/compile-struct |
| 507 : |
|
|
|
| 508 : |
|
|
: interpret/compile: ( interp-xt comp-xt "name" -- ) \ gforth |
| 509 : |
|
|
Create immediate swap A, A, |
| 510 : |
|
|
DOES> |
| 511 : |
|
|
abort" executed primary cfa of an interpret/compile: word" ; |
| 512 : |
|
|
\ state @ IF cell+ THEN perform ; |
| 513 : |
|
|
|
| 514 : |
pazsan
|
1.1
|
\ IS Defer What's Defers TO 24feb93py |
| 515 : |
|
|
|
| 516 : |
anton
|
1.68
|
defer defer-default ( -- ) |
| 517 : |
anton
|
1.69
|
' abort is defer-default |
| 518 : |
|
|
\ default action for deferred words (overridden by a warning later) |
| 519 : |
anton
|
1.67
|
|
| 520 : |
pazsan
|
1.1
|
doer? :dodefer [IF] |
| 521 : |
|
|
|
| 522 : |
|
|
: Defer ( "name" -- ) \ gforth |
| 523 : |
anton
|
1.67
|
\G Define a deferred word @i{name}; its execution semantics can be |
| 524 : |
|
|
\G set with @code{defer!} or @code{is} (and they have to, before first |
| 525 : |
|
|
\G executing @i{name}. |
| 526 : |
pazsan
|
1.1
|
Header Reveal dodefer: cfa, |
| 527 : |
anton
|
1.67
|
['] defer-default A, ; |
| 528 : |
jwilke
|
1.18
|
|
| 529 : |
pazsan
|
1.1
|
[ELSE] |
| 530 : |
|
|
|
| 531 : |
pazsan
|
1.77
|
has? rom [IF] |
| 532 : |
|
|
: Defer ( "name" -- ) \ gforth |
| 533 : |
|
|
Create ['] defer-default A, |
| 534 : |
|
|
DOES> @ @ execute ; |
| 535 : |
|
|
[ELSE] |
| 536 : |
|
|
: Defer ( "name" -- ) \ gforth |
| 537 : |
|
|
Create ['] defer-default A, |
| 538 : |
|
|
DOES> @ execute ; |
| 539 : |
|
|
[THEN] |
| 540 : |
pazsan
|
1.1
|
[THEN] |
| 541 : |
|
|
|
| 542 : |
anton
|
1.67
|
: defer@ ( xt-deferred -- xt ) \ gforth defer-fetch |
| 543 : |
|
|
\G @i{xt} represents the word currently associated with the deferred |
| 544 : |
|
|
\G word @i{xt-deferred}. |
| 545 : |
|
|
>body @ ; |
| 546 : |
|
|
|
| 547 : |
anton
|
1.25
|
: Defers ( compilation "name" -- ; run-time ... -- ... ) \ gforth |
| 548 : |
|
|
\G Compiles the present contents of the deferred word @i{name} |
| 549 : |
|
|
\G into the current definition. I.e., this produces static |
| 550 : |
|
|
\G binding as if @i{name} was not deferred. |
| 551 : |
anton
|
1.67
|
' defer@ compile, ; immediate |
| 552 : |
jwilke
|
1.18
|
|
| 553 : |
|
|
:noname |
| 554 : |
|
|
dodoes, here !does ] |
| 555 : |
|
|
defstart :-hook ; |
| 556 : |
|
|
:noname |
| 557 : |
|
|
;-hook ?struc |
| 558 : |
|
|
[ has? xconds [IF] ] exit-like [ [THEN] ] |
| 559 : |
anton
|
1.64
|
here 5 cells + postpone aliteral postpone (does>2) [compile] exit |
| 560 : |
pazsan
|
1.80
|
[ has? peephole [IF] ] finish-code [ [THEN] ] dodoes, |
| 561 : |
jwilke
|
1.18
|
defstart :-hook ; |
| 562 : |
|
|
interpret/compile: DOES> ( compilation colon-sys1 -- colon-sys2 ; run-time nest-sys -- ) \ core does |
| 563 : |
|
|
|
| 564 : |
anton
|
1.73
|
: defer! ( xt xt-deferred -- ) \ gforth defer-store |
| 565 : |
anton
|
1.67
|
\G Changes the @code{defer}red word @var{xt-deferred} to execute @var{xt}. |
| 566 : |
|
|
>body ! ; |
| 567 : |
|
|
|
| 568 : |
anton
|
1.20
|
: <IS> ( "name" xt -- ) \ gforth |
| 569 : |
|
|
\g Changes the @code{defer}red word @var{name} to execute @var{xt}. |
| 570 : |
anton
|
1.67
|
' defer! ; |
| 571 : |
anton
|
1.20
|
|
| 572 : |
|
|
: [IS] ( compilation "name" -- ; run-time xt -- ) \ gforth bracket-is |
| 573 : |
|
|
\g At run-time, changes the @code{defer}red word @var{name} to |
| 574 : |
|
|
\g execute @var{xt}. |
| 575 : |
anton
|
1.67
|
' postpone ALiteral postpone defer! ; immediate restrict |
| 576 : |
jwilke
|
1.18
|
|
| 577 : |
anton
|
1.20
|
' <IS> |
| 578 : |
jwilke
|
1.18
|
' [IS] |
| 579 : |
anton
|
1.67
|
interpret/compile: IS ( compilation/interpretation "name-deferred" -- ; run-time xt -- ) \ gforth |
| 580 : |
|
|
\G Changes the @code{defer}red word @var{name} to execute @var{xt}. |
| 581 : |
|
|
\G Its compilation semantics parses at compile time. |
| 582 : |
jwilke
|
1.18
|
|
| 583 : |
anton
|
1.20
|
' <IS> |
| 584 : |
|
|
' [IS] |
| 585 : |
|
|
interpret/compile: TO ( w "name" -- ) \ core-ext |
| 586 : |
jwilke
|
1.18
|
|
| 587 : |
|
|
: interpret/compile? ( xt -- flag ) |
| 588 : |
|
|
>does-code ['] DOES> >does-code = ; |
| 589 : |
pazsan
|
1.1
|
|
| 590 : |
|
|
\ \ : ; 24feb93py |
| 591 : |
|
|
|
| 592 : |
|
|
defer :-hook ( sys1 -- sys2 ) |
| 593 : |
|
|
|
| 594 : |
|
|
defer ;-hook ( sys2 -- sys1 ) |
| 595 : |
|
|
|
| 596 : |
jwilke
|
1.16
|
0 Constant defstart |
| 597 : |
|
|
|
| 598 : |
jwilke
|
1.14
|
[IFDEF] docol, |
| 599 : |
|
|
: (:noname) ( -- colon-sys ) |
| 600 : |
|
|
\ common factor of : and :noname |
| 601 : |
anton
|
1.34
|
docol, ]comp |
| 602 : |
jwilke
|
1.14
|
[ELSE] |
| 603 : |
anton
|
1.7
|
: (:noname) ( -- colon-sys ) |
| 604 : |
|
|
\ common factor of : and :noname |
| 605 : |
anton
|
1.34
|
docol: cfa, |
| 606 : |
jwilke
|
1.14
|
[THEN] |
| 607 : |
anton
|
1.40
|
defstart ] :-hook ; |
| 608 : |
anton
|
1.7
|
|
| 609 : |
pazsan
|
1.1
|
: : ( "name" -- colon-sys ) \ core colon |
| 610 : |
anton
|
1.7
|
Header (:noname) ; |
| 611 : |
|
|
|
| 612 : |
|
|
: :noname ( -- xt colon-sys ) \ core-ext colon-no-name |
| 613 : |
|
|
0 last ! |
| 614 : |
|
|
cfalign here (:noname) ; |
| 615 : |
pazsan
|
1.1
|
|
| 616 : |
jwilke
|
1.14
|
[IFDEF] fini, |
| 617 : |
|
|
: ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon |
| 618 : |
|
|
;-hook ?struc fini, comp[ reveal postpone [ ; immediate restrict |
| 619 : |
|
|
[ELSE] |
| 620 : |
pazsan
|
1.1
|
: ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon |
| 621 : |
pazsan
|
1.57
|
;-hook ?struc [compile] exit |
| 622 : |
|
|
[ has? peephole [IF] ] finish-code [ [THEN] ] |
| 623 : |
|
|
reveal postpone [ ; immediate restrict |
| 624 : |
jwilke
|
1.14
|
[THEN] |
| 625 : |
pazsan
|
1.1
|
|
| 626 : |
|
|
\ \ Search list handling: reveal words, recursive 23feb93py |
| 627 : |
|
|
|
| 628 : |
|
|
: last? ( -- false / nfa nfa ) |
| 629 : |
anton
|
1.56
|
latest ?dup ; |
| 630 : |
pazsan
|
1.1
|
|
| 631 : |
pazsan
|
1.80
|
has? ec 0= [IF] |
| 632 : |
pazsan
|
1.1
|
: (reveal) ( nt wid -- ) |
| 633 : |
pazsan
|
1.3
|
wordlist-id dup >r |
| 634 : |
pazsan
|
1.1
|
@ over ( name>link ) ! |
| 635 : |
|
|
r> ! ; |
| 636 : |
|
|
|
| 637 : |
|
|
\ make entry in wordlist-map |
| 638 : |
|
|
' (reveal) f83search reveal-method ! |
| 639 : |
pazsan
|
1.80
|
[ELSE] |
| 640 : |
|
|
: (reveal) ( nt wid -- ) |
| 641 : |
|
|
dup >r @ over ! r> ! ; |
| 642 : |
|
|
[THEN] |
| 643 : |
pazsan
|
1.1
|
|
| 644 : |
|
|
Variable warnings ( -- addr ) \ gforth |
| 645 : |
|
|
G -1 warnings T ! |
| 646 : |
|
|
|
| 647 : |
|
|
: check-shadow ( addr count wid -- ) |
| 648 : |
pazsan
|
1.2
|
\G prints a warning if the string is already present in the wordlist |
| 649 : |
|
|
>r 2dup 2dup r> (search-wordlist) warnings @ and ?dup if |
| 650 : |
|
|
>stderr |
| 651 : |
|
|
." redefined " name>string 2dup type |
| 652 : |
anton
|
1.43
|
str= 0= if |
| 653 : |
pazsan
|
1.2
|
." with " type |
| 654 : |
|
|
else |
| 655 : |
|
|
2drop |
| 656 : |
|
|
then |
| 657 : |
|
|
space space EXIT |
| 658 : |
|
|
then |
| 659 : |
|
|
2drop 2drop ; |
| 660 : |
pazsan
|
1.1
|
|
| 661 : |
|
|
: reveal ( -- ) \ gforth |
| 662 : |
|
|
last? |
| 663 : |
|
|
if \ the last word has a header |
| 664 : |
|
|
dup ( name>link ) @ 1 and |
| 665 : |
|
|
if \ it is still hidden |
| 666 : |
|
|
dup ( name>link ) @ 1 xor ( nt wid ) |
| 667 : |
|
|
2dup >r name>string r> check-shadow ( nt wid ) |
| 668 : |
pazsan
|
1.80
|
[ has? ec [IF] ] |
| 669 : |
|
|
(reveal) |
| 670 : |
|
|
[ [ELSE] ] |
| 671 : |
|
|
dup wordlist-map @ reveal-method perform |
| 672 : |
|
|
[ [THEN] ] |
| 673 : |
pazsan
|
1.1
|
else |
| 674 : |
|
|
drop |
| 675 : |
|
|
then |
| 676 : |
|
|
then ; |
| 677 : |
|
|
|
| 678 : |
pazsan
|
1.80
|
has? EC 0= [IF] |
| 679 : |
pazsan
|
1.1
|
: rehash ( wid -- ) |
| 680 : |
|
|
dup wordlist-map @ rehash-method perform ; |
| 681 : |
pazsan
|
1.80
|
[THEN] |
| 682 : |
pazsan
|
1.1
|
|
| 683 : |
|
|
' reveal alias recursive ( compilation -- ; run-time -- ) \ gforth |
| 684 : |
crook
|
1.10
|
\g Make the current definition visible, enabling it to call itself |
| 685 : |
pazsan
|
1.1
|
\g recursively. |
| 686 : |
|
|
immediate restrict |