Annotation of gforth/kernel/comp.fs, revision 1.113
1.1 pazsan 1: \ compiler definitions 14sep97jaw
2:
1.113 ! anton 3: \ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008,2009,2010,2011 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
1.93 anton 9: \ as published by the Free Software Foundation, either version 3
1.6 anton 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
1.93 anton 18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.6 anton 19:
1.1 pazsan 20: \ \ Revisions-Log
21:
22: \ put in seperate file 14sep97jaw
23:
24: \ \ here allot , c, A, 17dec92py
25:
1.14 jwilke 26: [IFUNDEF] allot
27: [IFUNDEF] forthstart
28: : allot ( n -- ) \ core
29: dup unused u> -8 and throw
30: dp +! ;
31: [THEN]
32: [THEN]
33:
34: \ we default to this version if we have nothing else 05May99jaw
35: [IFUNDEF] allot
1.1 pazsan 36: : allot ( n -- ) \ core
1.23 anton 37: \G Reserve @i{n} address units of data space without
38: \G initialization. @i{n} is a signed number, passing a negative
39: \G @i{n} releases memory. In ANS Forth you can only deallocate
40: \G memory from the current contiguous region in this way. In
41: \G Gforth you can deallocate anything in this way but named words.
42: \G The system does not check this restriction.
1.12 anton 43: here +
44: dup 1- usable-dictionary-end forthstart within -8 and throw
45: dp ! ;
1.14 jwilke 46: [THEN]
1.1 pazsan 47:
1.22 crook 48: : c, ( c -- ) \ core c-comma
1.15 crook 49: \G Reserve data space for one char and store @i{c} in the space.
1.110 pazsan 50: here 1 chars allot c! ;
1.1 pazsan 51:
1.22 crook 52: : , ( w -- ) \ core comma
1.15 crook 53: \G Reserve data space for one cell and store @i{w} in the space.
1.110 pazsan 54: here cell allot ! ;
1.1 pazsan 55:
56: : 2, ( w1 w2 -- ) \ gforth
1.15 crook 57: \G Reserve data space for two cells and store the double @i{w1
1.24 anton 58: \G w2} there, @i{w2} first (lower address).
1.110 pazsan 59: here 2 cells allot 2! ;
1.1 pazsan 60:
61: \ : aligned ( addr -- addr' ) \ core
62: \ [ cell 1- ] Literal + [ -1 cells ] Literal and ;
63:
64: : align ( -- ) \ core
1.15 crook 65: \G If the data-space pointer is not aligned, reserve enough space to align it.
1.1 pazsan 66: here dup aligned swap ?DO bl c, LOOP ;
67:
1.22 crook 68: \ : faligned ( addr -- f-addr ) \ float f-aligned
1.1 pazsan 69: \ [ 1 floats 1- ] Literal + [ -1 floats ] Literal and ;
70:
1.22 crook 71: : falign ( -- ) \ float f-align
1.15 crook 72: \G If the data-space pointer is not float-aligned, reserve
73: \G enough space to align it.
1.1 pazsan 74: here dup faligned swap
75: ?DO
76: bl c,
77: LOOP ;
78:
1.9 anton 79: : maxalign ( -- ) \ gforth
1.23 anton 80: \G Align data-space pointer for all alignment requirements.
1.1 pazsan 81: here dup maxaligned swap
82: ?DO
83: bl c,
84: LOOP ;
85:
86: \ the code field is aligned if its body is maxaligned
87: ' maxalign Alias cfalign ( -- ) \ gforth
1.24 anton 88: \G Align data-space pointer for code field requirements (i.e., such
89: \G that the corresponding body is maxaligned).
1.1 pazsan 90:
91: ' , alias A, ( addr -- ) \ gforth
92:
93: ' NOOP ALIAS const
94:
95: \ \ Header 23feb93py
96:
97: \ input-stream, nextname and noname are quite ugly (passing
98: \ information through global variables), but they are useful for dealing
99: \ with existing/independent defining words
100:
101: : string, ( c-addr u -- ) \ gforth
102: \G puts down string as cstring
1.110 pazsan 103: dup alias-mask or c,
104: here swap chars dup allot move ;
1.1 pazsan 105:
1.30 anton 106: : longstring, ( c-addr u -- ) \ gforth
1.55 anton 107: \G puts down string as longcstring
1.30 anton 108: dup , here swap chars dup allot move ;
109:
1.99 pazsan 110: [IFDEF] prelude-mask
1.96 anton 111: variable next-prelude
112:
113: : prelude, ( -- )
114: next-prelude @ if
115: align next-prelude @ ,
116: then ;
1.99 pazsan 117: [THEN]
1.96 anton 118:
1.1 pazsan 119: : header, ( c-addr u -- ) \ gforth
120: name-too-long?
1.53 anton 121: dup max-name-length @ max max-name-length !
1.99 pazsan 122: [ [IFDEF] prelude-mask ] prelude, [ [THEN] ]
1.1 pazsan 123: align here last !
124: current @ 1 or A, \ link field; before revealing, it contains the
125: \ tagged reveal-into wordlist
1.110 pazsan 126: longstring, alias-mask lastflags cset
127: next-prelude @ 0<> prelude-mask and lastflags cset
128: next-prelude off
1.83 pazsan 129: cfalign ;
1.1 pazsan 130:
1.107 pazsan 131: defer (header)
132: defer header ( -- ) \ gforth
133: ' (header) IS header
134:
1.1 pazsan 135: : input-stream-header ( "name" -- )
1.80 pazsan 136: parse-name name-too-short? header, ;
1.1 pazsan 137:
138: : input-stream ( -- ) \ general
139: \G switches back to getting the name from the input stream ;
140: ['] input-stream-header IS (header) ;
141:
142: ' input-stream-header IS (header)
143:
1.32 anton 144: 2variable nextname-string
1.1 pazsan 145:
146: : nextname-header ( -- )
1.32 anton 147: nextname-string 2@ header,
148: nextname-string free-mem-var
1.1 pazsan 149: input-stream ;
150:
151: \ the next name is given in the string
152:
153: : nextname ( c-addr u -- ) \ gforth
1.19 anton 154: \g The next defined word will have the name @var{c-addr u}; the
155: \g defining word will leave the input stream alone.
1.1 pazsan 156: name-too-long?
1.32 anton 157: nextname-string free-mem-var
158: save-mem nextname-string 2!
1.1 pazsan 159: ['] nextname-header IS (header) ;
160:
161: : noname-header ( -- )
162: 0 last ! cfalign
163: input-stream ;
164:
165: : noname ( -- ) \ gforth
1.19 anton 166: \g The next defined word will be anonymous. The defining word will
167: \g leave the input stream alone. The xt of the defined word will
1.56 anton 168: \g be given by @code{latestxt}.
1.1 pazsan 169: ['] noname-header IS (header) ;
170:
1.56 anton 171: : latestxt ( -- xt ) \ gforth
1.15 crook 172: \G @i{xt} is the execution token of the last word defined.
1.13 crook 173: \ The main purpose of this word is to get the xt of words defined using noname
1.1 pazsan 174: lastcfa @ ;
175:
1.56 anton 176: ' latestxt alias lastxt \ gforth-obsolete
177: \G old name for @code{latestxt}.
178:
179: : latest ( -- nt ) \ gforth
180: \G @var{nt} is the name token of the last word defined; it is 0 if the
181: \G last word has no name.
182: last @ ;
183:
1.1 pazsan 184: \ \ literals 17dec92py
185:
186: : Literal ( compilation n -- ; run-time -- n ) \ core
1.27 anton 187: \G Compilation semantics: compile the run-time semantics.@*
188: \G Run-time Semantics: push @i{n}.@*
189: \G Interpretation semantics: undefined.
1.110 pazsan 190: postpone lit , ; immediate restrict
1.1 pazsan 191:
1.72 anton 192: : 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:
1.1 pazsan 197: : ALiteral ( compilation addr -- ; run-time -- addr ) \ gforth
1.110 pazsan 198: postpone lit A, ; 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.87 pazsan 206: parse-name 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:
1.111 pazsan 217: has? ec 0= [IF]
1.112 pazsan 218: ' noop Alias recurse
1.111 pazsan 219: \g Call the current definition.
1.112 pazsan 220: unlock tlastcfa @ lock AConstant lastcfa
221: \ this is the alias pointer in the recurse header, named lastcfa.
222: \ changing lastcfa now changes where recurse aliases to
223: \ it's always an alias of the current definition
224: \ it won't work in a flash/rom environment, therefore for Gforth EC
225: \ we stick to the traditional implementation
1.111 pazsan 226: [ELSE]
1.112 pazsan 227: : recurse ( compilation -- ; run-time ?? -- ?? ) \ core
228: \g Call the current definition.
229: latestxt compile, ; immediate restrict
1.111 pazsan 230: [THEN]
231:
1.1 pazsan 232: : cfa, ( code-address -- ) \ gforth cfa-comma
233: here
234: dup lastcfa !
1.110 pazsan 235: 0 A, 0 ,
1.84 pazsan 236: code-address! ;
1.1 pazsan 237:
1.14 jwilke 238: [IFUNDEF] compile,
1.34 anton 239: defer compile, ( xt -- ) \ core-ext compile-comma
240: \G Compile the word represented by the execution token @i{xt}
241: \G into the current definition.
242:
243: ' , is compile,
1.14 jwilke 244: [THEN]
1.1 pazsan 245:
1.40 anton 246: defer basic-block-end ( -- )
247:
1.60 anton 248: :noname ( -- )
249: 0 compile-prim1 ;
250: is basic-block-end
1.40 anton 251:
1.99 pazsan 252: has? primcentric [IF]
253: has? peephole [IF]
254: \ dynamic only
255: : peephole-compile, ( xt -- )
256: \ compile xt, appending its code to the current dynamic superinstruction
257: here swap , compile-prim1 ;
258: [ELSE]
259: : peephole-compile, ( xt -- addr ) @ , ;
260: [THEN]
1.40 anton 261:
1.35 anton 262: : compile-to-prims, ( xt -- )
263: \G compile xt to use primitives (and their peephole optimization)
264: \G instead of ","-ing the xt.
265: \ !! all POSTPONEs here postpone primitives; this can be optimized
1.39 pazsan 266: dup >does-code if
1.66 anton 267: ['] does-exec peephole-compile, , EXIT
268: \ dup >body POSTPONE literal ['] call peephole-compile, >does-code , EXIT
1.35 anton 269: then
270: dup >code-address CASE
1.91 pazsan 271: dovalue: OF >body ['] lit@ peephole-compile, , EXIT ENDOF
272: docon: OF >body @ ['] lit peephole-compile, , EXIT ENDOF
1.66 anton 273: \ docon: OF >body POSTPONE literal ['] @ peephole-compile, EXIT ENDOF
1.42 anton 274: \ docon is also used by VALUEs, so don't @ at compile time
1.66 anton 275: docol: OF >body ['] call peephole-compile, , EXIT ENDOF
276: dovar: OF >body ['] lit peephole-compile, , EXIT ENDOF
277: douser: OF >body @ ['] useraddr peephole-compile, , EXIT ENDOF
278: dodefer: OF >body ['] lit-perform peephole-compile, , EXIT ENDOF
279: dofield: OF >body @ ['] lit+ peephole-compile, , EXIT ENDOF
1.103 anton 280: \ dofield: OF >body @ POSTPONE literal ['] + peephole-compile, EXIT ENDOF
1.100 dvdkhlng 281: doabicode: OF >body ['] abi-call peephole-compile, , EXIT ENDOF
1.103 anton 282: do;abicode: OF ['] ;abi-code-exec peephole-compile, , EXIT ENDOF
1.104 anton 283: \ code words and ;code-defined words (code words could be
284: \ optimized, if we could identify them):
1.105 anton 285: dup in-dictionary? IF ( xt code-address )
286: over >body = if ( xt )
287: \ definitely a CODE word
288: peephole-compile, EXIT THEN
289: \ not sure, might be a ;CODE word
290: ['] lit-execute peephole-compile, , EXIT
1.104 anton 291: \ drop POSTPONE literal ['] execute peephole-compile, EXIT
292: THEN
1.35 anton 293: ENDCASE
1.49 anton 294: peephole-compile, ;
1.35 anton 295:
296: ' compile-to-prims, IS compile,
1.36 pazsan 297: [ELSE]
298: ' , is compile,
299: [THEN]
1.34 anton 300:
1.1 pazsan 301: : !does ( addr -- ) \ gforth store-does
1.56 anton 302: latestxt does-code! ;
1.1 pazsan 303:
1.61 pazsan 304: : (compile) ( -- ) \ gforth-obsolete: dummy
1.63 anton 305: true abort" (compile) doesn't work, use POSTPONE instead" ;
1.1 pazsan 306:
307: \ \ ticks
308:
1.90 anton 309: : name>comp ( nt -- w xt ) \ gforth name-to-comp
1.15 crook 310: \G @i{w xt} is the compilation token for the word @i{nt}.
1.1 pazsan 311: (name>comp)
312: 1 = if
313: ['] execute
314: else
315: ['] compile,
316: then ;
317:
318: : [(')] ( compilation "name" -- ; run-time -- nt ) \ gforth bracket-paren-tick
319: (') postpone ALiteral ; immediate restrict
320:
321: : ['] ( compilation. "name" -- ; run-time. -- xt ) \ core bracket-tick
1.15 crook 322: \g @i{xt} represents @i{name}'s interpretation
323: \g semantics. Perform @code{-14 throw} if the word has no
1.1 pazsan 324: \g interpretation semantics.
325: ' postpone ALiteral ; immediate restrict
326:
1.5 anton 327: : COMP' ( "name" -- w xt ) \ gforth comp-tick
1.15 crook 328: \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
1.1 pazsan 329: (') name>comp ;
330:
331: : [COMP'] ( compilation "name" -- ; run-time -- w xt ) \ gforth bracket-comp-tick
1.15 crook 332: \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
1.1 pazsan 333: COMP' swap POSTPONE Aliteral POSTPONE ALiteral ; immediate restrict
334:
1.18 jwilke 335: : postpone, ( w xt -- ) \ gforth postpone-comma
1.26 anton 336: \g Compile the compilation semantics represented by the
337: \g compilation token @i{w xt}.
1.18 jwilke 338: dup ['] execute =
339: if
340: drop compile,
341: else
1.61 pazsan 342: swap POSTPONE aliteral compile,
1.18 jwilke 343: then ;
344:
1.109 pazsan 345: has? recognizer [IF]
346: include ./recognizer.fs
347: [ELSE]
1.18 jwilke 348: : POSTPONE ( "name" -- ) \ core
349: \g Compiles the compilation semantics of @i{name}.
1.48 anton 350: COMP' postpone, ; immediate
1.109 pazsan 351: [THEN]
1.18 jwilke 352:
1.1 pazsan 353: \ \ compiler loop
354:
1.109 pazsan 355: has? recognizer 0= [IF]
1.72 anton 356: : compiler1 ( c-addr u -- ... xt )
1.99 pazsan 357: 2dup find-name [ [IFDEF] prelude-mask ] run-prelude [ [THEN] ] dup
1.1 pazsan 358: if ( c-addr u nt )
1.72 anton 359: nip nip name>comp
1.1 pazsan 360: else
361: drop
1.72 anton 362: 2dup 2>r snumber? dup
1.1 pazsan 363: IF
364: 0>
365: IF
1.72 anton 366: ['] 2literal
367: ELSE
368: ['] literal
1.1 pazsan 369: THEN
1.72 anton 370: 2rdrop
1.1 pazsan 371: ELSE
1.72 anton 372: drop 2r> compiler-notfound1
1.1 pazsan 373: THEN
374: then ;
375:
1.22 crook 376: : [ ( -- ) \ core left-bracket
1.8 crook 377: \G Enter interpretation state. Immediate word.
1.72 anton 378: ['] interpreter1 IS parser1 state off ; immediate
1.1 pazsan 379:
380: : ] ( -- ) \ core right-bracket
1.8 crook 381: \G Enter compilation state.
1.72 anton 382: ['] compiler1 IS parser1 state on ;
1.109 pazsan 383: [THEN]
1.1 pazsan 384:
385: \ \ Strings 22feb93py
386:
1.44 anton 387: : S, ( addr u -- )
1.45 anton 388: \ allot string as counted string
1.110 pazsan 389: here over char+ allot place align ;
1.45 anton 390:
391: : mem, ( addr u -- )
392: \ allot the memory block HERE (do alignment yourself)
1.110 pazsan 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:
1.83 pazsan 400: \ problematic only for big endian machines
401:
1.1 pazsan 402: : cset ( bmask c-addr -- )
1.30 anton 403: tuck @ or swap ! ;
1.1 pazsan 404:
405: : creset ( bmask c-addr -- )
1.30 anton 406: tuck @ swap invert and swap ! ;
1.1 pazsan 407:
408: : ctoggle ( bmask c-addr -- )
1.30 anton 409: tuck @ xor swap ! ;
1.1 pazsan 410:
411: : lastflags ( -- c-addr )
412: \ the address of the flags byte in the last header
413: \ aborts if the last defined word was headerless
1.56 anton 414: latest dup 0= abort" last word was headerless" cell+ ;
1.1 pazsan 415:
416: : immediate ( -- ) \ core
1.10 crook 417: \G Make the compilation semantics of a word be to @code{execute}
418: \G the execution semantics.
1.110 pazsan 419: immediate-mask lastflags cset ;
1.1 pazsan 420:
421: : restrict ( -- ) \ gforth
1.10 crook 422: \G A synonym for @code{compile-only}
1.110 pazsan 423: restrict-mask lastflags cset ;
1.18 jwilke 424:
1.1 pazsan 425: ' restrict alias compile-only ( -- ) \ gforth
1.10 crook 426: \G Remove the interpretation semantics of a word.
1.1 pazsan 427:
428: \ \ Create Variable User Constant 17mar93py
429:
1.15 crook 430: : Alias ( xt "name" -- ) \ gforth
1.1 pazsan 431: Header reveal
432: alias-mask lastflags creset
433: dup A, lastcfa ! ;
434:
435: : Create ( "name" -- ) \ core
436: Header reveal dovar: cfa, ;
437:
1.108 pazsan 438: : buffer: ( u "name" -- ) \ core ext
439: Create allot ;
440:
1.1 pazsan 441: : Variable ( "name" -- ) \ core
442: Create 0 , ;
443:
444: : AVariable ( "name" -- ) \ gforth
445: Create 0 A, ;
446:
1.22 crook 447: : 2Variable ( "name" -- ) \ double two-variable
1.85 pazsan 448: Create 0 , 0 , ;
1.1 pazsan 449:
1.21 crook 450: : uallot ( n -- ) \ gforth
451: udp @ swap udp +! ;
1.1 pazsan 452:
453: : User ( "name" -- ) \ gforth
454: Header reveal douser: cfa, cell uallot , ;
455:
456: : AUser ( "name" -- ) \ gforth
457: User ;
458:
1.110 pazsan 459: : (Constant) Header reveal docon: cfa, ;
1.1 pazsan 460:
1.110 pazsan 461: : (Value) Header reveal dovalue: cfa, ;
1.76 pazsan 462:
1.1 pazsan 463: : Constant ( w "name" -- ) \ core
1.15 crook 464: \G Define a constant @i{name} with value @i{w}.
1.1 pazsan 465: \G
1.15 crook 466: \G @i{name} execution: @i{-- w}
1.1 pazsan 467: (Constant) , ;
468:
469: : AConstant ( addr "name" -- ) \ gforth
470: (Constant) A, ;
471:
472: : Value ( w "name" -- ) \ core-ext
1.76 pazsan 473: (Value) , ;
1.1 pazsan 474:
1.37 jwilke 475: : AValue ( w "name" -- ) \ core-ext
1.76 pazsan 476: (Value) A, ;
1.37 jwilke 477:
1.22 crook 478: : 2Constant ( w1 w2 "name" -- ) \ double two-constant
1.1 pazsan 479: Create ( w1 w2 "name" -- )
480: 2,
481: DOES> ( -- w1 w2 )
482: 2@ ;
1.110 pazsan 483:
484: : (Field) Header reveal dofield: cfa, ;
1.39 pazsan 485:
486: \ \ interpret/compile:
487:
488: struct
489: >body
490: cell% field interpret/compile-int
491: cell% field interpret/compile-comp
492: end-struct interpret/compile-struct
493:
494: : interpret/compile: ( interp-xt comp-xt "name" -- ) \ gforth
495: Create immediate swap A, A,
496: DOES>
497: abort" executed primary cfa of an interpret/compile: word" ;
498: \ state @ IF cell+ THEN perform ;
499:
1.1 pazsan 500: \ IS Defer What's Defers TO 24feb93py
501:
1.68 anton 502: defer defer-default ( -- )
1.69 anton 503: ' abort is defer-default
504: \ default action for deferred words (overridden by a warning later)
1.67 anton 505:
1.1 pazsan 506: : Defer ( "name" -- ) \ gforth
1.67 anton 507: \G Define a deferred word @i{name}; its execution semantics can be
508: \G set with @code{defer!} or @code{is} (and they have to, before first
509: \G executing @i{name}.
1.1 pazsan 510: Header Reveal dodefer: cfa,
1.110 pazsan 511: ['] defer-default A, ;
1.1 pazsan 512:
1.67 anton 513: : defer@ ( xt-deferred -- xt ) \ gforth defer-fetch
514: \G @i{xt} represents the word currently associated with the deferred
515: \G word @i{xt-deferred}.
1.110 pazsan 516: >body @ ;
1.67 anton 517:
1.25 anton 518: : Defers ( compilation "name" -- ; run-time ... -- ... ) \ gforth
519: \G Compiles the present contents of the deferred word @i{name}
520: \G into the current definition. I.e., this produces static
521: \G binding as if @i{name} was not deferred.
1.67 anton 522: ' defer@ compile, ; immediate
1.18 jwilke 523:
1.103 anton 524: : does>-like ( xt -- )
525: \ xt ( addr -- ) is !does or !;abi-code etc, addr is the address
526: \ that should be stored right after the code address.
527: >r ;-hook ?struc
1.110 pazsan 528: exit-like
1.103 anton 529: here [ has? peephole [IF] ] 5 [ [ELSE] ] 4 [ [THEN] ] cells +
530: postpone aliteral r> compile, [compile] exit
531: [ has? peephole [IF] ] finish-code [ [THEN] ]
532: defstart ;
533:
1.18 jwilke 534: :noname
1.101 anton 535: here !does ]
1.18 jwilke 536: defstart :-hook ;
537: :noname
1.103 anton 538: ['] !does does>-like :-hook ;
1.18 jwilke 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}.
1.110 pazsan 543: >body ! ;
1.67 anton 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.7 anton 575: : (:noname) ( -- colon-sys )
576: \ common factor of : and :noname
1.34 anton 577: docol: cfa,
1.40 anton 578: defstart ] :-hook ;
1.7 anton 579:
1.1 pazsan 580: : : ( "name" -- colon-sys ) \ core colon
1.7 anton 581: Header (:noname) ;
582:
583: : :noname ( -- xt colon-sys ) \ core-ext colon-no-name
584: 0 last !
585: cfalign here (:noname) ;
1.1 pazsan 586:
587: : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon
1.57 pazsan 588: ;-hook ?struc [compile] exit
589: [ has? peephole [IF] ] finish-code [ [THEN] ]
590: reveal postpone [ ; immediate restrict
1.1 pazsan 591:
592: \ \ Search list handling: reveal words, recursive 23feb93py
593:
594: : last? ( -- false / nfa nfa )
1.56 anton 595: latest ?dup ;
1.1 pazsan 596:
1.83 pazsan 597: Variable warnings ( -- addr ) \ gforth
598: G -1 warnings T !
599:
1.1 pazsan 600: : (reveal) ( nt wid -- )
1.3 pazsan 601: wordlist-id dup >r
1.1 pazsan 602: @ over ( name>link ) !
603: r> ! ;
604:
605: \ make entry in wordlist-map
606: ' (reveal) f83search reveal-method !
607:
608: : check-shadow ( addr count wid -- )
1.2 pazsan 609: \G prints a warning if the string is already present in the wordlist
610: >r 2dup 2dup r> (search-wordlist) warnings @ and ?dup if
611: >stderr
612: ." redefined " name>string 2dup type
1.43 anton 613: str= 0= if
1.2 pazsan 614: ." with " type
615: else
616: 2drop
617: then
618: space space EXIT
619: then
620: 2drop 2drop ;
1.1 pazsan 621:
622: : reveal ( -- ) \ gforth
623: last?
624: if \ the last word has a header
625: dup ( name>link ) @ 1 and
626: if \ it is still hidden
627: dup ( name>link ) @ 1 xor ( nt wid )
628: 2dup >r name>string r> check-shadow ( nt wid )
1.83 pazsan 629: dup wordlist-map @ reveal-method perform
1.1 pazsan 630: else
631: drop
632: then
633: then ;
634:
635: : rehash ( wid -- )
636: dup wordlist-map @ rehash-method perform ;
637:
638: ' reveal alias recursive ( compilation -- ; run-time -- ) \ gforth
1.10 crook 639: \g Make the current definition visible, enabling it to call itself
1.1 pazsan 640: \g recursively.
641: immediate restrict
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>