[<<][staapl][>>][..]
Thu Dec 30 11:29:22 EST 2010

s-expression only: splitting forth parser and dictionary compiler

coma/macro-forth.ss:

Currently has both the forth parsing and dictionary compilation parts.
Luckily those are already separate.  Let's just put them in a separate
module.


Using `forth-dictionary-log' to see what's actually passed in.  I had
to fix a bug here: dynamic parameter needs to be a function.


The question is: why does the expanded dictionary have `forth-parse'
calls?  This happends after require statements.  I have the feeling
that this feedback loop is what makes some things behave badly.
Basicly, we don't compile to a flat dictionary structure, but compile
to something that has a recursively defined dictionary structure.

It's a bit of a mess...

It's probably best to start somewhere else.  The ingredients are:

  code-register-postponed!
  wrap-macro
  wrap-word
  wrap-variable

This is exactly what is passed to `define-forth-parser' in the
pic18.ss module.  The first one is defined in the code.ss module.  The
latter 3 are defined in the comp/compiler-unit.ss module.

The word "postponed" just means "postponed to run time", i.e. compiled
code.

So, how to use that interface directly?  I.e. let's define some
variables and some words.

          (wrap-word name loc macro)

box> (wrap-word 'foo #f (macro: 1 +))
#<target-word>
#state->state
#state->state

The values are: label (contains code), label compiler (i.e. for call
or address as data), and the code generator.

So this doesn't yet compile anything.  That's what the
`code-register-postponed!' is about.  I.e. see ther `forth-word' macro
in the macro-forth.ss module.  That one obtains the 3 values as:
label, wrapper, inline, and will perform registration.

This is where we can tap in.

Maybe the `forth-word' should be renamed, or at least moved to a
different location, i.e. in the compiler-unit.ss module.

( Hmm.. Spagetti code.  Or too much parameterized code.  )

Why is the `compile' parameter used ion forth-word set to
`rpn-lambda'?  It is explaned in the docs even, but I don't get it.
Wait, it is `macro:' : see `forth-begin/init'.  Indeed, just a
parameter.

Next problem: why doesn't this work?

;; similar to macro-forth.ss: forth-word
(define-syntax-rule (instantiate-code name word ...)
  (begin
   (define-values
     (label wrapper inline)
     (wrap-word 'name
                #f                    ;; source location
                (macro: word ...)))   ;; compiler
   (ns (target) (define name label))
   (ns (macro)  (define name wrapper))
   ;; (ns (inline) (define name inline)) ;; not necessary
   (code-register-postponed! inline)))


box> (instantiate-code foo 1 +)
box> (print-target-word target/foo)
foo:

It probably needs just to be compiled.  I've added some code to
`print-target-word' to deal with non-compiled code.  Something calls
compile somewhere..  It's `compile!' defined in the pic18.ss module.

Ok, that seems to work fine.


Observation: The convoluted code seems to come mostly from the Forth
syntax which has parsing state that doesn't mesh too well with the way
PLT modules work.  The rest seems to be fine.  State involves:
   - forth / macro switching
   - recursive "require" expansion




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