1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 23:38:06 +11:00

forth: add words "[" and "]"

This commit is contained in:
Virgil Dupras 2020-03-27 15:25:20 -04:00
parent 839021e0f8
commit 684cb028ff
3 changed files with 14 additions and 10 deletions

View File

@ -1,7 +1,8 @@
: H@ HERE @ ; : H@ HERE @ ;
: -^ SWAP - ; : -^ SWAP - ;
: [LITN] LITN ; IMMEDIATE : [ INTERPRET 1 FLAGS ! ; IMMEDIATE
: LIT ROUTINE S [LITN] , ; : ] R> DROP ;
: LIT [ ROUTINE S LITN ] , ;
: LITS LIT SCPY ; : LITS LIT SCPY ;
: LIT< WORD LITS ; IMMEDIATE : LIT< WORD LITS ; IMMEDIATE
: _err LIT< word-not-found (print) ABORT ; : _err LIT< word-not-found (print) ABORT ;
@ -48,9 +49,9 @@
; IMMEDIATE ; IMMEDIATE
: CREATE : CREATE
(entry) ( empty header with name ) (entry) ( empty header with name )
ROUTINE C [LITN] ( push cellWord addr ) [ ROUTINE C LITN ] ( push cellWord addr )
, ( write it ) , ( write it )
; ;
: VARIABLE CREATE 2 ALLOT ; : VARIABLE CREATE 2 ALLOT ;
: CONSTANT CREATE H@ ! DOES> @ ; : CONSTANT CREATE H@ ! DOES> @ ;
@ -86,7 +87,7 @@
: (sysv) : (sysv)
(entry) (entry)
ROUTINE Y [LITN] , [ ROUTINE Y LITN ] ,
SYSVNXT @ , SYSVNXT @ ,
2 SYSVNXT +! 2 SYSVNXT +!
; ;

View File

@ -52,7 +52,6 @@ DOES> -- See description at top of file
IMMED? a -- f Checks whether wordref at a is immediate. IMMED? a -- f Checks whether wordref at a is immediate.
IMMEDIATE -- Flag the latest defined word as immediate. IMMEDIATE -- Flag the latest defined word as immediate.
LITN n -- Write number n as a literal. LITN n -- Write number n as a literal.
[LITN] n -- *I* Immediate version of LITN.
ROUTINE x -- a Push the addr of the specified core routine ROUTINE x -- a Push the addr of the specified core routine
C=cellWord J=JUMPTBL V=nativeWord N=next S=LIT C=cellWord J=JUMPTBL V=nativeWord N=next S=LIT
M=NUMBER Y=sysvarWord D=doesWord M=NUMBER Y=sysvarWord D=doesWord
@ -81,6 +80,10 @@ input stream is executed immediately. In this context, branching doesn't work.
atom's cell. atom's cell.
(bbr) -- Branches backward by the number specified in its (bbr) -- Branches backward by the number specified in its
atom's cell. atom's cell.
[ -- Begin interetative mode. In a definition, words
between here and "]" will be executed instead of
compiled.
] -- End interpretative mode.
ABORT -- Resets PS and RS and returns to interpreter ABORT -- Resets PS and RS and returns to interpreter
ABORT" x" -- *I* Compiles a ." followed by a ABORT. ABORT" x" -- *I* Compiles a ." followed by a ABORT.
AGAIN I:a -- *I* Jump backwards to preceeding BEGIN. AGAIN I:a -- *I* Jump backwards to preceeding BEGIN.

View File

@ -222,16 +222,16 @@
0x10 OPJR DJNZe, 0x10 OPJR DJNZe,
( Specials ) ( Specials )
: JPNEXT, ROUTINE N [LITN] JPnn, ; : JPNEXT, [ ROUTINE N LITN ] JPnn, ;
: CODE : CODE
( same as CREATE, but with ROUTINE V ) ( same as CREATE, but with ROUTINE V )
(entry) (entry)
ROUTINE V [LITN] , [ ROUTINE V LITN ] ,
; ;
: ;CODE JPNEXT, ; : ;CODE JPNEXT, ;
( Routines ) ( Routines )
: chkPS, ROUTINE P [LITN] CALLnn, ; : chkPS, [ ROUTINE P LITN ] CALLnn, ;