From 4336bb7e47303e8433ac1b7ed91221b53ae1a769 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Mon, 2 May 2016 14:11:33 +1200 Subject: [PATCH] CREATE, ALLOT and VARIABLE now work as they should. --- src/forth.jl | 9 +++++++-- src/lib.4th | 9 ++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/forth.jl b/src/forth.jl index c1ca1a0..98999a3 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -768,6 +768,8 @@ end) # Compilation +STATE, STATE_CFA = defNewVar("STATE", 0) + HEADER = defPrimWord("HEADER", () -> begin wordLen = popPS() @@ -786,8 +788,6 @@ COMMA = defPrimWord(",", () -> begin return NEXT end) -STATE, STATE_CFA = defNewVar("STATE", 0) - LBRAC = defPrimWord("[", () -> begin mem[STATE] = 0 return NEXT @@ -810,6 +810,11 @@ HIDE = defWord("HIDE", HIDDEN, EXIT]) +CREATE = defWord("CREATE", + [WORD, + HEADER, + LIT, DOVAR, COMMA, EXIT]); + COLON = defWord(":", [WORD, HEADER, diff --git a/src/lib.4th b/src/lib.4th index 28aa451..9e40b2d 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -478,18 +478,13 @@ ['] EXIT , ( append the codeword EXIT ) ; -: ALLOT ( n -- addr ) - HERE @ SWAP ( here n ) +: ALLOT ( n -- ) HERE +! ( adds n to HERE, after this the old value of HERE is still on the stack ) ; : VARIABLE + CREATE 1 CELLS ALLOT ( allocate 1 cell of memory, push the pointer to this memory ) - WORD HEADER ( make the dictionary entry (the name follows VARIABLE) ) - DOCOL , ( append DOCOL (the codeword field of this word) ) - ['] LIT , ( append the codeword LIT ) - , ( append the pointer to the new memory ) - ['] EXIT , ( append the codeword EXIT ) ; -- 2.20.1