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 @ ;
: -^ SWAP - ;
: [LITN] LITN ; IMMEDIATE
: LIT ROUTINE S [LITN] , ;
: [ INTERPRET 1 FLAGS ! ; IMMEDIATE
: ] R> DROP ;
: LIT [ ROUTINE S LITN ] , ;
: LITS LIT SCPY ;
: LIT< WORD LITS ; IMMEDIATE
: _err LIT< word-not-found (print) ABORT ;
@ -48,9 +49,9 @@
; IMMEDIATE
: CREATE
(entry) ( empty header with name )
ROUTINE C [LITN] ( push cellWord addr )
, ( write it )
(entry) ( empty header with name )
[ ROUTINE C LITN ] ( push cellWord addr )
, ( write it )
;
: VARIABLE CREATE 2 ALLOT ;
: CONSTANT CREATE H@ ! DOES> @ ;
@ -86,7 +87,7 @@
: (sysv)
(entry)
ROUTINE Y [LITN] ,
[ ROUTINE Y LITN ] ,
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.
IMMEDIATE -- Flag the latest defined word as immediate.
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
C=cellWord J=JUMPTBL V=nativeWord N=next S=LIT
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.
(bbr) -- Branches backward by the number specified in its
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" x" -- *I* Compiles a ." followed by a ABORT.
AGAIN I:a -- *I* Jump backwards to preceeding BEGIN.

View File

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