Fri Nov 2 15:19:40 CET 2007

instantiating abstract objects

i'm giving myself one hour to think about how to fix the verbosity of
the following code:

: tx         #x100 tx-r/w #x0F ;  \ put buffers in RAM page 1
: rx         #x110 rx-r/w #x0F ;

: tx-ready?  tx-empty>z z? not ;
: rx-ready?  rx-empty>z z? not ;
: tx-room?   tx-room>z z? ;
: rx-room?   rx-room>z z? ;

2variable tx-r/w
2variable rx-r/w

: tx-empty>z tx buffer.empty>z ;
: rx-empty>z rx buffer.empty>z ;
: rx-room>z  rx buffer.room>z ;
: tx-room>z  tx buffer.room>z ;

: >tx      tx buffer.write ;
: >rx      rx buffer.write ;
: tx>      tx buffer.read ;
: rx>      rx buffer.read ;
: clear-tx tx buffer.clear ;
: clear-rx rx buffer.clear ;

the ONLY difficulty here is that i can't generate macros, including
variables. is there an other way to solve the problem?

is it possibly to hide everything in one single macro? yes. if
tx-empty>z is never expanded as a function this is actually
possible. then what remains is just:

: tx         #x100 tx-r/w #x0F ;  \ put buffers in RAM page 1
: rx         #x110 rx-r/w #x0F ;

2variable tx-r/w
2variable rx-r/w

tx >buf
tx buf>

maybe i can somehow make an 'un-inline' function work? like

something which gets me half way there is a blocking read/write
operation: only for dispatch loops this then becomes problematic.

conclusion: i guess it's ok to go for this approach:

   On the subject of code reuse, there are 2 options. Either you write
   it as procedure words, or as macros. Using the procedure word
   approach will lead to smaller code size but slower speed (since
   run-time dispatch is probably necessary).

   Using the macro word approach can lead to fast inline code which
   might be not optimial for code size.