[Joypy-announce] joypy/Joypy: 2 new changesets

Back to archive index
scmno****@osdn***** scmno****@osdn*****
Sat Feb 1 01:30:22 JST 2020


changeset 801e1c92a555 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=801e1c92a555
user: Simon Forman <sform****@hushm*****>
date: Fri Jan 31 08:26:10 2020 -0800
description: Freeing registers before using them is simpler.

https://todo.sr.ht/~sforman/thun-der/3
changeset 6a98a3a4a83c in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=6a98a3a4a83c
user: Simon Forman <sform****@hushm*****>
date: Fri Jan 31 08:30:10 2020 -0800
description: Remove unused predicates appears_only_once/2 and  reg_used_once/2.

diffstat:

 thun/thun.pl |  60 ++++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 42 insertions(+), 18 deletions(-)

diffs (109 lines):

diff -r e8fcdbf066e2 -r 6a98a3a4a83c thun/thun.pl
--- a/thun/thun.pl	Thu Jan 30 10:25:12 2020 -0800
+++ b/thun/thun.pl	Fri Jan 31 08:30:10 2020 -0800
@@ -24,8 +24,22 @@
     You should have received a copy of the GNU General Public License
     along with Thun.  If not see <http://www.gnu.org/licenses/>.
 
+(Big fonts are from Figlet "ANSI Shadow" http://www.patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=formatter
+ and "Small".)
 
-(Big fonts are from Figlet ANSI Shadow http://www.patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=formatter )
+Table of Contents
+    Parser & Grammar
+    Semantics
+        Functions
+        Combinators
+        Definitions
+    Compiler
+        to Prolog
+        to Machine Code
+    Meta-Programming
+        Expand/Contract Definitions
+        Formatter
+        Partial Reducer
 
  */
 
@@ -171,7 +185,9 @@
 % expression and we don't want to process combo/5 twice just to
 % notice that, eh?  Swap the rules and add green cuts after combo/5
 % and that should make it more efficient.
-%
+
+% Ach!  THe "green" cuts would mess up multi-rule combinators!  D'oh!
+
 % Neither functions nor definitions can affect the expression so we
 % don't need to do similar gardening to those rules.  The unification
 % of the head clauses will distinguish the cases for them.
@@ -715,10 +731,6 @@
 encode_list(List, FP, FP, Addr) --> [],
     {addr(list(List))=Addr}.
 
-appears_only_once(Term, List) :- append(_, [Term|Tail], List), !, \+ member(Term, Tail).
-
-reg_used_once(Reg, reggy(_, References, _)) :- appears_only_once(Reg, References).
-
 get_reggy([], _, _) :- writeln('Out of Registers'), fail.
 get_reggy([Reg|FreePool], Reg, FreePool).
 
@@ -788,17 +800,13 @@
 % Functions delegate to a per-function compilation relation.
 
 func_compile(+, E, [A, B|S], So, FP0, FP) --> !,
-    % If either register A or B is only used once we can reuse it.
-    ( {reg_used_once(B, FP0)} -> [add(B, A, B)], free_reg(A, FP0, FP4), {Si=[B|S]}
-    ; {reg_used_once(A, FP0)} -> [add(A, A, B)], free_reg(B, FP0, FP4), {Si=[A|S]}
-    ;   get_reg(R, FP0, FP1),    [add(R, A, B)],
-      assoc_reg(R, int(_), FP1, FP2),
-       free_reg(A, FP2, FP3),
-       free_reg(B, FP3, FP4),
-      {Si=[R|S]}   % Can all this be simplified by freeing first?
-    ),
+    free_reg(A, FP0, FP1),
+    free_reg(B, FP1, FP2),
+    get_reg(R, FP2, FP3),
+    assoc_reg(R, int(_), FP3, FP4),
+    [add(R, A, B)],
     % Update value in the context?
-    thun_compile(E, Si, So, FP4, FP).
+    thun_compile(E, [R|S], So, FP4, FP).
 
 func_compile(dup, E, [A|S], So, FP0, FP) --> !,
     add_ref(A, FP0, FP1),
@@ -810,10 +818,11 @@
 
 func_compile(cons, E, [List, Item|S], So, FP0, FP) --> !,
     % allocate a cons cell
+    % https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-33.html#%_sec_5.3
     thun_compile(E, S, So, FP0, FP).
 
-func_compile(Func, E, Si, So, FP0, FP) --> 
-    { non_alloc(Func), !, func(Func, Si, S) },
+func_compile(Func, E, Si, So, FP0, FP) --> { non_alloc(Func), !,
+    func(Func, Si, S) },
     thun_compile(E, S, So, FP0, FP).
 
 func_compile(_Func, E, Si, So, FP0, FP) -->
@@ -933,6 +942,21 @@
 
 Fun!
 
+- - - -
+
+Test that returning registers before asking for new ones
+does reuse registers that are unused and preserve registers
+that are still in use.
+
+?- show_compiler(`1 dup 2 + swap 3 +`, StackIn, StackOut).
+mov_imm(r0, int(1)).
+mov_imm(r1, int(2)).
+add(r1, r1, r0).
+mov_imm(r2, int(3)).
+add(r0, r2, r0).
+[r0-int(_), r1-int(_)].
+StackOut = [r0, r1|StackIn] .
+
 
 
 



More information about the Joypy-announce mailing list
Back to archive index