From e4f1fba4e8cc3991a6b6f40570c096c01f7c302d Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 17 Nov 2023 20:27:33 -0500 Subject: add native definition bit --- forth/tools.fth | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'forth') diff --git a/forth/tools.fth b/forth/tools.fth index b27955d..3cee2bf 100644 --- a/forth/tools.fth +++ b/forth/tools.fth @@ -6,8 +6,8 @@ : words _latest @ begin dup @ dup 31 & 2 pick cell+ \ lt l len ws - 2 pick 6 >> 1023 < if \ lt l len ws - rot 6 >> else \ lt len ws adv + 2 pick 7 >> 1023 < if \ lt l len ws + rot 7 >> else \ lt len ws adv >r cell+ rot drop r> @ then -rot swap type space \ lt adv over _begin <> while - repeat 2drop ; -- cgit v1.2.3 From a3fca07d87a2d057657af9bb79de9f595e4b1a10 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 17 Nov 2023 21:22:37 -0500 Subject: fix aligned and doublecell ops --- forth/core.fth | 11 +++++------ libalee/corewords.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'forth') diff --git a/forth/core.fth b/forth/core.fth index d198583..ff4c18f 100644 --- a/forth/core.fth +++ b/forth/core.fth @@ -99,10 +99,6 @@ : j postpone 2r> ['] r> , postpone r@ ['] swap , ['] >r , ['] -rot , postpone 2>r ; imm -: aligned dup [ 1 cells 1- ] literal swap over & if [ 1 cells ] literal - swap - + else drop then ; -: align here dup aligned swap - allot ; - : and & ; : or | ; : xor ^ ; @@ -114,6 +110,9 @@ : _msb [ 1 1 cells 8 * 1- << ] literal ; : 2/ dup 1 >> swap 0< if _msb or then ; +: aligned [ 1 cells 1- ] literal swap over + swap invert and ; +: align here dup aligned swap - allot ; + : /mod 2dup % -rot / ; : */ >r m* r> _/ ; : sm/rem >r 2dup r@ _% -rot r> _/ ; @@ -221,8 +220,8 @@ dup _isdigit - _uma r> char+ r> 1- repeat ; -: <# 40 here c! ; -: #> 2drop here dup c@ + 40 here c@ - ; +: <# [ 20 cells ] literal here c! ; +: #> 2drop here dup c@ + [ 20 cells ] literal here c@ - ; : hold -1 here +! here dup c@ + c! ; : # base @ >r 0 i um/mod r> swap >r um/mod r> diff --git a/libalee/corewords.cpp b/libalee/corewords.cpp index 8ff7ac6..292e3cf 100644 --- a/libalee/corewords.cpp +++ b/libalee/corewords.cpp @@ -147,17 +147,17 @@ void CoreWords::word_sub(State& state) { } void CoreWords::word_mul(State& state) { // ( n n -- d ) auto cell = state.pop(); - auto dcell = state.pop() * cell; + auto dcell = (DoubleCell)state.pop() * cell; pushd(state, dcell); } void CoreWords::word_div(State& state) { // ( d n -- n ) auto cell = state.pop(); - auto dcell = popd(state); + auto dcell = (DoubleCell)popd(state); state.push(static_cast(dcell / cell)); } void CoreWords::word_mod(State& state) { // ( d n -- n ) auto cell = state.pop(); - auto dcell = popd(state); + auto dcell = (DoubleCell)popd(state); state.push(static_cast(dcell % cell)); } void CoreWords::word_peek(State& state) { // ( addr cell? -- n ) @@ -233,7 +233,7 @@ void CoreWords::word_semic(State& state) { // Concludes word definition. state.compiling(false); auto cell = state.pop(); - auto dcell = cell - state.dict.latest(); + auto dcell = (DoubleCell)cell - state.dict.latest(); if (dcell >= Dictionary::MaxDistance) { // Large distance to previous entry: store in dedicated cell. state.dict.write(static_cast(cell) + sizeof(Cell), -- cgit v1.2.3