2020-03-26 11:13:33 +11:00
|
|
|
: H@ HERE @ ;
|
2020-04-09 06:23:02 +10:00
|
|
|
: IMMEDIATE
|
2020-04-16 11:29:39 +10:00
|
|
|
CURRENT @ 1-
|
2020-04-09 06:23:02 +10:00
|
|
|
DUP C@ 128 OR SWAP C!
|
|
|
|
;
|
2020-03-28 06:25:20 +11:00
|
|
|
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE
|
|
|
|
: ] R> DROP ;
|
2020-04-12 03:13:20 +10:00
|
|
|
: LITS 34 , SCPY ;
|
2020-03-23 02:56:40 +11:00
|
|
|
: LIT< WORD LITS ; IMMEDIATE
|
2020-04-12 03:13:20 +10:00
|
|
|
: LITA 36 , , ;
|
2020-04-03 22:44:44 +11:00
|
|
|
: '
|
|
|
|
WORD (find) (?br) [ 4 , ] EXIT
|
|
|
|
LIT< (wnf) (find) DROP EXECUTE
|
|
|
|
;
|
2020-04-12 03:13:20 +10:00
|
|
|
: ['] ' LITA ; IMMEDIATE
|
|
|
|
: COMPILE ' LITA ['] , , ; IMMEDIATE
|
2020-03-22 07:17:51 +11:00
|
|
|
: [COMPILE] ' , ; IMMEDIATE
|
2020-03-26 11:13:33 +11:00
|
|
|
: BEGIN H@ ; IMMEDIATE
|
2020-03-29 02:03:04 +11:00
|
|
|
: AGAIN COMPILE (br) H@ - , ; IMMEDIATE
|
2020-03-30 00:10:23 +11:00
|
|
|
: UNTIL COMPILE (?br) H@ - , ; IMMEDIATE
|
2020-04-16 02:15:35 +10:00
|
|
|
: ( BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE
|
2020-03-15 10:10:39 +11:00
|
|
|
( Hello, hello, krkrkrkr... do you hear me?
|
|
|
|
Ah, voice at last! Some lines above need comments
|
|
|
|
BTW: Forth lines limited to 64 cols because of default
|
|
|
|
input buffer size in Collapse OS
|
2020-03-17 12:31:43 +11:00
|
|
|
|
2020-03-26 11:06:06 +11:00
|
|
|
"_": words starting with "_" are meant to be "private",
|
|
|
|
that is, only used by their immediate surrondings.
|
|
|
|
|
2020-04-12 03:13:20 +10:00
|
|
|
LITS: 34 == litWord
|
|
|
|
LITA: 36 == addrWord
|
2020-03-21 04:35:02 +11:00
|
|
|
COMPILE: Tough one. Get addr of caller word (example above
|
2020-04-12 03:13:20 +10:00
|
|
|
(br)) and then call LITA on it. )
|
2020-03-19 07:39:22 +11:00
|
|
|
|
2020-03-21 04:35:02 +11:00
|
|
|
: +! SWAP OVER @ + SWAP ! ;
|
2020-04-09 06:23:02 +10:00
|
|
|
: -^ SWAP - ;
|
2020-03-21 04:35:02 +11:00
|
|
|
: ALLOT HERE +! ;
|
2020-03-17 13:09:23 +11:00
|
|
|
|
|
|
|
: IF ( -- a | a: br cell addr )
|
2020-03-30 00:10:23 +11:00
|
|
|
COMPILE (?br)
|
2020-03-26 11:13:33 +11:00
|
|
|
H@ ( push a )
|
2020-03-29 02:03:04 +11:00
|
|
|
2 ALLOT ( br cell allot )
|
2020-03-17 13:09:23 +11:00
|
|
|
; IMMEDIATE
|
|
|
|
|
|
|
|
: THEN ( a -- | a: br cell addr )
|
2020-03-26 11:13:33 +11:00
|
|
|
DUP H@ -^ SWAP ( a-H a )
|
2020-03-29 02:03:04 +11:00
|
|
|
!
|
2020-03-17 13:09:23 +11:00
|
|
|
; IMMEDIATE
|
|
|
|
|
|
|
|
: ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell )
|
2020-03-29 02:03:04 +11:00
|
|
|
COMPILE (br)
|
|
|
|
2 ALLOT
|
2020-03-26 11:13:33 +11:00
|
|
|
DUP H@ -^ SWAP ( a-H a )
|
2020-03-29 02:03:04 +11:00
|
|
|
!
|
2020-04-16 11:29:39 +10:00
|
|
|
H@ 2- ( push a. -2 for allot offset )
|
2020-03-17 13:09:23 +11:00
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-04-17 05:07:31 +10:00
|
|
|
( During a CASE, the stack grows by 1 at each ENDOF so that
|
|
|
|
we can fill all those ENDOF branching addrs. So that we
|
|
|
|
know when to stop, we put a 0 on PSP. That's our stopgap. )
|
2020-04-19 12:05:11 +10:00
|
|
|
: CASE 0 COMPILE >R ; IMMEDIATE
|
2020-04-17 05:07:31 +10:00
|
|
|
: OF
|
2020-04-19 12:05:11 +10:00
|
|
|
COMPILE I COMPILE =
|
2020-04-17 05:07:31 +10:00
|
|
|
[COMPILE] IF
|
|
|
|
; IMMEDIATE
|
|
|
|
: ENDOF [COMPILE] ELSE ; IMMEDIATE
|
|
|
|
|
|
|
|
( At this point, we have something like "0 e1 e2 e3 val". We
|
|
|
|
want top drop val, and then call THEN as long as we don't
|
|
|
|
hit 0. )
|
|
|
|
: ENDCASE
|
|
|
|
BEGIN
|
2020-04-19 12:05:11 +10:00
|
|
|
DUP NOT IF
|
|
|
|
DROP COMPILE R> COMPILE DROP EXIT
|
|
|
|
THEN
|
2020-04-17 05:07:31 +10:00
|
|
|
[COMPILE] THEN
|
|
|
|
AGAIN
|
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-03-23 02:49:09 +11:00
|
|
|
: CREATE
|
2020-03-28 06:25:20 +11:00
|
|
|
(entry) ( empty header with name )
|
2020-03-31 08:05:00 +11:00
|
|
|
11 ( 11 == cellWord )
|
2020-04-16 05:15:31 +10:00
|
|
|
C, ( write it )
|
2020-03-23 02:49:09 +11:00
|
|
|
;
|
2020-03-31 10:01:28 +11:00
|
|
|
|
|
|
|
( We run this when we're in an entry creation context. Many
|
|
|
|
things we need to do.
|
|
|
|
1. Change the code link to doesWord
|
|
|
|
2. Leave 2 bytes for regular cell variable.
|
|
|
|
3. Write down RS' RTOS to entry.
|
|
|
|
4. exit parent definition
|
|
|
|
)
|
|
|
|
: DOES>
|
|
|
|
( Overwrite cellWord in CURRENT )
|
2020-04-01 12:46:52 +11:00
|
|
|
( 43 == doesWord )
|
2020-04-16 05:15:31 +10:00
|
|
|
43 CURRENT @ C!
|
2020-03-31 10:01:28 +11:00
|
|
|
( When we have a DOES>, we forcefully place HERE to 4
|
|
|
|
bytes after CURRENT. This allows a DOES word to use ","
|
|
|
|
and "C," without messing everything up. )
|
2020-04-16 05:15:31 +10:00
|
|
|
CURRENT @ 3 + HERE !
|
2020-03-31 10:01:28 +11:00
|
|
|
( HERE points to where we should write R> )
|
|
|
|
R> ,
|
|
|
|
( We're done. Because we've popped RS, we'll exit parent
|
|
|
|
definition )
|
|
|
|
;
|
|
|
|
|
2020-03-14 10:33:16 +11:00
|
|
|
: VARIABLE CREATE 2 ALLOT ;
|
2020-03-31 10:01:28 +11:00
|
|
|
: CONSTANT CREATE , DOES> @ ;
|
2020-03-17 13:36:29 +11:00
|
|
|
: / /MOD SWAP DROP ;
|
|
|
|
: MOD /MOD DROP ;
|
2020-03-19 11:04:44 +11:00
|
|
|
|
2020-03-26 11:13:33 +11:00
|
|
|
( In addition to pushing H@ this compiles 2 >R so that loop
|
2020-03-22 08:21:01 +11:00
|
|
|
variables are sent to PS at runtime )
|
2020-03-19 11:04:44 +11:00
|
|
|
: DO
|
|
|
|
COMPILE SWAP COMPILE >R COMPILE >R
|
2020-03-26 11:13:33 +11:00
|
|
|
H@
|
2020-03-19 11:04:44 +11:00
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-04-15 04:59:01 +10:00
|
|
|
( Increase loop counter and returns whether we should loop. )
|
|
|
|
: _
|
|
|
|
R> ( IP, keep for later )
|
2020-04-16 11:29:39 +10:00
|
|
|
R> 1+ ( ip i+1 )
|
2020-04-15 04:59:01 +10:00
|
|
|
DUP >R ( ip i )
|
|
|
|
I' = ( ip f )
|
|
|
|
SWAP >R ( f )
|
|
|
|
;
|
|
|
|
|
2020-03-22 08:21:01 +11:00
|
|
|
( One could think that we should have a sub word to avoid all
|
|
|
|
these COMPILE, but we can't because otherwise it messes with
|
|
|
|
the RS )
|
2020-03-19 11:04:44 +11:00
|
|
|
: LOOP
|
2020-04-15 04:59:01 +10:00
|
|
|
COMPILE _ COMPILE (?br)
|
2020-03-29 02:03:04 +11:00
|
|
|
H@ - ,
|
2020-03-19 11:04:44 +11:00
|
|
|
COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP
|
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-04-18 01:27:17 +10:00
|
|
|
: LEAVE R> R> DROP I 1- >R >R ;
|
|
|
|
|
2020-04-06 11:01:19 +10:00
|
|
|
( a1 a2 u -- )
|
|
|
|
: MOVE
|
|
|
|
( u ) 0 DO
|
2020-04-07 06:54:56 +10:00
|
|
|
SWAP DUP I + C@ ( a2 a1 x )
|
2020-04-06 11:01:19 +10:00
|
|
|
ROT SWAP OVER I + ( a1 a2 x a2 )
|
2020-04-07 06:54:56 +10:00
|
|
|
C! ( a1 a2 )
|
2020-04-06 11:01:19 +10:00
|
|
|
LOOP
|
2020-04-07 09:59:20 +10:00
|
|
|
2DROP
|
2020-04-06 11:01:19 +10:00
|
|
|
;
|
2020-04-09 10:40:23 +10:00
|
|
|
|
|
|
|
: DELW
|
2020-04-16 11:29:39 +10:00
|
|
|
1- 0 SWAP C!
|
2020-04-09 10:40:23 +10:00
|
|
|
;
|
2020-04-13 22:09:36 +10:00
|
|
|
|
|
|
|
: PREV
|
|
|
|
3 - DUP @ ( a o )
|
|
|
|
- ( a-o )
|
|
|
|
;
|
|
|
|
|
2020-04-19 06:51:48 +10:00
|
|
|
: WORD(
|
|
|
|
DUP 1- C@ ( name len field )
|
2020-04-13 22:09:36 +10:00
|
|
|
127 AND ( 0x7f. remove IMMEDIATE flag )
|
|
|
|
3 + ( fixed header len )
|
2020-04-19 06:51:48 +10:00
|
|
|
-
|
2020-04-13 22:09:36 +10:00
|
|
|
;
|
|
|
|
|
|
|
|
: FORGET
|
|
|
|
' DUP ( w w )
|
|
|
|
( HERE must be at the end of prev's word, that is, at the
|
|
|
|
beginning of w. )
|
2020-04-19 06:51:48 +10:00
|
|
|
WORD( HERE ! ( w )
|
2020-04-13 22:09:36 +10:00
|
|
|
PREV CURRENT !
|
|
|
|
;
|
2020-04-15 06:07:07 +10:00
|
|
|
|
|
|
|
: EMPTY
|
|
|
|
LIT< _sys (find) NOT IF ABORT THEN
|
|
|
|
DUP HERE ! CURRENT !
|
|
|
|
;
|
2020-04-15 11:04:07 +10:00
|
|
|
|
|
|
|
( Drop RSP until I-2 == INTERPRET. )
|
|
|
|
: EXIT!
|
|
|
|
['] INTERPRET ( I )
|
|
|
|
BEGIN ( I )
|
|
|
|
DUP ( I I )
|
2020-04-16 11:29:39 +10:00
|
|
|
R> DROP I 2- @ ( I I a )
|
2020-04-15 11:04:07 +10:00
|
|
|
= UNTIL
|
2020-04-17 10:59:20 +10:00
|
|
|
DROP
|
2020-04-15 11:04:07 +10:00
|
|
|
;
|
2020-04-17 08:58:11 +10:00
|
|
|
|
|
|
|
( a -- a+1 c )
|
|
|
|
: C@+ DUP C@ SWAP 1+ SWAP ;
|