-
Notifications
You must be signed in to change notification settings - Fork 2
/
banpipe.lgt
154 lines (120 loc) · 3.91 KB
/
banpipe.lgt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
% Dependency rule operator, note that it has same precendece as :-
:- op(1200, xfx, '<-').
:- dynamic(('<-')/2).
:- object(banpipe).
:- info([
version is 1:0:0,
author is 'Christian Theil Have',
date is 2012-11-13,
comment is 'The main object for interaction with banpipe scripts.'
]).
:- public(load/1).
:- dynamic(('<-')/2).
:- public(version/0).
:- info(version/0,[
comment is 'Writes current version of BANpipe.'
]).
version :-
version(V),
write(V), nl.
:- public(version/1).
:- info(version/1, [
comment is 'Version is the current version of banpipe',
argnames is ['Version']
]).
version('1.0 alpha release 1').
:- public(listing/1).
:- info(listing/1,
[ comment is 'Lists all banpipe dependency rules where the goal G occurs in the head.',
argnames is ['G']
]).
listing(Goal) :-
% escaped using {}/1 operator to find clause from "global" database rather than this objects database
findall([Head,Body],({clause('<-'(Head,Body),true)},term_extras::conjunction_as_list(Head,HeadList),list::nth1(_,HeadList,Goal)),Rules),
forall(list::member([Head,Body],Rules),(write(Head), write(' <- '), write(Body), nl)).
:- public(listing/0).
:- info(listing/0, [
comment is 'Lists all banpipe dependency rules.'
]).
listing :- listing(_).
% This simply loads a script using Prologs normal mechanism
:- info(load/1, [
comment is 'Loads a banpipe script. Script is the (quoted) filename of the script (absolute or relative to current directory).',
argnames is ['Script']
]).
load(Script) :- {[Script]}.
:- public(run/1).
:- info(run/1, [
comment is 'RRecursively (sequentially) compute the File associated with Goal.',
argnames is ['Goal']
]).
run(Goal) :-
::run(Goal,_).
:- public(run/2).
:- info(run/2, [
comment is 'Recursively (sequentially) compute the File associated with Goal.',
argnames is ['Goal','File']
]).
run(Goal,Result) :-
run_with_semantics(execution_semantics,Goal,Result).
:- private(run_with_semantics/3).
run_with_semantics(Semantics,Goal,Result) :-
( config::get(trace,true) ->
Sem=trace(Semantics)
; Sem=Semantics
),
sequential_interpreter(Sem)::run(Goal,Result).
:- public(prun/1).
:- info(prun/1, [
comment is 'Compute the File associated with Goal. Independent sub-tasks are computed in parallel.',
argnames is ['Goal']
]).
prun(Goal) :-
prun(Goal,_).
:- public(prun/2).
:- info(prun/2,[
comment is 'Compute the File associated with Goal. Independent sub-tasks are computed in parallel.',
argnames is ['Goal','File']
]).
:- if(current_logtalk_flag(threads,supported)).
prun(Goal,Result) :-
callgraph(Goal,_,Callgraph),
scheduler_tree::from_trace(Callgraph,Tree),
scheduler_tree::reduce_tree(Tree,ReducedTree),
scheduler::run(ReducedTree,[]),
% Result should now be available on file, use 'sequential' run to retrieve it
run(Goal,Result).
:- else.
prun(_Goal,_Result) :-
reporting::error('parallel execution is not supported.').
:- endif.
:- public(callgraph/1).
callgraph(Goal) :-
::callgraph(Goal,_,Callgraph),
scheduler_tree::from_trace(Callgraph,Tree1),
scheduler_tree::reduce_tree(Tree1,Tree2),
scheduler_tree::print(Tree2).
:- public(callgraph/3).
callgraph(Goal,Result,Callgraph) :-
sequential_interpreter(callgraph_semantics)::run(Goal,Result,Callgraph), !.
:- public(typecheck/1).
:- info(typecheck/1,[
comment is 'Typecheck Goal -- recursively check that the types of input files for Goal are compatible.',
argnames is ['Goal']
]).
typecheck(Goal) :-
typecheck(Goal,_).
:- public(typecheck/2).
:- info(typecheck/2,[
comment is 'Typecheck Goal -- recursively check that the types of input files for Goal are compatible and unify resulting Type.',
argnames is ['Goal','Type']
]).
typecheck(Goal,Type) :-
run_with_semantics(typecheck_semantics,Goal,Type).
:- public(trace/0).
trace :- config::set(trace).
:- public(notrace/0).
notrace :-
config::pop(trace).
notrace.
:- end_object.