Annotation of gforth/anslocal.fs, revision 1.1
1.1 ! anton 1: \ This implements a subset of the gforth locals syntax in pure ANS Forth
! 2:
! 3: \ This implementation technique has been described by John Hayes in
! 4: \ the SigForth Newsletter 4(2), Fall '92. He did not do the complete
! 5: \ job, but left some more mundane parts as an exercise to the reader.
! 6:
! 7: \ I don't implement the "|" part, because 1) gforth does not implement
! 8: \ it and 2) it's unnecessary; just put a 0 before the "{" for every
! 9: \ additional local you want to declare.
! 10:
! 11: \ This program uses PARSE from the core ext and compare from the
! 12: \ string wordsets
! 13:
! 14: : local ( "name" -- )
! 15: bl word count (local) ;
! 16:
! 17: : {helper ( -- final-offset )
! 18: >in @
! 19: bl parse
! 20: 2dup s" --" compare 0= if
! 21: 2drop [char] } parse 2drop true
! 22: else
! 23: s" }" compare 0=
! 24: then
! 25: if
! 26: drop >in @
! 27: else
! 28: recurse
! 29: swap >in ! local
! 30: then ;
! 31:
! 32: : { ( -- )
! 33: {helper >in ! 0 0 (local) ; immediate
! 34:
! 35: \ : test-swap { a b -- b a } ." xxx"
! 36: \ b a ;
! 37:
! 38: \ 1 2 test-swap . . .s cr
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>