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