Annotation of gforth/prims2x.fs, revision 1.27

1.16      anton       1: \ converts primitives to, e.g., C code 
                      2: 
                      3: \ Copyright (C) 1995 Free Software Foundation, Inc.
                      4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
                      9: \ as published by the Free Software Foundation; either version 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
                     19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     20: 
                     21: 
1.1       anton      22: \ This is not very nice (hard limits, no checking, assumes 1 chars = 1)
                     23: 
                     24: \ Optimizations:
                     25: \ superfluous stores are removed. GCC removes the superfluous loads by itself
                     26: \ TOS and FTOS can be kept in register( variable)s.
                     27: \ 
                     28: \ Problems:
                     29: \ The TOS optimization is somewhat hairy. The problems by example:
                     30: \ 1) dup ( w -- w w ): w=TOS; sp-=1; sp[1]=w; TOS=w;
                     31: \    The store is not superfluous although the earlier opt. would think so
                     32: \    Alternatively:    sp[0]=TOS; w=TOS; sp-=1; TOS=w;
                     33: \ 2) ( -- .. ): sp[0] = TOS; ... /* This additional store is necessary */
                     34: \ 3) ( .. -- ): ... TOS = sp[0]; /* as well as this load */
                     35: \ 4) ( -- ): /* but here they are unnecessary */
                     36: \ 5) Words that call NEXT themselves have to be done very carefully.
                     37: \
                     38: \ To do:
1.8       pazsan     39: \ add the store optimization for doubles
1.1       anton      40: \ regarding problem 1 above: It would be better (for over) to implement
                     41: \      the alternative
                     42: 
1.3       pazsan     43: warnings off
                     44: 
1.25      pazsan     45: include extend.fs
                     46: 
1.24      anton      47: \ require interpretation.fs
1.27    ! anton      48: \ require debugs.fs
        !            49: [IFUNDEF] vocabulary    include search.fs [THEN]
1.11      pazsan     50: [IFUNDEF] environment?  include environ.fs      [THEN]
1.1       anton      51: include gray.fs
                     52: 
                     53: 100 constant max-effect \ number of things on one side of a stack effect
                     54: 255 constant maxchar
                     55: maxchar 1+ constant eof-char
1.17      anton      56: #tab constant tab-char
                     57: #lf constant nl-char
1.1       anton      58: 
                     59: : read-whole-file ( c-addr1 file-id -- c-addr2 )
                     60: \ reads the contents of the file file-id puts it into memory at c-addr1
                     61: \ c-addr2 is the first address after the file block
1.23      anton      62:   >r dup $7fffffff r> read-file throw + ;
1.1       anton      63: 
1.18      anton      64: variable rawinput \ pointer to next character to be scanned
                     65: variable endrawinput \ pointer to the end of the input (the char after the last)
                     66: variable cookedinput \ pointer to the next char to be parsed
1.17      anton      67: variable line \ line number of char pointed to by input
                     68: 1 line !
                     69: 2variable filename \ filename of original input file
                     70: 0 0 filename 2!
1.25      pazsan     71: 2variable f-comment
                     72: 0 0 f-comment 2!
1.17      anton      73: variable skipsynclines \ are sync lines ("#line ...") invisible to the parser?
                     74: skipsynclines on 
1.1       anton      75: 
1.26      pazsan     76: Variable flush-comment flush-comment off
                     77: 
                     78: : ?flush-comment
                     79:  flush-comment @ 0= ?EXIT
                     80:  f-comment 2@ nip
                     81:  IF  cr f-comment 2@ 2 /string type 0 0 f-comment 2! THEN ;
                     82: 
1.1       anton      83: : start ( -- addr )
1.18      anton      84:  cookedinput @ ;
1.1       anton      85: 
                     86: : end ( addr -- addr u )
