|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
First test:
5 DUP DUP * * .
mode=interpret DS={ } word="5"
mode=interpret DS={ 5 } word="DUP"
mode=interpret DS={ 5 5 } word="DUP"
mode=interpret DS={ 5 5 5 } word="*"
mode=interpret DS={ 5 25 } word="*"
mode=interpret DS={ 125 } word="."
125
mode=interpret DS={ } word=""
Run "5 CUBE" (from the inner interpreter):
RS={ 5 } mode=head DS={ 5 } head="DOCOL"
RS={ 6 } mode=forth DS={ 5 } instr="DUP"
RS={ 7 } mode=forth DS={ 5 5 } instr=1
RS={ 8 1 } mode=head DS={ 5 5 } head="DOCOL"
RS={ 8 2 } mode=forth DS={ 5 5 } instr="DUP"
RS={ 8 3 } mode=forth DS={ 5 5 5 } instr="*"
RS={ 8 4 } mode=forth DS={ 5 25 } instr="EXIT"
RS={ 8 } mode=forth DS={ 5 25 } instr="*"
RS={ 9 } mode=forth DS={ 125 } instr="EXIT"
memory =
{1="DOCOL", 2="DUP", 3="*", 4="EXIT", 5="DOCOL", 6="DUP", 7=1, 8="*", 9="EXIT", "n"=10}
Compile SQUARE and CUBE; run "5 CUBE ." (from the outer interpreter):
: SQUARE DUP * ;
: CUBE DUP SQUARE * ;
5 CUBE .
RS={ } mode=interpret DS={ } word=":"
RS={ } mode=compile DS={ } here=2 word="DUP"
RS={ } mode=compile DS={ } here=3 word="*"
RS={ } mode=compile DS={ } here=4 word=";"
RS={ } mode=interpret DS={ } word="\n"
RS={ } mode=interpret DS={ } word=":"
RS={ } mode=compile DS={ } here=6 word="DUP"
RS={ } mode=compile DS={ } here=7 word="SQUARE"
RS={ } mode=compile DS={ } here=8 word="*"
RS={ } mode=compile DS={ } here=9 word=";"
RS={ } mode=interpret DS={ } word="\n"
RS={ } mode=interpret DS={ } word="5"
RS={ } mode=interpret DS={ 5 } word="CUBE"
RS={ interpret 5 } mode=head DS={ 5 } head="DOCOL"
RS={ interpret 6 } mode=forth DS={ 5 } instr="DUP"
RS={ interpret 7 } mode=forth DS={ 5 5 } instr=1
RS={ interpret 8 1 } mode=head DS={ 5 5 } head="DOCOL"
RS={ interpret 8 2 } mode=forth DS={ 5 5 } instr="DUP"
RS={ interpret 8 3 } mode=forth DS={ 5 5 5 } instr="*"
RS={ interpret 8 4 } mode=forth DS={ 5 25 } instr="EXIT"
RS={ interpret 8 } mode=forth DS={ 5 25 } instr="*"
RS={ interpret 9 } mode=forth DS={ 125 } instr="EXIT"
RS={ } mode=interpret DS={ 125 } word="."
125
RS={ } mode=interpret DS={ } word="\n"
RS={ } mode=interpret DS={ } word=""
memory =
{1="DOCOL", 2="DUP", 3="*", 4="EXIT", 5="DOCOL", 6="DUP", 7=1, 8="*", 9="EXIT", "n"=10}
Test the support for arbitrary numbers:
: SQUARE DUP * ;
: +20000 20000 + ;
22 SQUARE +20000 .
RS={ } mode=interpret DS={ } word=":"
RS={ } mode=compile DS={ } here=2 word="DUP"
RS={ } mode=compile DS={ } here=3 word="*"
RS={ } mode=compile DS={ } here=4 word=";"
RS={ } mode=interpret DS={ } word="\n"
RS={ } mode=interpret DS={ } word=":"
RS={ } mode=compile DS={ } here=6 word="20000"
RS={ } mode=compile DS={ } here=8 word="+"
RS={ } mode=compile DS={ } here=9 word=";"
RS={ } mode=interpret DS={ } word="\n"
RS={ } mode=interpret DS={ } word="22"
RS={ } mode=interpret DS={ 22 } word="SQUARE"
RS={ interpret 1 } mode=head DS={ 22 } head="DOCOL"
RS={ interpret 2 } mode=forth DS={ 22 } instr="DUP"
RS={ interpret 3 } mode=forth DS={ 22 22 } instr="*"
RS={ interpret 4 } mode=forth DS={ 484 } instr="EXIT"
RS={ } mode=interpret DS={ 484 } word="+20000"
RS={ interpret 5 } mode=head DS={ 484 } head="DOCOL"
RS={ interpret 6 } mode=forth DS={ 484 } instr="LIT"
RS={ interpret 7 } mode=lit DS={ 484 } data=20000
RS={ interpret 8 } mode=forth DS={ 484 20000 } instr="+"
RS={ interpret 9 } mode=forth DS={ 20484 } instr="EXIT"
RS={ } mode=interpret DS={ 20484 } word="."
20484
RS={ } mode=interpret DS={ } word="\n"
RS={ } mode=interpret DS={ } word=""
memory =
{1="DOCOL", 2="DUP", 3="*", 4="EXIT", 5="DOCOL", 6="LIT", 7=20000, 8="+", 9="EXIT", "n"=10}
A simple test for LIT: MINUTES
: MINUTES 60 * ;
20 MINUTES .
RS={ 1 } mode=head DS={ 20 } head="DOCOL"
RS={ 2 } mode=forth DS={ 20 } instr="LIT"
RS={ 3 } mode=lit DS={ 20 } data=60
RS={ 4 } mode=forth DS={ 20 60 } instr="*"
RS={ 5 } mode=forth DS={ 1200 } instr="EXIT"
memory =
{1="DOCOL", 2="LIT", 3=60, 4="*", 5="EXIT"}
Virtual modes (LIT vs. VLIT):
t=0 RS={ 6 } mode=head PS={ } DS={ } head="DOCOL"
t=1 RS={ 7 } mode=forth PS={ } DS={ } instr="LIT"
t=2 RS={ 8 } mode=lit PS={ } DS={ } data=123
t=3 RS={ 9 } mode=forth PS={ } DS={ 123 } instr=1
t=4 RS={ 10 1 } mode=head PS={ } DS={ 123 } head="DOCOL"
t=5 RS={ 10 2 } mode=forth PS={ } DS={ 123 } instr="R>P"
t=6 RS={ 3 } mode=forth PS={ 10 } DS={ 123 } instr="PCELL"
t=7 RS={ 4 } mode=pcell PS={ 10 } DS={ 123 } pdata=234
t=8 RS={ 4 } mode=forth PS={ 11 } DS={ 123 234 } instr="P>R"
t=9 RS={ 11 5 } mode=forth PS={ } DS={ 123 234 } instr="EXIT"
t=10 RS={ 11 } mode=forth PS={ } DS={ 123 234 } instr="EXIT"
memory =
{1="DOCOL", 2="R>P", 3="PCELL", 4="P>R", 5="EXIT", 6="DOCOL", 7="LIT", 8=123, 9=1, 10=234, 11="EXIT", "n"=12}
A bytecode for polynomials, 1: PPOLY
memory =
{1="DOADDR", 2=4, 3=2, 4=3, 5=4, 6=5.5, "n"=7}
RS={ } mode=ppolyn PS={ 2 } DS={ 10 } n=4
RS={ } mode=ppolyc PS={ 3 } DS={ 10 } n=4 acc=0 coef=2
RS={ } mode=ppolyc PS={ 4 } DS={ 10 } n=3 acc=2 coef=3
RS={ } mode=ppolyc PS={ 5 } DS={ 10 } n=2 acc=23 coef=4
RS={ } mode=ppolyc PS={ 6 } DS={ 10 } n=1 acc=234 coef=5.5
RS={ } mode=ppolye PS={ 7 } DS={ 10 } acc=2345.5
2345.5
A bytecode for polynomials, 2: POLY
memory =
{1="DOCOL", 2="R>P", 3="PPOLY", 4="P>R", 5="EXIT", 6="DOCOL", 7=1, 8=4, 9=2, 10=3, 11=4, 12=5.5, 13="EXIT", "n"=14}
RS={ 6 } mode=head PS={ } DS={ 10 } head="DOCOL"
RS={ 7 } mode=forth PS={ } DS={ 10 } instr=1
RS={ 8 1 } mode=head PS={ } DS={ 10 } head="DOCOL"
RS={ 8 2 } mode=forth PS={ } DS={ 10 } instr="R>P"
RS={ 3 } mode=forth PS={ 8 } DS={ 10 } instr="PPOLY"
RS={ 4 forth } mode=ppolyn PS={ 8 } DS={ 10 } n=4
RS={ 4 forth } mode=ppolyc PS={ 9 } DS={ 10 } n=4 acc=0 coef=2
RS={ 4 forth } mode=ppolyc PS={ 10 } DS={ 10 } n=3 acc=2 coef=3
RS={ 4 forth } mode=ppolyc PS={ 11 } DS={ 10 } n=2 acc=23 coef=4
RS={ 4 forth } mode=ppolyc PS={ 12 } DS={ 10 } n=1 acc=234 coef=5.5
RS={ 4 forth } mode=ppolye PS={ 13 } DS={ 10 } acc=2345.5
RS={ 4 } mode=forth PS={ 13 } DS={ 2345.5 } instr="P>R"
RS={ 13 5 } mode=forth PS={ } DS={ 2345.5 } instr="EXIT"
RS={ 13 } mode=forth PS={ } DS={ 2345.5 } instr="EXIT"
A bytecode for polynomials 3: DOPOLY
memory =
{1="DOPOLY", 2="DOADDR", 3=4, 4=2, 5=3, 6=4, 7=5.5, 8="DOCOL", 9="LIT", 10=10, 11=1, 12="EXIT", "n"=13}
RS={ 8 } mode=head PS={ } DS={ } head="DOCOL"
RS={ 9 } mode=forth PS={ } DS={ } instr="LIT"
RS={ 10 } mode=lit PS={ } DS={ } data=10
RS={ 11 } mode=forth PS={ } DS={ 10 } instr=1
RS={ 12 1 } mode=head PS={ } DS={ 10 } head="DOPOLY"
RS={ 12 forth } mode=ppolyn PS={ 3 } DS={ 10 } n=4
RS={ 12 forth } mode=ppolyc PS={ 4 } DS={ 10 } n=4 acc=0 coef=2
RS={ 12 forth } mode=ppolyc PS={ 5 } DS={ 10 } n=3 acc=2 coef=3
RS={ 12 forth } mode=ppolyc PS={ 6 } DS={ 10 } n=2 acc=23 coef=4
RS={ 12 forth } mode=ppolyc PS={ 7 } DS={ 10 } n=1 acc=234 coef=5.5
RS={ 12 forth } mode=ppolye PS={ 8 } DS={ 10 } acc=2345.5
RS={ 12 } mode=forth PS={ 8 } DS={ 2345.5 } instr="EXIT"
Recursive immediate data: propositional calculus
memory =
{1="=>", 2="=>", 3="Q", 4="R", 5="=>", 6="&", 7="P", 8="Q", 9="&", 10="P", 11="R", "n"=12}
props =
1: { addr=1, cc="=>", l=2, r=5, next=12, name="((Q=>R)=>((P&Q)=>(P&R)))" }
2: { addr=2, cc="=>", l=3, r=4, next=5, name="(Q=>R)" }
3: { addr=3, next=4, name="Q" }
4: { addr=4, next=5, name="R" }
5: { addr=5, cc="=>", l=6, r=9, next=12, name="((P&Q)=>(P&R))" }
6: { addr=6, cc="&", l=7, r=8, next=9, name="(P&Q)" }
7: { addr=7, next=8, name="P" }
8: { addr=8, next=9, name="Q" }
9: { addr=9, cc="&", l=10, r=11, next=12, name="(P&R)" }
10: { addr=10, next=11, name="P" }
11: { addr=11, next=12, name="R" }