Annotation of gforth/prims2x.fs, revision 1.78

1.16      anton       1: \ converts primitives to, e.g., C code 
                      2: 
1.47      anton       3: \ Copyright (C) 1995,1996,1997,1998,2000 Free Software Foundation, Inc.
1.16      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.48      anton      19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.16      anton      20: 
                     21: 
1.71      anton      22: \ This is not very nice (hard limits, no checking, assumes 1 chars = 1).
                     23: \ And it grew even worse when it aged.
1.1       anton      24: 
                     25: \ Optimizations:
                     26: \ superfluous stores are removed. GCC removes the superfluous loads by itself
                     27: \ TOS and FTOS can be kept in register( variable)s.
                     28: \ 
                     29: \ Problems:
                     30: \ The TOS optimization is somewhat hairy. The problems by example:
                     31: \ 1) dup ( w -- w w ): w=TOS; sp-=1; sp[1]=w; TOS=w;
                     32: \    The store is not superfluous although the earlier opt. would think so
                     33: \    Alternatively:    sp[0]=TOS; w=TOS; sp-=1; TOS=w;
                     34: \ 2) ( -- .. ): sp[0] = TOS; ... /* This additional store is necessary */
                     35: \ 3) ( .. -- ): ... TOS = sp[0]; /* as well as this load */
                     36: \ 4) ( -- ): /* but here they are unnecessary */
                     37: \ 5) Words that call NEXT themselves have to be done very carefully.
                     38: \
                     39: \ To do:
1.8       pazsan     40: \ add the store optimization for doubles
1.1       anton      41: \ regarding problem 1 above: It would be better (for over) to implement
                     42: \      the alternative
                     43: 
1.3       pazsan     44: warnings off
                     45: 
1.39      jwilke     46: [IFUNDEF] vocabulary   \ we are executed just with kernel image
                     47:                        \ load the rest that is needed
                     48:                        \ (require fails because this file is needed from a
                     49:                        \ different directory with the wordlibraries)
                     50: include ./search.fs                    
                     51: include ./extend.fs
1.40      anton      52: [THEN]
1.76      pazsan     53: include ./stuff.fs
1.40      anton      54: 
                     55: [IFUNDEF] environment?
1.39      jwilke     56: include ./environ.fs
                     57: [THEN]
1.25      pazsan     58: 
1.49      anton      59: : struct% struct ; \ struct is redefined in gray
                     60: 
1.39      jwilke     61: include ./gray.fs
1.1       anton      62: 
1.69      anton      63: 32 constant max-effect \ number of things on one side of a stack effect
1.71      anton      64: 4 constant max-stacks  \ the max. number of stacks (including inst-stream).
1.1       anton      65: 255 constant maxchar
                     66: maxchar 1+ constant eof-char
1.17      anton      67: #tab constant tab-char
                     68: #lf constant nl-char
1.1       anton      69: 
1.18      anton      70: variable rawinput \ pointer to next character to be scanned
                     71: variable endrawinput \ pointer to the end of the input (the char after the last)
                     72: variable cookedinput \ pointer to the next char to be parsed
1.17      anton      73: variable line \ line number of char pointed to by input
1.65      anton      74: variable line-start \ pointer to start of current line (for error messages)
                     75: 0 line !
1.17      anton      76: 2variable filename \ filename of original input file
                     77: 0 0 filename 2!
1.25      pazsan     78: 2variable f-comment
                     79: 0 0 f-comment 2!
1.17      anton      80: variable skipsynclines \ are sync lines ("#line ...") invisible to the parser?
                     81: skipsynclines on 
1.1       anton      82: 
1.72      anton      83: : th ( addr1 n -- addr2 )
                     84:     cells + ;
                     85: 
                     86: : holds ( addr u -- )
                     87:     \ like HOLD, but for a string
                     88:     tuck + swap 0 +do
                     89:        1- dup c@ hold
                     90:     loop
                     91:     drop ;
1.71      anton      92: 
1.1       anton      93: : start ( -- addr )
1.18      anton      94:  cookedinput @ ;
1.1       anton      95: 
                     96: : end ( addr -- addr u )
1.18      anton      97:  cookedinput @ over - ;
1.1       anton      98: 
1.71      anton      99: : print-error-line ( -- )
                    100:     \ print the current line and position
                    101:     line-start @ endrawinput @ over - 2dup nl-char scan drop nip ( start end )
                    102:     over - type cr
                    103:     line-start @ rawinput @ over - typewhite ." ^" cr ;
                    104: 
                    105: : ?print-error { f addr u -- }
                    106:     f ?not? if
                    107:        outfile-id >r try
                    108:            stderr to outfile-id
                    109:            filename 2@ type ." :" line @ 0 .r ." : " addr u type cr
                    110:            print-error-line
                    111:            0
                    112:        recover endtry
                    113:        r> to outfile-id throw
                    114:        abort
                    115:     endif ;
                    116: 
1.63      anton     117: : quote ( -- )
                    118:     [char] " emit ;
                    119: 
1.72      anton     120: variable output          \ xt ( -- ) of output word for simple primitives
                    121: variable output-combined \ xt ( -- ) of output word for combined primitives
1.1       anton     122: 
                    123: : printprim ( -- )
                    124:  output @ execute ;
                    125: 
1.49      anton     126: struct%
1.71      anton     127:     cell%    field stack-number \ the number of this stack
1.49      anton     128:     cell% 2* field stack-pointer \ stackpointer name
1.74      anton     129:     cell%    field stack-type \ name for default type of stack items
1.49      anton     130:     cell% 2* field stack-cast \ cast string for assignments to stack elements
1.53      anton     131:     cell%    field stack-in-index-xt \ ( in-size item -- in-index )
1.49      anton     132: end-struct stack%
                    133: 
1.53      anton     134: struct%
                    135:  cell% 2* field item-name   \ name, excluding stack prefixes
                    136:  cell%    field item-stack  \ descriptor for the stack used, 0 is default
                    137:  cell%    field item-type   \ descriptor for the item type
                    138:  cell%    field item-offset \ offset in stack items, 0 for the deepest element