1.18      anton      87:  cookedinput @ over - ;
1.1       anton      88: 
                     89: variable output \ xt ( -- ) of output word
                     90: 
                     91: : printprim ( -- )
                     92:  output @ execute ;
                     93: 
                     94: : field
                     95:  <builds-field ( n1 n2 -- n3 )
                     96:  does>         ( addr1 -- addr2 )
                     97:    @ + ;
                     98: 
                     99: : const-field
                    100:  <builds-field ( n1 n2 -- n3 )
                    101:  does>         ( addr -- w )
                    102:    @ + @ ;
                    103: 
                    104: struct
                    105:  2 cells field item-name
                    106:  cell field item-d-offset
                    107:  cell field item-f-offset
                    108:  cell field item-type
                    109: constant item-descr
                    110: 
                    111: 2variable forth-name
                    112: 2variable wordset
                    113: 2variable c-name
                    114: 2variable doc
                    115: 2variable c-code
                    116: 2variable forth-code
                    117: 2variable stack-string
                    118: create effect-in  max-effect item-descr * allot
                    119: create effect-out max-effect item-descr * allot
                    120: variable effect-in-end ( pointer )
                    121: variable effect-out-end ( pointer )
                    122: 2variable effect-in-size
                    123: 2variable effect-out-size
1.17      anton     124: variable c-line
                    125: 2variable c-filename
                    126: variable name-line
                    127: 2variable name-filename
                    128: 2variable last-name-filename
