• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisãoa7bd9deb786473f9e03b6ef7f6355ed3548b9939 (tree)
Hora2020-01-29 05:44:19
AutorSimon Forman <sforman@hush...>
CommiterSimon Forman

Mensagem de Log

dup, add_ref/3.

Mudança Sumário

Diff

diff -r eeff4cb90202 -r a7bd9deb7864 thun/thun.pl
--- a/thun/thun.pl Tue Jan 28 12:24:04 2020 -0800
+++ b/thun/thun.pl Tue Jan 28 12:44:19 2020 -0800
@@ -653,7 +653,7 @@
653653
654654 */
655655
656-get_reggy([], _, _):- writeln('Out of Registers'), fail.
656+get_reggy([], _, _) :- writeln('Out of Registers'), fail.
657657 get_reggy([Reg|FreePool], Reg, FreePool).
658658
659659
@@ -668,11 +668,15 @@
668668 ; FreePool=[Reg|FreePool0] % otherwise we put it back in the pool.
669669 )}.
670670
671+add_ref(Reg, reggy(FreePool, References), reggy(FreePool, [Reg|References])) --> [].
672+
671673 assoc_reg(_, _, _) --> [].
672674
673675 thun_compile(E, Si, So) -->
674- {FP=reggy([r0, r1, r2, r3, r4, r5, r6, r7,
675- r8, r9, rA, rB, rC, rD, rE, rF], [])},
676+ {FP=reggy([r0, r1, r2, r3,
677+ r4, r5, r6, r7,
678+ r8, r9, rA, rB,
679+ rC, rD, rE, rF], [])},
676680 thun_compile(E, Si, So, FP, _).
677681
678682 thun_compile([], S, S, FP, FP) --> [].
@@ -712,6 +716,10 @@
712716 free_reg(A, FP0, FP1),
713717 thun_compile(E, [B|S], So, FP1, FP).
714718
719+func_compile(dup, E, [A|S], So, FP0, FP) --> !,
720+ add_ref(A, FP0, FP1),
721+ thun_compile(E, [A, A|S], So, FP1, FP).
722+
715723
716724 func_compile(_Func, E, Si, So, FP0, FP) -->
717725 % look up function, compile it...
@@ -783,7 +791,43 @@
783791 StackOut = [r0|StackIn] ;
784792 false.
785793
794+- - - -
786795
796+?- compiler(`1 2 dup + 3 +`, MachineCode, StackIn, StackOut).
797+MachineCode = [mov_imm(r0, int(1)), mov_imm(r1, int(2)), add(r1, r1, r1), mov_imm(r2, int(3)), add(r1, r2, r1)],
798+StackOut = [r1, r0|StackIn] .
799+
800+?- compiler(`dup +`, MachineCode, StackIn, StackOut).
801+MachineCode = [add(_37000, _37000, _37000)],
802+StackIn = StackOut, StackOut = [_37000|_37002].
803+
804+?- compiler(`dup +`, MachineCode, [r0], StackOut).
805+MachineCode = [add(r0, r0, r0)],
806+StackOut = [r0].
807+
808+?- compiler(`dup +`, MachineCode, [r0], [r0]).
809+MachineCode = [add(r0, r0, r0)].
810+
811+- - - -
812+
813+?- compiler(`1 2 3 4 5 + + + 6 7 + 8 + +`, MachineCode, StackIn, StackOut), maplist(portray_clause, MachineCode).
814+mov_imm(r0, int(1)).
815+mov_imm(r1, int(2)).
816+mov_imm(r2, int(3)).
817+mov_imm(r3, int(4)).
818+mov_imm(r4, int(5)).
819+add(r3, r4, r3).
820+add(r2, r3, r2).
821+add(r1, r2, r1).
822+mov_imm(r2, int(6)).
823+mov_imm(r3, int(7)).
824+add(r2, r3, r2).
825+mov_imm(r3, int(8)).
826+add(r2, r3, r2).
827+add(r1, r2, r1).
828+
829+
830+Fun!
787831
788832
789833
Show on old repository browser