s", quit, abort

llvm
Clyne 2 years ago
parent 5632b65540
commit 9a5b8581d0

@ -42,7 +42,7 @@ yes 6.1.0560 >IN
yes 6.1.0580 >R yes 6.1.0580 >R
yes 6.1.0630 ?DUP yes 6.1.0630 ?DUP
yes 6.1.0650 @ yes 6.1.0650 @
6.1.0670 ABORT yes 6.1.0670 ABORT
6.1.0680 ABORT" 6.1.0680 ABORT"
yes 6.1.0690 ABS yes 6.1.0690 ABS
6.1.0695 ACCEPT 6.1.0695 ACCEPT
@ -101,14 +101,14 @@ yes 6.1.1910 NEGATE
yes 6.1.1980 OR yes 6.1.1980 OR
yes 6.1.1990 OVER yes 6.1.1990 OVER
yes 6.1.2033 POSTPONE yes 6.1.2033 POSTPONE
6.1.2050 QUIT yes 6.1.2050 QUIT
yes 6.1.2060 R> yes 6.1.2060 R>
yes 6.1.2070 R@ yes 6.1.2070 R@
6.1.2120 RECURSE 6.1.2120 RECURSE
yes 6.1.2140 REPEAT yes 6.1.2140 REPEAT
yes 6.1.2160 ROT yes 6.1.2160 ROT
yes 6.1.2162 RSHIFT yes 6.1.2162 RSHIFT
6.1.2165 S" yes 6.1.2165 S"
6.1.2170 S>D 6.1.2170 S>D
6.1.2210 SIGN 6.1.2210 SIGN
6.1.2214 SM/REM 6.1.2214 SM/REM

@ -88,7 +88,7 @@
: cr 9 emit ; : cr 9 emit ;
: bl 32 ; : bl 32 ;
: space bl emit ; : 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 ; : ?dup dup if dup then ;
@ -104,8 +104,14 @@
: char bl word cell+ c@ ; : char bl word cell+ c@ ;
: [char] char postpone literal ; imm : [char] char postpone literal ; imm
: type begin dup 0 > while swap dup c@ emit char+ swap 1- repeat ; : type begin dup 0 > while swap dup c@ emit char+ swap 1- repeat 2drop ;
: ." [char] " word count type ; : 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 : create align here bl word count nip cell+ allot align
['] _lit , here 3 cells + , ['] exit , 0 , ['] _lit , here 3 cells + , ['] exit , 0 ,
@ -123,3 +129,6 @@
: >in _input 80 chars + cell+ _input @ - 4 chars - ; : >in _input 80 chars + cell+ _input @ - 4 chars - ;
: source _input @ 6 chars + >in 3 chars - swap ; : 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 ;

@ -28,7 +28,7 @@ Func CoreWords::get(int index)
/*20*/ op_xor, op_shl, op_shr, op_comment, op_colon, /*20*/ op_xor, op_shl, op_shr, op_comment, op_colon,
op_semic, op_here, op_const, op_depth, op_key, op_semic, op_here, op_const, op_depth, op_key,
/*30*/ op_exit, op_tick, op_execute, op_jmp, op_jmp0, /*30*/ op_exit, op_tick, op_execute, op_jmp, op_jmp0,
op_lit, op_literal op_lit, op_literal, op_rdepth
}; };
return index >= 0 && index < WordCount ? ops[index] : nullptr; return index >= 0 && index < WordCount ? ops[index] : nullptr;
@ -259,6 +259,11 @@ void CoreWords::op_depth(State& state)
state.push(state.size()); state.push(state.size());
} }
void CoreWords::op_rdepth(State& state)
{
state.push(state.rsize());
}
void CoreWords::op_key(State& state) void CoreWords::op_key(State& state)
{ {
auto len = state.dict.read(Dictionary::Input); auto len = state.dict.read(Dictionary::Input);

@ -29,7 +29,7 @@ void user_sys(State&);
class CoreWords class CoreWords
{ {
public: public:
constexpr static std::size_t WordCount = 37; constexpr static std::size_t WordCount = 38;
constexpr static Cell Immediate = (1 << 5); constexpr static Cell Immediate = (1 << 5);
constexpr static Cell Compiletime = (1 << 6); constexpr static Cell Compiletime = (1 << 6);
@ -50,7 +50,7 @@ private:
"^\0<<\0>>\0(\0:\1" "^\0<<\0>>\0(\0:\1"
";\1here\0const\0depth\0" ";\1here\0const\0depth\0"
"key\0exit\0'\0execute\0_jmp\0" "key\0exit\0'\0execute\0_jmp\0"
"_jmp0\0_lit\0literal\1"; "_jmp0\0_lit\0literal\1_rdepth\0";
static Func get(int); static Func get(int);
@ -84,6 +84,7 @@ private:
static void op_const(State&); static void op_const(State&);
static void op_lit(State&); static void op_lit(State&);
static void op_depth(State&); static void op_depth(State&);
static void op_rdepth(State&);
static void op_key(State&); static void op_key(State&);
static void op_exit(State&); static void op_exit(State&);
static void op_tick(State&); static void op_tick(State&);

Loading…
Cancel
Save