1: \ compiler definitions 14sep97jaw
2:
3: \ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
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 3
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, see http://www.gnu.org/licenses/.
19:
20: \ \ Revisions-Log
21:
22: \ put in seperate file 14sep97jaw
23:
24: \ \ here allot , c, A, 17dec92py
25:
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
36: : allot ( n -- ) \ core
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.
43: here +
44: dup 1- usable-dictionary-end forthstart within -8 and throw
45: dp ! ;
46: [THEN]
47:
48: : c, ( c -- ) \ core c-comma
49: \G Reserve data space for one char and store @i{c} in the space.
50: here 1 chars allot [ has? flash [IF] ] flashc! [ [ELSE] ] c! [ [THEN] ] ;
51:
52: : , ( w -- ) \ core comma
53: \G Reserve data space for one cell and store @i{w} in the space.
54: here cell allot [ has? flash [IF] ] flash! [ [ELSE] ] ! [ [THEN] ] ;
55:
56: : 2, ( w1 w2 -- ) \ gforth
57: \G Reserve data space for two cells and store the double @i{w1
58: \G w2} there, @i{w2} first (lower address).
59: here 2 cells allot [ has? flash [IF] ] tuck flash! cell+ flash!
60: [ [ELSE] ] 2! [ [THEN] ] ;
61:
62: \ : aligned ( addr -- addr' ) \ core
63: \ [ cell 1- ] Literal + [ -1 cells ] Literal and ;
64:
65: : align ( -- ) \ core
66: \G If the data-space pointer is not aligned, reserve enough space to align it.
67: here dup aligned swap ?DO bl c, LOOP ;
68:
69: \ : faligned ( addr -- f-addr ) \ float f-aligned
70: \ [ 1 floats 1- ] Literal + [ -1 floats ] Literal and ;
71:
72: : falign ( -- ) \ float f-align
73: \G If the data-space pointer is not float-aligned, reserve
74: \G enough space to align it.
75: here dup faligned swap
76: ?DO
77: bl c,
78: LOOP ;
79:
80: : maxalign ( -- ) \ gforth
81: \G Align data-space pointer for all alignment requirements.
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
89: \G Align data-space pointer for code field requirements (i.e., such
90: \G that the corresponding body is maxaligned).
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 [ has? rom [IF] ] $E0 [ [ELSE] ] alias-mask [ [THEN] ] or c,
109: [ has? flash [IF] ]
110: bounds ?DO I c@ c, LOOP
111: [ [ELSE] ]
112: here swap chars dup allot move
113: [ [THEN] ] ;
114:
115: : longstring, ( c-addr u -- ) \ gforth
116: \G puts down string as longcstring
117: dup , here swap chars dup allot move ;
118:
119: [IFDEF] prelude-mask
120: variable next-prelude
121:
122: : prelude, ( -- )
123: next-prelude @ if
124: align next-prelude @ ,
125: then ;
126: [THEN]
127:
128: : header, ( c-addr u -- ) \ gforth
129: name-too-long?
130: dup max-name-length @ max max-name-length !
131: [ [IFDEF] prelude-mask ] prelude, [ [THEN] ]
132: align here last !
133: [ has? ec [IF] ]
134: -1 A,
135: [ [ELSE] ]
136: current @ 1 or A, \ link field; before revealing, it contains the
137: \ tagged reveal-into wordlist
138: [ [THEN] ]
139: [ has? f83headerstring [IF] ]
140: string,
141: [ [ELSE] ]
142: longstring, alias-mask lastflags cset
143: next-prelude @ 0<> prelude-mask and lastflags cset
144: next-prelude off
145: [ [THEN] ]
146: cfalign ;
147:
148: : input-stream-header ( "name" -- )
149: parse-name name-too-short? header, ;
150:
151: : input-stream ( -- ) \ general
152: \G switches back to getting the name from the input stream ;
153: ['] input-stream-header IS (header) ;
154:
155: ' input-stream-header IS (header)
156:
157: 2variable nextname-string
158:
159: has? OS [IF]
160: : nextname-header ( -- )
161: nextname-string 2@ header,
162: nextname-string free-mem-var
163: input-stream ;
164: [THEN]
165:
166: \ the next name is given in the string
167:
168: has? OS [IF]
169: : nextname ( c-addr u -- ) \ gforth
170: \g The next defined word will have the name @var{c-addr u}; the
171: \g defining word will leave the input stream alone.
172: name-too-long?
173: nextname-string free-mem-var
174: save-mem nextname-string 2!
175: ['] nextname-header IS (header) ;
176: [THEN]
177:
178: : noname-header ( -- )
179: 0 last ! cfalign
180: input-stream ;
181:
182: : noname ( -- ) \ gforth
183: \g The next defined word will be anonymous. The defining word will
184: \g leave the input stream alone. The xt of the defined word will
185: \g be given by @code{latestxt}.
186: ['] noname-header IS (header) ;
187:
188: : latestxt ( -- xt ) \ gforth
189: \G @i{xt} is the execution token of the last word defined.
190: \ The main purpose of this word is to get the xt of words defined using noname
191: lastcfa @ ;
192:
193: ' latestxt alias lastxt \ gforth-obsolete
194: \G old name for @code{latestxt}.
195:
196: : latest ( -- nt ) \ gforth
197: \G @var{nt} is the name token of the last word defined; it is 0 if the
198: \G last word has no name.
199: last @ ;
200:
201: \ \ literals 17dec92py
202:
203: : Literal ( compilation n -- ; run-time -- n ) \ core
204: \G Compilation semantics: compile the run-time semantics.@*
205: \G Run-time Semantics: push @i{n}.@*
206: \G Interpretation semantics: undefined.
207: [ [IFDEF] lit, ]
208: lit,
209: [ [ELSE] ]
210: postpone lit ,
211: [ [THEN] ] ; immediate restrict
212:
213: : 2Literal ( compilation w1 w2 -- ; run-time -- w1 w2 ) \ double two-literal
214: \G Compile appropriate code such that, at run-time, @i{w1 w2} are
215: \G placed on the stack. Interpretation semantics are undefined.
216: swap postpone Literal postpone Literal ; immediate restrict
217:
218: : ALiteral ( compilation addr -- ; run-time -- addr ) \ gforth
219: [ [IFDEF] alit, ]
220: alit,
221: [ [ELSE] ]
222: postpone lit A,
223: [ [THEN] ] ; immediate restrict
224:
225: Defer char@ ( addr u -- char addr' u' )
226: :noname over c@ -rot 1 /string ; IS char@
227:
228: : char ( '<spaces>ccc' -- c ) \ core
229: \G Skip leading spaces. Parse the string @i{ccc} and return @i{c}, the
230: \G display code representing the first character of @i{ccc}.
231: parse-name char@ 2drop ;
232:
233: : [char] ( compilation '<spaces>ccc' -- ; run-time -- c ) \ core bracket-char
234: \G Compilation: skip leading spaces. Parse the string
235: \G @i{ccc}. Run-time: return @i{c}, the display code
236: \G representing the first character of @i{ccc}. Interpretation
237: \G semantics for this word are undefined.
238: char postpone Literal ; immediate restrict
239:
240: \ \ threading 17mar93py
241:
242: : cfa, ( code-address -- ) \ gforth cfa-comma
243: here
244: dup lastcfa !
245: [ has? rom [IF] ] 2 cells allot [ [ELSE] ] 0 A, 0 , [ [THEN] ]
246: code-address! ;
247:
248: [IFUNDEF] compile,
249: defer compile, ( xt -- ) \ core-ext compile-comma
250: \G Compile the word represented by the execution token @i{xt}
251: \G into the current definition.
252:
253: ' , is compile,
254: [THEN]
255:
256: has? ec 0= [IF]
257: defer basic-block-end ( -- )
258:
259: :noname ( -- )
260: 0 compile-prim1 ;
261: is basic-block-end
262: [THEN]
263:
264: has? primcentric [IF]
265: has? peephole [IF]
266: \ dynamic only
267: : peephole-compile, ( xt -- )
268: \ compile xt, appending its code to the current dynamic superinstruction
269: here swap , compile-prim1 ;
270: [ELSE]
271: : peephole-compile, ( xt -- addr ) @ , ;
272: [THEN]
273:
274: : compile-to-prims, ( xt -- )
275: \G compile xt to use primitives (and their peephole optimization)
276: \G instead of ","-ing the xt.
277: \ !! all POSTPONEs here postpone primitives; this can be optimized
278: dup >does-code if
279: ['] does-exec peephole-compile, , EXIT
280: \ dup >body POSTPONE literal ['] call peephole-compile, >does-code , EXIT
281: then
282: dup >code-address CASE
283: dovalue: OF >body ['] lit@ peephole-compile, , EXIT ENDOF
284: docon: OF >body @ ['] lit peephole-compile, , EXIT ENDOF
285: \ docon: OF >body POSTPONE literal ['] @ peephole-compile, EXIT ENDOF
286: \ docon is also used by VALUEs, so don't @ at compile time
287: docol: OF >body ['] call peephole-compile, , EXIT ENDOF
288: dovar: OF >body ['] lit peephole-compile, , EXIT ENDOF
289: douser: OF >body @ ['] useraddr peephole-compile, , EXIT ENDOF
290: dodefer: OF >body ['] lit-perform peephole-compile, , EXIT ENDOF
291: dofield: OF >body @ ['] lit+ peephole-compile, , EXIT ENDOF
292: doabicode: OF >body ['] abi-call peephole-compile, , EXIT ENDOF
293: \ dofield: OF >body @ POSTPONE literal ['] + peephole-compile, EXIT ENDOF
294: \ code words and ;code-defined words (code words could be optimized):
295: dup in-dictionary? IF drop POSTPONE literal ['] execute peephole-compile, EXIT THEN
296: ENDCASE
297: peephole-compile, ;
298:
299: ' compile-to-prims, IS compile,
300: [ELSE]
301: ' , is compile,
302: [THEN]
303:
304: : !does ( addr -- ) \ gforth store-does
305: latestxt does-code! ;
306:
307: \ : (does>) ( R: addr -- )
308: \ r> cfaligned /does-handler + !does ; \ !! no gforth-native
309:
310: \ \ !! unused, but ifdefed/gosted in some places
311: \ : (does>2) ( addr -- )
312: \ cfaligned /does-handler + !does ;
313:
314: : (compile) ( -- ) \ gforth-obsolete: dummy
315: true abort" (compile) doesn't work, use POSTPONE instead" ;
316:
317: \ \ ticks
318:
319: : name>comp ( nt -- w xt ) \ gforth name-to-comp
320: \G @i{w xt} is the compilation token for the word @i{nt}.
321: (name>comp)
322: 1 = if
323: ['] execute
324: else
325: ['] compile,
326: then ;
327:
328: : [(')] ( compilation "name" -- ; run-time -- nt ) \ gforth bracket-paren-tick
329: (') postpone ALiteral ; immediate restrict
330:
331: : ['] ( compilation. "name" -- ; run-time. -- xt ) \ core bracket-tick
332: \g @i{xt} represents @i{name}'s interpretation
333: \g semantics. Perform @code{-14 throw} if the word has no
334: \g interpretation semantics.
335: ' postpone ALiteral ; immediate restrict
336:
337: : COMP' ( "name" -- w xt ) \ gforth comp-tick
338: \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
339: (') name>comp ;
340:
341: : [COMP'] ( compilation "name" -- ; run-time -- w xt ) \ gforth bracket-comp-tick
342: \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
343: COMP' swap POSTPONE Aliteral POSTPONE ALiteral ; immediate restrict
344:
345: : postpone, ( w xt -- ) \ gforth postpone-comma
346: \g Compile the compilation semantics represented by the
347: \g compilation token @i{w xt}.
348: dup ['] execute =
349: if
350: drop compile,
351: else
352: swap POSTPONE aliteral compile,
353: then ;
354:
355: : POSTPONE ( "name" -- ) \ core
356: \g Compiles the compilation semantics of @i{name}.
357: COMP' postpone, ; immediate
358:
359: \ \ recurse 17may93jaw
360:
361: : recurse ( compilation -- ; run-time ?? -- ?? ) \ core
362: \g Call the current definition.
363: latestxt compile, ; immediate restrict
364:
365: \ \ compiler loop
366:
367: : compiler1 ( c-addr u -- ... xt )
368: 2dup find-name [ [IFDEF] prelude-mask ] run-prelude [ [THEN] ] dup
369: if ( c-addr u nt )
370: nip nip name>comp
371: else
372: drop
373: 2dup 2>r snumber? dup
374: IF
375: 0>
376: IF
377: ['] 2literal
378: ELSE
379: ['] literal
380: THEN
381: 2rdrop
382: ELSE
383: drop 2r> compiler-notfound1
384: THEN
385: then ;
386:
387: : [ ( -- ) \ core left-bracket
388: \G Enter interpretation state. Immediate word.
389: ['] interpreter1 IS parser1 state off ; immediate
390:
391: : ] ( -- ) \ core right-bracket
392: \G Enter compilation state.
393: ['] compiler1 IS parser1 state on ;
394:
395: \ \ Strings 22feb93py
396:
397: : S, ( addr u -- )
398: \ allot string as counted string
399: [ has? flash [IF] ]
400: dup c, bounds ?DO I c@ c, LOOP
401: [ [ELSE] ]
402: here over char+ allot place align
403: [ [THEN] ] ;
404:
405: : mem, ( addr u -- )
406: \ allot the memory block HERE (do alignment yourself)
407: [ has? flash [IF] ]
408: bounds ?DO I c@ c, LOOP
409: [ [ELSE] ]
410: here over allot swap move
411: [ [THEN] ] ;
412:
413: : ," ( "string"<"> -- )
414: [char] " parse s, ;
415:
416: \ \ Header states 23feb93py
417:
418: \ problematic only for big endian machines
419:
420: has? f83headerstring [IF]
421: : cset ( bmask c-addr -- )
422: tuck c@ or swap c! ;
423:
424: : creset ( bmask c-addr -- )
425: tuck c@ swap invert and swap c! ;
426:
427: : ctoggle ( bmask c-addr -- )
428: tuck c@ xor swap c! ;
429: [ELSE]
430: : cset ( bmask c-addr -- )
431: tuck @ or swap ! ;
432:
433: : creset ( bmask c-addr -- )
434: tuck @ swap invert and swap ! ;
435:
436: : ctoggle ( bmask c-addr -- )
437: tuck @ xor swap ! ;
438: [THEN]
439:
440: : lastflags ( -- c-addr )
441: \ the address of the flags byte in the last header
442: \ aborts if the last defined word was headerless
443: latest dup 0= abort" last word was headerless" cell+ ;
444:
445: : immediate ( -- ) \ core
446: \G Make the compilation semantics of a word be to @code{execute}
447: \G the execution semantics.
448: immediate-mask lastflags [ has? rom [IF] ] creset [ [ELSE] ] cset [ [THEN] ] ;
449:
450: : restrict ( -- ) \ gforth
451: \G A synonym for @code{compile-only}
452: restrict-mask lastflags [ has? rom [IF] ] creset [ [ELSE] ] cset [ [THEN] ] ;
453:
454: ' restrict alias compile-only ( -- ) \ gforth
455: \G Remove the interpretation semantics of a word.
456:
457: \ \ Create Variable User Constant 17mar93py
458:
459: : Alias ( xt "name" -- ) \ gforth
460: Header reveal
461: alias-mask lastflags creset
462: dup A, lastcfa ! ;
463:
464: doer? :dovar [IF]
465:
466: : Create ( "name" -- ) \ core
467: Header reveal dovar: cfa, ;
468: [ELSE]
469:
470: : Create ( "name" -- ) \ core
471: Header reveal here lastcfa ! 0 A, 0 , DOES> ;
472: [THEN]
473:
474: has? flash [IF]
475: : (variable) dpp @ normal-dp = IF Create dpp @
476: ELSE normal-dp @ Constant dpp @ ram THEN ;
477: : Variable ( "name" -- ) \ core
478: (Variable) 0 , dpp ! ;
479:
480: : AVariable ( "name" -- ) \ gforth
481: (Variable) 0 A, dpp ! ;
482:
483: : 2Variable ( "name" -- ) \ double two-variable
484: (Variable) 0 , 0 , dpp ! ;
485: [ELSE]
486: : Variable ( "name" -- ) \ core
487: Create 0 , ;
488:
489: : AVariable ( "name" -- ) \ gforth
490: Create 0 A, ;
491:
492: : 2Variable ( "name" -- ) \ double two-variable
493: Create 0 , 0 , ;
494: [THEN]
495:
496: has? no-userspace 0= [IF]
497: : uallot ( n -- ) \ gforth
498: udp @ swap udp +! ;
499:
500: doer? :douser [IF]
501:
502: : User ( "name" -- ) \ gforth
503: Header reveal douser: cfa, cell uallot , ;
504:
505: : AUser ( "name" -- ) \ gforth
506: User ;
507: [ELSE]
508:
509: : User Create cell uallot , DOES> @ up @ + ;
510:
511: : AUser User ;
512: [THEN]
513: [THEN]
514:
515: doer? :docon [IF]
516: : (Constant) Header reveal docon: cfa, ;
517: [ELSE]
518: : (Constant) Create DOES> @ ;
519: [THEN]
520:
521: doer? :dovalue [IF]
522: : (Value) Header reveal dovalue: cfa, ;
523: [ELSE]
524: has? rom [IF]
525: : (Value) Create DOES> @ @ ;
526: [ELSE]
527: : (Value) Create DOES> @ ;
528: [THEN]
529: [THEN]
530:
531: : Constant ( w "name" -- ) \ core
532: \G Define a constant @i{name} with value @i{w}.
533: \G
534: \G @i{name} execution: @i{-- w}
535: (Constant) , ;
536:
537: : AConstant ( addr "name" -- ) \ gforth
538: (Constant) A, ;
539:
540: has? flash [IF]
541: : Value ( w "name" -- ) \ core-ext
542: (Value) dpp @ >r here cell allot >r
543: ram here >r , r> r> flash! r> dpp ! ;
544:
545: ' Value alias AValue
546: [ELSE]
547: : Value ( w "name" -- ) \ core-ext
548: (Value) , ;
549:
550: : AValue ( w "name" -- ) \ core-ext
551: (Value) A, ;
552: [THEN]
553:
554: : 2Constant ( w1 w2 "name" -- ) \ double two-constant
555: Create ( w1 w2 "name" -- )
556: 2,
557: DOES> ( -- w1 w2 )
558: 2@ ;
559:
560: doer? :dofield [IF]
561: : (Field) Header reveal dofield: cfa, ;
562: [ELSE]
563: : (Field) Create DOES> @ + ;
564: [THEN]
565:
566: \ \ interpret/compile:
567:
568: struct
569: >body
570: cell% field interpret/compile-int
571: cell% field interpret/compile-comp
572: end-struct interpret/compile-struct
573:
574: : interpret/compile: ( interp-xt comp-xt "name" -- ) \ gforth
575: Create immediate swap A, A,
576: DOES>
577: abort" executed primary cfa of an interpret/compile: word" ;
578: \ state @ IF cell+ THEN perform ;
579:
580: \ IS Defer What's Defers TO 24feb93py
581:
582: defer defer-default ( -- )
583: ' abort is defer-default
584: \ default action for deferred words (overridden by a warning later)
585:
586: doer? :dodefer [IF]
587:
588: : Defer ( "name" -- ) \ gforth
589: \G Define a deferred word @i{name}; its execution semantics can be
590: \G set with @code{defer!} or @code{is} (and they have to, before first
591: \G executing @i{name}.
592: Header Reveal dodefer: cfa,
593: [ has? rom [IF] ] here >r cell allot
594: dpp @ ram here r> flash! ['] defer-default A, dpp !
595: [ [ELSE] ] ['] defer-default A, [ [THEN] ] ;
596:
597: [ELSE]
598:
599: has? rom [IF]
600: : Defer ( "name" -- ) \ gforth
601: Create here >r cell allot
602: dpp @ ram here r> flash! ['] defer-default A, dpp !
603: DOES> @ @ execute ;
604: [ELSE]
605: : Defer ( "name" -- ) \ gforth
606: Create ['] defer-default A,
607: DOES> @ execute ;
608: [THEN]
609: [THEN]
610:
611: : defer@ ( xt-deferred -- xt ) \ gforth defer-fetch
612: \G @i{xt} represents the word currently associated with the deferred
613: \G word @i{xt-deferred}.
614: >body @ [ has? rom [IF] ] @ [ [THEN] ] ;
615:
616: : Defers ( compilation "name" -- ; run-time ... -- ... ) \ gforth
617: \G Compiles the present contents of the deferred word @i{name}
618: \G into the current definition. I.e., this produces static
619: \G binding as if @i{name} was not deferred.
620: ' defer@ compile, ; immediate
621:
622: :noname
623: here !does ]
624: defstart :-hook ;
625: :noname
626: ;-hook ?struc
627: [ has? xconds [IF] ] exit-like [ [THEN] ]
628: here [ has? peephole [IF] ] 5 [ [ELSE] ] 4 [ [THEN] ] cells +
629: postpone aliteral postpone !does [compile] exit
630: [ has? peephole [IF] ] finish-code [ [THEN] ]
631: defstart :-hook ;
632: interpret/compile: DOES> ( compilation colon-sys1 -- colon-sys2 ; run-time nest-sys -- ) \ core does
633:
634: : defer! ( xt xt-deferred -- ) \ gforth defer-store
635: \G Changes the @code{defer}red word @var{xt-deferred} to execute @var{xt}.
636: >body [ has? rom [IF] ] @ [ [THEN] ] ! ;
637:
638: : <IS> ( "name" xt -- ) \ gforth
639: \g Changes the @code{defer}red word @var{name} to execute @var{xt}.
640: ' defer! ;
641:
642: : [IS] ( compilation "name" -- ; run-time xt -- ) \ gforth bracket-is
643: \g At run-time, changes the @code{defer}red word @var{name} to
644: \g execute @var{xt}.
645: ' postpone ALiteral postpone defer! ; immediate restrict
646:
647: ' <IS>
648: ' [IS]
649: interpret/compile: IS ( compilation/interpretation "name-deferred" -- ; run-time xt -- ) \ gforth
650: \G Changes the @code{defer}red word @var{name} to execute @var{xt}.
651: \G Its compilation semantics parses at compile time.
652:
653: ' <IS>
654: ' [IS]
655: interpret/compile: TO ( w "name" -- ) \ core-ext
656:
657: : interpret/compile? ( xt -- flag )
658: >does-code ['] DOES> >does-code = ;
659:
660: \ \ : ; 24feb93py
661:
662: defer :-hook ( sys1 -- sys2 )
663:
664: defer ;-hook ( sys2 -- sys1 )
665:
666: 0 Constant defstart
667:
668: [IFDEF] docol,
669: : (:noname) ( -- colon-sys )
670: \ common factor of : and :noname
671: docol, ]comp
672: [ELSE]
673: : (:noname) ( -- colon-sys )
674: \ common factor of : and :noname
675: docol: cfa,
676: [THEN]
677: defstart ] :-hook ;
678:
679: : : ( "name" -- colon-sys ) \ core colon
680: Header (:noname) ;
681:
682: : :noname ( -- xt colon-sys ) \ core-ext colon-no-name
683: 0 last !
684: cfalign here (:noname) ;
685:
686: [IFDEF] fini,
687: : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon
688: ;-hook ?struc fini, comp[ reveal postpone [ ; immediate restrict
689: [ELSE]
690: : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core semicolon
691: ;-hook ?struc [compile] exit
692: [ has? peephole [IF] ] finish-code [ [THEN] ]
693: reveal postpone [ ; immediate restrict
694: [THEN]
695:
696: \ \ Search list handling: reveal words, recursive 23feb93py
697:
698: : last? ( -- false / nfa nfa )
699: latest ?dup ;
700:
701: Variable warnings ( -- addr ) \ gforth
702: G -1 warnings T !
703:
704: has? ec [IF]
705: : reveal ( -- ) \ gforth
706: last?
707: if \ the last word has a header
708: dup ( name>link ) @ -1 =
709: if \ it is still hidden
710: forth-wordlist dup >r @ over
711: [ has? flash [IF] ] flash! [ [ELSE] ] ! [ [THEN] ] r> !
712: else
713: drop
714: then
715: then ;
716: [ELSE]
717: : (reveal) ( nt wid -- )
718: wordlist-id dup >r
719: @ over ( name>link ) !
720: r> ! ;
721:
722: \ make entry in wordlist-map
723: ' (reveal) f83search reveal-method !
724:
725: : check-shadow ( addr count wid -- )
726: \G prints a warning if the string is already present in the wordlist
727: >r 2dup 2dup r> (search-wordlist) warnings @ and ?dup if
728: >stderr
729: ." redefined " name>string 2dup type
730: str= 0= if
731: ." with " type
732: else
733: 2drop
734: then
735: space space EXIT
736: then
737: 2drop 2drop ;
738:
739: : reveal ( -- ) \ gforth
740: last?
741: if \ the last word has a header
742: dup ( name>link ) @ 1 and
743: if \ it is still hidden
744: dup ( name>link ) @ 1 xor ( nt wid )
745: 2dup >r name>string r> check-shadow ( nt wid )
746: dup wordlist-map @ reveal-method perform
747: else
748: drop
749: then
750: then ;
751:
752: : rehash ( wid -- )
753: dup wordlist-map @ rehash-method perform ;
754: [THEN]
755:
756: ' reveal alias recursive ( compilation -- ; run-time -- ) \ gforth
757: \g Make the current definition visible, enabling it to call itself
758: \g recursively.
759: immediate restrict
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>