[gforth] / gforth / prims2x.fs  

gforth: gforth/prims2x.fs

Diff for /gforth/prims2x.fs between version 1.49 and 1.50

version 1.49, Fri Nov 10 10:04:20 2000 UTC version 1.50, Sun Nov 12 14:09:45 2000 UTC
Line 430 
Line 430 
 \ allocate a string  \ allocate a string
  here swap dup allot move ;   here swap dup allot move ;
   
 : starts-with { addr u xt1 xt2 n stack -- } ( "prefix" -- )  wordlist constant prefixes
   
   : declare ( addr "name" -- )
   \ remember that there is a stack item at addr called name
    create , ;
   
   : !default ( w addr -- )
       dup @ if
           2drop \ leave nonzero alone
       else
           !
       endif ;
   
   : create-type { addr u xt1 xt2 n stack -- } ( "prefix" -- )
     \ describes a type      \ describes a type
     \ addr u specifies the C type name      \ addr u specifies the C type name
     \ stack effect entries of the type start with prefix      \ stack effect entries of the type start with prefix
Line 442 
Line 455 
     stack r@ type-stack !      stack r@ type-stack !
     rdrop ;      rdrop ;
   
 wordlist constant types  : type-prefix ( addr u xt1 xt2 n stack "prefix" -- )
 get-current      create-type
 types set-current  does> ( item -- )
       \ initialize item
 s" Bool"        single-type starts-with f      { item typ }
 s" Char"        single-type starts-with c      typ item item-type !
 s" Cell"        single-type starts-with n      typ type-stack @ item item-stack !default
 s" Cell"        single-type starts-with w      item item-name 2@ items @ search-wordlist 0= if \ new name
 s" UCell"       single-type starts-with u          item item-name 2@ 2dup nextname item declare
 s" DCell"       double-type starts-with d          typ type-c-name 2@ type space type  ." ;" cr
 s" UDCell"      double-type starts-with ud      else
 s" Float"       float-type  starts-with r          drop
 s" Cell *"      single-type starts-with a_      endif ;
 s" Char *"      single-type starts-with c_  
 s" Float *"     single-type starts-with f_  
 s" DFloat *"    single-type starts-with df_  
 s" SFloat *"    single-type starts-with sf_  
 s" Xt"          single-type starts-with xt  
 s" WID"         single-type starts-with wid  
 s" struct F83Name *"    single-type starts-with f83name  
   
 set-current  
   
 : get-type ( addr1 u1 -- type-descr )  : execute-prefix ( item addr1 u1 -- )
 \ get the type of the name in addr1 u1      \ execute the word ( item -- ) associated with the longest prefix
 \ type-descr is a pointer to a type-descriptor      \ of addr1 u1
  0 swap ?do   0 swap ?do
    dup i types search-wordlist          dup i prefixes search-wordlist
    if \ ok, we have the type ( addr1 xt )          if \ ok, we have the type ( item addr1 xt )
      execute nip              nip execute
      UNLOOP EXIT       UNLOOP EXIT
    endif     endif
  -1 s+loop   -1 s+loop
  \ we did not find a type, abort   \ we did not find a type, abort
  true abort" unknown type prefix" ;      true abort" unknown prefix" ;
   
 : declare ( addr "name" -- )  
 \ remember that there is a stack item at addr called name  
  create , ;  
   
 : declaration ( item -- )  : declaration ( item -- )
  dup item-name 2@ items @ search-wordlist      dup item-name 2@ execute-prefix ;
  if \ already declared ( item xt )  
      execute @ 2dup item-type @ swap item-type !  
      item-stack @ swap item-stack ! \ !! does not generalize to stack prefixes  
  else ( addr )  
    dup item-name 2@ nextname dup declare ( addr )  
    dup >r item-name 2@ 2dup get-type ( addr1 u type-descr )  
    dup type-stack @ r@ item-stack ! \ !! only if item-stack @ 0=  
    dup r> item-type ! ( addr1 u type-descr )  
    type-c-name 2@ type space type ." ;" cr  
  endif ;  
   
 : declaration-list ( addr1 addr2 -- )  : declaration-list ( addr1 addr2 -- )
  swap ?do   swap ?do
Line 505 
Line 495 
  effect-in effect-in-end @ declaration-list   effect-in effect-in-end @ declaration-list
  effect-out effect-out-end @ declaration-list ;   effect-out effect-out-end @ declaration-list ;
   
   get-current
   prefixes set-current
   
   s" Bool"        single-type type-prefix f
   s" Char"        single-type type-prefix c
   s" Cell"        single-type type-prefix n
   s" Cell"        single-type type-prefix w
   s" UCell"       single-type type-prefix u
   s" DCell"       double-type type-prefix d
   s" UDCell"      double-type type-prefix ud
   s" Float"       float-type  type-prefix r
   s" Cell *"      single-type type-prefix a_
   s" Char *"      single-type type-prefix c_
   s" Float *"     single-type type-prefix f_
   s" DFloat *"    single-type type-prefix df_
   s" SFloat *"    single-type type-prefix sf_
   s" Xt"          single-type type-prefix xt
   s" WID"         single-type type-prefix wid
   s" struct F83Name *"    single-type type-prefix f83name
   
   set-current
   
 \ offset computation  \ offset computation
 \ the leftmost (i.e. deepest) item has offset 0  \ the leftmost (i.e. deepest) item has offset 0
 \ the rightmost item has the highest offset  \ the rightmost item has the highest offset


Generate output suitable for use with a patch program
Legend:
Removed from v.1.49  
changed lines
  Added in v.1.50

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help