3 \ More Core Extention wordset words for hForth - code definitions
\r
5 \ COREEXT.F can be loaded as following order:
\r
15 \ Fix colon definition of do?DO.
\r
17 \ Facelift to be used with other CPUs.
\r
19 \ Provide CODE definition of ROLL.
\r
20 \ Revise '?DO' for control-flow stack.
\r
21 \ Revise 'C"' to catch exception -24 'parsed string overflow'.
\r
24 CHAR " PARSE model" ENVIRONMENT? DROP
\r
25 CHAR " PARSE ROM Model" COMPARE 0=
\r
26 [IF] RAM/ROM@ [THEN]
\r
27 GET-ORDER GET-CURRENT
\r
29 FORTH-WORDLIST SET-CURRENT
\r
31 \ <> ( x1 x2 -- flag ) \ CORE EXT
\r
32 \ Return false if x1 is the same as x2.
\r
33 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
48 \ 0<> ( x -- flag ) \ CORE EXT
\r
49 \ flag is true if and only if x is not equal to zero.
\r
50 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
64 \ 0> ( n -- flag ) \ CORE EXT
\r
65 \ flag is true if and only if n is greater than zero.
\r
66 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
80 \ 2>R ( x1 x2 -- ) ( R: -- x1 x2 ) \ CORE EXT
\r
81 \ Transfer cell pair to the return stack.
\r
82 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
84 : 2>R SWAP R> SWAP >R SWAP >R >R ;
\r
89 AX 1 CELLS [BP] MOV,
\r
93 END-CODE COMPILE-ONLY
\r
96 \ 2R> ( -- x1 x2 ) ( R: x1 x2 -- ) \ CORE EXT
\r
97 \ Transfer cell pair from the return stack.
\r
98 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
100 : 2R> R> R> SWAP R> SWAP >R SWAP ;
\r
104 1 CELLS [BP] AX MOV,
\r
109 END-CODE COMPILE-ONLY
\r
112 \ 2R@ ( -- x1 x2 ) ( R: x1 x2 -- x1 x2 ) \ CORE EXT
\r
113 \ Copy cell pair from the return stack.
\r
114 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
116 : 2R@ R> R> R> 2DUP >R >R SWAP ROT >R ;
\r
120 1 CELLS [BP] AX MOV,
\r
124 END-CODE COMPILE-ONLY
\r
128 NONSTANDARD-WORDLIST SET-CURRENT
\r
130 \ do?DO ( n1|u1 n2|u2 -- ) ( R: -- n1 n2-n1-max_negative )
\r
131 \ Run-time funtion of ?DO.
\r
132 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
134 CHAR " PARSE model" ENVIRONMENT? DROP
\r
135 CHAR " PARSE ROM Model" COMPARE 0=
\r
136 CHAR " PARSE model" ENVIRONMENT? DROP
\r
137 CHAR " PARSE RAM Model" COMPARE 0= OR
\r
140 2DUP = IF 2DROP R> @ >R EXIT THEN
\r
143 [ -1 BL PARSE MAX-N ENVIRONMENT? DROP - ] LITERAL
\r
144 + R> OVER - SWAP R> SWAP >R SWAP >R CELL+ >R ; COMPILE-ONLY
\r
146 CHAR " PARSE model" ENVIRONMENT? DROP
\r
147 CHAR " PARSE EXE Model" COMPARE 0=
\r
150 2DUP = IF 2DROP R> code@ >R EXIT THEN
\r
153 [ -1 BL PARSE MAX-N ENVIRONMENT? DROP - ] LITERAL
\r
154 + R> OVER - SWAP R> SWAP >R SWAP >R CELL+ >R ; COMPILE-ONLY
\r
164 AX 1 CELLS [BP] MOV,
\r
174 END-CODE COMPILE-ONLY
\r
177 FORTH-WORDLIST SET-CURRENT
\r
179 \ ?DO ( C: -- do-sys ) \ CORE EXT
\r
180 \ Run-time: ( n1|u1 n2|u2 -- ) ( R: -- | loop-sys )
\r
181 \ Start a ?DO ... LOOP structure in a colon definition.
\r
182 \ On execution do as DO only if n1|u1 is not equal to n2|u2.
\r
185 POSTPONE do?DO xhere 0 code, \ leave ?DO-orig
\r
186 xhere bal+ \ leave DO-dest
\r
187 ; COMPILE-ONLY IMMEDIATE
\r
189 CHAR " PARSE model" ENVIRONMENT? DROP
\r
190 CHAR " PARSE ROM Model" COMPARE 0=
\r
191 CHAR " PARSE model" ENVIRONMENT? DROP
\r
192 CHAR " PARSE RAM Model" COMPARE 0= OR
\r
194 NONSTANDARD-WORDLIST SET-CURRENT
\r
195 : doC" ( -- c-addr ) R> DUP COUNT + ALIGNED >R ; COMPILE-ONLY
\r
196 FORTH-WORDLIST SET-CURRENT
\r
199 \ C" ( "ccc<">" -- )
\r
200 \ Run-time: ( -- c-addr )
\r
201 \ Parse ccc delimetered by " . Return the counted string, c-addr.
\r
202 CHAR " PARSE model" ENVIRONMENT? DROP
\r
203 CHAR " PARSE ROM Model" COMPARE 0=
\r
205 : C" [CHAR] " PARSE
\r
206 DUP [ BL PARSE /COUNTED-STRING ENVIRONMENT? DROP ] LITERAL
\r
207 > IF -18 THROW THEN \ parsed string overflow
\r
208 POSTPONE doC" xhere pack" TOxhere ; COMPILE-ONLY IMMEDIATE
\r
210 CHAR " PARSE model" ENVIRONMENT? DROP
\r
211 CHAR " PARSE RAM Model" COMPARE 0=
\r
213 : C" [CHAR] " PARSE
\r
214 DUP [ BL PARSE /COUNTED-STRING ENVIRONMENT? DROP ] LITERAL
\r
215 > IF -18 THROW THEN \ parsed string overflow
\r
216 POSTPONE doC" HERE pack" TO HERE ; COMPILE-ONLY IMMEDIATE
\r
218 CHAR " PARSE model" ENVIRONMENT? DROP
\r
219 CHAR " PARSE EXE Model" COMPARE 0=
\r
221 : C" [CHAR] " PARSE
\r
222 DUP [ BL PARSE /COUNTED-STRING ENVIRONMENT? DROP ] LITERAL
\r
223 > IF -18 THROW THEN \ parsed string overflow
\r
224 ALIGN HERE DUP POSTPONE LITERAL
\r
225 pack" ALIGNED TO HERE ; COMPILE-ONLY IMMEDIATE
\r
228 \ ERASE ( addr u -- ) \ CORE EXT
\r
229 \ If u is greater than zero, clear all bits in each of u
\r
230 \ consecutive address units of memory beginning at addr .
\r
231 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
233 CR .( ERASE need to be CODE defined.) CR
\r
234 .( No ANS Standard word except MOVE and ERASE can access address unit directly.)
\r
242 AX ES MOV, \ set ES same as DS
\r
243 SI DX MOV, \ save SI
\r
258 \ ROLL ( xu xu-1 ... x0 u -- xu-1 ... x0 xu ) \ CORE EXT
\r
259 \ Remove u. Rotate u+1 items on the top of the stack. An
\r
260 \ ambiguous condition exists if there are less than u+2 items
\r
261 \ on the stack before ROLL is executed.
\r
262 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
265 DEPTH DUP 2 < IF -4 THROW THEN \ stack underflow
\r
266 2 - OVER U< IF -4 THROW THEN
\r
267 DUP 1+ PICK >R >R \ x_u ... x1 x0 R: x_u u
\r
268 sp@ DUP CELL+ R> CELLS MOVE DROP R> ;
\r
272 1 CELLS [DI] DI MOV, \ sp0
\r
274 DI 1 SAR, \ depth-1 in DI
\r
299 \ TUCK ( x1 x2 -- x2 x1 x2 ) \ CORE EXT
\r
300 \ Copy the first (top) stack item below the second stack item.
\r
301 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
313 \ U> ( u1 u2 -- flag ) \ CORE EXT
\r
314 \ flag is true if and only if u1 is greater than u2.
\r
315 CHAR " PARSE ASM8086" ENVIRONMENT? 0=
\r
330 \ CS-PICK \ TOOLS EXT
\r
331 \ Execution: ( C: destu ... orig0|dest0 -- destu ... orig0|dest0 destu )
\r
333 \ Interpretation: Interpretation semantics for this word are undefined.
\r
335 \ Remove u. Copy destu to the top of the control-flow
\r
336 \ stack. An ambiguous condition exists if there are
\r
337 \ less than u+1 items, each of which shall be an orig
\r
338 \ or dest, on the control-flow stack before CS-PICK is
\r
341 \ If the control-flow stack is implemented using the
\r
342 \ data stack, u shall be the topmost item on the data
\r
344 : CS-PICK ( destu ... orig0|dest0 u -- destu ... orig0|dest0 destu )
\r
345 DUP 2* 1+ PICK \ check destu; dest type is 0
\r
346 IF -22 THROW THEN \ control structure mismatch
\r
347 DUP >R 0 SWAP \ destu ... orig0|dest0 0 u R: u
\r
348 1+ 0 DO I 2* 1+ PICK OR LOOP \ dest type is 0; orig type is 1
\r
349 1 INVERT AND IF -22 THROW THEN \ ORed types should be 0
\r
351 bal 1+ TO bal ; COMPILE-ONLY
\r
353 \ CS-ROLL \ TOOLS EXT
\r
354 \ Execution: ( C: origu|destu origu-1|destu-1 ... orig0|dest0 --
\r
355 \ origu-1|destu-1 ... orig0|dest0 origu|destu )
\r
357 \ Interpretation: Interpretation semantics for this word are undefined.
\r
359 \ Remove u. Rotate u+1 elements on top of the
\r
360 \ control-flow stack so that origu|destu is on top of
\r
361 \ the control-flow stack. An ambiguous condition
\r
362 \ exists if there are less than u+1 items, each of
\r
363 \ which shall be an orig or dest, on the control-flow
\r
364 \ stack before CS-ROLL is executed.
\r
366 \ If the control-flow stack is implemented using the
\r
367 \ data stack, u shall be the topmost item on the data
\r
369 : CS-ROLL ( origu|destu origu-1|destu-1 ... orig0|dest0 u --
\r
370 \ origu-1|destu-1 ... orig0|dest0 origu|destu )
\r
371 DUP >R 0 SWAP \ destu ... orig0|dest0 0 u R: u
\r
372 1+ 0 DO I 2* 1+ PICK OR LOOP \ dest type is 0; orig type is 1
\r
373 1 INVERT AND IF -22 THROW THEN \ ORed types should be 0
\r
375 R> 2* 1+ ROLL ; COMPILE-ONLY
\r
377 SET-CURRENT SET-ORDER
\r
379 CHAR " PARSE model" ENVIRONMENT? DROP
\r
380 CHAR " PARSE ROM Model" COMPARE 0=
\r
381 [IF] RAM/ROM! [THEN]
\r
384 CHAR " PARSE FILE" ENVIRONMENT?
\r
386 0= [IF] << CON [THEN]
\r