• R/O
  • SSH

Joypy: コミット

Main interpreter and library.


コミットメタ情報

リビジョン37191890f191dfc351a6a64d4d94133e7831a9ed (tree)
日時2019-08-19 02:53:25
作者Simon Forman <sforman@hush...>
コミッターSimon Forman

ログメッセージ

truly fork, sort of

変更サマリ

差分

diff -r 438748ae49e1 -r 37191890f191 thun/gnu-prolog/Makefile
--- a/thun/gnu-prolog/Makefile Tue Aug 13 11:58:31 2019 -0700
+++ b/thun/gnu-prolog/Makefile Sun Aug 18 10:53:25 2019 -0700
@@ -2,7 +2,7 @@
22 GPLC_OPTIONS=--no-top-level
33 #GPLC_OPTIONS=
44
5-THUN_DEPS=parser.pl defs.pl main.pl math.pl DCG_basics.pl
5+THUN_DEPS=parser.pl defs.pl main.pl math.pl DCG_basics.pl fork.pl
66
77 thun: thun.pl $(THUN_DEPS) Makefile
88 gplc $(GPLC_OPTIONS) -o thun thun.pl $(THUN_DEPS)
@@ -11,6 +11,7 @@
1111 gprolog \
1212 --consult-file meta-defs.pl \
1313 --consult-file parser.pl \
14+ --consult-file fork.pl \
1415 --consult-file thun.pl \
1516 --consult-file DCG_basics.pl \
1617 --query-goal do
diff -r 438748ae49e1 -r 37191890f191 thun/gnu-prolog/defs.pl
--- a/thun/gnu-prolog/defs.pl Tue Aug 13 11:58:31 2019 -0700
+++ b/thun/gnu-prolog/defs.pl Sun Aug 18 10:53:25 2019 -0700
@@ -20,7 +20,6 @@
2020 def(dupdd,[[dup],dipd]).
2121 def(dupdipd,[dup,dipd]).
2222 def(enstacken,[stack,[clear],dip]).
23-def(fork,[[i],app2]).
2423 def(fourth,[rest,third]).
2524 def(gcd,[true,[tuck,mod,dup,0,>],loop,pop]).
2625 def(grabN,[[],swap,[cons],times]).
diff -r 438748ae49e1 -r 37191890f191 thun/gnu-prolog/defs.txt
--- a/thun/gnu-prolog/defs.txt Tue Aug 13 11:58:31 2019 -0700
+++ b/thun/gnu-prolog/defs.txt Sun Aug 18 10:53:25 2019 -0700
@@ -22,7 +22,6 @@
2222 dupdipd == dup dipd
2323 enstacken == stack [clear] dip
2424 flatten == [] swap [concat] step
25-fork == [i] app2
2625 fourth == rest third
2726 gcd == true [tuck mod dup 0 >] loop pop
2827 grabN == [] swap [cons] times
diff -r 438748ae49e1 -r 37191890f191 thun/gnu-prolog/fork.pl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/thun/gnu-prolog/fork.pl Sun Aug 18 10:53:25 2019 -0700
@@ -0,0 +1,41 @@
1+:- multifile(func/3).
2+
3+func(fork, [F, G|S], [X, Y|S]) :-
4+ fork(F, S, X, ChildPID),
5+ thun(G, S, [Y|_]),
6+ wait(ChildPID, Status). % FIXME check status!!!
7+
8+fork(Expr, Stack, Result, ChildPID) :-
9+ mkpipe(In, Out),
10+ fork_prolog(ChildPID),
11+ bar(ChildPID, In, Out, Expr, Stack, Result).
12+
13+bar(0, In, Out, Expr, Stack, Result) :-
14+ close(In),
15+ thun(Expr, Stack, [Result|_]),
16+ w(Out, Result),
17+ close(Out),
18+ halt.
19+
20+bar(P, In, Out, Expr, Stack, Result) :-
21+ integer(P), P =\= 0,
22+ close(Out),
23+ select([In], R, [], _, 1500),
24+ (R=[In] ->
25+ read(In, Result)
26+ ;
27+ Result=timeout
28+ ),
29+ close(In).
30+
31+mkpipe(In, Out) :-
32+ create_pipe(In, Out),
33+ set_stream_buffering(Out, none),
34+ set_stream_buffering(In, none).
35+
36+w(Out, Term) :- % To get a term written out and recognized,
37+ write(Out, Term), % you write it to the stream
38+ put_code(Out, 0'.), % add a period at the end
39+ nl(Out), % and a newline even if you set buffering
40+ flush_output(Out). % to none, then flush for good measure.
41+
旧リポジトリブラウザで表示