Thu Mar 27 16:17:00 EDT 2008
control structures / contitional jump
there's an opportunity now to write the forth-style control words in
terms of higher order abstractions. is this possible? or are the more
lowlevel forth constructs necessary?
probably things like for .. next are going to lead to
trouble. basicly, i need the equivalent of 'label' and a way to
the problematic part is the conditional jump.
conceptually, it joins 3 words parts: the part before, and the 2
branches. let's just do if:
: bla if do-it then go-on ;
: bla ' l0 ift go-on ;
: l0 do-it ;
forth-tx.ss has a 1-element stack. turn this in an arbitrary length
stack and all branches can be postponed and compiled after the word is
that's the mechanism: making this work so the current 'inline'
branches are still used should be straightforward. maybe it's just a
'swap' on that stack?
again. the idea is to make temporary at each brach point.
let's try the compilation stack thing.
OK. implemented. now what does it mean if there is more than 1
ok. i know what this is!
quoted code ;)
expression nesting should be part of the parser..
but the stack's not a stack but a queue: quoted defs come AFTER
i got a bit of a pardigm clash here: the scheme lexer has support for
s-expressions, so is a better candidate for building a syntax for a
language that supports code quotations. however, this is not
compatible with forth syntax. the question is: how to map
if <1> else <2> then -> [ <1> ] [ <2> ] ifte
begin <1> again -> [ <1> ] forever
doesn't look like it's a good idea to write a second recursive
expression parser.. really. stick to s-expressions for that. part of
the purrr kernel could be written in this different syntax: all the
machinery to manage that is available now.
rephrase the question: how can we keep the illusion of straight-line
code? it's very convenient to have as a low-level tool, but for
optimizations it's better to have a graph structure.
maybe forth chunks should just be lined up?
what about using an assembler instruction for this? fallthrough?
problem is that this doesn't collect all the variables.. maybe
variables should have them too? or variables represented as an 'allot'
so, what about:
* forth words have reversed asm code stored
* the head of the list (last instruction) is 'falltrough' which
points to the next word.
* compilation interface exposes 2 words: register and compile.