Annotation of gforth/kernel/comp.fs, revision 1.37

1.1       pazsan      1: \ compiler definitions                                         14sep97jaw
                      2: 
1.28      anton       3: \ Copyright (C) 1995,1996,1997,1998,2000 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?
                    116:     align here last !
                    117:     current @ 1 or A,  \ link field; before revealing, it contains the
                    118:                        \ tagged reveal-into wordlist
1.30      anton     119:     longstring, cfalign
1.1       pazsan    120:     alias-mask lastflags cset ;
                    121: 
                    122: : input-stream-header ( "name" -- )
                    123:     name name-too-short? header, ;
                    124: 
                    125: : input-stream ( -- )  \ general
                    126:     \G switches back to getting the name from the input stream ;
                    127:     ['] input-stream-header IS (header) ;
                    128: 
                    129: ' input-stream-header IS (header)
                    130: 
1.32      anton     131: 2variable nextname-string
1.1       pazsan    132: 
1.33      pazsan    133: has? OS [IF]
1.1       pazsan    134: : nextname-header ( -- )
1.32      anton     135:     nextname-string 2@ header,
                    136:     nextname-string free-mem-var
1.1       pazsan    137:     input-stream ;
1.33      pazsan    138: [THEN]
1.1       pazsan    139: 
                    140: \ the next name is given in the string
                    141: 
1.33      pazsan    142: has? OS [IF]
1.1       pazsan    143: : nextname ( c-addr u -- ) \ gforth
1.19      anton     144:     \g The next defined word will have the name @var{c-addr u}; the
                    145:     \g defining word will leave the input stream alone.
1.1       pazsan    146:     name-too-long?
1.32      anton     147:     nextname-string free-mem-var
                    148:     save-mem nextname-string 2!
1.1       pazsan    149:     ['] nextname-header IS (header) ;
1.33      pazsan    150: [THEN]
1.1       pazsan    151: 
                    152: : noname-header ( -- )
                    153:     0 last ! cfalign
                    154:     input-stream ;
                    155: 
                    156: : noname ( -- ) \ gforth
1.19      anton     157:     \g The next defined word will be anonymous. The defining word will
                    158:     \g leave the input stream alone. The xt of the defined word will
                    159:     \g be given by @code{lastxt}.
1.1       pazsan    160:     ['] noname-header IS (header) ;
                    161: 
                    162: : lastxt ( -- xt ) \ gforth
1.15      crook     163:     \G @i{xt} is the execution token of the last word defined.
1.13      crook     164:     \ The main purpose of this word is to get the xt of words defined using noname
1.1       pazsan    165:     lastcfa @ ;
                    166: 
                    167: \ \ literals                                                   17dec92py
                    168: 
                    169: : Literal  ( compilation n -- ; run-time -- n ) \ core
1.27      anton     170:     \G Compilation semantics: compile the run-time semantics.@*
                    171:     \G Run-time Semantics: push @i{n}.@*
                    172:     \G Interpretation semantics: undefined.
1.14      jwilke    173: [ [IFDEF] lit, ]
                    174:     lit,
                    175: [ [ELSE] ]
1.27      anton     176:     postpone lit ,
1.14      jwilke    177: [ [THEN] ] ; immediate restrict
1.1       pazsan    178: 
                    179: : ALiteral ( compilation addr -- ; run-time -- addr ) \ gforth
1.14      jwilke    180: [ [IFDEF] alit, ]
                    181:     alit,
                    182: [ [ELSE] ]
                    183:     postpone lit A, 
                    184: [ [THEN] ] ; immediate restrict
1.1       pazsan    185: 
1.8       crook     186: : char   ( '<spaces>ccc' -- c ) \ core
1.15      crook     187:     \G Skip leading spaces. Parse the string @i{ccc} and return @i{c}, the
                    188:     \G display code representing the first character of @i{ccc}.
1.1       pazsan    189:     bl word char+ c@ ;
                    190: 
1.8       crook     191: : [char] ( compilation '<spaces>ccc' -- ; run-time -- c ) \ core bracket-char
1.10      crook     192:     \G Compilation: skip leading spaces. Parse the string
1.15      crook     193:     \G @i{ccc}. Run-time: return @i{c}, the display code
                    194:     \G representing the first character of @i{ccc}.  Interpretation
1.10      crook     195:     \G semantics for this word are undefined.
1.1       pazsan    196:     char postpone Literal ; immediate restrict
                    197: 
                    198: \ \ threading                                                  17mar93py
                    199: 
                    200: : cfa,     ( code-address -- )  \ gforth       cfa-comma
                    201:     here
                    202:     dup lastcfa !
                    203:     0 A, 0 ,  code-address! ;
                    204: 
1.14      jwilke    205: [IFUNDEF] compile,
1.34      anton     206: defer compile, ( xt -- )       \ core-ext      compile-comma
                    207: \G  Compile the word represented by the execution token @i{xt}
                    208: \G  into the current definition.
                    209: 
                    210: ' , is compile,
1.14      jwilke    211: [THEN]
1.1       pazsan    212: 
1.36      pazsan    213: has? peephole [IF]
1.34      anton     214: : peephole-compile, ( xt -- )
                    215:     last-compiled @ ?dup if
                    216:        @ over peeptable peephole-opt ?dup if
                    217:            last-compiled @ ! drop EXIT
                    218:        then
                    219:     then
                    220:     here last-compiled !
                    221:     , ;
                    222: 
1.35      anton     223: : compile-to-prims, ( xt -- )
                    224:     \G compile xt to use primitives (and their peephole optimization)
                    225:     \G instead of ","-ing the xt.
                    226:     \ !! all POSTPONEs here postpone primitives; this can be optimized
                    227:     dup >does-code ?dup if
                    228:        swap >body POSTPONE literal POSTPONE call , EXIT
                    229:     then
                    230:     dup >code-address CASE
                    231:        docon:   OF >body POSTPONE literal POSTPONE @ EXIT ENDOF
                    232:           \ docon is also used by VALUEs, so don't @ at compile time
                    233:        docol:   OF >body POSTPONE call , EXIT ENDOF
                    234:        dovar:   OF >body POSTPONE literal EXIT ENDOF
                    235:        douser:  OF >body @ POSTPONE useraddr , EXIT ENDOF
                    236:        dodefer: OF >body POSTPONE literal POSTPONE @ POSTPONE EXECUTE EXIT
                    237:        ENDOF
                    238:        dofield: OF >body @ POSTPONE literal POSTPONE + EXIT ENDOF
                    239:     ENDCASE
                    240:     peephole-compile, ;
                    241: 
                    242: ' compile-to-prims, IS compile,
1.36      pazsan    243: [ELSE]
                    244: ' , is compile,
                    245: [THEN]
1.34      anton     246: 
1.1       pazsan    247: : !does    ( addr -- ) \ gforth        store-does
                    248:     lastxt does-code! ;
                    249: 
                    250: : (does>)  ( R: addr -- )
                    251:     r> cfaligned /does-handler + !does ;
                    252: 
                    253: : dodoes,  ( -- )
                    254:   cfalign here /does-handler allot does-handler! ;
                    255: 
                    256: : (compile) ( -- ) \ gforth
                    257:     r> dup cell+ >r @ compile, ;
                    258: 
                    259: \ \ ticks
                    260: 
                    261: : name>comp ( nt -- w xt ) \ gforth
1.15      crook     262:     \G @i{w xt} is the compilation token for the word @i{nt}.
1.1       pazsan    263:     (name>comp)
                    264:     1 = if
                    265:         ['] execute
                    266:     else
                    267:         ['] compile,
                    268:     then ;
                    269: 
                    270: : [(')]  ( compilation "name" -- ; run-time -- nt ) \ gforth bracket-paren-tick
                    271:     (') postpone ALiteral ; immediate restrict
                    272: 
                    273: : [']  ( compilation. "name" -- ; run-time. -- xt ) \ core      bracket-tick
1.15      crook     274:     \g @i{xt} represents @i{name}'s interpretation
                    275:     \g semantics. Perform @code{-14 throw} if the word has no
1.1       pazsan    276:     \g interpretation semantics.
                    277:     ' postpone ALiteral ; immediate restrict
                    278: 
1.5       anton     279: : COMP'    ( "name" -- w xt ) \ gforth  comp-tick
1.15      crook     280:     \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
1.1       pazsan    281:     (') name>comp ;
                    282: 
                    283: : [COMP']  ( compilation "name" -- ; run-time -- w xt ) \ gforth bracket-comp-tick
1.15      crook     284:     \g Compilation token @i{w xt} represents @i{name}'s compilation semantics.
1.1       pazsan    285:     COMP' swap POSTPONE Aliteral POSTPONE ALiteral ; immediate restrict
                    286: 
1.18      jwilke    287: : postpone, ( w xt -- ) \ gforth       postpone-comma
1.26      anton     288:     \g Compile the compilation semantics represented by the
                    289:     \g compilation token @i{w xt}.
1.18      jwilke    290:     dup ['] execute =
                    291:     if
                    292:        drop compile,
                    293:     else
                    294:        dup ['] compile, =
                    295:        if
                    296:            drop POSTPONE (compile) a,
                    297:        else
                    298:            swap POSTPONE aliteral compile,
                    299:        then
                    300:     then ;
                    301: 
                    302: : POSTPONE ( "name" -- ) \ core
                    303:     \g Compiles the compilation semantics of @i{name}.
                    304:     COMP' postpone, ; immediate restrict
                    305: 
1.1       pazsan    306: \ \ recurse                                                    17may93jaw
                    307: 
                    308: : recurse ( compilation -- ; run-time ?? -- ?? ) \ core
1.10      crook     309:     \g Call the current definition.
1.1       pazsan    310:     lastxt compile, ; immediate restrict
                    311: 
                    312: \ \ compiler loop
                    313: 
                    314: : compiler ( c-addr u -- )
                    315:     2dup find-name dup
                    316:     if ( c-addr u nt )
                    317:        nip nip name>comp execute
                    318:     else
                    319:        drop
                    320:        2dup snumber? dup
                    321:        IF
                    322:            0>
                    323:            IF
                    324:                swap postpone Literal
                    325:            THEN
                    326:            postpone Literal
                    327:            2drop
                    328:        ELSE
                    329:            drop compiler-notfound
                    330:        THEN
                    331:     then ;
                    332: 
1.22      crook     333: : [ ( -- ) \  core     left-bracket
1.8       crook     334:     \G Enter interpretation state. Immediate word.
1.1       pazsan    335:     ['] interpreter  IS parser state off ; immediate
                    336: 
                    337: : ] ( -- ) \ core      right-bracket
1.8       crook     338:     \G Enter compilation state.
1.1       pazsan    339:     ['] compiler     IS parser state on  ;
                    340: 
                    341: \ \ Strings                                                    22feb93py
                    342: 
                    343: : ," ( "string"<"> -- ) [char] " parse
                    344:   here over char+ allot  place align ;
                    345: 
                    346: : SLiteral ( Compilation c-addr1 u ; run-time -- c-addr2 u ) \ string
1.15      crook     347:     \G Compilation: compile the string specified by @i{c-addr1},
                    348:     \G @i{u} into the current definition. Run-time: return
                    349:     \G @i{c-addr2 u} describing the address and length of the
1.10      crook     350:     \G string.
1.1       pazsan    351:     postpone (S") here over char+ allot  place align ;
                    352:                                              immediate restrict
                    353: 
                    354: \ \ abort"                                                     22feb93py
                    355: 
                    356: : abort" ( compilation 'ccc"' -- ; run-time f -- ) \ core,exception-ext        abort-quote
1.15      crook     357:     \G If any bit of @i{f} is non-zero, perform the function of @code{-2 throw},
                    358:     \G displaying the string @i{ccc} if there is no exception frame on the
1.10      crook     359:     \G exception stack.
1.1       pazsan    360:     postpone (abort") ," ;        immediate restrict
                    361: 
                    362: \ \ Header states                                              23feb93py
                    363: 
                    364: : cset ( bmask c-addr -- )
1.30      anton     365:     tuck @ or swap ! ; 
1.1       pazsan    366: 
                    367: : creset ( bmask c-addr -- )
1.30      anton     368:     tuck @ swap invert and swap ! ; 
1.1       pazsan    369: 
                    370: : ctoggle ( bmask c-addr -- )
1.30      anton     371:     tuck @ xor swap ! ; 
1.1       pazsan    372: 
                    373: : lastflags ( -- c-addr )
                    374:     \ the address of the flags byte in the last header
                    375:     \ aborts if the last defined word was headerless
                    376:     last @ dup 0= abort" last word was headerless" cell+ ;
                    377: 
                    378: : immediate ( -- ) \ core
1.10      crook     379:     \G Make the compilation semantics of a word be to @code{execute}
                    380:     \G the execution semantics.
1.1       pazsan    381:     immediate-mask lastflags cset ;
                    382: 
                    383: : restrict ( -- ) \ gforth
1.10      crook     384:     \G A synonym for @code{compile-only}
1.1       pazsan    385:     restrict-mask lastflags cset ;
1.18      jwilke    386: 
1.1       pazsan    387: ' restrict alias compile-only ( -- ) \ gforth
1.10      crook     388: \G Remove the interpretation semantics of a word.
1.1       pazsan    389: 
                    390: \ \ Create Variable User Constant                              17mar93py
                    391: 
1.15      crook     392: : Alias    ( xt "name" -- ) \ gforth
1.1       pazsan    393:     Header reveal
                    394:     alias-mask lastflags creset
                    395:     dup A, lastcfa ! ;
                    396: 
                    397: doer? :dovar [IF]
                    398: 
                    399: : Create ( "name" -- ) \ core
                    400:     Header reveal dovar: cfa, ;
                    401: [ELSE]
                    402: 
                    403: : Create ( "name" -- ) \ core
                    404:     Header reveal here lastcfa ! 0 A, 0 , DOES> ;
                    405: [THEN]
                    406: 
                    407: : Variable ( "name" -- ) \ core
                    408:     Create 0 , ;
                    409: 
                    410: : AVariable ( "name" -- ) \ gforth
                    411:     Create 0 A, ;
                    412: 
1.22      crook     413: : 2Variable ( "name" -- ) \ double two-variable
1.1       pazsan    414:     create 0 , 0 , ;
                    415: 
1.21      crook     416: : uallot ( n -- ) \ gforth
                    417:     udp @ swap udp +! ;
1.1       pazsan    418: 
                    419: doer? :douser [IF]
                    420: 
                    421: : User ( "name" -- ) \ gforth
                    422:     Header reveal douser: cfa, cell uallot , ;
                    423: 
                    424: : AUser ( "name" -- ) \ gforth
                    425:     User ;
                    426: [ELSE]
                    427: 
                    428: : User Create cell uallot , DOES> @ up @ + ;
                    429: 
                    430: : AUser User ;
                    431: [THEN]
                    432: 
                    433: doer? :docon [IF]
                    434:     : (Constant)  Header reveal docon: cfa, ;
                    435: [ELSE]
                    436:     : (Constant)  Create DOES> @ ;
                    437: [THEN]
                    438: 
                    439: : Constant ( w "name" -- ) \ core
1.15      crook     440:     \G Define a constant @i{name} with value @i{w}.
1.1       pazsan    441:     \G  
1.15      crook     442:     \G @i{name} execution: @i{-- w}
1.1       pazsan    443:     (Constant) , ;
                    444: 
                    445: : AConstant ( addr "name" -- ) \ gforth
                    446:     (Constant) A, ;
                    447: 
                    448: : Value ( w "name" -- ) \ core-ext
                    449:     (Constant) , ;
                    450: 
1.37    ! jwilke    451: : AValue ( w "name" -- ) \ core-ext
        !           452:     (Constant) A, ;
        !           453: 
1.22      crook     454: : 2Constant ( w1 w2 "name" -- ) \ double two-constant
1.1       pazsan    455:     Create ( w1 w2 "name" -- )
                    456:         2,
                    457:     DOES> ( -- w1 w2 )
                    458:         2@ ;
                    459:     
                    460: doer? :dofield [IF]
                    461:     : (Field)  Header reveal dofield: cfa, ;
                    462: [ELSE]
                    463:     : (Field)  Create DOES> @ + ;
                    464: [THEN]
                    465: \ IS Defer What's Defers TO                            24feb93py
                    466: 
                    467: doer? :dodefer [IF]
                    468: 
                    469: : Defer ( "name" -- ) \ gforth
                    470:     \ !! shouldn't it be initialized with abort or something similar?
                    471:     Header Reveal dodefer: cfa,
                    472:     ['] noop A, ;
1.18      jwilke    473: 
1.1       pazsan    474: [ELSE]
                    475: 
                    476: : Defer ( "name" -- ) \ gforth
                    477:     Create ['] noop A,
                    478: DOES> @ execute ;
1.18      jwilke    479: 
1.1       pazsan    480: [THEN]
                    481: 
1.25      anton     482: : Defers ( compilation "name" -- ; run-time ... -- ... ) \ gforth
                    483:     \G Compiles the present contents of the deferred word @i{name}
                    484:     \G into the current definition.  I.e., this produces static
                    485:     \G binding as if @i{name} was not deferred.
1.1       pazsan    486:     ' >body @ compile, ; immediate
1.18      jwilke    487: 
                    488: :noname
                    489:     dodoes, here !does ]
                    490:     defstart :-hook ;
                    491: :noname
                    492:     ;-hook ?struc
                    493:     [ has? xconds [IF] ] exit-like [ [THEN] ]
                    494:     postpone (does>) dodoes,
                    495:     defstart :-hook ;
                    496: interpret/compile: DOES>  ( compilation colon-sys1 -- colon-sys2 ; run-time nest-sys -- ) \ core        does
                    497: 
1.20      anton     498: : <IS> ( "name" xt -- ) \ gforth
                    499:     \g Changes the @code{defer}red word @var{name} to execute @var{xt}.
                    500:     ' >body ! ;
                    501: 
                    502: : [IS] ( compilation "name" -- ; run-time xt -- ) \ gforth bracket-is
                    503:     \g At run-time, changes the @code{defer}red word @var{name} to
                    504:     \g execute @var{xt}.
1.18      jwilke    505:     ' >body postpone ALiteral postpone ! ; immediate restrict
                    506: 
1.20      anton     507: ' <IS>
1.18      jwilke    508: ' [IS]
                    509: interpret/compile: IS ( xt "name" -- ) \ gforth
1.21      crook     510: \G A combined word made up from @code{<IS>} and @code{[IS]}.
1.18      jwilke    511: 
1.20      anton     512: ' <IS>
                    513: ' [IS]
                    514: interpret/compile: TO ( w "name" -- ) \ core-ext
1.18      jwilke    515: 
                    516: :noname    ' >body @ ;
                    517: :noname    ' >body postpone ALiteral postpone @ ;
1.25      anton     518: interpret/compile: What's ( interpretation "name" -- xt; compilation "name" -- ; run-time -- xt ) \ gforth
                    519: \G @i{Xt} is the XT that is currently assigned to @i{name}.
1.18      jwilke    520: 
                    521: \ \ interpret/compile:
                    522: 
                    523: struct
                    524:     >body
                    525:     cell% field interpret/compile-int
                    526:     cell% field interpret/compile-comp
                    527: end-struct interpret/compile-struct
                    528: 
                    529: : interpret/compile: ( interp-xt comp-xt "name" -- ) \ gforth
                    530:     Create immediate swap A, A,
                    531: DOES>
                    532:     abort" executed primary cfa of an interpret/compile: word" ;
                    533: \    state @ IF  cell+  THEN  perform ;
                    534: 
                    535: : interpret/compile? ( xt -- flag )
                    536:     >does-code ['] DOES> >does-code = ;
1.1       pazsan    537: 
                    538: \ \ : ;                                                        24feb93py
                    539: 
                    540: defer :-hook ( sys1 -- sys2 )
                    541: 
                    542: defer ;-hook ( sys2 -- sys1 )
                    543: 
1.16      jwilke    544: 0 Constant defstart
                    545: 
1.14      jwilke    546: [IFDEF] docol,
                    547: : (:noname) ( -- colon-sys )
                    548:     \ common factor of : and :noname
1.34      anton     549:     docol, ]comp
1.14      jwilke    550: [ELSE]
1.7       anton     551: : (:noname) ( -- colon-sys )
                    552:     \ common factor of : and :noname
1.34      anton     553:     docol: cfa,
1.14      jwilke    554: [THEN]
1.34      anton     555:     0 last-compiled ! defstart ] :-hook ;
1.7       anton     556: 
1.1       pazsan    557: : : ( "name" -- colon-sys ) \ core     colon
1.7       anton     558:     Header (:noname) ;
                    559: 
                    560: : :noname ( -- xt colon-sys ) \ core-ext       colon-no-name
                    561:     0 last !
                    562:     cfalign here (:noname) ;
1.1       pazsan    563: 
1.14      jwilke    564: [IFDEF] fini,
                    565: : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core   semicolon
                    566:     ;-hook ?struc fini, comp[ reveal postpone [ ; immediate restrict
                    567: [ELSE]
1.1       pazsan    568: : ; ( compilation colon-sys -- ; run-time nest-sys ) \ core    semicolon
1.37    ! jwilke    569:     ;-hook ?struc [compile] exit reveal postpone [ ; immediate restrict
1.14      jwilke    570: [THEN]
1.1       pazsan    571: 
                    572: \ \ Search list handling: reveal words, recursive              23feb93py
                    573: 
                    574: : last?   ( -- false / nfa nfa )
                    575:     last @ ?dup ;
                    576: 
                    577: : (reveal) ( nt wid -- )
1.3       pazsan    578:     wordlist-id dup >r
1.1       pazsan    579:     @ over ( name>link ) ! 
                    580:     r> ! ;
                    581: 
                    582: \ make entry in wordlist-map
                    583: ' (reveal) f83search reveal-method !
                    584: 
                    585: Variable warnings ( -- addr ) \ gforth
                    586: G -1 warnings T !
                    587: 
                    588: : check-shadow  ( addr count wid -- )
1.2       pazsan    589:     \G prints a warning if the string is already present in the wordlist
                    590:     >r 2dup 2dup r> (search-wordlist) warnings @ and ?dup if
                    591:        >stderr
                    592:        ." redefined " name>string 2dup type
                    593:        compare 0<> if
                    594:            ."  with " type
                    595:        else
                    596:            2drop
                    597:        then
                    598:        space space EXIT
                    599:     then
                    600:     2drop 2drop ;
1.1       pazsan    601: 
                    602: : reveal ( -- ) \ gforth
                    603:     last?
                    604:     if \ the last word has a header
                    605:        dup ( name>link ) @ 1 and
                    606:        if \ it is still hidden
                    607:            dup ( name>link ) @ 1 xor           ( nt wid )
                    608:            2dup >r name>string r> check-shadow ( nt wid )
                    609:            dup wordlist-map @ reveal-method perform
                    610:        else
                    611:            drop
                    612:        then
                    613:     then ;
                    614: 
                    615: : rehash  ( wid -- )
                    616:     dup wordlist-map @ rehash-method perform ;
                    617: 
                    618: ' reveal alias recursive ( compilation -- ; run-time -- ) \ gforth
1.10      crook     619: \g Make the current definition visible, enabling it to call itself
1.1       pazsan    620: \g recursively.
                    621:        immediate restrict

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>