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

Back to archive index
scmno****@osdn***** scmno****@osdn*****
Sat May 4 07:21:54 JST 2019


changeset 69a7e3b9464d in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=69a7e3b9464d
user: Simon Forman <sform****@hushm*****>
date: Fri May 03 15:21:06 2019 -0700
description: Some docs, and a thing to print out the dictionary after compilation.
changeset 81f5dd52c508 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=81f5dd52c508
user: Simon Forman <sform****@hushm*****>
date: Fri May 03 15:21:29 2019 -0700
description: A Tracing Meta-Interpreter for Thun

diffstat:

 thun/compiler.pl    |  31 +++++++++++++++++++++++++++-
 thun/metalogical.pl |  55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 2 deletions(-)

diffs (119 lines):

diff -r cd6dc7112759 -r 81f5dd52c508 thun/compiler.pl
--- a/thun/compiler.pl	Thu May 02 20:39:30 2019 -0700
+++ b/thun/compiler.pl	Fri May 03 15:21:29 2019 -0700
@@ -17,6 +17,27 @@
 You should have received a copy of the GNU General Public License
 along with Thun.  If not see <http://www.gnu.org/licenses/>.
 
+The Joy interpreter that this implements is pretty crude.  the only types
+are 16-bit integers and linked lists.  The lists are 32-bit words divided
+into two 16-bit fields.  The high half is the node value and the low half
+points directly (not offset) to the next cell, zero terminates the list.
+
+The expression is expected to be already written in RAM as a linked list at
+the time the mainloop starts.  As yet there is no support for actually doing
+this.  Both the new stack and expression cells are written to the same heap
+intermixed.  The stack and expression pointers never decrease, the whole
+history of the computation is recorded in RAM.  If the computation of the
+expression overruns the end of RAM (or 16-bits whichever comes first) the
+machine crashes.
+
+At the moment, functions are recognized by setting high bit, but I don't
+think I remembered to set the bits during compilation, so it won't work
+at all right now.  Er...  Boo.  Anyhow, the whole thing is very crude and
+not at all what I am hoping eventually to build.
+
+But it's a start, and I feel good about emitting machine code (even if the
+program doesn't do anything useful yet.)
+
 */
 :- use_module(library(assoc)).
 :- use_module(library(clpfd)).
@@ -38,11 +59,17 @@
 
 
 compile_program(Program, Binary) :-
-    phrase((init, ⦾(Program, IR)), [], _),
+    phrase((init, ⦾(Program, IR)), [], [Context]),
     phrase(⟐(IR), ASM),
     phrase(linker(ASM), EnumeratedASM),
+    foo(Context),
     phrase(asm(EnumeratedASM), Binary).
 
+foo(Context) :-
+    get_assoc(dictionary, Context, D),
+    assoc_to_list(D, Dictionary),
+    portray_clause(Dictionary).
+
 
 /*
 
@@ -110,7 +137,7 @@
     ⦾(Terms, Ts).
 
 ⦾([Body, ≡(NameAtom)|Terms], [defi(Name, B, Prev, I, SP, TOS)|Ts]) -->
-    get(dict, Prev), set(dict, Name), get(sp, SP), get(tos, TOS),
+    get(dict, Prev), set(dict, Name), get([sp, SP, tos, TOS]),
     inscribe(NameAtom, Name), ⦾(Terms, Ts), lookup(i, I), lookup(Body, B).
 
 ⦾([Body, ヮ(NameAtom)|Terms], [definition(Name, DONE, B, Prev)|Ts]) -->
diff -r cd6dc7112759 -r 81f5dd52c508 thun/metalogical.pl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/thun/metalogical.pl	Fri May 03 15:21:29 2019 -0700
@@ -0,0 +1,55 @@
+% A Tracing Meta-Interpreter for Thun
+
+alpha(true).
+alpha((A, B)) :- alpha(A), alpha(B).
+alpha(number(A)) :- !, number(A).
+alpha(var(A)) :- !, var(A).
+alpha(!) :- !.
+
+% Meta-logical print trace.
+% (Could also be captured in a list or something instead.)
+alpha(thun(E, Si, _)) :- portray_clause(Si-E), fail.
+
+alpha(Goal) :-
+    checky(Goal),
+    clause(Goal, Body),  % doesn't work for e.g. +
+    alpha(Body).
+
+checky(Goal) :-
+    Goal \= true,
+    Goal \= (_,_),
+    Goal \= var(_),
+    Goal \= number(_),
+    Goal \= !.
+
+/*
+
+[debug]  ?- alpha(thun([1, 2, swap], Si, So)).
+_-[1, 2, swap].
+[1|_]-[2, swap].
+[2, 1|_]-[swap].
+[1, 2|_]-[].
+So = [1, 2|Si] ;
+false.
+
+[debug]  ?- alpha(thun([[1], 2, swons], Si, So)).
+_-[[1], 2, swons].
+[[1]|_]-[2, swons].
+[2, [1]|_]-[swons].
+[2, [1]|_]-[swap, cons].
+[[1], 2|_]-[cons].
+[[2, 1]|_]-[].
+So = [[2, 1]|Si] .
+
+[debug]  ?- alpha(thun([[1], 2, [swons], i], Si, So)).
+_-[[1], 2, [swons], i].
+[[1]|_]-[2, [swons], i].
+[2, [1]|_]-[[swons], i].
+[[swons], 2, [1]|_]-[i].
+[2, [1]|_]-[swons].
+[2, [1]|_]-[swap, cons].
+[[1], 2|_]-[cons].
+[[2, 1]|_]-[].
+So = [[2, 1]|Si] .
+
+*/
\ No newline at end of file


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