fix aligned and doublecell ops

native
Clyne 1 year ago
parent e4f1fba4e8
commit a3fca07d87
Signed by: clyne
GPG Key ID: 1B74EE6C49C96795

@ -99,10 +99,6 @@
: j postpone 2r> ['] r> , postpone r@ ['] swap , : j postpone 2r> ['] r> , postpone r@ ['] swap ,
['] >r , ['] -rot , postpone 2>r ; imm ['] >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 & ; : and & ;
: or | ; : or | ;
: xor ^ ; : xor ^ ;
@ -114,6 +110,9 @@
: _msb [ 1 1 cells 8 * 1- << ] literal ; : _msb [ 1 1 cells 8 * 1- << ] literal ;
: 2/ dup 1 >> swap 0< if _msb or then ; : 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 / ; : /mod 2dup % -rot / ;
: */ >r m* r> _/ ; : */ >r m* r> _/ ;
: sm/rem >r 2dup r@ _% -rot r> _/ ; : sm/rem >r 2dup r@ _% -rot r> _/ ;
@ -221,8 +220,8 @@
dup _isdigit - _uma dup _isdigit - _uma
r> char+ r> 1- repeat ; r> char+ r> 1- repeat ;
: <# 40 here c! ; : <# [ 20 cells ] literal here c! ;
: #> 2drop here dup c@ + 40 here c@ - ; : #> 2drop here dup c@ + [ 20 cells ] literal here c@ - ;
: hold -1 here +! here dup c@ + c! ; : hold -1 here +! here dup c@ + c! ;
: # base @ : # base @
>r 0 i um/mod r> swap >r um/mod r> >r 0 i um/mod r> swap >r um/mod r>

@ -147,17 +147,17 @@ void CoreWords::word_sub(State& state) {
} }
void CoreWords::word_mul(State& state) { // ( n n -- d ) void CoreWords::word_mul(State& state) { // ( n n -- d )
auto cell = state.pop(); auto cell = state.pop();
auto dcell = state.pop() * cell; auto dcell = (DoubleCell)state.pop() * cell;
pushd(state, dcell); pushd(state, dcell);
} }
void CoreWords::word_div(State& state) { // ( d n -- n ) void CoreWords::word_div(State& state) { // ( d n -- n )
auto cell = state.pop(); auto cell = state.pop();
auto dcell = popd(state); auto dcell = (DoubleCell)popd(state);
state.push(static_cast<Cell>(dcell / cell)); state.push(static_cast<Cell>(dcell / cell));
} }
void CoreWords::word_mod(State& state) { // ( d n -- n ) void CoreWords::word_mod(State& state) { // ( d n -- n )
auto cell = state.pop(); auto cell = state.pop();
auto dcell = popd(state); auto dcell = (DoubleCell)popd(state);
state.push(static_cast<Cell>(dcell % cell)); state.push(static_cast<Cell>(dcell % cell));
} }
void CoreWords::word_peek(State& state) { // ( addr cell? -- n ) 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); state.compiling(false);
auto cell = state.pop(); auto cell = state.pop();
auto dcell = cell - state.dict.latest(); auto dcell = (DoubleCell)cell - state.dict.latest();
if (dcell >= Dictionary::MaxDistance) { if (dcell >= Dictionary::MaxDistance) {
// Large distance to previous entry: store in dedicated cell. // Large distance to previous entry: store in dedicated cell.
state.dict.write(static_cast<Addr>(cell) + sizeof(Cell), state.dict.write(static_cast<Addr>(cell) + sizeof(Cell),

Loading…
Cancel
Save