]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
s", quit, abort
authorClyne Sullivan <clyne@bitgloo.com>
Tue, 21 Feb 2023 14:08:30 +0000 (09:08 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Tue, 21 Feb 2023 14:08:30 +0000 (09:08 -0500)
compat.txt
core.fth
corewords.cpp
corewords.hpp

index 6891a2dd5c90ab6ad2baf638f5919e240ebd8a5a..bfdbb5edc8f955c8436197b9d2c07a9b65ce68a7 100644 (file)
@@ -42,7 +42,7 @@ yes 6.1.0560 >IN
 yes 6.1.0580 >R
 yes 6.1.0630 ?DUP
 yes 6.1.0650 @
-    6.1.0670 ABORT
+yes 6.1.0670 ABORT
     6.1.0680 ABORT"
 yes 6.1.0690 ABS
     6.1.0695 ACCEPT
@@ -101,14 +101,14 @@ yes 6.1.1910 NEGATE
 yes 6.1.1980 OR
 yes 6.1.1990 OVER
 yes 6.1.2033 POSTPONE
-    6.1.2050 QUIT
+yes 6.1.2050 QUIT
 yes 6.1.2060 R>
 yes 6.1.2070 R@
     6.1.2120 RECURSE
 yes 6.1.2140 REPEAT
 yes 6.1.2160 ROT
 yes 6.1.2162 RSHIFT
-    6.1.2165 S"
+yes 6.1.2165 S"
     6.1.2170 S>D
     6.1.2210 SIGN
     6.1.2214 SM/REM
index 3f103716e139f2a20342c1f1380a1fb5648dfa59..e46196459ff54888b02130decd6b66255bd3ae29 100644 (file)
--- a/core.fth
+++ b/core.fth
@@ -88,7 +88,7 @@
 : cr       9 emit ;
 : bl       32 ;
 : space    bl emit ;
-: spaces   begin dup 0 > while space 1- repeat ;
+: spaces   begin dup 0 > while space 1- repeat drop ;
 
 : ?dup     dup if dup then ;
 
 : char     bl word cell+ c@ ;
 : [char]   char postpone literal ; imm
 
-: type     begin dup 0 > while swap dup c@ emit char+ swap 1- repeat ;
-: ."       [char] " word count type ;
+: type     begin dup 0 > while swap dup c@ emit char+ swap 1- repeat 2drop ;
+: s"       state @ if ['] _jmp , here 0 , then
+           [char] " word count
+           state @ 0= if exit then
+           dup cell+ allot
+           rot here swap !
+           swap postpone literal postpone literal ; imm
+: ."       postpone s" state @ if ['] type , else type then ; imm
 
 : create   align here bl word count nip cell+ allot align
            ['] _lit , here 3 cells + , ['] exit , 0 ,
 
 : >in      _input 80 chars + cell+ _input @ - 4 chars - ;
 : source   _input @ 6 chars + >in 3 chars - swap ;
+
+: quit     begin _rdepth 1 > while r> drop repeat postpone [ ;
+: abort    begin depth 0 > while drop repeat quit ;
index 3fc5f5156bc00c42c14adb3716eff6ebb60eaa52..c6b3d7d6432cc3975ce3bc1455da659bc2625dcf 100644 (file)
 Func CoreWords::get(int index)
 {
     static const Func ops[WordCount] = {
-        op_drop,  op_dup,    op_swap,    op_pick,    op_sys,
-        op_add,   op_sub,    op_mul,     op_div,     op_mod,
- /*10*/ op_peek,  op_poke,   op_rot,     op_pushr,   op_popr,
-        op_eq,    op_lt,     op_allot,   op_and,     op_or,
- /*20*/ op_xor,   op_shl,    op_shr,     op_comment, op_colon,
-        op_semic, op_here,   op_const,   op_depth,   op_key,
- /*30*/ op_exit,  op_tick,   op_execute, op_jmp,     op_jmp0,
-        op_lit,   op_literal
+        op_drop,  op_dup,     op_swap,    op_pick,    op_sys,
+        op_add,   op_sub,     op_mul,     op_div,     op_mod,
+ /*10*/ op_peek,  op_poke,    op_rot,     op_pushr,   op_popr,
+        op_eq,    op_lt,      op_allot,   op_and,     op_or,
+ /*20*/ op_xor,   op_shl,     op_shr,     op_comment, op_colon,
+        op_semic, op_here,    op_const,   op_depth,   op_key,
+ /*30*/ op_exit,  op_tick,    op_execute, op_jmp,     op_jmp0,
+        op_lit,   op_literal, op_rdepth
     };
 
     return index >= 0 && index < WordCount ? ops[index] : nullptr;
@@ -259,6 +259,11 @@ void CoreWords::op_depth(State& state)
     state.push(state.size());
 }
 
+void CoreWords::op_rdepth(State& state)
+{
+    state.push(state.rsize());
+}
+
 void CoreWords::op_key(State& state)
 {
     auto len = state.dict.read(Dictionary::Input);
index 126878ed9bbd32319d3347444ec6a34ed9eb8da2..d4eb8810b22e4299214a84c30fe05e2b8c48e9df 100644 (file)
@@ -29,7 +29,7 @@ void user_sys(State&);
 class CoreWords
 {
 public:
-    constexpr static std::size_t WordCount = 37;
+    constexpr static std::size_t WordCount = 38;
 
     constexpr static Cell Immediate   = (1 << 5);
     constexpr static Cell Compiletime = (1 << 6);
@@ -50,7 +50,7 @@ private:
         "^\0<<\0>>\0(\0:\1"
         ";\1here\0const\0depth\0"
         "key\0exit\0'\0execute\0_jmp\0"
-        "_jmp0\0_lit\0literal\1";
+        "_jmp0\0_lit\0literal\1_rdepth\0";
 
     static Func get(int);
 
@@ -84,6 +84,7 @@ private:
     static void op_const(State&);
     static void op_lit(State&);
     static void op_depth(State&);
+    static void op_rdepth(State&);
     static void op_key(State&);
     static void op_exit(State&);
     static void op_tick(State&);