2013-10-08 12:46:06 +01:00
|
|
|
:- module(cuda, [cuda_extensional/2,
|
|
|
|
cuda_inline/2,
|
|
|
|
cuda_rule/2,
|
|
|
|
cuda_erase/1,
|
|
|
|
cuda_eval/2,
|
2013-10-09 11:23:45 +01:00
|
|
|
cuda_coverage/4,
|
2013-10-16 16:19:03 +01:00
|
|
|
cuda_statistics/0,
|
2013-10-08 12:46:06 +01:00
|
|
|
cuda_count/2]).
|
2013-10-04 13:22:00 +01:00
|
|
|
|
|
|
|
tell_warning :-
|
|
|
|
print_message(warning,functionality(cuda)).
|
|
|
|
|
2013-10-08 12:46:06 +01:00
|
|
|
:- dynamic inline/2.
|
|
|
|
|
2013-10-04 13:22:00 +01:00
|
|
|
:- catch(load_foreign_files([cuda], [], init_cuda),_,fail) -> true ; tell_warning.
|
|
|
|
|
|
|
|
:- meta_predicate cudda_extensional(:,-).
|
|
|
|
|
2013-10-08 12:46:06 +01:00
|
|
|
cuda_inline(P, Q) :-
|
|
|
|
assert(inline(P,Q)).
|
|
|
|
|
2013-10-04 13:22:00 +01:00
|
|
|
cuda_extensional( Call, IdFacts) :-
|
|
|
|
strip_module(Call, Mod, Name/Arity),
|
|
|
|
functor(S, Name, Arity),
|
2013-10-12 12:46:01 +01:00
|
|
|
count_answers( Mod:S, N),
|
|
|
|
% reserve space
|
|
|
|
cuda_init_facts( N, Arity, Name, IdFacts ),
|
|
|
|
% fill it out
|
|
|
|
( Mod:S, cuda_load_fact(S), fail ; true ).
|
|
|
|
|
|
|
|
count_answers(G, N) :-
|
|
|
|
S = count(0),
|
|
|
|
(
|
|
|
|
G,
|
|
|
|
arg(1, S, I0),
|
|
|
|
I is I0+1,
|
|
|
|
nb_setarg(1, S, I),
|
|
|
|
fail ;
|
|
|
|
S = count(N) ).
|
2013-10-04 13:22:00 +01:00
|
|
|
|
|
|
|
cuda_rule((Head :- Body) , IdRules) :-
|
|
|
|
body_to_list( Body, L, [], 1, N),
|
|
|
|
functor(Head, Na, Ar),
|
2013-10-04 14:42:18 +01:00
|
|
|
load_rule( N, Ar, [Head|L], IdRules ).
|
2013-10-04 13:22:00 +01:00
|
|
|
|
|
|
|
|
2013-10-04 14:42:18 +01:00
|
|
|
body_to_list( (B1, B2), LF, L0, N0, NF) :- !,
|
2013-10-04 13:22:00 +01:00
|
|
|
body_to_list( B1, LF, LI, N0, N1),
|
|
|
|
body_to_list( B2, LI, L0, N1, NF).
|
2013-10-08 12:46:06 +01:00
|
|
|
body_to_list( true, L, L, N, N) :- !.
|
2013-10-16 11:15:26 +01:00
|
|
|
body_to_list( B, NL, L, N0, N) :-
|
2013-10-08 12:46:06 +01:00
|
|
|
inline( B, NB ), !,
|
2013-10-16 11:24:23 +01:00
|
|
|
body_to_list( NB, NL, L, N0, N).
|
2013-10-04 13:22:00 +01:00
|
|
|
body_to_list( B, [B|L], L, N0, N) :-
|
|
|
|
N is N0+1.
|
|
|
|
|