Sun Aug 16 11:44:20 CEST 2009
"Compiler" is a strong word: it's mostly a linker. As mentioned in
the previous post, this is a bit awkward due to the graph patching
that needs to be done. There are many corner cases related to
singleton words (that need ``eta-reduction'') or primitives, that can
The real question is (and I've run into this before) does the
dictionary contain CODE references, or SUB references?
CODE = RETURN | (SUB : CODE) ;; ':' is a GC CONS
SUB = PRIM | QUOTE | CODE
RS = MT | (CODE . RS) ;; '.' is a linear CONS
It might make more sense to use SUB refs. Tail calls are tricky!
Let's change the types a bit:
CPAIR = (SUB : CODE)
CODE = RETURN | CPAIR
SUB = PRIM | QUOTE | CPAIR
RS = NIL | (CPAIR . RS)
The reason this feels a bit weird is that composite code doesn't need
RETURN. The only way to ever pop RS is to have a word end in a
primitive, i.e. [ PRIM RETURN ]. Composite code can always just jump.
Looking at CPS versions of Scheme, this is also quite clear: the only
thing that ever _invokes_ the continuation, is a primitive.
So, can the types be made a bit more intuitive?