From 9a5b8581d0fb18d20ac21b8d1f96bf18806f1742 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 21 Feb 2023 09:08:30 -0500 Subject: [PATCH] s", quit, abort --- compat.txt | 6 +++--- core.fth | 15 ++++++++++++--- corewords.cpp | 21 +++++++++++++-------- corewords.hpp | 5 +++-- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/compat.txt b/compat.txt index 6891a2d..bfdbb5e 100644 --- a/compat.txt +++ b/compat.txt @@ -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 diff --git a/core.fth b/core.fth index 3f10371..e461964 100644 --- 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 ; @@ -104,8 +104,14 @@ : 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 , @@ -123,3 +129,6 @@ : >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 ; diff --git a/corewords.cpp b/corewords.cpp index 3fc5f51..c6b3d7d 100644 --- a/corewords.cpp +++ b/corewords.cpp @@ -21,14 +21,14 @@ 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); diff --git a/corewords.hpp b/corewords.hpp index 126878e..d4eb881 100644 --- a/corewords.hpp +++ b/corewords.hpp @@ -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&);