1.1       anton     129: 
1.14      pazsan    130: variable primitive-number -10 primitive-number !
1.1       anton     131: 
                    132: \ for several reasons stack items of a word are stored in a wordlist
                    133: \ since neither forget nor marker are implemented yet, we make a new
                    134: \ wordlist for every word and store it in the variable items
                    135: variable items
                    136: 
                    137: \ a few more set ops
                    138: 
                    139: : bit-equivalent ( w1 w2 -- w3 )
                    140:  xor invert ;
                    141: 
                    142: : complement ( set1 -- set2 )
                    143:  empty ['] bit-equivalent binary-set-operation ;
                    144: 
                    145: \ the parser
                    146: 
                    147: eof-char max-member \ the whole character set + EOF
                    148: 
                    149: : getinput ( -- n )
1.18      anton     150:  rawinput @ endrawinput @ =
1.1       anton     151:  if
1.18      anton     152:    eof-char
1.1       anton     153:  else
1.18      anton     154:    cookedinput @ c@
1.1       anton     155:  endif ;
                    156: 
                    157: :noname ( n -- )
                    158:  dup bl > if
                    159:   emit space
                    160:  else
                    161:   .
                    162:  endif ;
                    163: print-token !
                    164: 
                    165: : testchar? ( set -- f )
                    166:  getinput member? ;
                    167: ' testchar? test-vector !
                    168: 
1.17      anton     169: : checksyncline ( -- )
                    170:     \ when input points to a newline, check if the next line is a
                    171:     \ sync line.  If it is, perform the appropriate actions.
1.18      anton     172:     rawinput @ >r
1.17      anton     173:     s" #line " r@ over compare 0<> if
                    174:        rdrop 1 line +! EXIT
                    175:     endif
                    176:     0. r> 6 chars + 20 >number drop >r drop line ! r> ( c-addr )
                    177:     dup c@ bl = if
                    178:        char+ dup c@ [char] " <> abort" sync line syntax"
1.24      anton     179:        char+ dup 100 [char] " scan drop swap 2dup - save-mem filename 2!
1.17      anton     180:        char+
                    181:     endif
                    182:     dup c@ nl-char <> abort" sync line syntax"
                    183:     skipsynclines @ if
1.18      anton     184:        dup char+ rawinput !
                    185:        rawinput @ c@ cookedinput @ c!
1.17      anton     186:     endif
                    187:     drop ;
                    188: 
1.1       anton     189: : ?nextchar ( f -- )
1.17      anton     190:     ?not? if
1.18      anton     191:        filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:"
1.17      anton     192:        getinput . cr
1.18      anton     193:        rawinput @ endrawinput @ over - 100 min type cr
1.17      anton     194:        abort
                    195:     endif
1.18      anton     196:     rawinput @ endrawinput @ <> if
                    197:        rawinput @ c@
                    198:        1 chars rawinput +!
                    199:        1 chars cookedinput +!
1.17      anton     200:        nl-char = if
                    201:            checksyncline
                    202:        endif
1.18      anton     203:        rawinput @ c@ cookedinput @ c!
1.17      anton     204:     endif ;
1.1       anton     205: 
                    206: : charclass ( set "name" -- )
                    207:  ['] ?nextchar terminal ;
                    208: 
                    209: : .. ( c1 c2 -- set )
                    210:  ( creates a set that includes the characters c, c1<=c<=c2 )
                    211:  empty copy-set
                    212:  swap 1+ rot do
                    213:   i over add-member
                    214:  loop ;
                    215: 
                    216: : ` ( -- terminal ) ( use: ` c )
                    217:  ( creates anonymous terminal for the character c )
1.21      anton     218:  char singleton ['] ?nextchar make-terminal ;
1.1       anton     219: 
                    220: char a char z ..  char A char Z ..  union char _ singleton union  charclass letter
                    221: char 0 char 9 ..                                       charclass digit
                    222: bl singleton                                           charclass blank
                    223: tab-char singleton                                     charclass tab
                    224: nl-char singleton eof-char over add-member complement  charclass nonl
                    225: nl-char singleton eof-char over add-member char : over add-member complement  charclass nocolonnl
                    226: bl 1+ maxchar ..                                       charclass nowhite
                    227: char " singleton eof-char over add-member complement   charclass noquote
                    228: nl-char singleton                                      charclass nl
                    229: eof-char singleton                                     charclass eof
                    230: 
                    231: 
                    232: (( letter (( letter || digit )) **
                    233: )) <- c-name ( -- )
                    234: 
                    235: nowhite ++
                    236: <- name ( -- )
                    237: 
1.26      pazsan    238: (( {{ ?flush-comment start }} ` \ nonl ** nl {{ end
1.25      pazsan    239:       2dup 2 min s" \+" compare 0= IF  f-comment 2!  ELSE  2drop  THEN }}
1.1       anton     240: )) <- comment ( -- )
                    241: 
                    242: (( {{ effect-in }} (( {{ start }} c-name {{ end 2 pick item-name 2! item-descr + }} blank ** )) ** {{ effect-in-end ! }}
                    243:    ` - ` - blank **
                    244:    {{ effect-out }} (( {{ start }} c-name {{ end 2 pick item-name 2! item-descr + }} blank ** )) ** {{ effect-out-end ! }}
                    245: )) <- stack-effect ( -- )
                    246: 
                    247: (( {{ s" " doc 2! s" " forth-code 2! }}
                    248:    (( comment || nl )) **
1.17      anton     249:    (( {{ line @ name-line ! filename 2@ name-filename 2! }}
                    250:       {{ start }} name {{ end 2dup forth-name 2! c-name 2! }}  tab ++
1.1       anton     251:       {{ start }} stack-effect {{ end stack-string 2! }} tab ++
                    252:         {{ start }} name {{ end wordset 2! }} tab **
                    253:         (( {{ start }}  c-name {{ end c-name 2! }} )) ??  nl
                    254:    ))
                    255:    (( ` " ` "  {{ start }} (( noquote ++ ` " )) ++ {{ end 1- doc 2! }} ` " nl )) ??
1.18      anton     256:    {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl **  nl )) ** {{ end c-code 2! skipsynclines on }}
1.1       anton     257:    (( ` :  nl
                    258:       {{ start }} (( nonl ++  nl )) ++ {{ end forth-code 2! }}
                    259:    )) ??
                    260:    (( nl || eof ))
                    261: )) <- primitive ( -- )
                    262: 
                    263: (( (( primitive {{ printprim }} )) **  eof ))
                    264: parser primitives2something
1.3       pazsan    265: warnings @ [IF]
1.1       anton     266: .( parser generated ok ) cr
1.3       pazsan    267: [THEN]
1.1       anton     268: 
                    269: : primfilter ( file-id xt -- )
                    270: \ fileid is for the input file, xt ( -- ) is for the output word
                    271:  output !
1.18      anton     272:  here dup rawinput ! cookedinput !
1.1       anton     273:  here swap read-whole-file
1.18      anton     274:  dup endrawinput !
1.1       anton     275:  here - allot
1.2       pazsan    276:  align
1.17      anton     277:  checksyncline
1.18      anton     278: \ begin
                    279: \     getinput dup eof-char = ?EXIT emit true ?nextchar
                    280: \ again ;
1.1       anton     281:  primitives2something ;
                    282: 
                    283: \ types
                    284: 
                    285: struct
                    286:  2 cells field type-c-name
                    287:  cell const-field type-d-size
                    288:  cell const-field type-f-size
                    289:  cell const-field type-fetch-handler
                    290:  cell const-field type-store-handler
                    291: constant type-description
                    292: 
                    293: : data-stack-access ( n1 n2 n3 -- )
                    294: \ n1 is the offset of the accessed item, n2, n3 are effect-*-size
                    295:  drop swap - 1- dup
                    296:  if
1.2       pazsan    297:    ." sp[" 0 .r ." ]"
1.1       anton     298:  else
                    299:    drop ." TOS"
                    300:  endif ;
                    301: 
                    302: : fp-stack-access ( n1 n2 n3 -- )
                    303: \ n1 is the offset of the accessed item, n2, n3 are effect-*-size
                    304:  nip swap - 1- dup
                    305:  if
1.2       pazsan    306:    ." fp[" 0 .r ." ]"
1.1       anton     307:  else
                    308:    drop ." FTOS"
                    309:  endif ;
                    310: 
                    311: : fetch-single ( item -- )
                    312:  >r
1.8       pazsan    313:  r@ item-name 2@ type
                    314:  ."  = (" 
1.1       anton     315:  r@ item-type @ type-c-name 2@ type ." ) "
                    316:  r@ item-d-offset @ effect-in-size 2@ data-stack-access ." ;" cr
                    317:  rdrop ; 
                    318: 
                    319: : fetch-double ( item -- )
                    320:  >r
1.20      anton     321:  ." FETCH_DCELL("
                    322:  r@ item-name 2@ type ." , "
1.1       anton     323:  r@ item-d-offset @ dup    effect-in-size 2@ data-stack-access
1.20      anton     324:  ." , "                        1+ effect-in-size 2@ data-stack-access
                    325:  ." );" cr
1.1       anton     326:  rdrop ;
                    327: 
                    328: : fetch-float ( item -- )
                    329:  >r
1.8       pazsan    330:  r@ item-name 2@ type
                    331:  ."  = "
1.1       anton     332:  \ ." (" r@ item-type @ type-c-name 2@ type ." ) "
                    333:  r@ item-f-offset @ effect-in-size 2@ fp-stack-access ." ;" cr
                    334:  rdrop ;
                    335: 
                    336: : d-same-as-in? ( item -- f )
                    337: \ f is true iff the offset of item is the same as on input
                    338:  >r
                    339:  r@ item-name 2@ items @ search-wordlist 0=
1.8       pazsan    340:  abort" bug"
1.1       anton     341:  execute @
                    342:  dup r@ =
                    343:  if \ item first appeared in output
                    344:    drop false
                    345:  else
                    346:    item-d-offset @ r@ item-d-offset @ =
                    347:  endif
                    348:  rdrop ;
                    349: 
                    350: : is-in-tos? ( item -- f )
                    351: \ true if item has the same offset as the input TOS
                    352:  item-d-offset @ 1+ effect-in-size 2@ drop = ;
                    353: 
                    354: : really-store-single ( item -- )
                    355:  >r
                    356:  r@ item-d-offset @ effect-out-size 2@ data-stack-access ."  = (Cell)"
                    357:  r@ item-name 2@ type ." ;"
                    358:  rdrop ;
                    359: 
                    360: : store-single ( item -- )
                    361:  >r
                    362:  r@ d-same-as-in?
                    363:  if
                    364:    r@ is-in-tos?
                    365:    if
                    366:      ." IF_TOS(" r@ really-store-single ." );" cr
                    367:    endif
                    368:  else
                    369:    r@ really-store-single cr
                    370:  endif
                    371:  rdrop ;
                    372: 
                    373: : store-double ( item -- )
                    374: \ !! store optimization is not performed, because it is not yet needed
                    375:  >r
1.20      anton     376:  ." STORE_DCELL(" r@ item-name 2@ type ." , "
                    377:  r@ item-d-offset @ dup    effect-out-size 2@ data-stack-access
                    378:  ." , "                        1+ effect-out-size 2@ data-stack-access
                    379:  ." );" cr
1.1       anton     380:  rdrop ;
                    381: 
                    382: : f-same-as-in? ( item -- f )
                    383: \ f is true iff the offset of item is the same as on input
                    384:  >r
                    385:  r@ item-name 2@ items @ search-wordlist 0=
1.8       pazsan    386:  abort" bug"
1.1       anton     387:  execute @
                    388:  dup r@ =
                    389:  if \ item first appeared in output
                    390:    drop false
                    391:  else
                    392:    item-f-offset @ r@ item-f-offset @ =
                    393:  endif
                    394:  rdrop ;
                    395: 
                    396: : is-in-ftos? ( item -- f )
                    397: \ true if item has the same offset as the input TOS
                    398:  item-f-offset @ 1+ effect-in-size 2@ nip = ;
                    399: 
                    400: : really-store-float ( item -- )
                    401:  >r
                    402:  r@ item-f-offset @ effect-out-size 2@ fp-stack-access ."  = "
                    403:  r@ item-name 2@ type ." ;"
                    404:  rdrop ;
                    405: 
                    406: : store-float ( item -- )
                    407:  >r
                    408:  r@ f-same-as-in?
                    409:  if
                    410:    r@ is-in-ftos?
                    411:    if
                    412:      ." IF_FTOS(" r@ really-store-float ." );" cr
                    413:    endif
                    414:  else
                    415:    r@ really-store-float cr
                    416:  endif
                    417:  rdrop ;
                    418:  
1.10      anton     419: : single-type ( -- xt1 xt2 n1 n2 )
1.1       anton     420:  ['] fetch-single ['] store-single 1 0 ;
                    421: 
1.10      anton     422: : double-type ( -- xt1 xt2 n1 n2 )
1.1       anton     423:  ['] fetch-double ['] store-double 2 0 ;
                    424: 
1.10      anton     425: : float-type ( -- xt1 xt2 n1 n2 )
1.1       anton     426:  ['] fetch-float ['] store-float 0 1 ;
                    427: 
                    428: : s, ( addr u -- )
                    429: \ allocate a string
                    430:  here swap dup allot move ;
                    431: 
                    432: : starts-with ( addr u xt1 xt2 n1 n2 "prefix" -- )
                    433: \ describes a type
                    434: \ addr u specifies the C type name
                    435: \ n1 is the size of the type on the data stack
                    436: \ n2 is the size of the type on the FP stack
                    437: \ stack effect entries of the type start with prefix
                    438:  >r >r >r >r
                    439:  dup >r here >r s,
                    440:  create
                    441:  r> r> 2,
                    442:  r> r> r> , r> , swap , , ;
                    443: 
                    444: wordlist constant types
                    445: get-current
                    446: types set-current
                    447: 
                    448: s" Bool"       single-type starts-with f
                    449: s" Char"       single-type starts-with c
                    450: s" Cell"       single-type starts-with n
                    451: s" Cell"       single-type starts-with w
                    452: s" UCell"      single-type starts-with u
                    453: s" DCell"      double-type starts-with d
                    454: s" UDCell"     double-type starts-with ud
                    455: s" Float"      float-type  starts-with r
                    456: s" Cell *"     single-type starts-with a_
                    457: s" Char *"     single-type starts-with c_
                    458: s" Float *"    single-type starts-with f_
                    459: s" DFloat *"   single-type starts-with df_
                    460: s" SFloat *"   single-type starts-with sf_
                    461: s" Xt"         single-type starts-with xt
                    462: s" WID"                single-type starts-with wid
                    463: s" F83Name *"  single-type starts-with f83name
                    464: 
                    465: set-current
                    466: 
                    467: : get-type ( addr1 u1 -- type-descr )
                    468: \ get the type of the name in addr1 u1
                    469: \ type-descr is a pointer to a type-descriptor
                    470:  0 swap ?do
                    471:    dup i types search-wordlist
                    472:    if \ ok, we have the type ( addr1 xt )
                    473:      execute nip
                    474:      UNLOOP EXIT
                    475:    endif
1.9       anton     476:  -1 s+loop
1.1       anton     477:  \ we did not find a type, abort
1.8       pazsan    478:  true abort" unknown type prefix" ;
1.1       anton     479: 
                    480: : declare ( addr "name" -- )
                    481: \ remember that there is a stack item at addr called name
                    482:  create , ;
                    483: 
                    484: : declaration ( item -- )
                    485:  dup item-name 2@ items @ search-wordlist
                    486:  if \ already declared ( item xt )
                    487:    execute @ item-type @ swap item-type !
                    488:  else ( addr )
                    489:    dup item-name 2@ nextname dup declare ( addr )
                    490:    dup >r item-name 2@ 2dup get-type ( addr1 u type-descr )
                    491:    dup r> item-type ! ( addr1 u type-descr )
                    492:    type-c-name 2@ type space type ." ;" cr
                    493:  endif ;
                    494: 
                    495: : declaration-list ( addr1 addr2 -- )
                    496:  swap ?do
                    497:   i declaration
                    498:  item-descr +loop ;
                    499: 
1.8       pazsan    500: : fetch ( addr -- )
                    501:  dup item-type @ type-fetch-handler execute ;
                    502: 
1.1       anton     503: : declarations ( -- )
                    504:  wordlist dup items ! set-current
                    505:  effect-in effect-in-end @ declaration-list
                    506:  effect-out effect-out-end @ declaration-list ;
                    507: 
                    508: \ offset computation
                    509: \ the leftmost (i.e. deepest) item has offset 0
                    510: \ the rightmost item has the highest offset
                    511: 
                    512: : compute-offset ( n1 n2 item -- n3 n4 )
                    513: \ n1, n3 are data-stack-offsets
                    514: \ n2, n4 are the fp-stack-offsets
                    515:  >r
                    516:  swap dup r@ item-d-offset !
                    517:  r@ item-type @ type-d-size +
                    518:  swap dup r@ item-f-offset !
                    519:  r@ item-type @ type-f-size +
                    520:  rdrop ;
                    521: 
                    522: : compute-list ( addr1 addr2 -- n1 n2 )
                    523: \ n1, n2 are the final offsets
                    524:  0 0 2swap swap ?do
                    525:   i compute-offset
                    526:  item-descr +loop ;
                    527: 
                    528: : compute-offsets ( -- )
                    529:  effect-in effect-in-end @ compute-list effect-in-size 2!
                    530:  effect-out effect-out-end @ compute-list effect-out-size 2! ;
                    531: 
                    532: : flush-tos ( -- )
                    533:  effect-in-size 2@ effect-out-size 2@
                    534:  0<> rot 0= and
                    535:  if
1.13      anton     536:    ." IF_FTOS(fp[0] = FTOS);" cr
                    537:  endif
1.1       anton     538:  0<> swap 0= and
                    539:  if
1.13      anton     540:    ." IF_TOS(sp[0] = TOS);" cr
                    541:  endif ;
1.1       anton     542: 
                    543: : fill-tos ( -- )
                    544:  effect-in-size 2@ effect-out-size 2@
                    545:  0= rot 0<> and
                    546:  if
                    547:    ." IF_FTOS(FTOS = fp[0]);" cr
                    548:  endif
                    549:  0= swap 0<> and
                    550:  if
                    551:    ." IF_TOS(TOS = sp[0]);" cr
                    552:  endif ;
                    553: 
                    554: : fetches ( -- )
                    555:  effect-in-end @ effect-in ?do
                    556:    i fetch
                    557:  item-descr +loop ; 
                    558: 
                    559: : stack-pointer-updates ( -- )
1.8       pazsan    560: \ we need not check if an update is a noop; gcc does this for us
1.1       anton     561:  effect-in-size 2@
                    562:  effect-out-size 2@
                    563:  rot swap - ( d-in d-out f-diff )
                    564:  rot rot - ( f-diff d-diff )
1.2       pazsan    565:  ?dup IF  ." sp += " 0 .r ." ;" cr  THEN
                    566:  ?dup IF  ." fp += " 0 .r ." ;" cr  THEN ;
1.1       anton     567: 
                    568: : store ( item -- )
                    569: \ f is true if the item should be stored
                    570: \ f is false if the store is probably not necessary
                    571:  dup item-type @ type-store-handler execute ;
                    572: 
                    573: : stores ( -- )
                    574:  effect-out-end @ effect-out ?do
                    575:    i store
                    576:  item-descr +loop ; 
                    577: 
1.8       pazsan    578: : .stack-list ( start end -- )
                    579:  swap ?do
                    580:    i item-name 2@ type space
                    581:  item-descr +loop ; 
                    582: 
1.1       anton     583: : output-c ( -- )
1.2       pazsan    584:  ." I_" c-name 2@ type ." :    /* " forth-name 2@ type ."  ( " stack-string 2@ type ."  ) */" cr
1.1       anton     585:  ." /* " doc 2@ type ."  */" cr
1.13      anton     586:  ." NAME(" [char] " emit forth-name 2@ type [char] " emit ." )" cr \ debugging
1.1       anton     587:  ." {" cr
                    588:  ." DEF_CA" cr
                    589:  declarations
                    590:  compute-offsets \ for everything else
1.13      anton     591:  ." NEXT_P0;" cr
                    592:  flush-tos
1.1       anton     593:  fetches
1.13      anton     594:  stack-pointer-updates
1.1       anton     595:  ." {" cr
1.17      anton     596:  ." #line " c-line @ . [char] " emit c-filename 2@ type [char] " emit cr
1.1       anton     597:  c-code 2@ type
                    598:  ." }" cr
                    599:  ." NEXT_P1;" cr
                    600:  stores
                    601:  fill-tos
1.9       anton     602:  ." NEXT_P2;" cr
1.1       anton     603:  ." }" cr
                    604:  cr
                    605: ;
                    606: 
                    607: : output-label ( -- )
                    608:  ." &&I_" c-name 2@ type ." ," cr ;
                    609: 
1.26      pazsan    610: : output-alias ( -- )  flush-comment on
                    611:  ?flush-comment
1.1       anton     612:  primitive-number @ . ." alias " forth-name 2@ type cr
                    613:  -1 primitive-number +! ;
                    614: 
1.26      pazsan    615: : output-forth ( -- )  flush-comment on
                    616:  ?flush-comment
1.8       pazsan    617:  forth-code @ 0=
                    618:  IF    output-alias
                    619:  ELSE  ." : " forth-name 2@ type ."   ( "
                    620:        effect-in effect-in-end @ .stack-list ." -- "
                    621:        effect-out effect-out-end @ .stack-list ." )" cr
                    622:        forth-code 2@ type cr
                    623:        -1 primitive-number +!
1.10      anton     624:  THEN ;
                    625: 
1.17      anton     626: : output-tag-file ( -- )
                    627:     name-filename 2@ last-name-filename 2@ compare if
                    628:        name-filename 2@ last-name-filename 2!
                    629:        #ff emit cr
                    630:        name-filename 2@ type
                    631:        ." ,0" cr
                    632:     endif ;
                    633: 
                    634: : output-tag ( -- )
                    635:     output-tag-file
                    636:     forth-name 2@ 1+ type
                    637:     127 emit
                    638:     space forth-name 2@ type space
                    639:     1 emit
                    640:     name-line @ 0 .r
                    641:     ." ,0" cr ;
                    642: 
1.10      anton     643: [IFDEF] documentation
                    644: : register-doc ( -- )
                    645:     get-current documentation set-current
                    646:     forth-name 2@ nextname create
                    647:     forth-name 2@ 2,
1.15      anton     648:     stack-string 2@ condition-stack-effect 2,
1.10      anton     649:     wordset 2@ 2,
1.15      anton     650:     c-name 2@ condition-pronounciation 2,
1.10      anton     651:     doc 2@ 2,
                    652:     set-current ;
                    653: [THEN]
1.8       pazsan    654: 
1.1       anton     655: : process-file ( addr u xt -- )
1.17      anton     656:     >r
                    657:     2dup filename 2!
                    658:     r/o open-file abort" cannot open file"
                    659:     warnings @ if
                    660:        ." ------------ CUT HERE -------------" cr  endif
                    661:     r> primfilter ;
1.5       pazsan    662: 

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