[gforth] / gforth / kernel / comp.fs  

gforth: gforth/kernel/comp.fs


1 : pazsan 1.1 \ compiler definitions 14sep97jaw
2 :    
3 : anton 1.54 \ Copyright (C) 1995,1996,1997,1998,2000,2003 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 : anton 1.30 longstring, cfalign
121 : pazsan 1.1 alias-mask lastflags cset ;
122 :    
123 :     : input-stream-header ( "name" -- )
124 :     name name-too-short? header, ;
125 :    
126 :     : input-stream ( -- ) \ general
127 :     \G switches back to getting the name from the input stream ;
128 :     ['] input-stream-header IS (header) ;
129 :    
130 :     ' input-stream-header IS (header)
131 :    
132 : anton 1.32 2variable nextname-string
133 : pazsan 1.1
134 : pazsan 1.33 has? OS [IF]
135 : pazsan 1.1 : nextname-header ( -- )
136 : anton 1.32 nextname-string 2@ header,
137 :     nextname-string free-mem-var
138 : pazsan 1.1 input-stream ;
139 : pazsan 1.33 [THEN]
140 : pazsan 1.1
141 :     \ the next name is given in the string
142 :    
143 : pazsan 1.33 has? OS [IF]
144 : pazsan 1.1 : nextname ( c-addr u -- ) \ gforth
145 : anton 1.19 \g The next defined word will have the name @var{c-addr u}; the
146 :     \g defining word will leave the input stream alone.
147 : pazsan 1.1 name-too-long?
148 : anton 1.32 nextname-string free-mem-var
149 :     save-mem nextname-string 2!
150 : pazsan 1.1 ['] nextname-header IS (header) ;
151 : pazsan 1.33 [THEN]
152 : pazsan 1.1
153 :     : noname-header ( -- )
154 :     0 last ! cfalign
155 :     input-stream ;
156 :    
157 :     : noname ( -- ) \ gforth
158 : anton 1.19 \g The next defined word will be anonymous. The defining word will
159 :     \g leave the input stream alone. The xt of the defined word will
160 : anton 1.56 \g be given by @code{latestxt}.
161 : pazsan 1.1 ['] noname-header IS (header) ;
162 :    
163 : anton 1.56 : latestxt ( -- xt ) \ gforth
164 : crook 1.15 \G @i{xt} is the execution token of the last word defined.
165 : crook 1.13 \ The main purpose of this word is to get the xt of words defined using noname
166 : pazsan 1.1 lastcfa @ ;
167 :    
168 : anton 1.56 ' latestxt alias lastxt \ gforth-obsolete
169 :     \G old name for @code{latestxt}.
170 :    
171 :     : latest ( -- nt ) \ gforth
172 :     \G @var{nt} is the name token of the last word defined; it is 0 if the
173 :     \G last word has no name.
174 :     last @ ;
175 :    
176 : pazsan 1.1 \ \ literals 17dec92py
177 :    
178 :     : Literal ( compilation n -- ; run-time -- n ) \ core
179 : anton 1.27 \G Compilation semantics: compile the run-time semantics.@*
180 :     \G Run-time Semantics: push @i{n}.@*
181 :     \G Interpretation semantics: undefined.
182 : jwilke 1.14 [ [IFDEF] lit, ]
183 :     lit,
184 :     [ [ELSE] ]
185 : anton 1.27 postpone lit ,
186 : jwilke 1.14 [ [THEN] ] ; immediate restrict
187 : pazsan 1.1
188 :     : ALiteral ( compilation addr -- ; run-time -- addr ) \ gforth
189 : jwilke 1.14 [ [IFDEF] alit, ]
190 :     alit,
191 :     [ [ELSE] ]
192 :     postpone lit A,
193 :     [ [THEN] ] ; immediate restrict
194 : pazsan 1.1
195 : crook 1.8 : char ( '<spaces>ccc' -- c ) \ core
196 : crook 1.15 \G Skip leading spaces. Parse the string @i{ccc} and return @i{c}, the
197 :     \G display code representing the first character of @i{ccc}.
198 : pazsan 1.1 bl word char+ c@ ;
199 :    
200 : crook 1.8 : [char] ( compilation '<spaces>ccc' -- ; run-time -- c ) \ core bracket-char
201 : crook 1.10 \G Compilation: skip leading spaces. Parse the string
202 : crook 1.15 \G @i{ccc}. Run-time: return @i{c}, the display code
203 :     \G representing the first character of @i{ccc}. Interpretation
204 : crook 1.10 \G semantics for this word are undefined.
205 : pazsan 1.1 char postpone Literal ; immediate restrict
206 :    
207 :     \ \ threading 17mar93py
208 :    
209 :     : cfa, ( code-address -- ) \ gforth cfa-comma
210 :     here
211 :     dup lastcfa !
212 :     0 A, 0 , code-address! ;
213 :    
214 : jwilke 1.14 [IFUNDEF] compile,
215 : anton 1.34 defer compile, ( xt -- ) \ core-ext compile-comma
216 :     \G Compile the word represented by the execution token @i{xt}
217 :     \G into the current definition.
218 :    
219 :     ' , is compile,
220 : jwilke 1.14 [THEN]
221 : pazsan 1.1
222 : anton 1.40 defer basic-block-end ( -- )
223 :    
224 : anton 1.48 :noname ( -- )
225 : anton 1.40 0 last-compiled ! ;
226 : anton 1.48 is basic-block-end
227 : anton 1.40
228 : pazsan 1.36 has? peephole [IF]
229 : anton 1.40
230 :     \ dynamic only
231 : anton 1.49 : peephole-compile, ( xt -- )
232 :     \ compile xt, appending its code to the current dynamic superinstruction
233 :     here swap , compile-prim1 ;
234 : anton 1.38
235 : anton 1.40 \ static only
236 : anton 1.38 \ : peephole-compile, ( xt -- )
237 :     \ \ compile xt, possibly combining it with the previous compiled xt
238 :     \ \ into a superinstruction (static superinstructions)
239 :     \ last-compiled @ ?dup if
240 :     \ @ over peeptable peephole-opt ?dup if
241 :     \ last-compiled @ ! drop EXIT
242 :     \ then
243 :     \ then
244 :     \ here last-compiled !
245 :     \ dyn-compile, ;
246 : anton 1.34
247 : anton 1.49 \ combine greedy static with dynamic
248 :     \ : dyn-compile! ( xt -- )
249 :     \ \ compile xt, appending its code to the current dynamic superinstruction
250 :     \ last-compiled-here @ tuck ! compile-prim1 ;
251 : anton 1.40
252 : anton 1.49 \ :noname ( -- )
253 :     \ last-compiled @ if
254 :     \ last-compiled @ dyn-compile!
255 :     \ 0 last-compiled !
256 :     \ then ;
257 :     \ is basic-block-end
258 : anton 1.40
259 : anton 1.49 \ : peephole-compile, ( xt -- )
260 :     \ \ compile xt, possibly combining it with the previous compiled xt
261 :     \ \ into a superinstruction (static superinstructions)
262 :     \ last-compiled @ ?dup if
263 :     \ over peeptable peephole-opt ?dup if ( xt comb-xt )
264 :     \ last-compiled ! drop EXIT
265 :     \ then ( xt )
266 :     \ last-compiled @ dyn-compile!
267 :     \ then ( xt )
268 :     \ last-compiled !
269 :     \ here last-compiled-here ! 0 , ;
270 : anton 1.42
271 : anton 1.35 : compile-to-prims, ( xt -- )
272 :     \G compile xt to use primitives (and their peephole optimization)
273 :     \G instead of ","-ing the xt.
274 :     \ !! all POSTPONEs here postpone primitives; this can be optimized
275 : pazsan 1.39 dup >does-code if
276 :     POSTPONE does-exec , EXIT
277 : anton 1.41 \ dup >body POSTPONE literal POSTPONE call >does-code , EXIT
278 : anton 1.35 then
279 :     dup >code-address CASE
280 : anton 1.47 docon: OF >body POSTPONE lit@ , EXIT ENDOF
281 :     \ docon: OF >body POSTPONE literal POSTPONE @ EXIT ENDOF
282 : anton 1.42 \ docon is also used by VALUEs, so don't @ at compile time
283 : anton 1.35 docol: OF >body POSTPONE call , EXIT ENDOF
284 :     dovar: OF >body POSTPONE literal EXIT ENDOF
285 :     douser: OF >body @ POSTPONE useraddr , EXIT ENDOF
286 : anton 1.42 dodefer: OF >body POSTPONE lit-perform , EXIT ENDOF
287 : anton 1.47 dofield: OF >body @ POSTPONE lit+ , EXIT ENDOF
288 :     \ dofield: OF >body @ POSTPONE literal POSTPONE + EXIT ENDOF
289 : anton 1.48 \ code words and ;code-defined words (code words could be optimized):
290 :     dup in-dictionary? IF drop POSTPONE literal POSTPONE execute EXIT THEN
291 : anton 1.35 ENDCASE
292 : anton 1.49 peephole-compile, ;
293 : anton 1.35
294 :     ' compile-to-prims, IS compile,
295 : pazsan 1.36 [ELSE]
296 :     ' , is compile,
297 :     [THEN]
298 : anton 1.34
299 : pazsan 1.1 : !does ( addr -- ) \ gforth store-does
300 : anton 1.56 latestxt does-code! ;
301 : pazsan 1.1
302 :     : (does>) ( R: addr -- )
303 :     r> cfaligned /does-handler + !does ;
304 :    
305 :     : dodoes, ( -- )
306 :     cfalign here /does-handler allot does-handler! ;
307 :    
308 :     : (compile) ( -- ) \ gforth
309 :     r> dup cell+ >r @ compile, ;
310 :    
311 :     \ \ ticks
312 :    
313 :     : name>comp ( nt -- w xt ) \ gforth
314 : crook 1.15 \G @i{w xt} is the compilation token for the word @i{nt}.
315 : pazsan 1.1 (name>comp)
316 :     1 = if
317 :     ['] execute
318 :     else
319 :     ['] compile,
320 :     then ;
321 :    
322 :     : [(')] ( compilation "name" -- ; run-time -- nt ) \ gforth bracket-paren-tick
323 :     (') postpone ALiteral ; immediate restrict
324 :    
325 :     : ['] ( compilation. "name" -- ; run-time. -- xt ) \ core bracket-tick
326 : crook 1.15 \g @i{xt} represents @i{name}'s interpretation
327 :     \g semantics. Perform @code{-14 throw} if the word has no
328 : pazsan 1.1 \g interpretation semantics.
329 :     ' postpone ALiteral ; immediate restrict
330 :    
331 : anton 1.5 : COMP' ( "name" -- w xt ) \ gforth comp-tick
332 : crook 1.15 \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
333 : pazsan 1.1 (') name>comp ;
334 :    
335 :     : [COMP'] ( compilation "name" -- ; run-time -- w xt ) \ gforth bracket-comp-tick
336 : crook 1.15 \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
337 : pazsan 1.1 COMP' swap POSTPONE Aliteral POSTPONE ALiteral ; immediate restrict
338 :    
339 : jwilke 1.18 : postpone, ( w xt -- ) \ gforth postpone-comma
340 : anton 1.26 \g Compile the compilation semantics represented by the
341 :     \g compilation token @i{w xt}.
342 : jwilke 1.18 dup ['] execute =
343 :     if
344 :     drop compile,
345 :     else
346 :     dup ['] compile, =
347 :     if
348 :     drop POSTPONE (compile) a,
349 :     else
350 :     swap POSTPONE aliteral compile,
351 :     then
352 :     then ;
353 :    
354 :     : POSTPONE ( "name" -- ) \ core
355 :     \g Compiles the compilation semantics of @i{name}.
356 : anton 1.48 COMP' postpone, ; immediate
357 : jwilke 1.18
358 : pazsan 1.1 \ \ recurse 17may93jaw
359 :    
360 :     : recurse ( compilation -- ; run-time ?? -- ?? ) \ core
361 : crook 1.10 \g Call the current definition.
362 : anton 1.56 latestxt compile, ; immediate restrict
363 : pazsan 1.1
364 :     \ \ compiler loop
365 :    
366 :     : compiler ( c-addr u -- )
367 :     2dup find-name dup
368 :     if ( c-addr u nt )
369 :     nip nip name>comp execute
370 :     else
371 :     drop
372 :     2dup snumber? dup
373 :     IF
374 :     0>
375 :     IF
376 :     swap postpone Literal
377 :     THEN
378 :     postpone Literal
379 :     2drop
380 :     ELSE
381 :     drop compiler-notfound
382 :     THEN
383 :     then ;
384 :    
385 : crook 1.22 : [ ( -- ) \ core left-bracket
386 : crook 1.8 \G Enter interpretation state. Immediate word.
387 : pazsan 1.1 ['] interpreter IS parser state off ; immediate
388 :    
389 :     : ] ( -- ) \ core right-bracket
390 : crook 1.8 \G Enter compilation state.
391 : pazsan 1.1 ['] compiler IS parser state on ;
392 :    
393 :     \ \ Strings 22feb93py
394 :    
395 : anton 1.44 : S, ( addr u -- )
396 : anton 1.45 \ allot string as counted string
397 : anton 1.44 here over char+ allot place align ;
398 : anton 1.45
399 :     : mem, ( addr u -- )
400 :     \ allot the memory block HERE (do alignment yourself)
401 :     here over allot swap move ;
402 : pazsan 1.1
403 : anton 1.44 : ," ( "string"<"> -- )
404 :     [char] " parse s, ;
405 : pazsan 1.1
406 :     \ \ Header states 23feb93py
407 :    
408 :     : cset ( bmask c-addr -- )
409 : anton 1.30 tuck @ or swap ! ;
410 : pazsan 1.1
411 :     : creset ( bmask c-addr -- )
412 : anton 1.30 tuck @ swap invert and swap ! ;
413 : pazsan 1.1
414 :     : ctoggle ( bmask c-addr -- )
415 : anton 1.30 tuck @ xor swap ! ;
416 : pazsan 1.1
417 :     : lastflags ( -- c-addr )
418 :     \ the address of the flags byte in the last header
419 :     \ aborts if the last defined word was headerless
420 : anton 1.56 latest dup 0= abort" last word was headerless" cell+ ;
421 : pazsan 1.1
422 :     : immediate ( -- ) \ core
423 : crook 1.10 \G Make the compilation semantics of a word be to @code{execute}
424 :     \G the execution semantics.
425 : pazsan 1.1 immediate-mask lastflags cset ;
426 :    
427 :     : restrict ( -- ) \ gforth
428 : crook 1.10 \G A synonym for @code{compile-only}
429 : pazsan 1.1 restrict-mask lastflags cset ;
430 : jwilke 1.18
431 : pazsan 1.1 ' restrict alias compile-only ( -- ) \ gforth
432 : crook 1.10 \G Remove the interpretation semantics of a word.
433 : pazsan 1.1
434 :     \ \ Create Variable User Constant 17mar93py
435 :    
436 : crook 1.15 : Alias ( xt "name" -- ) \ gforth
437 : pazsan 1.1 Header reveal
438 :     alias-mask lastflags creset
439 :     dup A, lastcfa ! ;
440 :    
441 :     doer? :dovar [IF]
442 :    
443 :     : Create ( "name" -- ) \ core
444 :     Header reveal dovar: cfa, ;
445 :     [ELSE]
446 :    
447 :     : Create ( "name" -- ) \ core
448 :     Header reveal here lastcfa ! 0 A, 0 , DOES> ;
449 :     [THEN]
450 :    
451 :     : Variable ( "name" -- ) \ core
452 :     Create 0 , ;
453 :    
454 :     : AVariable ( "name" -- ) \ gforth
455 :     Create 0 A, ;
456 :    
457 : crook 1.22 : 2Variable ( "name" -- ) \ double two-variable
458 : pazsan 1.1 create 0 , 0 , ;
459 :    
460 : crook 1.21 : uallot ( n -- ) \ gforth
461 :     udp @ swap udp +! ;
462 : pazsan 1.1
463 :     doer? :douser [IF]
464 :    
465 :     : User ( "name" -- ) \ gforth
466 :     Header reveal douser: cfa, cell uallot , ;
467 :    
468 :     : AUser ( "name" -- ) \ gforth
469 :     User ;
470 :     [ELSE]
471 :    
472 :     : User Create cell uallot , DOES> @ up @ + ;
473 :    
474 :     : AUser User ;
475 :     [THEN]
476 :    
477 :     doer? :docon [IF]
478 :     : (Constant) Header reveal docon: cfa, ;
479 :     [ELSE]
480 :     : (Constant) Create DOES> @ ;
481 :     [THEN]
482 :    
483 :     : Constant ( w "name" -- ) \ core
484 : crook 1.15 \G Define a constant @i{name} with value @i{w}.
485 : pazsan 1.1 \G
486 : crook 1.15 \G @i{name} execution: @i{-- w}
487 : pazsan 1.1 (Constant) , ;
488 :    
489 :     : AConstant ( addr "name" -- ) \ gforth
490 :     (Constant) A, ;
491 :    
492 :     : Value ( w "name" -- ) \ core-ext
493 :     (Constant) , ;
494 :    
495 : jwilke 1.37 : AValue ( w "name" -- ) \ core-ext
496 :     (Constant) A, ;
497 :    
498 : crook 1.22 : 2Constant ( w1 w2 "name" -- ) \ double two-constant
499 : pazsan 1.1 Create ( w1 w2 "name" -- )
500 :     2,
501 :     DOES> ( -- w1 w2 )
502 :     2@ ;
503 :    
504 :     doer? :dofield [IF]
505 :     : (Field) Header reveal dofield: cfa, ;
506 :     [ELSE]
507 :     : (Field) Create DOES> @ + ;
508 :     [THEN]
509 : pazsan 1.39
510 :     \ \ interpret/compile:
511 :    
512 :     struct
513 :     >body
514 :     cell% field interpret/compile-int
515 :     cell% field interpret/compile-comp
516 :     end-struct interpret/compile-struct
517 :    
518 :     : interpret/compile: ( interp-xt comp-xt "name" -- ) \ gforth
519 :     Create immediate swap A, A,
520 :     DOES>
521 :     abort" executed primary cfa of an interpret/compile: word" ;
522 :     \ state @ IF cell+ THEN perform ;
523 :    
524 : pazsan 1.1 \ IS Defer What's Defers TO 24feb93py
525 :    
526 :     doer? :dodefer [IF]
527 :    
528 :     : Defer ( "name" -- ) \ gforth
529 :     \ !! shouldn't it be initialized with abort or something similar?
530 :     Header Reveal dodefer: cfa,
531 :     ['] noop A, ;
532 : jwilke 1.18
533 : pazsan 1.1 [ELSE]
534 :    
535 :     : Defer ( "name" -- ) \ gforth
536 :     Create ['] noop A,
537 :     DOES> @ execute ;
538 : jwilke 1.18
539 : pazsan 1.1 [THEN]
540 :    
541 : anton 1.25 : Defers ( compilation "name" -- ; run-time ... -- ... ) \ gforth
542 :     \G Compiles the present contents of the deferred word @i{name}
543 :     \G into the current definition. I.e., this produces static
544 :     \G binding as if @i{name} was not deferred.
545 : pazsan 1.1 ' >body @ compile, ; immediate
546 : jwilke 1.18
547 :     :noname
548 :     dodoes, here !does ]
549 :     defstart :-hook ;
550 :     :noname
551 :     ;-hook ?struc
552 :     [ has? xconds [IF] ] exit-like [ [THEN] ]
553 :     postpone (does>) dodoes,
554 :     defstart :-hook ;
555 :     interpret/compile: DOES> ( compilation colon-sys1 -- colon-sys2 ; run-time nest-sys -- ) \ core does
556 :    
557 : anton 1.20 : <IS> ( "name" xt -- ) \ gforth
558 :     \g Changes the @code{defer}red word @var{name} to execute @var{xt}.
559 :     ' >body ! ;
560 :    
561 :     : [IS] ( compilation "name" -- ; run-time xt -- ) \ gforth bracket-is
562 :     \g At run-time, changes the @code{defer}red word @var{name} to
563 :     \g execute @var{xt}.
564 : jwilke 1.18 ' >body postpone ALiteral postpone ! ; immediate restrict
565 :    
566 : anton 1.20 ' <IS>
567 : jwilke 1.18 ' [IS]
568 :     interpret/compile: IS ( xt "name" -- ) \ gforth
569 : crook 1.21 \G A combined word made up from @code{<IS>} and @code{[IS]}.
570 : jwilke 1.18
571 : anton 1.20 ' <IS>
572 :     ' [IS]
573 :     interpret/compile: TO ( w "name" -- ) \ core-ext
574 : jwilke 1.18
575 :     :noname ' >body @ ;
576 :     :noname ' >body postpone ALiteral postpone @ ;
577 : anton 1.25 interpret/compile: What's ( interpretation "name" -- xt; compilation "name" -- ; run-time -- xt ) \ gforth
578 :     \G @i{Xt} is the XT that is currently assigned to @i{name}.
579 : jwilke 1.18
580 :     : interpret/compile? ( xt -- flag )
581 :     >does-code ['] DOES> >does-code = ;
582 : pazsan 1.1
583 :     \ \ : ; 24feb93py
584 :    
585 :     defer :-hook ( sys1 -- sys2 )
586 :    
587 :     defer ;-hook ( sys2 -- sys1 )
588 :    
589 : jwilke 1.16 0 Constant defstart
590 :    
591 : jwilke 1.14 [IFDEF] docol,
592 :     : (:noname) ( -- colon-sys )
593 :     \ common factor of : and :noname
594 : anton 1.34 docol, ]comp
595 : jwilke 1.14 [ELSE]
596 : anton 1.7 : (:noname) ( -- colon-sys )
597 :     \ common factor of : and :noname
598 : anton 1.34 docol: cfa,
599 : jwilke 1.14 [THEN]
600 : anton 1.40 defstart ] :-hook ;
601 : anton 1.7
602 : pazsan 1.1 : : ( "name" -- colon-sys ) \ core colon
603 : anton 1.7 Header (:noname) ;
604 :    
605 :     : :noname ( -- xt colon-sys ) \ core-ext colon-no-name
606 :     0 last !
607 :     cfalign here (:noname) ;
608 : pazsan 1.1
609 : jwilke 1.14 [IFDEF] fini,
610 :     : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon
611 :     ;-hook ?struc fini, comp[ reveal postpone [ ; immediate restrict
612 :     [ELSE]
613 : pazsan 1.1 : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon
614 : anton 1.50 ;-hook ?struc [compile] exit finish-code reveal postpone [ ; immediate restrict
615 : jwilke 1.14 [THEN]
616 : pazsan 1.1
617 :     \ \ Search list handling: reveal words, recursive 23feb93py
618 :    
619 :     : last? ( -- false / nfa nfa )
620 : anton 1.56 latest ?dup ;
621 : pazsan 1.1
622 :     : (reveal) ( nt wid -- )
623 : pazsan 1.3 wordlist-id dup >r
624 : pazsan 1.1 @ over ( name>link ) !
625 :     r> ! ;
626 :    
627 :     \ make entry in wordlist-map
628 :     ' (reveal) f83search reveal-method !
629 :    
630 :     Variable warnings ( -- addr ) \ gforth
631 :     G -1 warnings T !
632 :    
633 :     : check-shadow ( addr count wid -- )
634 : pazsan 1.2 \G prints a warning if the string is already present in the wordlist
635 :     >r 2dup 2dup r> (search-wordlist) warnings @ and ?dup if
636 :     >stderr
637 :     ." redefined " name>string 2dup type
638 : anton 1.43 str= 0= if
639 : pazsan 1.2 ." with " type
640 :     else
641 :     2drop
642 :     then
643 :     space space EXIT
644 :     then
645 :     2drop 2drop ;
646 : pazsan 1.1
647 :     : reveal ( -- ) \ gforth
648 :     last?
649 :     if \ the last word has a header
650 :     dup ( name>link ) @ 1 and
651 :     if \ it is still hidden
652 :     dup ( name>link ) @ 1 xor ( nt wid )
653 :     2dup >r name>string r> check-shadow ( nt wid )
654 :     dup wordlist-map @ reveal-method perform
655 :     else
656 :     drop
657 :     then
658 :     then ;
659 :    
660 :     : rehash ( wid -- )
661 :     dup wordlist-map @ rehash-method perform ;
662 :    
663 :     ' reveal alias recursive ( compilation -- ; run-time -- ) \ gforth
664 : crook 1.10 \g Make the current definition visible, enabling it to call itself
665 : pazsan 1.1 \g recursively.
666 :     immediate restrict

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help