Annotation of gforth/compat/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 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 parse
! 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>