changeset d22e7f2be31b in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=d22e7f2be31b user: Simon Forman <sform****@hushm*****> date: Sun Aug 11 14:51:13 2019 -0700 description: Extract mainloop to own file. changeset 3d02093c3fe9 in joypy/Joypy details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=3d02093c3fe9 user: Simon Forman <sform****@hushm*****> date: Sun Aug 11 14:56:20 2019 -0700 description: Don't shadow funcs & combos. diffstat: thun/gnu-prolog/Makefile | 12 ++++++++---- thun/gnu-prolog/main.pl | 37 +++++++++++++++++++++++++++++++++++++ thun/gnu-prolog/meta-defs.pl | 4 +++- thun/gnu-prolog/thun.pl | 25 ------------------------- 4 files changed, 48 insertions(+), 30 deletions(-) diffs (125 lines): diff -r d971151a2c99 -r 3d02093c3fe9 thun/gnu-prolog/Makefile --- a/thun/gnu-prolog/Makefile Sat Aug 10 22:21:57 2019 -0700 +++ b/thun/gnu-prolog/Makefile Sun Aug 11 14:56:20 2019 -0700 @@ -1,8 +1,12 @@ GPLC_OPTIONS="--min-size" -thun: thun.pl parser.pl defs.pl - gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl defs.pl +thun: thun.pl parser.pl defs.pl main.pl + gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl defs.pl main.pl -defs.pl: meta-defs.pl parser.pl defs.txt - gprolog --consult-file meta-defs.pl --consult-file parser.pl --query-goal do +defs.pl: meta-defs.pl parser.pl defs.txt thun.pl + gprolog \ + --consult-file meta-defs.pl \ + --consult-file parser.pl \ + --consult-file thun.pl \ + --query-goal do diff -r d971151a2c99 -r 3d02093c3fe9 thun/gnu-prolog/main.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/thun/gnu-prolog/main.pl Sun Aug 11 14:56:20 2019 -0700 @@ -0,0 +1,37 @@ +/* + Copyright 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/>. + +Main Loop + +*/ + +:- initialization(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 d971151a2c99 -r 3d02093c3fe9 thun/gnu-prolog/meta-defs.pl --- a/thun/gnu-prolog/meta-defs.pl Sat Aug 10 22:21:57 2019 -0700 +++ b/thun/gnu-prolog/meta-defs.pl Sun Aug 11 14:56:20 2019 -0700 @@ -14,11 +14,12 @@ phrase(joy_defs, Codes). assert_def(def(Def, Body)) :- + \+ func(Def, _, _), + \+ combo(Def, _, _, _, _), retractall(def(Def, _)), assertz(def(Def, Body)). - read_file_to_codes(File, Codes, _) :- open(File, read, Stream), stream_to_codes(Stream, Codes), @@ -32,6 +33,7 @@ stream_to_codes(-1, _, []) :- !. stream_to_codes(Ch, Stream, [Ch|Codes]) :- stream_to_codes(Stream, Codes). + print_defs :- findall(def(Name, Body), def(Name, Body), List), open(`defs.pl`, write, Stream), diff -r d971151a2c99 -r 3d02093c3fe9 thun/gnu-prolog/thun.pl --- a/thun/gnu-prolog/thun.pl Sat Aug 10 22:21:57 2019 -0700 +++ b/thun/gnu-prolog/thun.pl Sun Aug 11 14:56:20 2019 -0700 @@ -20,10 +20,6 @@ % :- dynamic(func/3). % :- discontiguous(func/3). - -:- initialization(loop). - - /* Interpreter thun(Expression, InputStack, OutputStack) @@ -194,24 +190,3 @@ prepare_mapping( P, S, [T|In], Acc, Out) :- prepare_mapping(P, S, In, [[T|S], P, infrst|Acc], Out). - - -/* -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. - - -