• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisãoa03395e3871758a5a730cf09bc547130e324006c (tree)
Hora2020-01-29 11:04:51
AutorSimon Forman <sforman@hush...>
CommiterSimon Forman

Mensagem de Log

Add assoc to kinda sorta track the values in the registers.

But it doesn't update e.g. if you add two numbers, the value int(N) stays the same.

It could be modified to track the value as it computes? But then why keep them in registers at all? Sometimes a value must arrive at runtime, eh?

Mudança Sumário

Diff

diff -r 3e3aa5df0d83 -r a03395e38717 thun/thun.pl
--- a/thun/thun.pl Tue Jan 28 17:16:17 2020 -0800
+++ b/thun/thun.pl Tue Jan 28 18:04:51 2020 -0800
@@ -652,54 +652,62 @@
652652 member/3. Or you can just keep a reference count for each register...
653653 Would it be useful to put CLP(FD) constraints on the ref counts?
654654
655-reggy(FreePool, References)
655+reggy(FreePool, References, ValueMap)
656656
657657 */
658658
659+encode_list(List, FP, FP, Addr) --> [],
660+ {addr(list(List))=Addr}.
661+
659662 appears_only_once(Term, List) :- append(_, [Term|Tail], List), !, \+ member(Term, Tail).
660663
661-reg_used_once(Reg, reggy(_, References)) :- appears_only_once(Reg, References).
664+reg_used_once(Reg, reggy(_, References, _)) :- appears_only_once(Reg, References).
662665
663666 get_reggy([], _, _) :- writeln('Out of Registers'), fail.
664667 get_reggy([Reg|FreePool], Reg, FreePool).
665668
666-get_reg(Reg, reggy(FreePool0, References), reggy(FreePool, [Reg|References])) --> [],
669+get_reg(Reg, reggy(FreePool0, References, V), reggy(FreePool, [Reg|References], V)) --> [],
667670 {get_reggy(FreePool0, Reg, FreePool)}.
668671
669-free_reg(Reg, reggy(FreePool0, References0), reggy(FreePool, References)) --> [],
672+free_reg(Reg, reggy(FreePool0, References0, V0), reggy(FreePool, References, V)) --> [],
670673 { select(Reg, References0, References),
671674 ( member(Reg, References) % If reg is still in use
672675 -> FreePool= FreePool0 % we can't free it yet
673- ; FreePool=[Reg|FreePool0] % otherwise we put it back in the pool.
676+ ; FreePool=[Reg|FreePool0], % otherwise we put it back in the pool.
677+ del_assoc(Reg, V0, _, V)
674678 )}.
675679
676-add_ref(Reg, reggy(FreePool, References), reggy(FreePool, [Reg|References])) --> [].
680+add_ref(Reg, reggy(FreePool, References, V), reggy(FreePool, [Reg|References], V)) --> [].
677681
678-assoc_reg(_, _, _) --> [].
682+assoc_reg(Reg, Value, reggy(FreePool, References, V0), reggy(FreePool, References, V)) --> [],
683+ {put_assoc(Reg, V0, Value, V)}.
679684
680-thun_compile(E, Si, So) -->
681- {FP=reggy([r0, r1, r2, r3,
685+thun_compile(E, Si, So, FP) -->
686+ {empty_assoc(V),
687+ FP0=reggy([r0, r1, r2, r3,
682688 r4, r5, r6, r7,
683689 r8, r9, rA, rB,
684- rC, rD, rE, rF], [])},
685- thun_compile(E, Si, So, FP, _).
690+ rC, rD, rE, rF], [], V)},
691+ thun_compile(E, Si, So, FP0, FP).
686692
687693 thun_compile([], S, S, FP, FP) --> [].
688694 thun_compile([Term|Rest], Si, So, FP0, FP1) --> thun_compile(Term, Rest, Si, So, FP0, FP1).
689695
690696 thun_compile(int(I), E, Si, So, FP0, FP) -->
691697 [mov_imm(R, int(I))],
692- get_reg(R, FP0, FP1), assoc_reg(R, int(I), _),
693- thun_compile(E, [R|Si], So, FP1, FP).
698+ get_reg(R, FP0, FP1), assoc_reg(R, int(I), FP1, FP2),
699+ thun_compile(E, [R|Si], So, FP2, FP).
694700
695701 thun_compile(bool(B), E, Si, So, FP0, FP) -->
696- get_reg(R, FP0, FP1), assoc_reg(R, bool(B), _),
697- thun_compile(E, [R|Si], So, FP1, FP).
702+ get_reg(R, FP0, FP1), assoc_reg(R, bool(B), FP1, FP2),
703+ thun_compile(E, [R|Si], So, FP2, FP).
698704
699705 thun_compile(list(L), E, Si, So, FP0, FP) -->
700- % encode_list(_), ???
701- get_reg(R, FP0, FP1), assoc_reg(R, list(L), _),
702- thun_compile(E, [R|Si], So, FP1, FP).
706+ encode_list(L, FP0, FP1, Addr),
707+ get_reg(R, FP1, FP2),
708+ [load_imm(R, Addr)],
709+ assoc_reg(R, Addr, FP2, FP3),
710+ thun_compile(E, [R|Si], So, FP3, FP).
703711
704712 thun_compile(symbol(Name), E, Si, So, FP0, FP) --> {def(Name, _)}, !, def_compile(Name, E, Si, So, FP0, FP).
705713 thun_compile(symbol(Name), E, Si, So, FP0, FP) --> {func(Name, _, _)}, !, func_compile(Name, E, Si, So, FP0, FP).
@@ -725,6 +733,7 @@
725733 free_reg(B, FP2, FP3),
726734 {Si=[R|S]}
727735 ),
736+ % Update value in the context?
728737 thun_compile(E, Si, So, FP3, FP).
729738
730739 func_compile(dup, E, [A|S], So, FP0, FP) --> !,
@@ -751,13 +760,15 @@
751760
752761 compiler(InputString, MachineCode, StackIn, StackOut) :-
753762 phrase(joy_parse(Expression), InputString), !,
754- phrase(thun_compile(Expression, StackIn, StackOut), MachineCode, []).
763+ phrase(thun_compile(Expression, StackIn, StackOut, _), MachineCode, []).
755764
756765
757766 show_compiler(InputString, StackIn, StackOut) :-
758767 phrase(joy_parse(Expression), InputString), !,
759- phrase(thun_compile(Expression, StackIn, StackOut), MachineCode, []),
760- maplist(portray_clause, MachineCode).
768+ phrase(thun_compile(Expression, StackIn, StackOut, reggy(_, _, V)), MachineCode, []),
769+ maplist(portray_clause, MachineCode),
770+ assoc_to_list(V, VP),
771+ portray_clause(VP).
761772
762773
763774 /*
Show on old repository browser