From: Jonas Hvid Date: Tue, 10 Dec 2019 15:26:36 +0000 (+0100) Subject: Define IF and THEN X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=03fd7979b12ff7cc5d074bb83c9d4e3fcdf616c3;p=rrq%2Fjonasforth.git Define IF and THEN --- diff --git a/main.asm b/main.asm index e6b0ac2..086d1dc 100644 --- a/main.asm +++ b/main.asm @@ -288,18 +288,19 @@ forth INTERPRET, 'INTERPRET' ;; Stack is (word length word length). dq FIND ; Try to find word dq DUP_ - dq ZBRANCH, 8 * 20 ; Check if word is found + dq ZBRANCH, 8 * 22 ; Check if word is found ;; - Word is found - - dq STATE, GET, ZBRANCH, 8 * 9 ; Check whether we are in compilation or immediate mode + dq STATE, GET, ZBRANCH, 8 * 11 ; Check whether we are in compilation or immediate mode ;; (Word found, compilation mode) - dq DUP_, IS_IMMEDIATE, NOT_, ZBRANCH, 8 * 4 ; If the word is immediate, continue as we would in immediate mode + dq DUP_, IS_IMMEDIATE, NOT_, ZBRANCH, 8 * 6 ; If the word is immediate, continue as we would in immediate mode ;; Otherwise, we want to compile this word dq TCFA dq COMMA + dq DROP, DROP dq EXIT ;; (Word found, immediate mode) @@ -557,6 +558,11 @@ forth OUTOF_IMMEDIATE, ']' dq LIT, 1, STATE, PUT_BYTE dq EXIT +forth_asm TICK, "'" + lodsq + push rax + next + forth MAIN, 'MAIN' dq HELLO dq INTERPRET @@ -591,7 +597,7 @@ DOTU.printed_length dq ? ;; Reserve space for compiled words, accessed through HERE. here dq here_top -here_top rq $2000 +here_top rq $4000 ;; Return stack rq $2000 diff --git a/sys.f b/sys.f index 23fed87..df2d231 100644 --- a/sys.f +++ b/sys.f @@ -13,3 +13,16 @@ EXIT [ : / /MOD DROP ; : MOD /MOD SWAP DROP ; : NEG 0 SWAP - ; + +: IF IMMEDIATE + ' 0BRANCH , + HERE @ + 0 , +; + +: THEN IMMEDIATE + DUP + HERE @ SWAP - + SWAP ! +; +