Wed Mar 19 18:41:12 EDT 2008

forth / macro mode

the next thing to implement is the forth / macro mode. this is a key
issue, since i'd like to change this to a set of LHS = RHS expressions
where names are clearly defined.

part of this is delimited parsing. (EDIT: solved)

to make this transition as smooth as possible, the basic syntactic
form which defines both macros and words needs to be defined. the core
problem is a tough one: allowing identifiers to be overridden requires
some lexical structure. the second problem is to retain the 'inner'
names after a compilation. maybe the enclosing structure can be saved
and incrementally extended?

what i'm talking about is this:

(let-ns (macro)
    ((foo (macro: 1 2 3))
     (bar (macro: 456)))
  <forth> )

(let-ns (macro)
    ((foo (macro: 1 2 3))
     (bar (macro: 456)))
    (let-ns (macro)
        ((word (target-word 123))
         (burp (target-word 567)))

basicly, the target dictionary is a nested lexical structure like the
above, which has a 'hole' in it. on the next compilation step, this
hole can be extended. this way all name management can be delegated to
the scheme expander.

to make this workable, the state should be stored in a form that's
like the above, but flat.

see target-tx.ss for the resulting code.

to summarize:

  * target state = dictionary = listof listof (name . code) each
    element in the top dictionary list consists of an association list
    for one compilation level. names within a level need to be unique
    and can be used recursively.

  * each forth <-> macro transition in forth code introduces a new
    nesting level.

remaining q: how to represent non-macros? what about using 'forth:' to
mean something that generates a macro which compiles an address.

what about treating words as macros, but mark them as 'instantiated?'
this might be interesting, since it allows some flexibility for code
processing (i.e. code inlining).

one thing at a time..
what's next?

need to define some interfaces. most likely the assembler. where does
it fit in? what does a forth file represent?