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),