2 \ ** ficl/softwords/jhlocal.fr
3 \ ** stack comment style local syntax...
4 \ { a b c | cleared -- d e }
5 \ variables before the "|" are initialized in reverse order
6 \ from the stack. Those after the "|" are zero initialized.
7 \ Anything between "--" and "}" is treated as comment
9 \ locstate: 0 = looking for | or -- or }}
15 \ revised 2 June 2000 - { | a -- } now works correctly
17 \ $FreeBSD: src/sys/boot/ficl/softwords/jhlocal.fr,v 1.5 2007/03/23 22:26:01 jkim Exp $
18 \ $DragonFly: src/sys/boot/ficl/softwords/jhlocal.fr,v 1.4 2008/03/29 23:31:07 swildner Exp $
25 : ?-- ( c-addr u -- c-addr u flag )
26 2dup s" --" compare 0= ;
27 : ?} ( c-addr u -- c-addr u flag )
28 2dup s" }" compare 0= ;
29 : ?| ( c-addr u -- c-addr u flag )
30 2dup s" |" compare 0= ;
32 \ examine name - if it's a 2local (starts with "2:"),
33 \ nibble the prefix (the "2:") off the name and push true.
34 \ Otherwise push false
35 \ Problem if the local is named "2:" - we fall off the end...
36 : ?2loc ( c-addr u -- c-addr u flag )
37 over dup c@ [char] 2 =
38 swap 1+ c@ [char] : = and
40 2 - swap char+ char+ swap \ dcs/jws: nibble the '2:'
47 : ?delim ( c-addr u -- state | c-addr u 0 )
48 ?| if 2drop 1 exit endif
49 ?-- if 2drop 2 exit endif
50 ?} if 2drop 3 exit endif
59 0 dup locals| locstate |
61 \ stack locals until we hit a delimiter
63 parse-word \ ( nLocals c-addr u )
64 ?delim dup to locstate
66 rot 1+ \ ( c-addr u ... c-addr u nLocals )
69 \ now unstack the locals
71 ?2loc if (2local) else (local) endif
74 \ zero locals until -- or }
78 ?delim dup to locstate
81 postpone zero postpone zero (2local)
91 \ (explicitly allow | and -- in the comment)
95 ?delim dup to locstate
97 locstate 0= if 2drop endif
101 locstate 3 <> abort" syntax error in { } local line"
102 ; immediate compile-only