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

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

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