From 15ee0ce37b55ff3de1767a2aeda4f1fbf491c871 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 8 Apr 2018 13:56:53 +0200 Subject: [PATCH 1/2] fixes #183 Enable EVALUATE-like feature by using indirect addressing for TIB --- forth.asm | 44 ++++++++++++++++++++++++++++++++------------ "lib/S\"" | 11 +++++++++++ 2 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 "lib/S\"" diff --git a/forth.asm b/forth.asm index 95d91a2..bb7a9fb 100644 --- a/forth.asm +++ b/forth.asm @@ -257,7 +257,10 @@ USRHLD = UPP+24 ; "HLD" hold a pointer of output string USRNTIB = UPP+26 ; "#TIB" count in terminal input buffer USR_IN = UPP+28 ; ">IN" hold parsing pointer - YTEMP = UPP+30 ; extra working register for core words + USRBUFFER = UPP+30 ; "BUFFER" address, defaults to TIBB + + ; temporary core variables + RamWord YTEMP ; extra working register for core words ;*********************** ;****** 7) Code ****** @@ -2068,8 +2071,8 @@ COUNT: RAMHERE: TNZ USRCP JRPL HERE ; NVM: CP points to NVM, NVMCP points to RAM - DoLitW NVMCP ; 'eval in Interpreter mode: HERE returns pointer to RAM - JP AT + LD A,#(NVMCP) ; 'eval in Interpreter mode: HERE returns pointer to RAM + JP AAT .else RAMHERE = HERE .endif @@ -2747,7 +2750,8 @@ SUBPARS: HEADER PARSE "PARSE" PARSE: - DoLitW TIBB + LD A,#(USRBUFFER) + CALL AAT ADDW Y,USR_IN ; current input buffer pointer LDW (X),Y LD A,USRNTIB+1 @@ -2848,7 +2852,6 @@ NAMET: 1$: RET ; THEN .endif - ; R@ indexed char lookup for SAME? SAMEQCAT: CALL OVER @@ -2925,8 +2928,7 @@ FIND: CALLR SWAPPF FIND1: CALL AT JREQ FIND6 - CALL DUPP - CALL AT + CALL YAT ; DUPP AT DoLitW MASKK CALL ANDD .ifne CASEINSENSITIVE @@ -3056,7 +3058,8 @@ ACCP4: CALL DROP HEADER QUERY "QUERY" QUERY: - DoLitW TIBB + LD A,#(USRBUFFER) + CALL AAT DoLitC TIBLENGTH CALLR ACCEP CALL AFLAGS ; NTIB ! @@ -3103,6 +3106,8 @@ ABOR2: CALL DOSTR PRESE: CLRW X LDW USRNTIB,X + LDW X,#(TIBB) + LDW USRBUFFER,X LDW X,#SPP ; initialize data stack RET @@ -3786,6 +3791,21 @@ DOESS: .db EXIT_OPC ; 1 RET (EXIT) RET +; A@ ( A:shortAddr -- n ) +; push contents of A:shortAddr on stack +; HEADER AAT "A@" +AAT: + CLRW Y + LD YL,A + ; fall through + +; Y@ ( Y:Addr -- n ) +; push contents of Y:Addr on stack +; HEADER YAT "Y@" +YAT: + LDW Y,(Y) + JP YSTOR + ; dodoes ( -- ) ; link action to words created by defining words @@ -3793,8 +3813,8 @@ DOESS: HEADER DODOES "dodoes" .endif DODOES: - CALL LAST ; ( link field of current word ) - CALL AT + LD A,#(USRLAST) ; ( link field of current word ) + CALLR AAT CALL NAMET ; ' ( 'last ) DoLitC BRAN_OPC ; ' JP CALL OVER ; ' JP ' @@ -3849,8 +3869,8 @@ CONST: HEADER DOCON "docon" DOCON: - CALL RFROM - CALL AT ; push constant in interpreter mode + POPW Y + CALLR YAT ; R> AT push constant in interpreter mode CALL COMPIQ JREQ 1$ CALL LITER ; compile constant in compiler mode diff --git "a/lib/S\"" "b/lib/S\"" new file mode 100644 index 0000000..deed352 --- /dev/null +++ "b/lib/S\"" @@ -0,0 +1,11 @@ +\ S" STM8 eForth string utility word +\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md + +#require COMPILE +#require [COMPILE] +#require COUNT +#require $" + +: S" ( string -- a u ) + [COMPILE] $" COMPILE COUNT +; IMMEDIATE From f6f87dd1caeb3136bf6029f46779388d9f4bd219 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 8 Apr 2018 14:03:12 +0200 Subject: [PATCH 2/2] fixes #183 Enable EVALUATE-like feature by using indirect addressing for TIB --- forth.asm | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/forth.asm b/forth.asm index bb7a9fb..3c10684 100644 --- a/forth.asm +++ b/forth.asm @@ -3765,7 +3765,6 @@ RBRAC: LDW USREVAL,Y RET - ; Defining words .ifne HAS_DOES @@ -3791,21 +3790,6 @@ DOESS: .db EXIT_OPC ; 1 RET (EXIT) RET -; A@ ( A:shortAddr -- n ) -; push contents of A:shortAddr on stack -; HEADER AAT "A@" -AAT: - CLRW Y - LD YL,A - ; fall through - -; Y@ ( Y:Addr -- n ) -; push contents of Y:Addr on stack -; HEADER YAT "Y@" -YAT: - LDW Y,(Y) - JP YSTOR - ; dodoes ( -- ) ; link action to words created by defining words @@ -3838,6 +3822,21 @@ DODOES: RET .endif +; A@ ( A:shortAddr -- n ) +; push contents of A:shortAddr on stack +; HEADER AAT "A@" +AAT: + CLRW Y + LD YL,A + ; fall through + +; Y@ ( Y:Addr -- n ) +; push contents of Y:Addr on stack +; HEADER YAT "Y@" +YAT: + LDW Y,(Y) + JP YSTOR + ; CREATE ( -- ; ) ; Compile a new array ; without allocating space.