2020-03-26 11:13:33 +11:00
|
|
|
: H@ HERE @ ;
|
2020-03-13 12:49:10 +11:00
|
|
|
: -^ SWAP - ;
|
2020-03-28 06:25:20 +11:00
|
|
|
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE
|
|
|
|
: ] R> DROP ;
|
2020-03-31 08:05:00 +11:00
|
|
|
: LIT 34 , ;
|
2020-03-23 02:56:40 +11:00
|
|
|
: LITS LIT SCPY ;
|
|
|
|
: LIT< WORD LITS ; IMMEDIATE
|
2020-03-26 11:06:06 +11:00
|
|
|
: _err LIT< word-not-found (print) ABORT ;
|
2020-03-30 00:10:23 +11:00
|
|
|
: ' WORD (find) NOT (?br) [ 4 , ] _err ;
|
|
|
|
: ['] ' LITN ; IMMEDIATE
|
2020-03-19 11:04:44 +11:00
|
|
|
: COMPILE ' LITN ['] , , ; 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-03-22 07:27:21 +11:00
|
|
|
: ( BEGIN LIT< ) WORD SCMP NOT 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-03-31 08:05:00 +11:00
|
|
|
LIT: 34 == LIT
|
2020-03-21 04:35:02 +11:00
|
|
|
COMPILE: Tough one. Get addr of caller word (example above
|
2020-03-29 02:03:04 +11:00
|
|
|
(br)) and then call LITN on it. )
|
2020-03-19 07:39:22 +11:00
|
|
|
|
2020-03-21 04:35:02 +11:00
|
|
|
: +! SWAP OVER @ + SWAP ! ;
|
|
|
|
: 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
|
|
|
!
|
|
|
|
H@ 2 - ( push a. -2 for allot offset )
|
2020-03-17 13:09:23 +11:00
|
|
|
; 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-03-28 06:25:20 +11:00
|
|
|
, ( 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 )
|
|
|
|
( 63 == doesWord )
|
|
|
|
63 CURRENT @ !
|
|
|
|
( 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. )
|
|
|
|
CURRENT @ 4 + HERE !
|
|
|
|
( 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-12 15:14:44 +11:00
|
|
|
: = CMP NOT ;
|
|
|
|
: < CMP 0 1 - = ;
|
|
|
|
: > CMP 1 = ;
|
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-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
|
|
|
|
COMPILE R> 1 LITN COMPILE + COMPILE DUP COMPILE >R
|
2020-03-30 00:10:23 +11:00
|
|
|
COMPILE I' 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-03-25 23:39:44 +11:00
|
|
|
( WARNING: there are no limit checks. We must be cautious, in
|
|
|
|
core code, not to create more than SYSV_BUFSIZE/2 sys vars.
|
|
|
|
Also: SYSV shouldn't be used during runtime: SYSVNXT won't
|
|
|
|
point at the right place. It should only be used during
|
|
|
|
stage1 compilation. This is why this word is not documented
|
|
|
|
in dictionary.txt )
|
|
|
|
|
|
|
|
: (sysv)
|
|
|
|
(entry)
|
2020-03-31 08:05:00 +11:00
|
|
|
( 8 == sysvarWord )
|
|
|
|
8 ,
|
|
|
|
( 50 == SYSVNXT )
|
|
|
|
[ 50 @ LITN ] DUP ( a a )
|
2020-03-31 05:19:47 +11:00
|
|
|
( Get new sysv addr )
|
|
|
|
@ , ( a )
|
|
|
|
( increase current sysv counter )
|
|
|
|
2 SWAP +!
|
2020-03-25 23:39:44 +11:00
|
|
|
;
|
2020-03-26 11:39:07 +11:00
|
|
|
|
|
|
|
: ."
|
|
|
|
LIT
|
|
|
|
BEGIN
|
|
|
|
C< DUP ( c c )
|
|
|
|
( 34 is ASCII for " )
|
|
|
|
DUP 34 = IF DROP DROP 0 0 THEN
|
|
|
|
C,
|
|
|
|
0 = UNTIL
|
|
|
|
COMPILE (print)
|
|
|
|
; IMMEDIATE
|
|
|
|
|
|
|
|
: ABORT" [COMPILE] ." COMPILE ABORT ; IMMEDIATE
|