: 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 ;
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;
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);
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);
"^\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);
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&);