1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;; fun observation
: cmov seems
to be slower than jumps
8 URF_USE_CMOV_IN_BRANCHES equ
0
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 code: LIT-FALSE ( -- 0 )
25 code: LIT-TRUE ( -- 1 )
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 $ifnot URFORTH_ALIGN_PFA
101 code: LITC4STR ( -- addr count )
107 ;; skip trailing zero and align
112 (arg
-c4strz
) (hidden
)
114 code: LITC1STR ( -- addr count )
120 ;; skip trailing zero and align
125 (arg
-c1strz
) (hidden
)
136 ;; next cell is
continue address
137 ;; leave next next cell address as cfa
144 (arg
-cblock
) (hidden
)
147 code: LITTO! ( value -- )
149 $
if URFORTH_ALIGN_PFA
150 add eax
,8 ;; skip cfa
152 add eax
,5 ;; skip cfa
161 code: LIT^TO ( -- dataaddr )
163 $
if URFORTH_ALIGN_PFA
164 add eax
,8 ;; skip cfa
166 add eax
,5 ;; skip cfa
175 code: LIT+TO! ( value -- )
177 $
if URFORTH_ALIGN_PFA
178 add eax
,8 ;; skip cfa
180 add eax
,5 ;; skip cfa
189 code: LIT-TO! ( value -- )
191 $
if URFORTH_ALIGN_PFA
192 add eax
,8 ;; skip cfa
194 add eax
,5 ;; skip cfa
202 code: LIT-EXECTAIL ( -- )
207 (arg
-cfa
) (noreturn
) (hidden
)
210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
216 (arg
-branch
) (hidden
)
222 $
if URF_USE_CMOV_IN_BRANCHES
231 (arg
-branch
) (hidden
)
237 $
if URF_USE_CMOV_IN_BRANCHES
246 (arg
-branch
) (hidden
)
248 ;; branch
if positive or zero
253 $
if URF_USE_CMOV_IN_BRANCHES
262 (arg
-branch
) (hidden
)
264 ;; branch
if negative or zero
269 $
if URF_USE_CMOV_IN_BRANCHES
278 (arg
-branch
) (hidden
)
280 ;; used in
"CASE": drops additional value
if branch is NOT taken
285 $
if URF_USE_CMOV_IN_BRANCHES
288 ;; branch not taken
, drop one more data value
296 ;; branch not taken
, drop one more data value
301 (arg
-branch
) (hidden
)
303 ;; if two values on the stack are equal
, drop them
, and take a branch
304 ;; if they aren
't equal, do nothing
309 ;; values are equal, drop them, and take a branch
316 (arg-branch) (hidden)
319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
326 ;; tail call (will not return to the caller)
341 ;; tail call (will not return to the caller)
350 code: OVERRIDE-EXECUTE
351 ;; ( ... xtoken -- ... )
366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
367 ;; this is support for "FOR"
368 ;; it checks if the value on the stack is positive
369 ;; if it is not (or zero), it drops the value, and jumps
370 ;; if the value is positive, it prepares the stack in the
371 ;; same manner as "(DO)" does
380 ;; prepare stack as "(DO)" does (so `I` and `(LOOP)` could work)
390 (arg-branch) (hidden)
392 ;; loops from start to limit-1
393 code: (DO) ( limit start -- | limit counter )
400 ld [ERP+4],edx ;; 80000000h-to
401 ld [ERP],TOS ;; 80000000h-to+from
407 code: (+LOOP) ( delta -- | limit counter )
409 ;; most of the time we need jump address, so always load it
410 ;; it also frees us from "add EIP,4" on exit
424 (arg-branch) (hidden)
426 code: (LOOP) ( -- | limit counter )
428 ;; this is faster version of "(+LOOP)"
429 ;; most of the time we need jump address, so always load it
430 ;; it also frees us from "add EIP,4" on exit
441 (arg-branch) (hidden)
444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
445 ;; as i moved high-level compiler out of the core, we should do it there
446 ;;alias "BREAK" cfa "LEAVE"
449 ;; removes loop arguments from return stack
450 ;; can be used as: UNLOOP EXIT
451 ;; "BREAK" compiles this word before branching out of the loop
452 code: UNLOOP ( | limit counter -- )
457 code: I ( -- counter )
464 code: J ( -- counter )
472 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
473 : TRUE ( -- 1 ) state @ if compile lit-true else 1 endif ; immediate
474 : FALSE ( -- 0 ) state @ if compile lit-false else 0 endif ; immediate