~vdupras/duskos

4072b5ca25e64a4d8e41ad5b1861546db1348971 — Virgil Dupras 3 months ago b780a2c
Change CALLSZ to DOESSZ

The only place CALLSZ was used in was "does'" and became a misnomer under ARM.

A call under ARM is 4 bytes, but for "does'" to return the right thing, it had
to be 8 because a pushret, comes before "compile (does)". It's simpler to change
the meaning of that constant and, while we're at it, include the 4b pointer that
follows it.

Also, correct outdated iter docs.
M fs/doc/dict.txt => fs/doc/dict.txt +2 -1
@@ 81,7 81,8 @@ ABORT      Address containing the value of "abort".
EMIT       Address containing the value of "emit".
IN<        Address containing the value of "in<".
CELLSZ     Size of a cell: 4
CALLSZ     The size in bytes of a native call.
BRSZ       Size in bytes of a "branch," or "branchC,"
DOESSZ     The size in bytes of a (does) header, after which there's data

SPC        $20
CR         $0d

M fs/doc/iter.txt => fs/doc/iter.txt +3 -3
@@ 112,8 112,8 @@ for something more... creative.
When the iterator is done iterating and is about to exit, it already knows where
it's going to exit to: the address following the "yield" call that the iterator
made. We already know what's after that call: a backward jump to the loop body.
We already know how many bytes such a jump takes: CALLSZ + CELLSZ.
We already know how many bytes such a jump takes: BRSZ.

Therefore, if we want to exit the iterator loop, all we need to do is to add
CALLSZ + CELLSZ to RS+0. That's what "unyield" does. Then, we exit the loop,
execute the loop cleanup code and go on with our lives.
BRSZ to RS+0. That's what "unyield" does. Then, we exit the loop, execute the
loop cleanup code and go on with our lives.

M fs/xcomp/arm/rpi/kernel.fs => fs/xcomp/arm/rpi/kernel.fs +1 -1
@@ 52,7 52,7 @@ forward b) ,) \ coldboot
HERESTART xconst herestart
PSTOP xconst PSTOP
RSTOP xconst RSTOP
4 xconst CALLSZ
12 xconst DOESSZ
4 xconst BRSZ

xcode bye 0 b) ,)

M fs/xcomp/bootlo.fs => fs/xcomp/bootlo.fs +1 -1
@@ 155,7 155,7 @@ create _ 0 ,
code (does) r> W>A, W) @, W<>A, CELLSZ W+n, branchA,
: doer code compile (does) HERE @ _ ! CELLSZ allot ;
: does> r> ( exit current definition ) _ @ ! ;
: does' ( w -- 'data ) CALLSZ + CELLSZ + ;
: does' ( w -- 'data ) DOESSZ + ;

: _to doer ' , ' , immediate does> toptr ! ;
: _!, !, drop, ; :16b 16b) !, drop, ; :8b 8b) !, drop, ;

M fs/xcomp/i386/kernel.fs => fs/xcomp/i386/kernel.fs +1 -1
@@ 59,7 59,7 @@ lblidt m) lidt, sti,
forward16 jmp, to L1

L2 xconst IDT
5 xconst CALLSZ
9 xconst DOESSZ
5 xconst BRSZ

HERESTART xconst herestart

M fs/xcomp/rpiboot.fs => fs/xcomp/rpiboot.fs +1 -1
@@ 155,7 155,7 @@ create _ 0 ,
code (does) pushret, r> W>A, W) @, W<>A, CELLSZ W+n, branchA,
: doer code pushret, compile (does) HERE @ _ ! CELLSZ allot ;
: does> r> ( exit current definition ) _ @ ! ;
: does' ( w -- 'data ) CALLSZ + CELLSZ + ;
: does' ( w -- 'data ) DOESSZ + ;

: test ( n ) dup 1+ >r >r V1 emit V2 emit 2rdrop ;
: test2 doer , does> @ emit ;

M posix/vm.c => posix/vm.c +1 -1
@@ 960,7 960,7 @@ static void buildsysdict() {
	sysconst("NEXTWORD", NEXTWORD);
	sysconst("HEREMAX", HEREMAX);
	sysconst("MOD", MOD);
	sysconst("CALLSZ", 5);
	sysconst("DOESSZ", 9);
	sysconst("BRSZ", 5);
	sysconst("PSTOP", PSTOP);
	sysconst("RSTOP", RSTOP);