From 684cb028ff7f7194cfa572612e20965217cafa0a Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 27 Mar 2020 15:25:20 -0400 Subject: [PATCH] forth: add words "[" and "]" --- forth/core.fs | 13 +++++++------ forth/dictionary.txt | 5 ++++- forth/z80a.fs | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/forth/core.fs b/forth/core.fs index b525791..9d7988a 100644 --- a/forth/core.fs +++ b/forth/core.fs @@ -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 +! ; diff --git a/forth/dictionary.txt b/forth/dictionary.txt index f94ae58..d37dff8 100644 --- a/forth/dictionary.txt +++ b/forth/dictionary.txt @@ -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. diff --git a/forth/z80a.fs b/forth/z80a.fs index f581b50..55a2c68 100644 --- a/forth/z80a.fs +++ b/forth/z80a.fs @@ -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, ;