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