xref: /freebsd/stand/ficl/softwords/jhlocal.fr (revision 2008043f386721d58158e37e0d7e50df8095942d)
1\ #if FICL_WANT_LOCALS
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
8\ Uses locals...
9\ locstate: 0 = looking for | or -- or }}
10\           1 = found |
11\           2 = found --
12\           3 = found }
13\           4 = end of line
14\
15\ revised 2 June 2000 - { | a -- } now works correctly
16\
17
18hide
19
200 constant zero
21
22
23: ?--   ( c-addr u -- c-addr u flag )
24    2dup s" --" compare 0= ;
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
30\ examine name - if it's a 2local (starts with "2:"),
31\ nibble the prefix (the "2:") off the name and push true.
32\ Otherwise push false
33\ Problem if the local is named "2:" - we fall off the end...
34: ?2loc ( c-addr u -- c-addr u flag )
35    over dup c@ [char] 2 =
36	swap 1+  c@ [char] : = and
37    if
38        2 - swap char+ char+ swap  \ dcs/jws: nibble the '2:'
39        true
40    else
41	    false
42    endif
43;
44
45: ?delim   ( c-addr u -- state | c-addr u 0 )
46    ?|  if  2drop 1 exit endif
47    ?-- if  2drop 2 exit endif
48    ?}  if  2drop 3 exit endif
49    dup 0=
50        if  2drop 4 exit endif
51    0
52;
53
54set-current
55
56: {
57    0 dup locals| locstate |
58
59    \ stack locals until we hit a delimiter
60    begin
61        parse-word      \ ( nLocals c-addr u )
62        ?delim dup to locstate
63    0= while
64        rot 1+          \ ( c-addr u ... c-addr u nLocals )
65    repeat
66
67    \ now unstack the locals
68    0 ?do
69	    ?2loc if (2local) else (local) endif
70	loop   \ ( )
71
72    \ zero locals until -- or }
73    locstate 1 = if
74        begin
75            parse-word
76            ?delim dup to locstate
77        0= while
78            ?2loc if
79                postpone zero postpone zero (2local)
80            else
81                postpone zero (local)
82            endif
83        repeat
84    endif
85
86    0 0 (local)
87
88    \ toss words until }
89    \ (explicitly allow | and -- in the comment)
90    locstate 2 = if
91        begin
92            parse-word
93            ?delim dup  to locstate
94        3 < while
95            locstate 0=  if 2drop endif
96        repeat
97    endif
98
99    locstate 3 <> abort" syntax error in { } local line"
100; immediate compile-only
101
102previous
103\ #endif
104
105