Remember how we needed two stacks? Maybe we don't.
srenner@mail.ru — 2000-05-10 21:24:20
The Joy-like VM has been rewritten. Now it is called "toy". This time,
it seemed not to need two stacks. It is true that this means that the
VM is implemented by a reentrant function, but the only time it will
reenter is when it executes a nested quotation. I think. That is, if
the stack is s, and the top of the stack is the quotation q0: [q1 i],
and we execute q0 with the procedure call (in Oberon):
VM(q0,stack.next);
then inside this procedure , q1 will be pushed, then executed with i:
VM(q1,stack.next);
(* stack.next is just the rest of the stack == the stack after the top
element is removed. Pop is implicit *)
so the VM is reentrant. But not in the sense that the Python
interpreter (pre- Christian Tismer's Stackless Python) is reentrant,
because Joy doesn't do recursion by building up indefinitely complex
programs and then executing them.
So far toy has only the integers, dup, and i. There is no input
scanner, either. But it works:
PROCEDURE Test*;
VAR
one,two,three: Int;
o: Op;
dup,i: opBox;
q: Quote;
BEGIN
o := Dup;
NEW(dup, o);
NEW(one,1); NEW(two,2); NEW(three, 3);
NEW(q);
q.first := one;
one.next := two;
VM(dup,q.first);
q.Print();
END Test;
END toy.
toy.Test
********** Output of toy.Test**********
OP BOX [ 1 1 2 ]
***************************************
The rest of the combinators & operations should be trivial to write
now. (You all are familiar with the joke that ends "...I have it. It
IS trivial!").
toy is almost too simple to think about. Much simpler even than a
dictionary-based Forth.
sr