1.66      anton     139:  cell%   field item-first  \ true if this is the first occurence of the item
1.53      anton     140: end-struct item%
                    141: 
                    142: struct%
                    143:     cell% 2* field type-c-name
                    144:     cell%    field type-stack \ default stack
                    145:     cell%    field type-size  \ size of type in stack items
                    146:     cell%    field type-fetch \ xt of fetch code generator ( item -- )
                    147:     cell%    field type-store \ xt of store code generator ( item -- )
                    148: end-struct type%
                    149: 
1.72      anton     150: variable next-stack-number 0 next-stack-number !
                    151: create stacks max-stacks cells allot \ array of stacks
                    152: 
1.53      anton     153: : stack-in-index ( in-size item -- in-index )
                    154:     item-offset @ - 1- ;
                    155: 
                    156: : inst-in-index ( in-size item -- in-index )
                    157:     nip dup item-offset @ swap item-type @ type-size @ + 1- ;
                    158: 
1.74      anton     159: : make-stack ( addr-ptr u1 type addr-cast u2 "stack-name" -- )
1.49      anton     160:     create stack% %allot >r
1.72      anton     161:     r@ stacks next-stack-number @ th !
1.71      anton     162:     next-stack-number @ r@ stack-number !  1 next-stack-number +!
1.49      anton     163:     save-mem r@ stack-cast 2!
1.74      anton     164:     r@ stack-type !
1.53      anton     165:     save-mem r@ stack-pointer 2! 
                    166:     ['] stack-in-index r> stack-in-index-xt ! ;
1.49      anton     167: 
                    168: \ stack items
                    169: 
                    170: : init-item ( addr u addr1 -- )
                    171:     \ initialize item at addr1 with name addr u
                    172:     \ !! remove stack prefix
                    173:     dup item% %size erase
                    174:     item-name 2! ;
                    175: 
1.64      anton     176: : map-items { addr end xt -- }
                    177:     \ perform xt for all items in array addr...end
                    178:     end addr ?do
                    179:        i xt execute
                    180:     item% %size +loop ;
                    181: 
1.77      anton     182: \ types
                    183: 
                    184: : print-type-prefix ( type -- )
                    185:     body> >head name>string type ;
                    186: 
1.49      anton     187: \ various variables for storing stuff of one primitive
1.1       anton     188: 
1.69      anton     189: struct%
                    190:     cell% 2* field prim-name
                    191:     cell% 2* field prim-wordset
                    192:     cell% 2* field prim-c-name
                    193:     cell% 2* field prim-doc
                    194:     cell% 2* field prim-c-code
                    195:     cell% 2* field prim-forth-code
                    196:     cell% 2* field prim-stack-string
1.75      anton     197:     cell%    field prim-items-wordlist \ unique items
1.69      anton     198:     item% max-effect * field prim-effect-in
                    199:     item% max-effect * field prim-effect-out
                    200:     cell%    field prim-effect-in-end
                    201:     cell%    field prim-effect-out-end
1.71      anton     202:     cell% max-stacks * field prim-stacks-in  \ number of in items per stack
                    203:     cell% max-stacks * field prim-stacks-out \ number of out items per stack
1.69      anton     204: end-struct prim%
                    205: 
1.70      anton     206: : make-prim ( -- prim )
                    207:     prim% %alloc { p }
                    208:     s" " p prim-doc 2! s" " p prim-forth-code 2! s" " p prim-wordset 2!
                    209:     p ;
                    210: 
                    211: 0 value prim
1.69      anton     212: 
1.71      anton     213: wordlist constant primitives
                    214: 
                    215: : create-prim ( prim -- )
                    216:     get-current >r
                    217:     primitives set-current
                    218:     dup prim-name 2@ nextname constant
                    219:     r> set-current ;
                    220: 
                    221: : stack-in ( stack -- addr )
                    222:     \ address of number of stack items in effect in
                    223:     stack-number @ cells prim prim-stacks-in + ;
                    224: 
                    225: : stack-out ( stack -- addr )
                    226:     \ address of number of stack items in effect out
                    227:     stack-number @ cells prim prim-stacks-out + ;
                    228: 
1.69      anton     229: \ global vars
1.17      anton     230: variable c-line
                    231: 2variable c-filename
                    232: variable name-line
                    233: 2variable name-filename
                    234: 2variable last-name-filename
1.30      pazsan    235: Variable function-number 0 function-number !
1.1       anton     236: 
                    237: \ a few more set ops
                    238: 
                    239: : bit-equivalent ( w1 w2 -- w3 )
                    240:  xor invert ;
                    241: 
                    242: : complement ( set1 -- set2 )
                    243:  empty ['] bit-equivalent binary-set-operation ;
                    244: 
                    245: \ types
                    246: 
1.49      anton     247: : stack-access ( n stack -- )
                    248:     \ print a stack access at index n of stack
                    249:     stack-pointer 2@ type
                    250:     dup
                    251:     if
                    252:        ." [" 0 .r ." ]"
                    253:     else
                    254:        drop ." TOS"
                    255:     endif ;
1.1       anton     256: 
1.53      anton     257: : item-in-index { item -- n }
1.49      anton     258:     \ n is the index of item (in the in-effect)
1.53      anton     259:     item item-stack @ dup >r stack-in @ ( in-size r:stack )
                    260:     item r> stack-in-index-xt @ execute ;
1.1       anton     261: 
1.78    ! anton     262: : item-stack-type-name ( item -- addr u )
        !           263:     item-stack @ stack-type @ type-c-name 2@ ;
        !           264: 
1.1       anton     265: : fetch-single ( item -- )
1.49      anton     266:  \ fetch a single stack item from its stack
1.1       anton     267:  >r
1.8       pazsan    268:  r@ item-name 2@ type
1.78    ! anton     269:  ."  = vm_" r@ item-stack-type-name type
1.77      anton     270:  ." 2" r@ item-type @ print-type-prefix ." ("
1.49      anton     271:  r@ item-in-index r@ item-stack @ stack-access
1.77      anton     272:  ." );" cr
1.1       anton     273:  rdrop ; 
                    274: 
                    275: : fetch-double ( item -- )
1.49      anton     276:  \ fetch a double stack item from its stack
1.1       anton     277:  >r
1.78    ! anton     278:  ." vm_two"
        !           279:  r@ item-stack-type-name type ." 2"
        !           280:  r@ item-type @ print-type-prefix ." ("
1.20      anton     281:  r@ item-name 2@ type ." , "
1.61      anton     282:  r@ item-in-index r@ item-stack @ 2dup ." (Cell)" stack-access
                    283:  ." , "                      -1 under+ ." (Cell)" stack-access
1.20      anton     284:  ." );" cr
1.1       anton     285:  rdrop ;
                    286: 
1.49      anton     287: : same-as-in? ( item -- f )
                    288:  \ f is true iff the offset and stack of item is the same as on input
1.1       anton     289:  >r
1.74      anton     290:  r@ item-first @ if
                    291:      rdrop false exit
                    292:  endif
1.75      anton     293:  r@ item-name 2@ prim prim-items-wordlist @ search-wordlist 0= abort" bug"
1.1       anton     294:  execute @
                    295:  dup r@ =
                    296:  if \ item first appeared in output
                    297:    drop false
                    298:  else
1.49      anton     299:    dup  item-stack  @ r@ item-stack  @ = 
                    300:    swap item-offset @ r@ item-offset @ = and
1.1       anton     301:  endif
                    302:  rdrop ;
                    303: 
1.49      anton     304: : item-out-index ( item -- n )
                    305:     \ n is the index of item (in the in-effect)
                    306:     >r r@ item-stack @ stack-out @ r> item-offset @ - 1- ;
1.31      pazsan    307: 
1.1       anton     308: : really-store-single ( item -- )
                    309:  >r
1.77      anton     310:  r@ item-out-index r@ item-stack @ stack-access ."  = vm_"
                    311:  r@ item-type @ print-type-prefix ." 2"
1.78    ! anton     312:  r@ item-stack-type-name type ." ("
1.77      anton     313:  r@ item-name 2@ type ." );"
1.1       anton     314:  rdrop ;
                    315: 
                    316: : store-single ( item -- )
                    317:  >r
1.49      anton     318:  r@ same-as-in?
1.1       anton     319:  if
1.49      anton     320:    r@ item-in-index 0= r@ item-out-index 0= xor
1.1       anton     321:    if
1.49      anton     322:        ." IF_" r@ item-stack @ stack-pointer 2@ type
                    323:        ." TOS(" r@ really-store-single ." );" cr
1.1       anton     324:    endif
                    325:  else
                    326:    r@ really-store-single cr
                    327:  endif
                    328:  rdrop ;
                    329: 
                    330: : store-double ( item -- )
                    331: \ !! store optimization is not performed, because it is not yet needed
                    332:  >r
1.78    ! anton     333:  ." vm_"
        !           334:  r@ item-type @ print-type-prefix ." 2two"
        !           335:  r@ item-stack-type-name type ." ("
        !           336:  r@ item-name 2@ type ." , "
1.49      anton     337:  r@ item-out-index r@ item-stack @ 2dup stack-access
                    338:  ." , "                       -1 under+ stack-access
1.20      anton     339:  ." );" cr
1.1       anton     340:  rdrop ;
                    341: 
1.54      anton     342: : single ( -- xt1 xt2 n )
                    343:     ['] fetch-single ['] store-single 1 ;
1.1       anton     344: 
1.54      anton     345: : double ( -- xt1 xt2 n )
                    346:     ['] fetch-double ['] store-double 2 ;
1.1       anton     347: 
                    348: : s, ( addr u -- )
                    349: \ allocate a string
                    350:  here swap dup allot move ;
                    351: 
1.50      anton     352: wordlist constant prefixes
                    353: 
                    354: : declare ( addr "name" -- )
                    355: \ remember that there is a stack item at addr called name
                    356:  create , ;
                    357: 
                    358: : !default ( w addr -- )
                    359:     dup @ if
                    360:        2drop \ leave nonzero alone
                    361:     else
                    362:        !
                    363:     endif ;
                    364: 
                    365: : create-type { addr u xt1 xt2 n stack -- } ( "prefix" -- )
1.49      anton     366:     \ describes a type
                    367:     \ addr u specifies the C type name
                    368:     \ stack effect entries of the type start with prefix
                    369:     create type% %allot >r
                    370:     addr u save-mem r@ type-c-name 2!
                    371:     xt1   r@ type-fetch !
                    372:     xt2   r@ type-store !
                    373:     n     r@ type-size !
                    374:     stack r@ type-stack !
                    375:     rdrop ;
1.1       anton     376: 
1.54      anton     377: : type-prefix ( xt1 xt2 n stack "prefix" -- )
1.50      anton     378:     create-type
                    379: does> ( item -- )
                    380:     \ initialize item
                    381:     { item typ }
                    382:     typ item item-type !
                    383:     typ type-stack @ item item-stack !default
1.75      anton     384:     item item-name 2@ prim prim-items-wordlist @ search-wordlist 0= if
1.66      anton     385:        item item-name 2@ nextname item declare
                    386:        item item-first on
                    387:        \ typ type-c-name 2@ type space type  ." ;" cr
1.50      anton     388:     else
                    389:        drop
1.66      anton     390:        item item-first off
1.50      anton     391:     endif ;
                    392: 
                    393: : execute-prefix ( item addr1 u1 -- )
                    394:     \ execute the word ( item -- ) associated with the longest prefix
                    395:     \ of addr1 u1
                    396:     0 swap ?do
                    397:        dup i prefixes search-wordlist
                    398:        if \ ok, we have the type ( item addr1 xt )
                    399:            nip execute
                    400:            UNLOOP EXIT
                    401:        endif
                    402:        -1 s+loop
                    403:     \ we did not find a type, abort
                    404:     true abort" unknown prefix" ;
1.1       anton     405: 
                    406: : declaration ( item -- )
1.50      anton     407:     dup item-name 2@ execute-prefix ;
1.1       anton     408: 
1.64      anton     409: : declaration-list ( addr1 addr2 -- )
                    410:     ['] declaration map-items ;
                    411: 
                    412: : declarations ( -- )
1.75      anton     413:  wordlist dup prim prim-items-wordlist ! set-current
1.69      anton     414:  prim prim-effect-in prim prim-effect-in-end @ declaration-list
                    415:  prim prim-effect-out prim prim-effect-out-end @ declaration-list ;
1.64      anton     416: 
1.66      anton     417: : print-declaration { item -- }
                    418:     item item-first @ if
                    419:        item item-type @ type-c-name 2@ type space
                    420:        item item-name 2@ type ." ;" cr
                    421:     endif ;
                    422: 
                    423: : print-declarations ( -- )
1.69      anton     424:     prim prim-effect-in  prim prim-effect-in-end  @ ['] print-declaration map-items
                    425:     prim prim-effect-out prim prim-effect-out-end @ ['] print-declaration map-items ;
1.66      anton     426:     
1.51      anton     427: : stack-prefix ( stack "prefix" -- )
                    428:     name tuck nextname create ( stack length ) 2,
                    429: does> ( item -- )
                    430:     2@ { item stack prefix-length }
                    431:     item item-name 2@ prefix-length /string item item-name 2!
                    432:     stack item item-stack !
                    433:     item declaration ;
1.73      anton     434: 
1.74      anton     435: \ types pointed to by stacks for use in combined prims
                    436: s" Cell"  single 0 create-type cell-type
                    437: s" Float" single 0 create-type float-type
                    438: 
                    439: s" sp" save-mem cell-type  s" (Cell)" make-stack data-stack 
1.77      anton     440: s" fp" save-mem float-type s" "       make-stack fp-stack
                    441: s" rp" save-mem cell-type  s" (Cell)" make-stack return-stack
1.74      anton     442: s" IP" save-mem cell-type  s" error don't use # on results" make-stack inst-stream
1.73      anton     443: ' inst-in-index inst-stream stack-in-index-xt !
                    444: \ !! initialize stack-in and stack-out
1.1       anton     445: 
                    446: \ offset computation
                    447: \ the leftmost (i.e. deepest) item has offset 0
                    448: \ the rightmost item has the highest offset
                    449: 
1.49      anton     450: : compute-offset { item xt -- }
                    451:     \ xt specifies in/out; update stack-in/out and set item-offset
                    452:     item item-type @ type-size @
                    453:     item item-stack @ xt execute dup @ >r +!
                    454:     r> item item-offset ! ;
                    455: 
1.64      anton     456: : compute-offset-in ( addr1 addr2 -- )
                    457:     ['] stack-in compute-offset ;
                    458: 
                    459: : compute-offset-out ( addr1 addr2 -- )
                    460:     ['] stack-out compute-offset ;
1.49      anton     461: 
                    462: : clear-stack { -- }
                    463:     dup stack-in off stack-out off ;
1.1       anton     464: 
                    465: : compute-offsets ( -- )
1.51      anton     466:     data-stack clear-stack  fp-stack clear-stack return-stack clear-stack
1.53      anton     467:     inst-stream clear-stack
1.69      anton     468:     prim prim-effect-in  prim prim-effect-in-end  @ ['] compute-offset-in  map-items
                    469:     prim prim-effect-out prim prim-effect-out-end @ ['] compute-offset-out map-items
1.53      anton     470:     inst-stream stack-out @ 0<> abort" # can only be on the input side" ;
1.49      anton     471: 
                    472: : flush-a-tos { stack -- }
                    473:     stack stack-out @ 0<> stack stack-in @ 0= and
                    474:     if
                    475:        ." IF_" stack stack-pointer 2@ 2dup type ." TOS("
                    476:        2dup type ." [0] = " type ." TOS);" cr
                    477:     endif ;
1.1       anton     478: 
                    479: : flush-tos ( -- )
1.51      anton     480:     data-stack   flush-a-tos
                    481:     fp-stack     flush-a-tos
                    482:     return-stack flush-a-tos ;
1.49      anton     483: 
                    484: : fill-a-tos { stack -- }
                    485:     stack stack-out @ 0= stack stack-in @ 0<> and
                    486:     if
                    487:        ." IF_" stack stack-pointer 2@ 2dup type ." TOS("
                    488:        2dup type ." TOS = " type ." [0]);" cr
                    489:     endif ;
1.1       anton     490: 
                    491: : fill-tos ( -- )
1.53      anton     492:     \ !! inst-stream for prefetching?
1.51      anton     493:     fp-stack     fill-a-tos
                    494:     data-stack   fill-a-tos
                    495:     return-stack fill-a-tos ;
1.49      anton     496: 
                    497: : fetch ( addr -- )
1.72      anton     498:     dup item-type @ type-fetch @ execute ;
1.1       anton     499: 
                    500: : fetches ( -- )
1.69      anton     501:     prim prim-effect-in prim prim-effect-in-end @ ['] fetch map-items ;
1.49      anton     502: 
                    503: : stack-pointer-update { stack -- }
                    504:     \ stack grow downwards
                    505:     stack stack-in @ stack stack-out @ -
                    506:     ?dup-if \ this check is not necessary, gcc would do this for us
                    507:        stack stack-pointer 2@ type ."  += " 0 .r ." ;" cr
                    508:     endif ;
1.1       anton     509: 
1.55      anton     510: : inst-pointer-update ( -- )
                    511:     inst-stream stack-in @ ?dup-if
                    512:        ." INC_IP(" 0 .r ." );" cr
                    513:     endif ;
                    514: 
1.1       anton     515: : stack-pointer-updates ( -- )
1.55      anton     516:     inst-pointer-update
1.51      anton     517:     data-stack   stack-pointer-update
                    518:     fp-stack     stack-pointer-update
                    519:     return-stack stack-pointer-update ;
1.1       anton     520: 
                    521: : store ( item -- )
                    522: \ f is true if the item should be stored
                    523: \ f is false if the store is probably not necessary
1.49      anton     524:  dup item-type @ type-store @ execute ;
1.1       anton     525: 
                    526: : stores ( -- )
1.69      anton     527:     prim prim-effect-out prim prim-effect-out-end @ ['] store map-items ;
1.8       pazsan    528: 
1.52      anton     529: : output-c-tail ( -- )
                    530:     \ the final part of the generated C code
                    531:     ." NEXT_P1;" cr
                    532:     stores
                    533:     fill-tos
                    534:     ." NEXT_P2;" cr ;
                    535: 
                    536: : type-c ( c-addr u -- )
                    537:     \ like TYPE, but replaces "TAIL;" with tail code
                    538:     begin ( c-addr1 u1 )
                    539:        2dup s" TAIL;" search
                    540:     while ( c-addr1 u1 c-addr3 u3 )
                    541:        2dup 2>r drop nip over - type
                    542:        output-c-tail
                    543:        2r> 5 /string
                    544:        \ !! resync #line missing
                    545:     repeat
                    546:     2drop type ;
1.63      anton     547: 
                    548: : print-debug-arg { item -- }
                    549:     ." fputs(" quote space item item-name 2@ type ." =" quote ." , vm_out); "
                    550:     ." printarg_" item item-type @ print-type-prefix
                    551:     ." (" item item-name 2@ type ." );" cr ;
                    552:     
                    553: : print-debug-args ( -- )
                    554:     ." #ifdef VM_DEBUG" cr
                    555:     ." if (vm_debug) {" cr
1.69      anton     556:     prim prim-effect-in prim prim-effect-in-end @ ['] print-debug-arg map-items
1.63      anton     557:     ." fputc('\n', vm_out);" cr
                    558:     ." }" cr
                    559:     ." #endif" cr ;
1.72      anton     560: 
                    561: : print-entry ( -- )
                    562:     ." I_" prim prim-c-name 2@ type ." :" ;
1.63      anton     563:     
1.43      jwilke    564: : output-c ( -- ) 
1.72      anton     565:  print-entry ."  /* " prim prim-name 2@ type ."  ( " prim prim-stack-string 2@ type ." ) */" cr
1.69      anton     566:  ." /* " prim prim-doc 2@ type ."  */" cr
                    567:  ." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging
1.1       anton     568:  ." {" cr
                    569:  ." DEF_CA" cr
1.66      anton     570:  print-declarations
1.13      anton     571:  ." NEXT_P0;" cr
                    572:  flush-tos
1.1       anton     573:  fetches
1.63      anton     574:  print-debug-args
1.13      anton     575:  stack-pointer-updates
1.1       anton     576:  ." {" cr
1.63      anton     577:  ." #line " c-line @ . quote c-filename 2@ type quote cr
1.69      anton     578:  prim prim-c-code 2@ type-c
1.1       anton     579:  ." }" cr
1.52      anton     580:  output-c-tail
1.1       anton     581:  ." }" cr
                    582:  cr
                    583: ;
                    584: 
1.56      anton     585: : disasm-arg { item -- }
                    586:     item item-stack @ inst-stream = if
1.63      anton     587:        ."   fputc(' ', vm_out); "
                    588:        ." printarg_" item item-type @ print-type-prefix
                    589:        ." ((" item item-type @ type-c-name 2@ type ." )"
                    590:        ." ip[" item item-offset @ 1+ 0 .r ." ]);" cr
1.56      anton     591:     endif ;
                    592: 
                    593: : disasm-args ( -- )
1.69      anton     594:     prim prim-effect-in prim prim-effect-in-end @ ['] disasm-arg map-items ;
1.56      anton     595: 
                    596: : output-disasm ( -- )
                    597:     \ generate code for disassembling VM instructions
                    598:     ." if (ip[0] == prim[" function-number @ 0 .r ." ]) {" cr
1.69      anton     599:     ."   fputs(" quote prim prim-name 2@ type quote ." , vm_out);" cr
1.56      anton     600:     disasm-args
                    601:     ."   ip += " inst-stream stack-in @ 1+ 0 .r ." ;" cr
1.68      anton     602:     ." } else " ;
1.56      anton     603: 
1.60      anton     604: : gen-arg-parm { item -- }
                    605:     item item-stack @ inst-stream = if
                    606:        ." , " item item-type @ type-c-name 2@ type space
                    607:        item item-name 2@ type
                    608:     endif ;
                    609: 
                    610: : gen-args-parm ( -- )
1.69      anton     611:     prim prim-effect-in prim prim-effect-in-end @ ['] gen-arg-parm map-items ;
1.60      anton     612: 
                    613: : gen-arg-gen { item -- }
                    614:     item item-stack @ inst-stream = if
                    615:        ."   genarg_" item item-type @ print-type-prefix
                    616:         ." (ctp, " item item-name 2@ type ." );" cr
                    617:     endif ;
                    618: 
                    619: : gen-args-gen ( -- )
1.69      anton     620:     prim prim-effect-in prim prim-effect-in-end @ ['] gen-arg-gen map-items ;
1.60      anton     621: 
                    622: : output-gen ( -- )
                    623:     \ generate C code for generating VM instructions
1.69      anton     624:     ." void gen_" prim prim-c-name 2@ type ." (Inst **ctp" gen-args-parm ." )" cr
1.60      anton     625:     ." {" cr
                    626:     ."   gen_inst(ctp, vm_prim[" function-number @ 0 .r ." ]);" cr
                    627:     gen-args-gen
1.68      anton     628:     ." }" cr ;
1.60      anton     629: 
1.49      anton     630: : stack-used? { stack -- f }
                    631:     stack stack-in @ stack stack-out @ or 0<> ;
1.44      jwilke    632: 
1.30      pazsan    633: : output-funclabel ( -- )
1.69      anton     634:   ." &I_" prim prim-c-name 2@ type ." ," cr ;
1.30      pazsan    635: 
                    636: : output-forthname ( -- )
1.69      anton     637:   '" emit prim prim-name 2@ type '" emit ." ," cr ;
1.30      pazsan    638: 
                    639: : output-c-func ( -- )
1.44      jwilke    640: \ used for word libraries
1.69      anton     641:     ." Cell * I_" prim prim-c-name 2@ type ." (Cell *SP, Cell **FP)      /* " prim prim-name 2@ type
                    642:     ."  ( " prim prim-stack-string 2@ type ."  ) */" cr
                    643:     ." /* " prim prim-doc 2@ type ."  */" cr
                    644:     ." NAME(" quote prim prim-name 2@ type quote ." )" cr
1.30      pazsan    645:     \ debugging
                    646:     ." {" cr
1.66      anton     647:     print-declarations
1.53      anton     648:     inst-stream  stack-used? IF ." Cell *ip=IP;" cr THEN
1.51      anton     649:     data-stack   stack-used? IF ." Cell *sp=SP;" cr THEN
                    650:     fp-stack     stack-used? IF ." Cell *fp=*FP;" cr THEN
                    651:     return-stack stack-used? IF ." Cell *rp=*RP;" cr THEN
1.30      pazsan    652:     flush-tos
                    653:     fetches
                    654:     stack-pointer-updates
1.49      anton     655:     fp-stack   stack-used? IF ." *FP=fp;" cr THEN
1.30      pazsan    656:     ." {" cr
1.63      anton     657:     ." #line " c-line @ . quote c-filename 2@ type quote cr
1.69      anton     658:     prim prim-c-code 2@ type
1.30      pazsan    659:     ." }" cr
                    660:     stores
                    661:     fill-tos
1.44      jwilke    662:     ." return (sp);" cr
1.30      pazsan    663:     ." }" cr
                    664:     cr ;
                    665: 
1.43      jwilke    666: : output-label ( -- )  
1.69      anton     667:     ." (Label)&&I_" prim prim-c-name 2@ type ." ," cr ;
1.1       anton     668: 
1.43      jwilke    669: : output-alias ( -- ) 
1.69      anton     670:     ( primitive-number @ . ." alias " ) ." Primitive " prim prim-name 2@ type cr ;
1.1       anton     671: 
1.43      jwilke    672: : output-forth ( -- )  
1.69      anton     673:     prim prim-forth-code @ 0=
1.30      pazsan    674:     IF         \ output-alias
1.28      jwilke    675:        \ this is bad for ec: an alias is compiled if tho word does not exist!
                    676:        \ JAW
1.69      anton     677:     ELSE  ." : " prim prim-name 2@ type ."   ( "
                    678:        prim prim-stack-string 2@ type ." )" cr
                    679:        prim prim-forth-code 2@ type cr
1.30      pazsan    680:     THEN ;
1.10      anton     681: 
1.17      anton     682: : output-tag-file ( -- )
                    683:     name-filename 2@ last-name-filename 2@ compare if
                    684:        name-filename 2@ last-name-filename 2!
                    685:        #ff emit cr
                    686:        name-filename 2@ type
                    687:        ." ,0" cr
                    688:     endif ;
                    689: 
                    690: : output-tag ( -- )
                    691:     output-tag-file
1.69      anton     692:     prim prim-name 2@ 1+ type
1.17      anton     693:     127 emit
1.69      anton     694:     space prim prim-name 2@ type space
1.17      anton     695:     1 emit
                    696:     name-line @ 0 .r
                    697:     ." ,0" cr ;
                    698: 
1.10      anton     699: [IFDEF] documentation
                    700: : register-doc ( -- )
                    701:     get-current documentation set-current
1.69      anton     702:     prim prim-name 2@ nextname create
                    703:     prim prim-name 2@ 2,
                    704:     prim prim-stack-string 2@ condition-stack-effect 2,
                    705:     prim prim-wordset 2@ 2,
                    706:     prim prim-c-name 2@ condition-pronounciation 2,
                    707:     prim prim-doc 2@ 2,
1.10      anton     708:     set-current ;
                    709: [THEN]
1.67      anton     710: 
                    711: 
1.69      anton     712: \ combining instructions
                    713: 
                    714: \ The input should look like this:
                    715: 
                    716: \ lit_+ = lit +
                    717: 
                    718: \ The output should look like this:
                    719: 
                    720: \  I_lit_+:
                    721: \  {
                    722: \  DEF_CA
                    723: \  Cell _x_ip0;
                    724: \  Cell _x_sp0;
                    725: \  Cell _x_sp1;
                    726: \  NEXT_P0;
                    727: \  _x_ip0 = (Cell) IPTOS;
                    728: \  _x_sp0 = (Cell) spTOS;
                    729: \  INC_IP(1);
                    730: \  /* sp += 0; */
                    731: \  /* lit ( #w -- w ) */
                    732: \  /*  */
                    733: \  NAME("lit")
                    734: \  {
                    735: \  Cell w;
                    736: \  w = (Cell) _x_ip0;
                    737: \  #ifdef VM_DEBUG
                    738: \  if (vm_debug) {
                    739: \  fputs(" w=", vm_out); printarg_w (w);
                    740: \  fputc('\n', vm_out);
                    741: \  }
                    742: \  #endif
                    743: \  {
                    744: \  #line 136 "./prim"
                    745: \  }
                    746: \  _x_sp1 = (Cell)w;
                    747: \  }
                    748: \  I_plus:     /* + ( n1 n2 -- n ) */
                    749: \  /*  */
                    750: \  NAME("+")
                    751: \  {
                    752: \  DEF_CA
                    753: \  Cell n1;
                    754: \  Cell n2;
                    755: \  Cell n;
                    756: \  NEXT_P0;
                    757: \  n1 = (Cell) _x_sp0;
                    758: \  n2 = (Cell) _x_sp1;
                    759: \  #ifdef VM_DEBUG
                    760: \  if (vm_debug) {
                    761: \  fputs(" n1=", vm_out); printarg_n (n1);
                    762: \  fputs(" n2=", vm_out); printarg_n (n2);
                    763: \  fputc('\n', vm_out);
                    764: \  }
                    765: \  #endif
                    766: \  {
                    767: \  #line 516 "./prim"
                    768: \  n = n1+n2;
                    769: \  }
                    770: \  NEXT_P1;
                    771: \  _x_sp0 = (Cell)n;
                    772: \  NEXT_P2;
                    773: \  }
                    774: \  NEXT_P1;
                    775: \  spTOS = (Cell)_x_sp0;
                    776: \  NEXT_P2;
                    777: 
1.71      anton     778: 1000 constant max-combined
                    779: create combined-prims max-combined cells allot
                    780: variable num-combined
                    781: 
                    782: create current-depth max-stacks cells allot
                    783: create max-depth     max-stacks cells allot
1.72      anton     784: create min-depth     max-stacks cells allot
1.71      anton     785: 
                    786: : init-combined ( -- )
                    787:     0 num-combined !
                    788:     current-depth max-stacks cells erase
1.72      anton     789:     max-depth     max-stacks cells erase
                    790:     min-depth     max-stacks cells erase
                    791:     prim prim-effect-in  prim prim-effect-in-end  !
                    792:     prim prim-effect-out prim prim-effect-out-end ! ;
1.71      anton     793: 
                    794: : max! ( n addr -- )
                    795:     tuck @ max swap ! ;
                    796: 
1.72      anton     797: : min! ( n addr -- )
                    798:     tuck @ min swap ! ;
                    799: 
1.71      anton     800: : add-depths { p -- }
                    801:     \ combine stack effect of p with *-depths
                    802:     max-stacks 0 ?do
1.72      anton     803:        current-depth i th @
                    804:        p prim-stacks-in  i th @ +
                    805:        dup max-depth i th max!
                    806:        p prim-stacks-out i th @ -
                    807:        dup min-depth i th min!
                    808:        current-depth i th !
1.71      anton     809:     loop ;
                    810: 
                    811: : add-prim ( addr u -- )
                    812:     \ add primitive given by "addr u" to combined-prims
                    813:     primitives search-wordlist s" unknown primitive" ?print-error
                    814:     execute { p }
1.72      anton     815:     p combined-prims num-combined @ th !
1.71      anton     816:     1 num-combined +!
                    817:     p add-depths ;
                    818: 
                    819: : compute-effects { q -- }
                    820:     \ compute the stack effects of q from the depths
                    821:     max-stacks 0 ?do
1.72      anton     822:        max-depth i th @ dup
                    823:        q prim-stacks-in i th !
                    824:        current-depth i th @ -
                    825:        q prim-stacks-out i th !
                    826:     loop ;
                    827: 
                    828: : make-effect-items { stack# items effect-endp -- }
                    829:     \ effect-endp points to a pointer to the end of the current item-array
                    830:     \ and has to be updated
                    831:     stacks stack# th @ { stack }
                    832:     items 0 +do
                    833:        effect-endp @ { item }
                    834:        i 0 <# #s stack stack-pointer 2@ holds [char] _ hold #> save-mem
                    835:        item item-name 2!
                    836:        stack item item-stack !
1.74      anton     837:        stack stack-type @ item item-type !
1.72      anton     838:        i item item-offset !
                    839:        item item-first on
                    840:        item% %size effect-endp +!
                    841:     loop ;
                    842: 
                    843: : init-effects { q -- }
                    844:     \ initialize effects field for FETCHES and STORES
                    845:     max-stacks 0 ?do
                    846:        i q prim-stacks-in  i th @ q prim-effect-in-end  make-effect-items
                    847:        i q prim-stacks-out i th @ q prim-effect-out-end make-effect-items
1.71      anton     848:     loop ;
                    849: 
                    850: : process-combined ( -- )
1.72      anton     851:     prim compute-effects
                    852:     prim init-effects
                    853:     output-combined perform ;
                    854: 
                    855: \ C output
                    856: 
                    857: : print-item { n stack -- }
                    858:     \ print nth stack item name
1.74      anton     859:     ." _" stack stack-type @ type-c-name 2@ type space
1.72      anton     860:     stack stack-pointer 2@ type n 0 .r ;
                    861: 
                    862: : print-declarations-combined ( -- )
                    863:     max-stacks 0 ?do
                    864:        max-depth i th @ min-depth i th @ - 0 +do
                    865:            i stacks j th @ print-item ." ;" cr
                    866:        loop
                    867:     loop ;
                    868:     
1.74      anton     869: : output-parts ( -- )
                    870:     prim >r
                    871:     num-combined @ 0 +do
                    872:        combined-prims i th @ to prim
                    873:        output-c
                    874:     loop
                    875:     r> to prim ;
                    876: 
1.72      anton     877: : output-c-combined ( -- )
                    878:     print-entry cr
1.74      anton     879:     \ debugging messages just in parts
1.72      anton     880:     ." {" cr
                    881:     ." DEF_CA" cr
                    882:     print-declarations-combined
                    883:     ." NEXT_P0;" cr
                    884:     flush-tos
                    885:     fetches
1.74      anton     886:     \ print-debug-args
                    887:     stack-pointer-updates
                    888:     output-parts
                    889:     output-c-tail
                    890:     ." }" cr
                    891:     cr ;
1.72      anton     892: 
                    893: : output-forth-combined ( -- )
                    894:     ;
1.69      anton     895: 
1.67      anton     896: \ the parser
                    897: 
                    898: eof-char max-member \ the whole character set + EOF
                    899: 
                    900: : getinput ( -- n )
                    901:  rawinput @ endrawinput @ =
                    902:  if
                    903:    eof-char
                    904:  else
                    905:    cookedinput @ c@
                    906:  endif ;
                    907: 
                    908: :noname ( n -- )
                    909:  dup bl > if
                    910:   emit space
                    911:  else
                    912:   .
                    913:  endif ;
                    914: print-token !
                    915: 
                    916: : testchar? ( set -- f )
                    917:  getinput member? ;
                    918: ' testchar? test-vector !
                    919: 
                    920: : checksyncline ( -- )
                    921:     \ when input points to a newline, check if the next line is a
                    922:     \ sync line.  If it is, perform the appropriate actions.
                    923:     rawinput @ >r
                    924:     s" #line " r@ over compare 0<> if
                    925:        rdrop 1 line +! EXIT
                    926:     endif
                    927:     0. r> 6 chars + 20 >number drop >r drop line ! r> ( c-addr )
                    928:     dup c@ bl = if
                    929:        char+ dup c@ [char] " <> abort" sync line syntax"
                    930:        char+ dup 100 [char] " scan drop swap 2dup - save-mem filename 2!
                    931:        char+
                    932:     endif
                    933:     dup c@ nl-char <> abort" sync line syntax"
                    934:     skipsynclines @ if
                    935:        dup char+ rawinput !
                    936:        rawinput @ c@ cookedinput @ c!
                    937:     endif
                    938:     drop ;
                    939: 
                    940: : ?nextchar ( f -- )
1.71      anton     941:     s" syntax error, wrong char" ?print-error
1.67      anton     942:     rawinput @ endrawinput @ <> if
                    943:        rawinput @ c@
                    944:        1 chars rawinput +!
                    945:        1 chars cookedinput +!
                    946:        nl-char = if
                    947:            checksyncline
                    948:            rawinput @ line-start !
                    949:        endif
                    950:        rawinput @ c@ cookedinput @ c!
                    951:     endif ;
                    952: 
                    953: : charclass ( set "name" -- )
                    954:  ['] ?nextchar terminal ;
                    955: 
                    956: : .. ( c1 c2 -- set )
                    957:  ( creates a set that includes the characters c, c1<=c<=c2 )
                    958:  empty copy-set
                    959:  swap 1+ rot do
                    960:   i over add-member
                    961:  loop ;
                    962: 
                    963: : ` ( -- terminal ) ( use: ` c )
                    964:  ( creates anonymous terminal for the character c )
                    965:  char singleton ['] ?nextchar make-terminal ;
                    966: 
                    967: char a char z ..  char A char Z ..  union char _ singleton union  charclass letter
                    968: char 0 char 9 ..                                       charclass digit
                    969: bl singleton tab-char over add-member                  charclass white
                    970: nl-char singleton eof-char over add-member complement  charclass nonl
                    971: nl-char singleton eof-char over add-member
                    972:     char : over add-member complement                   charclass nocolonnl
                    973: bl 1+ maxchar .. char \ singleton complement intersection
                    974:                                                         charclass nowhitebq
                    975: bl 1+ maxchar ..                                        charclass nowhite
                    976: char " singleton eof-char over add-member complement   charclass noquote
                    977: nl-char singleton                                      charclass nl
                    978: eof-char singleton                                     charclass eof
                    979: 
                    980: 
                    981: (( letter (( letter || digit )) **
                    982: )) <- c-ident ( -- )
                    983: 
                    984: (( ` # ?? (( letter || digit || ` : )) **
                    985: )) <- stack-ident ( -- )
                    986: 
                    987: (( nowhitebq nowhite ** ))
                    988: <- forth-ident ( -- )
                    989: 
                    990: Variable forth-flag
                    991: Variable c-flag
                    992: 
                    993: (( (( ` e || ` E )) {{ start }} nonl ** 
                    994:    {{ end evaluate }}
                    995: )) <- eval-comment ( ... -- ... )
                    996: 
                    997: (( (( ` f || ` F )) {{ start }} nonl ** 
                    998:    {{ end forth-flag @ IF type cr ELSE 2drop THEN }}
                    999: )) <- forth-comment ( -- )
                   1000: 
                   1001: (( (( ` c || ` C )) {{ start }} nonl ** 
                   1002:    {{ end c-flag @ IF type cr ELSE 2drop THEN }}
                   1003: )) <- c-comment ( -- )
                   1004: 
                   1005: (( ` - nonl ** {{ 
                   1006:        forth-flag @ IF ." [ELSE]" cr THEN
                   1007:        c-flag @ IF ." #else" cr THEN }}
                   1008: )) <- else-comment
                   1009: 
                   1010: (( ` + {{ start }} nonl ** {{ end
                   1011:        dup
                   1012:        IF      c-flag @
                   1013:                IF    ." #ifdef HAS_" bounds ?DO  I c@ toupper emit  LOOP cr
                   1014:                THEN
                   1015:                forth-flag @
                   1016:                IF  ." has? " type ."  [IF]"  cr THEN
                   1017:        ELSE    2drop
                   1018:            c-flag @      IF  ." #endif"  cr THEN
                   1019:            forth-flag @  IF  ." [THEN]"  cr THEN
                   1020:        THEN }}
                   1021: )) <- if-comment
                   1022: 
                   1023: (( (( eval-comment || forth-comment || c-comment || else-comment || if-comment )) ?? nonl ** )) <- comment-body
                   1024: 
                   1025: (( ` \ comment-body nl )) <- comment ( -- )
                   1026: 
                   1027: (( {{ start }} stack-ident {{ end 2 pick init-item item% %size + }} white ** )) **
                   1028: <- stack-items
                   1029: 
1.69      anton    1030: (( {{ prim prim-effect-in }}  stack-items {{ prim prim-effect-in-end ! }}
1.67      anton    1031:    ` - ` - white **
1.69      anton    1032:    {{ prim prim-effect-out }} stack-items {{ prim prim-effect-out-end ! }}
1.67      anton    1033: )) <- stack-effect ( -- )
                   1034: 
1.71      anton    1035: (( {{ prim create-prim }}
1.69      anton    1036:    ` ( white ** {{ start }} stack-effect {{ end prim prim-stack-string 2! }} ` ) white **
                   1037:    (( {{ start }} forth-ident {{ end prim prim-wordset 2! }} white **
                   1038:       (( {{ start }}  c-ident {{ end prim prim-c-name 2! }} )) ??
                   1039:    )) ??  nl
                   1040:    (( ` " ` "  {{ start }} (( noquote ++ ` " )) ++ {{ end 1- prim prim-doc 2! }} ` " white ** nl )) ??
                   1041:    {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl **  nl white ** )) ** {{ end prim prim-c-code 2! skipsynclines on }}
1.67      anton    1042:    (( ` :  white ** nl
1.69      anton    1043:       {{ start }} (( nonl ++  nl white ** )) ++ {{ end prim prim-forth-code 2! }}
1.68      anton    1044:    )) ?? {{  declarations compute-offsets printprim 1 function-number +! }}
1.67      anton    1045:    (( nl || eof ))
1.69      anton    1046: )) <- simple-primitive ( -- )
                   1047: 
1.71      anton    1048: (( {{ init-combined }}
                   1049:    ` = (( white ++ {{ start }} forth-ident {{ end add-prim }} )) ++
                   1050:    (( nl || eof )) {{ process-combined }}
1.69      anton    1051: )) <- combined-primitive
                   1052: 
1.70      anton    1053: (( {{ make-prim to prim
1.69      anton    1054:       line @ name-line ! filename 2@ name-filename 2!
                   1055:       start }} forth-ident {{ end 2dup prim prim-name 2! prim prim-c-name 2! }}  white ++
                   1056:    (( simple-primitive || combined-primitive ))
1.67      anton    1057: )) <- primitive ( -- )
                   1058: 
                   1059: (( (( comment || primitive || nl white ** )) ** eof ))
                   1060: parser primitives2something
                   1061: warnings @ [IF]
                   1062: .( parser generated ok ) cr
                   1063: [THEN]
                   1064: 
1.69      anton    1065: : primfilter ( addr u -- )
                   1066:     \ process the string at addr u
                   1067:     over dup rawinput ! dup line-start ! cookedinput !
                   1068:     + endrawinput !
                   1069:     checksyncline
                   1070:     primitives2something ;    
1.8       pazsan   1071: 
1.72      anton    1072: : process-file ( addr u xt-simple x-combined -- )
                   1073:     output-combined ! output !
1.61      anton    1074:     save-mem 2dup filename 2!
1.69      anton    1075:     slurp-file
1.17      anton    1076:     warnings @ if
                   1077:        ." ------------ CUT HERE -------------" cr  endif
1.69      anton    1078:     primfilter ;
1.30      pazsan   1079: 
1.72      anton    1080: \  : process      ( xt -- )
                   1081: \      bl word count rot
                   1082: \      process-file ;

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