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