Extract mainloop to own file.

This commit is contained in:
Simon Forman 2019-08-11 14:51:13 -07:00
parent 6bc1b5ec8b
commit 9e180e8173
3 changed files with 39 additions and 27 deletions

View File

@ -1,7 +1,7 @@
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

37
thun/gnu-prolog/main.pl Normal file
View File

@ -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.

View File

@ -20,10 +20,6 @@
% :- dynamic(func/3).
% :- discontiguous(func/3).
:- initialization(loop).
/*
Interpreter
thun(Expression, InputStack, OutputStack)
@ -194,24 +190,3 @@ prepare_mapping( _, _, [], Out, Out) :- !.
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.