Thun/thun
Simon Forman 76de590d27 Experiments with partial reduction are very promising.
Functions become clauses like these:

    thun(symbol(rolldown), [], [C, A, B|D], [A, B, C|D]).
    thun(symbol(rolldown), [A|B], [E, C, D|F], G) :-
        thun(A, B, [C, D, E|F], G).
    thun(symbol(dupd), [], [A, B|C], [A, B, B|C]).
    thun(symbol(dupd), [A|B], [C, D|E], F) :-
        thun(A, B, [C, D, D|E], F).
    thun(symbol(over), [], [B, A|C], [A, B, A|C]).7
    thun(symbol(over), [A|B], [D, C|E], F) :-
        thun(A, B, [C, D, C|E], F).


Definitions become

    thun(symbol(of), A, D, E) :-
        append([symbol(swap), symbol(at)], A, [B|C]),
        thun(B, C, D, E).
    thun(symbol(pam), A, D, E) :-
        append([list([symbol(i)]), symbol(map)], A, [B|C]),
        thun(B, C, D, E).
    thun(symbol(popd), A, D, E) :-
        append([list([symbol(pop)]), symbol(dip)], A, [B|C]),
        thun(B, C, D, E).


These are tail-recursive and allow for better indexing so I would expect
them to be more efficient than the originals.

Notice the difference between the original thun/4 rule for definitions
and this other one that actually works.

    thun(symbol(Def),   E, Si, So) :- def(Def, Body), append(Body, E,    E o),    thun(Eo, Si, So).
    thun(symbol(Def),   E, Si, So) :- def(Def, Body), append(Body, E, [T|Eo]), thun(T, Eo, Si, So)


The latter reduces to:

    thun(symbol(A), C, F, G) :-
        def(A, B),
        append(B, C, [D|E]),
        thun(D, E, F, G).


We want something like...

    thun(symbol(B), [], A, D) :- def(B, [H|C]), thun(H, C, A, D).
    thun(symbol(A), [H|E0], Si, So) :-
        def(A, [DH|DE]),
        append(DE, [H|E0], E),
        thun(DH, E, Si, So).

But it's good enough.  The earlier version doesn't transform into
correct code:

    thun(symbol(B), D, A, A) :- def(B, C), append(C, D, []).
    thun(symbol(A), C, F, G) :- def(A, B), append(B, C, [D|E]), thun(D, E, F, G).

It would probably be good to investigate what goes wrong there.)

It doesn't seem to work right for thun/4 combinator rules either.  Dunno what's
up there.
2020-01-26 13:21:47 -08:00
..
gnu-prolog Minor cleanup. 2019-11-07 07:55:01 -08:00
TLA.pl Minor cleanup. 2019-11-07 07:55:01 -08:00
asm-dump.txt 4 is already an offset 2019-11-13 15:07:27 -08:00
compiler.markII.pl Debugging this sucks. 2019-11-28 07:58:42 -08:00
compiler.pl Call for_serial/2 2019-11-07 07:43:21 -08:00
defs.txt Remove '==' from definitions. (Bools) 2020-01-26 09:48:30 -08:00
dump-asm.py Even "nicer". 2019-11-12 09:06:22 -08:00
joy_asm.bin Minor cleanup, bug fixes. 2019-11-09 11:27:29 -08:00
joy_asmii.bin Debugging this sucks. 2019-11-28 07:58:42 -08:00
markII.rst Debugging this sucks. 2019-11-28 07:58:42 -08:00
metalogical.pl Experiment in formatting stacks for output. 2019-08-03 19:01:45 -07:00
symbols.txt Debugging this sucks. 2019-11-28 07:58:42 -08:00
thun.pl Experiments with partial reduction are very promising. 2020-01-26 13:21:47 -08:00