• R/O
  • SSH

Joypy: Commit

Main interpreter and library.


Commit MetaInfo

Revisionc745734dea147d4f2f45d1b767087d9275463aa2 (tree)
Time2019-08-21 14:00:27
AuthorSimon Forman <sforman@hush...>
CommiterSimon Forman

Log Message

minor cleanup

Change Summary

Incremental Difference

diff -r ddbab0c8a528 -r c745734dea14 thun/gnu-prolog/fork.pl
--- a/thun/gnu-prolog/fork.pl Mon Aug 19 22:02:06 2019 -0700
+++ b/thun/gnu-prolog/fork.pl Tue Aug 20 22:00:27 2019 -0700
@@ -1,9 +1,31 @@
1+/*
2+ Copyright 2019 Simon Forman
3+
4+ This file is part of Thun
5+
6+ Thun is free software: you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation, either version 3 of the License, or
9+ (at your option) any later version.
10+
11+ Thun is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ You should have received a copy of the GNU General Public License
17+ along with Thun. If not see <http://www.gnu.org/licenses/>.
18+
19+A fork function that actually forks. Experimental.
20+
21+*/
122 :- multifile(func/3).
223
324 func(fork, [F, G|S], [X, Y|S]) :-
425 fork(F, S, R, ChildPID), % Send F off to the child,
526 thun(G, S, [Y|_]), % Run G locally,
627 read_pipe(R, X), % Collect the result from F,
28+ % FIXME deal with X=timeout...
729 wait(ChildPID, Status). % FIXME check status!!!
830
931 fork(Expr, Stack, In, ChildPID) :-
diff -r ddbab0c8a528 -r c745734dea14 thun/gnu-prolog/main.pl
--- a/thun/gnu-prolog/main.pl Mon Aug 19 22:02:06 2019 -0700
+++ b/thun/gnu-prolog/main.pl Tue Aug 20 22:00:27 2019 -0700
@@ -25,27 +25,26 @@
2525
2626 :- initialization(loop).
2727
28-loop :- prompt, line(Line), loop(Line, [], _Out).
28+loop :- prompt(Line), loop(Line, [], _Out).
2929
3030 loop([eof], S, S) :- !.
3131 loop( Line, In, Out) :-
3232 do_line(Line, In, S),
3333 show_stack(S),
34- prompt,
35- line(NextLine), !,
34+ prompt(NextLine), !,
3635 loop(NextLine, S, Out).
3736
3837 do_line(Line, In, Out) :- phrase(joy_parse(E), Line), thun(E, In, Out).
3938 do_line(_Line, S, S) :- write('Err'), nl.
4039
41-prompt :- write(`joy? `).
40+prompt(Line) :- write(`joy? `), get_line(Line).
4241 show_stack(S) :- nl, print_stack(S), write(` <-top`), nl, nl.
4342
4443
45-% Line is the next new-line delimited line from standard input stream as
44+% Line is the next newget_line-delimited line from standard input stream as
4645 % a list of character codes.
4746
48-line(Line) :- get_code(X), line(X, Line).
47+get_line(Line) :- get_code(X), line(X, Line).
4948
5049 line(10, []) :- !. % break on new-lines.
5150 line(-1, [eof]) :- !. % break on EOF
diff -r ddbab0c8a528 -r c745734dea14 thun/gnu-prolog/math.pl
--- a/thun/gnu-prolog/math.pl Mon Aug 19 22:02:06 2019 -0700
+++ b/thun/gnu-prolog/math.pl Tue Aug 20 22:00:27 2019 -0700
@@ -1,4 +1,5 @@
11 :- multifile(func/3).
2+
23 func(+, [A, B|C], [D|C]) :-
34 E =.. [+, B, A],
45 catch(D is E, _, D = E).
diff -r ddbab0c8a528 -r c745734dea14 thun/gnu-prolog/meta-math.pl
--- a/thun/gnu-prolog/meta-math.pl Mon Aug 19 22:02:06 2019 -0700
+++ b/thun/gnu-prolog/meta-math.pl Tue Aug 20 22:00:27 2019 -0700
@@ -78,7 +78,8 @@
7878
7979 do :-
8080 open(`math.pl`, write, Stream),
81- write(Stream, `:- multifile(func/3).`), nl(Stream),
81+ write(Stream, `:- multifile(func/3).`),
82+ nl(Stream), nl(Stream),
8283 print_o(Stream, math_operator(Op)),
8384 print_o(Stream, comparison_operator(Op)),
8485 print_o(Stream, comparison_operator(Op, Po)),
diff -r ddbab0c8a528 -r c745734dea14 thun/gnu-prolog/parser.pl
--- a/thun/gnu-prolog/parser.pl Mon Aug 19 22:02:06 2019 -0700
+++ b/thun/gnu-prolog/parser.pl Tue Aug 20 22:00:27 2019 -0700
@@ -38,6 +38,8 @@
3838
3939 number_digits(Codes) --> signed_float_or_integer(Codes), !, end_num.
4040
41+% At the end of a number look ahead one character for a space
42+% or '[' character, or the end of the code list.
4143 end_num, [Ch] --> [Ch], { [Ch] = "[" ; is_space(Ch) }.
4244 end_num([], []).
4345
@@ -54,7 +56,6 @@
5456 phrase(format_joy(Expression), ExpressionCodes),
5557 append(RStackCodes, [32, 46, 32|ExpressionCodes], Codes).
5658
57-
5859 frump(Stack, Expression) :-
5960 format_state(Stack, Expression, Codes),
6061 maplist(put_code, Codes), nl.
@@ -64,8 +65,6 @@
6465 phrase(format_joy(RStack), Codes),
6566 maplist(put_code, Codes).
6667
67-
68-
6968 % Print Joy expressions as text.
7069
7170 format_joy(Tail) --> {var(Tail)}, !, [46, 46, 46].
@@ -79,4 +78,3 @@
7978 format_term([A|As]) --> "[", format_joy([A|As]), "]".
8079 format_term(F) --> { write_to_codes(Codes, F)}, Codes.
8180
82-
Show on old repository browser