Annotation of gforth/compat/anslocal.fs, revision 1.3

1.1       anton       1: \ This implements a subset of the gforth locals syntax in pure ANS Forth
                      2: 
                      3: \ This file is in the public domain. NO WARRANTY.
                      4: 
                      5: \ This implementation technique has been described by John Hayes in
                      6: \ the SigForth Newsletter 4(2), Fall '92. He did not do the complete
                      7: \ job, but left some more mundane parts as an exercise to the reader.
                      8: 
                      9: \ I don't implement the "|" part, because 1) gforth does not implement
                     10: \ it and 2) it's unnecessary; just put a 0 before the "{" for every
                     11: \ additional local you want to declare.
                     12: 
1.3     ! anton      13: \ The program uses the following words
        !            14: \ from CORE :
        !            15: \ : bl word count ; >in @ 2dup 0= IF 2drop [char] ELSE THEN drop
        !            16: \ recurse swap ! immediate
        !            17: \ from CORE-EXT :
        !            18: \ parse true 
        !            19: \ from BLOCK-EXT :
        !            20: \ \ 
        !            21: \ from FILE :
        !            22: \ ( S" 
        !            23: \ from LOCAL :
        !            24: \ (local) 
        !            25: \ from STRING :
        !            26: \ compare 
1.1       anton      27: 
                     28: : local ( "name" -- )
                     29:     bl word count (local) ;
                     30: 
                     31: : {helper ( -- final-offset )
                     32:     >in @
1.2       anton      33:     bl word count
1.1       anton      34:     2dup s" --" compare 0= if
                     35:        2drop [char] } parse 2drop true
                     36:     else
                     37:        s" }" compare 0=
                     38:     then
                     39:     if
                     40:        drop >in @
                     41:     else
                     42:        recurse
                     43:        swap >in ! local
                     44:     then ;
                     45: 
                     46: : { ( -- )
                     47:     {helper >in ! 0 0 (local) ; immediate
                     48: 
                     49: \ : test-swap { a b -- b a } ." xxx"
                     50: \     b a ;
                     51: 
                     52: \ 1 2 test-swap . . .s cr

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