aboutsummaryrefslogtreecommitdiff
path: root/slof/engine.in
diff options
context:
space:
mode:
authorThomas Huth <thuth@linux.vnet.ibm.com>2011-11-11 17:25:27 +0100
committerThomas Huth <thuth@linux.vnet.ibm.com>2011-12-28 15:05:23 +0100
commitef727e4b6fd9ef1fc1024f1e2e07038d4679a604 (patch)
tree230724dd3ce0ee2ff5fd6eb8f8c065373fd2e354 /slof/engine.in
parent46b5160777477efaeea6aacc6a790581c1da92dc (diff)
downloadSLOF-ef727e4b6fd9ef1fc1024f1e2e07038d4679a604.zip
SLOF-ef727e4b6fd9ef1fc1024f1e2e07038d4679a604.tar.gz
SLOF-ef727e4b6fd9ef1fc1024f1e2e07038d4679a604.tar.bz2
Improved "tick", postpone and $FIND commands
When the ' (tick) or postpone commands hit an unknown function, they simply printed out "undefined word" without telling which word was not defined. These problems were quite cumbersome to debug since it was quite hard to find the right spot in the source code where such problems happened. Now the tick and postpone command store the name of the undefined word, too, so that the code which catches the ABORT also prints this information. I also fixed the $FIND command to be standard compliant right from the start (so that it leaves the string parameters on the stack in case the word has not been found). Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Diffstat (limited to 'slof/engine.in')
-rw-r--r--slof/engine.in16
1 files changed, 9 insertions, 7 deletions
diff --git a/slof/engine.in b/slof/engine.in
index d723bc2..0344a38 100644
--- a/slof/engine.in
+++ b/slof/engine.in
@@ -375,7 +375,8 @@ cod(STRING=CI)
dfr((FIND))
col(((FIND)) DUP 0BRANCH(15) >R 2DUP R@ LINK>NAME NAME>STRING STRING=CI 0BRANCH(3) 2DROP R> EXIT R> @ BRANCH(-18) 3DROP FALSE)
col((FIND-ORDER) CONTEXT DUP >R SEARCH-ORDER U>= 0BRANCH(18) 2DUP R@ @ CELL+ @ (FIND) ?DUP 0BRANCH(5) NIP NIP R> DROP EXIT R> CELL- BRANCH(-24) R> 3DROP 0)
-col($FIND (FIND-ORDER) DUP 0BRANCH(6) LINK>NAME DUP NAME> SWAP C@ TRUE)
+col(($FIND) (FIND-ORDER) DUP 0BRANCH(6) LINK>NAME DUP NAME> SWAP C@ TRUE)
+col($FIND 2DUP ($FIND) 0BRANCH(6) DROP NIP NIP TRUE BRANCH(1) FALSE)
// Flags on words.
con('IMMEDIATE 1)
@@ -471,8 +472,8 @@ col(PRINT-EXCEPTION DUP LIT(-99) = 0BRANCH(7) DOTICK UNKNOWN-STR COUNT TYPE CR D
col(PRINT-STATUS SPACE DUP 0= 0BRANCH(5) PRINT-STACK DOTICK OK-STR BRANCH(7) DUP -1 = 0BRANCH(6) DOTICK ABORTED-STR COUNT TYPE BRANCH(10) DUP LIT(-2) = 0BRANCH(7) ABORT"-STR @ COUNT TYPE DROP BRANCH(1) PRINT-EXCEPTION CR)
// The compiler and interpreter.
-col(COMPILE-WORD 2DUP $FIND 0BRANCH(10) IMMEDIATE? 0BRANCH(4) NIP NIP EXECUTE EXIT COMPILE, 2DROP EXIT 2DUP $NUMBER 0BRANCH(4) TYPE LIT(-99) THROW DOTICK DOLIT COMPILE, COMPILE, 2DROP)
-col(INTERPRET-WORD 2DUP $FIND 0BRANCH(5) DROP NIP NIP EXECUTE EXIT 2DUP $NUMBER 0BRANCH(4) TYPE LIT(-99) THROW >R 2DROP R>)
+col(COMPILE-WORD 2DUP ($FIND) 0BRANCH(10) IMMEDIATE? 0BRANCH(4) NIP NIP EXECUTE EXIT COMPILE, 2DROP EXIT 2DUP $NUMBER 0BRANCH(4) TYPE LIT(-99) THROW DOTICK DOLIT COMPILE, COMPILE, 2DROP)
+col(INTERPRET-WORD 2DUP ($FIND) 0BRANCH(5) DROP NIP NIP EXECUTE EXIT 2DUP $NUMBER 0BRANCH(4) TYPE LIT(-99) THROW >R 2DROP R>)
col(INTERPRET 0 >IN ! PARSE-WORD DUP 0BRANCH(10) STATE @ 0BRANCH(3) COMPILE-WORD BRANCH(1) INTERPRET-WORD BRANCH(-14) 2DROP)
// Evaluate, the one word to rule them all. It is evil, btw.
@@ -484,8 +485,9 @@ col(DOABORT" SWAP 0BRANCH(5) ABORT"-STR ! LIT(-2) THROW DROP)
imm(ABORT" C" DOTICK DOABORT" COMPILE,)
// Tick.
-str(UNDEFINED-STR "undefined word")
-col(' PARSE-WORD $FIND 0= DOTICK UNDEFINED-STR DOABORT" DROP)
+str(UNDEFINED-STR "undefined word ")
+col(SET-UNDEFINED-WORD POCKET >R DOTICK UNDEFINED-STR DUP C@ 1+ R@ SWAP MOVE R@ DUP C@ 1+ + SWAP DUP R@ C@ + R@ C! MOVE R>)
+col(' PARSE-WORD $FIND 0= 0BRANCH(4) SET-UNDEFINED-WORD TRUE SWAP DOABORT")
// The outer interpreter.
col(QUIT 0 RDEPTH! [ TERMINAL DEPTH . LIT('>') EMIT SPACE REFILL 0BRANCH(10) SPACE DOTICK INTERPRET CATCH DUP PRINT-STATUS 0BRANCH(-17) BRANCH(-23))
@@ -517,12 +519,12 @@ col(FIELD PARSE-WORD HEADER DOTICK DOFIELD COMPILE, OVER , + REVEAL)
// Words with (mostly) non-standard compilation behaviour.
imm(LITERAL DOTICK DOLIT COMPILE, COMPILE,)
imm([COMPILE] ' COMPILE,)
-imm(POSTPONE PARSE-WORD $FIND 0= DOTICK UNDEFINED-STR DOABORT" IMMEDIATE? 0= 0BRANCH(6) DOTICK DOTICK COMPILE, COMPILE, DOTICK COMPILE, COMPILE,)
+imm(POSTPONE PARSE-WORD 2DUP ($FIND) 0= 0BRANCH(4) SET-UNDEFINED-WORD TRUE SWAP DOABORT" IMMEDIATE? 0= 0BRANCH(6) DOTICK DOTICK COMPILE, COMPILE, DOTICK COMPILE, COMPILE, 2DROP)
imm([CHAR] CHAR LITERAL)
imm(['] ' DOTICK DOTICK COMPILE, COMPILE,)
// FIND.
-col(FIND DUP COUNT $FIND 0BRANCH(9) ROT DROP TRUE SWAP IMMEDIATE? 0BRANCH(1) NEGATE EXIT FALSE EXIT)
+col(FIND DUP COUNT ($FIND) 0BRANCH(9) ROT DROP TRUE SWAP IMMEDIATE? 0BRANCH(1) NEGATE EXIT FALSE EXIT)
// Accessing data in CREATE'd words.
imm(TO ' STATE @ 0BRANCH(5) DOTICK DOTO COMPILE, COMPILE, EXIT CELL+ !)