2020-03-25 20:13:33 -04:00
|
|
|
: H@ HERE @ ;
|
2020-03-12 21:49:10 -04:00
|
|
|
: -^ SWAP - ;
|
2020-03-27 15:25:20 -04:00
|
|
|
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE
|
|
|
|
: ] R> DROP ;
|
2020-03-27 19:52:45 -04:00
|
|
|
: LIT [ JTBL 26 + LITN ] , ;
|
2020-03-22 11:56:40 -04:00
|
|
|
: LITS LIT SCPY ;
|
|
|
|
: LIT< WORD LITS ; IMMEDIATE
|
2020-03-25 20:06:06 -04:00
|
|
|
: _err LIT< word-not-found (print) ABORT ;
|
|
|
|
: ' WORD (find) SKIP? _err ;
|
|
|
|
: ['] WORD (find) SKIP? _err LITN ; IMMEDIATE
|
2020-03-18 20:04:44 -04:00
|
|
|
: COMPILE ' LITN ['] , , ; IMMEDIATE
|
2020-03-21 16:17:51 -04:00
|
|
|
: [COMPILE] ' , ; IMMEDIATE
|
2020-03-25 20:13:33 -04:00
|
|
|
: BEGIN H@ ; IMMEDIATE
|
|
|
|
: AGAIN COMPILE (bbr) H@ -^ C, ; IMMEDIATE
|
|
|
|
: UNTIL COMPILE SKIP? COMPILE (bbr) H@ -^ C, ; IMMEDIATE
|
2020-03-21 16:27:21 -04:00
|
|
|
: ( BEGIN LIT< ) WORD SCMP NOT UNTIL ; IMMEDIATE
|
2020-03-14 19:10:39 -04: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-16 21:31:43 -04:00
|
|
|
|
2020-03-25 20:06:06 -04:00
|
|
|
"_": words starting with "_" are meant to be "private",
|
|
|
|
that is, only used by their immediate surrondings.
|
|
|
|
|
2020-03-20 13:35:02 -04:00
|
|
|
COMPILE: Tough one. Get addr of caller word (example above
|
|
|
|
(bbr)) and then call LITN on it. )
|
2020-03-18 16:39:22 -04:00
|
|
|
|
2020-03-20 13:35:02 -04:00
|
|
|
: +! SWAP OVER @ + SWAP ! ;
|
|
|
|
: ALLOT HERE +! ;
|
2020-03-16 22:09:23 -04:00
|
|
|
|
|
|
|
: IF ( -- a | a: br cell addr )
|
|
|
|
COMPILE SKIP? ( if true, don't branch )
|
|
|
|
COMPILE (fbr)
|
2020-03-25 20:13:33 -04:00
|
|
|
H@ ( push a )
|
2020-03-16 22:09:23 -04:00
|
|
|
1 ALLOT ( br cell allot )
|
|
|
|
; IMMEDIATE
|
|
|
|
|
|
|
|
: THEN ( a -- | a: br cell addr )
|
2020-03-25 20:13:33 -04:00
|
|
|
DUP H@ -^ SWAP ( a-H a )
|
2020-03-16 22:09:23 -04:00
|
|
|
C!
|
|
|
|
; IMMEDIATE
|
|
|
|
|
|
|
|
: ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell )
|
|
|
|
COMPILE (fbr)
|
|
|
|
1 ALLOT
|
2020-03-25 20:13:33 -04:00
|
|
|
DUP H@ -^ SWAP ( a-H a )
|
2020-03-16 22:09:23 -04:00
|
|
|
C!
|
2020-03-25 20:13:33 -04:00
|
|
|
H@ 1 - ( push a. -1 for allot offset )
|
2020-03-16 22:09:23 -04:00
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-03-22 11:49:09 -04:00
|
|
|
: CREATE
|
2020-03-27 15:25:20 -04:00
|
|
|
(entry) ( empty header with name )
|
2020-03-27 19:52:45 -04:00
|
|
|
[ JTBL 3 + LITN ] ( push cellWord addr )
|
2020-03-27 15:25:20 -04:00
|
|
|
, ( write it )
|
2020-03-22 11:49:09 -04:00
|
|
|
;
|
2020-03-13 19:33:16 -04:00
|
|
|
: VARIABLE CREATE 2 ALLOT ;
|
2020-03-25 20:13:33 -04:00
|
|
|
: CONSTANT CREATE H@ ! DOES> @ ;
|
2020-03-12 00:14:44 -04:00
|
|
|
: = CMP NOT ;
|
|
|
|
: < CMP 0 1 - = ;
|
|
|
|
: > CMP 1 = ;
|
2020-03-16 22:36:29 -04:00
|
|
|
: / /MOD SWAP DROP ;
|
|
|
|
: MOD /MOD DROP ;
|
2020-03-18 20:04:44 -04:00
|
|
|
|
2020-03-25 20:13:33 -04:00
|
|
|
( In addition to pushing H@ this compiles 2 >R so that loop
|
2020-03-21 17:21:01 -04:00
|
|
|
variables are sent to PS at runtime )
|
2020-03-18 20:04:44 -04:00
|
|
|
: DO
|
|
|
|
COMPILE SWAP COMPILE >R COMPILE >R
|
2020-03-25 20:13:33 -04:00
|
|
|
H@
|
2020-03-18 20:04:44 -04:00
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-03-21 17:21:01 -04: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-18 20:04:44 -04:00
|
|
|
: LOOP
|
|
|
|
COMPILE R> 1 LITN COMPILE + COMPILE DUP COMPILE >R
|
|
|
|
COMPILE I' COMPILE = COMPILE SKIP? COMPILE (bbr)
|
2020-03-25 20:13:33 -04:00
|
|
|
H@ -^ C,
|
2020-03-18 20:04:44 -04:00
|
|
|
COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP
|
|
|
|
; IMMEDIATE
|
|
|
|
|
2020-03-25 08:39:44 -04: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-27 19:52:45 -04:00
|
|
|
[ JTBL LITN ] ,
|
2020-03-25 08:39:44 -04:00
|
|
|
SYSVNXT @ ,
|
|
|
|
2 SYSVNXT +!
|
|
|
|
;
|
2020-03-25 20:39:07 -04: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
|