OSDN Git Service

minor cleanup
authorSimon Forman <sforman@hushmail.com>
Wed, 21 Aug 2019 05:00:27 +0000 (22:00 -0700)
committerSimon Forman <sforman@hushmail.com>
Wed, 21 Aug 2019 05:00:27 +0000 (22:00 -0700)
thun/gnu-prolog/fork.pl
thun/gnu-prolog/main.pl
thun/gnu-prolog/math.pl
thun/gnu-prolog/meta-math.pl
thun/gnu-prolog/parser.pl

index 39beaaf..e2aa8be 100644 (file)
@@ -1,9 +1,31 @@
+/*
+    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/>.
+
+A fork function that actually forks.  Experimental.
+
+*/
 :- multifile(func/3).
 
 func(fork, [F, G|S], [X, Y|S]) :-
     fork(F, S, R, ChildPID), % Send F off to the child,
     thun(G, S, [Y|_]),       % Run G locally,
     read_pipe(R, X),         % Collect the result from F,
+    % FIXME deal with X=timeout...
     wait(ChildPID, Status).  % FIXME check status!!!
 
 fork(Expr, Stack, In, ChildPID) :-
index 306ed76..ee7fc89 100644 (file)
@@ -25,27 +25,26 @@ Main Loop
 
 :- initialization(loop).
 
-loop :- prompt, line(Line), loop(Line, [], _Out).
+loop :- prompt(Line), loop(Line, [], _Out).
 
 loop([eof],  S,   S) :- !.
 loop( Line, In, Out) :-
   do_line(Line, In, S),
   show_stack(S),
-  prompt,
-  line(NextLine), !,
+  prompt(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.
 
-prompt :- write(`joy? `).
+prompt(Line) :- write(`joy? `), get_line(Line).
 show_stack(S) :- nl, print_stack(S), write(` <-top`), nl, nl.
 
 
-% Line is the next new-line delimited line from standard input stream as
+% Line is the next newget_line-delimited line from standard input stream as
 % a list of character codes.
 
-line(Line) :- get_code(X), line(X, Line).
+get_line(Line) :- get_code(X), line(X, Line).
 
 line(10,      []) :- !.  % break on new-lines.
 line(-1,   [eof]) :- !.  % break on EOF
index 6a41cd2..8e4727f 100644 (file)
@@ -1,4 +1,5 @@
 :- multifile(func/3).
+
 func(+, [A, B|C], [D|C]) :-
        E =.. [+, B, A],
        catch(D is E, _, D = E).
index c706806..f48b7c4 100644 (file)
@@ -78,7 +78,8 @@ writeln(Stream, Thing) :-
 
 do :-
     open(`math.pl`, write, Stream),
-    write(Stream, `:- multifile(func/3).`), nl(Stream),
+    write(Stream, `:- multifile(func/3).`),
+    nl(Stream), nl(Stream),
     print_o(Stream, math_operator(Op)),
     print_o(Stream, comparison_operator(Op)),
     print_o(Stream, comparison_operator(Op, Po)),
index c60d328..f24577b 100644 (file)
@@ -38,6 +38,8 @@ num(N) --> number_digits(Codes), { number_codes(N, Codes) }.
 
 number_digits(Codes) --> signed_float_or_integer(Codes), !, end_num.
 
+% At the end of a number look ahead one character for a space
+% or '[' character, or the end of the code list.
 end_num, [Ch] --> [Ch], { [Ch] = "[" ; is_space(Ch) }.
 end_num([], []).
 
@@ -54,7 +56,6 @@ format_state(Stack, Expression, Codes) :-
     phrase(format_joy(Expression), ExpressionCodes),
     append(RStackCodes, [32, 46, 32|ExpressionCodes], Codes).
 
-
 frump(Stack, Expression) :-
     format_state(Stack, Expression, Codes),
     maplist(put_code, Codes), nl.
@@ -64,8 +65,6 @@ print_stack(Stack) :-
     phrase(format_joy(RStack), Codes),
     maplist(put_code, Codes).
 
-
-
 % Print Joy expressions as text.
 
 format_joy(Tail)  --> {var(Tail)}, !, [46, 46, 46].
@@ -79,4 +78,3 @@ format_term(V) --> {   var(V), write_to_codes(Codes, V)}, Codes.
 format_term([A|As]) --> "[", format_joy([A|As]), "]".
 format_term(F) --> {    write_to_codes(Codes, F)}, Codes.
 
-