• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisão801e1c92a5550b3c7a5de81ea72557dc7f05015a (tree)
Hora2020-02-01 01:26:10
AutorSimon Forman <sforman@hush...>
CommiterSimon Forman

Mensagem de Log

Freeing registers before using them is simpler.

https://todo.sr.ht/~sforman/thun-der/3

Mudança Sumário

Diff

diff -r e8fcdbf066e2 -r 801e1c92a555 thun/thun.pl
--- a/thun/thun.pl Thu Jan 30 10:25:12 2020 -0800
+++ b/thun/thun.pl Fri Jan 31 08:26:10 2020 -0800
@@ -24,8 +24,22 @@
2424 You should have received a copy of the GNU General Public License
2525 along with Thun. If not see <http://www.gnu.org/licenses/>.
2626
27+(Big fonts are from Figlet "ANSI Shadow" http://www.patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=formatter
28+ and "Small".)
2729
28-(Big fonts are from Figlet ANSI Shadow http://www.patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=formatter )
30+Table of Contents
31+ Parser & Grammar
32+ Semantics
33+ Functions
34+ Combinators
35+ Definitions
36+ Compiler
37+ to Prolog
38+ to Machine Code
39+ Meta-Programming
40+ Expand/Contract Definitions
41+ Formatter
42+ Partial Reducer
2943
3044 */
3145
@@ -171,7 +185,9 @@
171185 % expression and we don't want to process combo/5 twice just to
172186 % notice that, eh? Swap the rules and add green cuts after combo/5
173187 % and that should make it more efficient.
174-%
188+
189+% Ach! THe "green" cuts would mess up multi-rule combinators! D'oh!
190+
175191 % Neither functions nor definitions can affect the expression so we
176192 % don't need to do similar gardening to those rules. The unification
177193 % of the head clauses will distinguish the cases for them.
@@ -788,17 +804,13 @@
788804 % Functions delegate to a per-function compilation relation.
789805
790806 func_compile(+, E, [A, B|S], So, FP0, FP) --> !,
791- % If either register A or B is only used once we can reuse it.
792- ( {reg_used_once(B, FP0)} -> [add(B, A, B)], free_reg(A, FP0, FP4), {Si=[B|S]}
793- ; {reg_used_once(A, FP0)} -> [add(A, A, B)], free_reg(B, FP0, FP4), {Si=[A|S]}
794- ; get_reg(R, FP0, FP1), [add(R, A, B)],
795- assoc_reg(R, int(_), FP1, FP2),
796- free_reg(A, FP2, FP3),
797- free_reg(B, FP3, FP4),
798- {Si=[R|S]} % Can all this be simplified by freeing first?
799- ),
807+ free_reg(A, FP0, FP1),
808+ free_reg(B, FP1, FP2),
809+ get_reg(R, FP2, FP3),
810+ assoc_reg(R, int(_), FP3, FP4),
811+ [add(R, A, B)],
800812 % Update value in the context?
801- thun_compile(E, Si, So, FP4, FP).
813+ thun_compile(E, [R|S], So, FP4, FP).
802814
803815 func_compile(dup, E, [A|S], So, FP0, FP) --> !,
804816 add_ref(A, FP0, FP1),
@@ -810,10 +822,11 @@
810822
811823 func_compile(cons, E, [List, Item|S], So, FP0, FP) --> !,
812824 % allocate a cons cell
825+ % https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-33.html#%_sec_5.3
813826 thun_compile(E, S, So, FP0, FP).
814827
815-func_compile(Func, E, Si, So, FP0, FP) -->
816- { non_alloc(Func), !, func(Func, Si, S) },
828+func_compile(Func, E, Si, So, FP0, FP) --> { non_alloc(Func), !,
829+ func(Func, Si, S) },
817830 thun_compile(E, S, So, FP0, FP).
818831
819832 func_compile(_Func, E, Si, So, FP0, FP) -->
@@ -933,6 +946,21 @@
933946
934947 Fun!
935948
949+- - - -
950+
951+Test that returning registers before asking for new ones
952+does reuse registers that are unused and preserve registers
953+that are still in use.
954+
955+?- show_compiler(`1 dup 2 + swap 3 +`, StackIn, StackOut).
956+mov_imm(r0, int(1)).
957+mov_imm(r1, int(2)).
958+add(r1, r1, r0).
959+mov_imm(r2, int(3)).
960+add(r0, r2, r0).
961+[r0-int(_), r1-int(_)].
962+StackOut = [r0, r1|StackIn] .
963+
936964
937965
938966
Show on old repository browser