[<<][staapl][>>][..]
Tue Jul 22 11:28:03 EDT 2014

singletons

I need an abstraction for static objects.

I.e. given a set of parameters - usually memory addresses -
instantiate a collection of words that bind these parameters to
abstract behavior.

This is nothing more than instantiation of objects, hower, with the
optimization of making singletons.

Often in deeply embedded work you only need one.

And if you need more, in forth it seems easier to have a dynamic
parameter pointing to a current object.  However that doesn't work
well if code is also to be used in interrupt routines or other
pre-emptive task switching.

So, for the (circular) array abstraction, the parameters are:
  - log size
  - start address



Summary:

- passing "current object" pointers on the stack isn't very practical
  in forth.  saving these in a dynamic parameter works as long as the
  code is not used in another part of the code that uses pre-emptive
  scheduling like an isr.

- it might be more useful to represent a singleton as a separate set
  of words bound to abstract state.  i.e. use compile-time instantiation.

Is it possible to have dynamic parameters during compilation?

Or just do this manually:

macro
: array-state #x1F0 5 ;
forth
: my-init array-state array-init ;
: my-!    array-state array-! ;
: my-@    array-state array-@ ;

Problem here is that the array-init, array-! and array-@ words have to
be macros, and can't use shared code bound to the memory.


So how to abstract this properly?

Input:  state vectors
Output: compile public words bound to state, make accessible to user
        compile private words bound to state, inaccessible to user

The interface should be simple, as above:

macro
: ob .... ;
forth
: bound1 ob method1 ;
: bound2 ob method2 ;

so essentially `ob' should contain all info
this means an indirection is necessary:

macro
: param ... ;            \ object instantiation parameters
: ob    param make-ob ;  \ compile time representation of ob
forth  \ for instantiated methods.  can also use inline here
: bound1 ob method1 ;
: bound2 ob method2 ;

not so simple to mix the ct and rt things here..


I wonder if all the low-level support is there.  It seems somehow this
needs an abstraction over a collection of words which doesn't seem to
be possible at this time apart from compiling anonymous words.

Let's see where we get with what is possible right now, i.e. no
intermediate words.  Then see what's necessary to add those.

So doing this for array it seems to go like this:

spec -> instatiate word
spec, word -> instantiate more words

so it looks like this needs extra functionality to abstract out completely.



[Reply][About]
[<<][staapl][>>][..]