1 S" FICL_WANT_LOCALS" ENVIRONMENT? drop [if]
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
16 .( loading Johns-Hopkins locals ) cr
19 \ What does this do? It's equivalent to "postpone 0", but faster.
20 \ "ficlInstruction0" is the FICL instruction for "push a 0 on the data stack".
22 : compiled-zero ficlInstruction0 , ;
23 S" FICL_WANT_FLOAT" ENVIRONMENT? drop [if]
24 \ And this is the instruction for a floating-point 0 (0.0e).
25 : compiled-float-zero ficlInstructionF0 , ;
28 : ?-- ( c-addr u -- c-addr u flag )
29 2dup s" --" compare 0= ;
30 : ?} ( c-addr u -- c-addr u flag )
31 2dup s" }" compare 0= ;
32 : ?| ( c-addr u -- c-addr u flag )
33 2dup s" |" compare 0= ;
35 1 constant local-is-double
36 2 constant local-is-float
38 \ parse-local-prefix-flags
40 \ Parses single-letter prefix flags from the name of a local, and returns
41 \ a bitfield of all flags (local-is-float | local-is-double) appropriate
42 \ for the local. Adjusts the "c-addr u" of the name to remove any prefix.
44 \ Handled single-letter prefix flags:
48 \ f floating-point (use floating stack)
49 \ i integer (use data stack)
51 \ Specify as many as you like; later flags have precidence.
52 \ Thus, "f2:foo" and "2is2f:foo" are both double-cell floats.
54 \ If you don't specify anything after the colon, like "f2:",
55 \ there is no legal prefix, so "2f:" becomes the name of the
56 \ (single-cell data stack) local.
58 \ For convention, the "f" is preferred first.
60 : parse-local-prefix-flags ( c-addr u -- c-addr u flags )
61 0 0 0 locals| stop-loop colon-offset flags u c-addr |
63 \ if the first character is a colon, remove the colon and return 0.
72 [char] 1 of flags local-is-double invert and to flags endof
73 [char] 2 of flags local-is-double or to flags endof
74 [char] d of flags local-is-double or to flags endof
75 [char] f of flags local-is-float or to flags endof
76 [char] i of flags local-is-float invert and to flags endof
77 [char] s of flags local-is-double invert and to flags endof
78 [char] : of i 1+ to colon-offset 1 to stop-loop endof
81 stop-loop if leave endif
88 \ ." Returning variable name -- " c-addr u type ." -- No flags." cr
94 \ ." Returning variable name -- " 2dup type ." -- Flags: " flags . cr
98 : ?delim ( c-addr u -- state | c-addr u 0 )
99 ?| if 2drop 1 exit endif
100 ?-- if 2drop 2 exit endif
101 ?} if 2drop 3 exit endif
103 if 2drop 4 exit endif
111 S" FICL_WANT_FLOAT" ENVIRONMENT? drop [if]
113 0 0 0 locals| flags local-state nLocals |
115 \ stack locals until we hit a delimiter
117 parse-word ?delim dup to local-state
119 nLocals 1+ to nLocals
122 \ now unstack the locals
124 parse-local-prefix-flags to flags
125 flags local-is-double and if
126 flags local-is-float and if (f2local) else (2local) endif
128 flags local-is-float and if (flocal) else (local) endif
132 \ zero locals until -- or }
136 ?delim dup to local-state
138 parse-local-prefix-flags to flags
139 flags local-is-double and if
140 flags local-is-float and if
141 compiled-float-zero compiled-float-zero (f2local)
143 compiled-zero compiled-zero (2local)
146 flags local-is-float and if
147 compiled-float-zero (flocal)
149 compiled-zero (local)
158 \ (explicitly allow | and -- in the comment)
162 ?delim dup to local-state
164 local-state 0= if 2drop endif
168 local-state 3 <> abort" syntax error in { } local line"
169 ; immediate compile-only
174 0 0 0 locals| flags local-state nLocals |
176 \ stack locals until we hit a delimiter
178 parse-word ?delim dup to local-state
180 nLocals 1+ to nLocals
183 \ now unstack the locals
185 parse-local-prefix-flags to flags
186 flags local-is-double and if
193 \ zero locals until -- or }
197 ?delim dup to local-state
199 parse-local-prefix-flags to flags
200 flags local-is-double and if
201 compiled-zero compiled-zero (2local)
203 compiled-zero (local)
211 \ (explicitly allow | and -- in the comment)
215 ?delim dup to local-state
217 local-state 0= if 2drop endif
221 local-state 3 <> abort" syntax error in { } local line"
222 ; immediate compile-only