File:  [gforth] / gforth / compat / anslocal.fs
Revision 1.2: download - view: text, annotated - select for diffs
Mon Sep 30 13:16:24 1996 UTC (27 years, 6 months ago) by anton
Branches: MAIN
CVS tags: v0-3-0, v0-2-1, v0-2-0, HEAD
Documentation changes
Building in a dir different from the srcdir now works
a few bug fixes

    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: 
   13: \ This program uses PARSE from the core ext and COMPARE from the
   14: \ string wordsets
   15: 
   16: : local ( "name" -- )
   17:     bl word count (local) ;
   18: 
   19: : {helper ( -- final-offset )
   20:     >in @
   21:     bl word count
   22:     2dup s" --" compare 0= if
   23: 	2drop [char] } parse 2drop true
   24:     else
   25: 	s" }" compare 0=
   26:     then
   27:     if
   28: 	drop >in @
   29:     else
   30: 	recurse
   31: 	swap >in ! local
   32:     then ;
   33: 
   34: : { ( -- )
   35:     {helper >in ! 0 0 (local) ; immediate
   36: 
   37: \ : test-swap { a b -- b a } ." xxx"
   38: \     b a ;
   39: 
   40: \ 1 2 test-swap . . .s cr

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