changeset a5b8b7826c48 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=a5b8b7826c48 user: Simon Forman <sform****@hushm*****> date: Sat Aug 10 22:07:17 2019 -0700 description: cleanup old files changeset d971151a2c99 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=d971151a2c99 user: Simon Forman <sform****@hushm*****> date: Sat Aug 10 22:21:57 2019 -0700 description: Use double-quoted string for codes. diffstat: thun/gnu-prolog/gthun.pl | 120 ------------- thun/gnu-prolog/junk/gthun.pl | 120 +++++++++++++ thun/gnu-prolog/junk/meta.pl | 10 + thun/gnu-prolog/junk/swi-thun.pl | 350 +++++++++++++++++++++++++++++++++++++++ thun/gnu-prolog/meta.pl | 10 - thun/gnu-prolog/parser.pl | 4 +- thun/gnu-prolog/swi-thun.pl | 350 --------------------------------------- 7 files changed, 481 insertions(+), 483 deletions(-) diffs (truncated from 1002 to 300 lines): diff -r 541a67d69c9a -r d971151a2c99 thun/gnu-prolog/gthun.pl --- a/thun/gnu-prolog/gthun.pl Sat Aug 10 22:03:44 2019 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ - -:- op(990, xfy, =-). -:- dynamic((=-)/2). - -:- initialization(loop). - - -/* -Parser -*/ - -joy_parse([T|S]) --> blanks, joy_term(T), blanks, joy_parse(S). -joy_parse([]) --> []. - -joy_term(N) --> num(N), !. -joy_term(S) --> [0'[], !, joy_parse(S), [0']]. -joy_term(A) --> chars(Chars), !, {atom_codes(A, Chars)}. - - -/* -Interpreter. -*/ - -thun([], S, S). - -thun( [Lit|E], Si, So) :- literal(Lit), !, thun(E, [Lit|Si], So). -thun( [Func|E], Si, So) :- func(Func, Si, S), !, thun(E, S, So). -thun([Combo|E], Si, So) :- combo(Combo, Si, S, E, Eo), !, thun(Eo, S, So). - -thun(Err, S, [Err|S]) :- write('Unknown term!'), nl. - - -/* -Literals -*/ - -literal(V) :- var(V). -literal(I) :- number(I). -literal([]). -literal([_|_]). -literal(true). -literal(false). - - -/* -Functions -*/ - -func(cons, [A, B|S], [[B|A]|S]). -func(swap, [A, B|S], [B, A|S]). -func(dup, [A|S], [A, A|S]). -func(pop, [_|S], S ). - -func(uncons, Si, So) :- func(cons, So, Si). - -func(+, [A, B|S], [B+A|S]). -func(=, [A|S], [B|S]) :- B is A. - -func(clear, _, []). -func(stack, S, [S|S]). - - -/* -Definitions -*/ - -% This is NOT the Continuation-Passing Style -% -% func(Name, Si, So) :- Name =- Body, thun(Body, Si, So). - -func(inscribe, [Definition|S], S) :- - Definition = [Name|Body], - atom(Name), - assertz(Name =- Body). - -swons =- [swap, cons]. -x =- [dup, i]. -unit =- [[], cons]. -enstacken =- [stack, [clear], dip]. - -% This IS the Continuation-Passing Style -% -combo(Name, S, S, Ei, Eo) :- Name =- Body, append(Body, Ei, Eo). - -/* -Combinators -*/ - -combo(i, [P|S], S, Ei, Eo) :- append(P, Ei, Eo). -combo(dip, [P, X|S], S, Ei, Eo) :- append(P, [X|Ei], Eo). -combo(dipd, [P, X, Y|S], S, Ei, Eo) :- append(P, [Y, X|Ei], Eo). - -combo(branch, [T, _, true|S], S, Ei, Eo) :- append(T, Ei, Eo). -combo(branch, [_, F, false|S], S, Ei, Eo) :- append(F, Ei, Eo). - -combo(loop, [_, false|S], S, E, E ). -combo(loop, [B, true|S], S, Ei, Eo) :- append(B, [B, loop|Ei], Eo). - -combo(step, [_, []|S], S, E, E ). -combo(step, [P, [X]|S], [X|S], Ei, Eo) :- !, append(P, Ei, Eo). -combo(step, [P, [X|Z]|S], [X|S], Ei, Eo) :- append(P, [Z, P, step|Ei], Eo). - - -/* -Main Loop -*/ - -loop :- line(Line), loop(Line, [], _Out). - -loop([eof], S, S) :- !. -loop( Line, In, Out) :- - do_line(Line, In, S), - write(S), nl, - line(NextLine), !, - loop(NextLine, S, Out). - - -do_line(Line, In, Out) :- phrase(joy_parse(E), Line), thun(E, In, Out). -do_line(_Line, S, S) :- write('Err'), nl. - diff -r 541a67d69c9a -r d971151a2c99 thun/gnu-prolog/junk/gthun.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thun/gnu-prolog/junk/gthun.pl Sat Aug 10 22:21:57 2019 -0700 @@ -0,0 +1,120 @@ + +:- op(990, xfy, =-). +:- dynamic((=-)/2). + +:- initialization(loop). + + +/* +Parser +*/ + +joy_parse([T|S]) --> blanks, joy_term(T), blanks, joy_parse(S). +joy_parse([]) --> []. + +joy_term(N) --> num(N), !. +joy_term(S) --> [0'[], !, joy_parse(S), [0']]. +joy_term(A) --> chars(Chars), !, {atom_codes(A, Chars)}. + + +/* +Interpreter. +*/ + +thun([], S, S). + +thun( [Lit|E], Si, So) :- literal(Lit), !, thun(E, [Lit|Si], So). +thun( [Func|E], Si, So) :- func(Func, Si, S), !, thun(E, S, So). +thun([Combo|E], Si, So) :- combo(Combo, Si, S, E, Eo), !, thun(Eo, S, So). + +thun(Err, S, [Err|S]) :- write('Unknown term!'), nl. + + +/* +Literals +*/ + +literal(V) :- var(V). +literal(I) :- number(I). +literal([]). +literal([_|_]). +literal(true). +literal(false). + + +/* +Functions +*/ + +func(cons, [A, B|S], [[B|A]|S]). +func(swap, [A, B|S], [B, A|S]). +func(dup, [A|S], [A, A|S]). +func(pop, [_|S], S ). + +func(uncons, Si, So) :- func(cons, So, Si). + +func(+, [A, B|S], [B+A|S]). +func(=, [A|S], [B|S]) :- B is A. + +func(clear, _, []). +func(stack, S, [S|S]). + + +/* +Definitions +*/ + +% This is NOT the Continuation-Passing Style +% +% func(Name, Si, So) :- Name =- Body, thun(Body, Si, So). + +func(inscribe, [Definition|S], S) :- + Definition = [Name|Body], + atom(Name), + assertz(Name =- Body). + +swons =- [swap, cons]. +x =- [dup, i]. +unit =- [[], cons]. +enstacken =- [stack, [clear], dip]. + +% This IS the Continuation-Passing Style +% +combo(Name, S, S, Ei, Eo) :- Name =- Body, append(Body, Ei, Eo). + +/* +Combinators +*/ + +combo(i, [P|S], S, Ei, Eo) :- append(P, Ei, Eo). +combo(dip, [P, X|S], S, Ei, Eo) :- append(P, [X|Ei], Eo). +combo(dipd, [P, X, Y|S], S, Ei, Eo) :- append(P, [Y, X|Ei], Eo). + +combo(branch, [T, _, true|S], S, Ei, Eo) :- append(T, Ei, Eo). +combo(branch, [_, F, false|S], S, Ei, Eo) :- append(F, Ei, Eo). + +combo(loop, [_, false|S], S, E, E ). +combo(loop, [B, true|S], S, Ei, Eo) :- append(B, [B, loop|Ei], Eo). + +combo(step, [_, []|S], S, E, E ). +combo(step, [P, [X]|S], [X|S], Ei, Eo) :- !, append(P, Ei, Eo). +combo(step, [P, [X|Z]|S], [X|S], Ei, Eo) :- append(P, [Z, P, step|Ei], Eo). + + +/* +Main Loop +*/ + +loop :- line(Line), loop(Line, [], _Out). + +loop([eof], S, S) :- !. +loop( Line, In, Out) :- + do_line(Line, In, S), + write(S), nl, + line(NextLine), !, + loop(NextLine, S, Out). + + +do_line(Line, In, Out) :- phrase(joy_parse(E), Line), thun(E, In, Out). +do_line(_Line, S, S) :- write('Err'), nl. + diff -r 541a67d69c9a -r d971151a2c99 thun/gnu-prolog/junk/meta.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thun/gnu-prolog/junk/meta.pl Sat Aug 10 22:21:57 2019 -0700 @@ -0,0 +1,10 @@ + + +do(DCG) :- + fd_domain(X, 0, 9), + fd_labeling(X), + number_codes(X, [C]), + DCG = `-->`(digit(C), [C]). + + + diff -r 541a67d69c9a -r d971151a2c99 thun/gnu-prolog/junk/swi-thun.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thun/gnu-prolog/junk/swi-thun.pl Sat Aug 10 22:21:57 2019 -0700 @@ -0,0 +1,350 @@ +:- dynamic(func/3). +:- discontiguous(func/3). + +/* + Copyright © 2018, 2019 Simon Forman + + This file is part of Thun + + Thun is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Thun is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Thun. If not see <http://www.gnu.org/licenses/>. + +*/ +:- dynamic(def/2). + + +/* + +To handle comparision operators the possibility of exceptions due to +insufficiently instantiated arguments must be handled. First try to make +the comparison and set the result to a Boolean atom. If an exception +happens just leave the comparison expression as the result and some other +function or combinator will deal with it. Example: + + func(>, [A, B|S], [C|S]) :- catch(