containers.lp
No OneTemporary

File Metadata

Created
Thu, Jul 9, 4:40 AM

containers.lp

% This Source Code Form is subject to the terms of the Mozilla Public
% License, v. 2.0. If a copy of the MPL was not distributed with this
% file, You can obtain one at http://mozilla.org/MPL/2.0/.
%defines
impl(solid; llvm_const_array; on_the_fly).
op(seqaccess). op(randaccess).
relation(recommends; satisfied; unsupported).
relation_score(satisfied, 0).
relation_score(recommends, 1).
relation_score(unsupported, -1).
score(-1..1).
%domain facts:
relation_op(seqaccess, on_the_fly, recommends).
relation_op(randaccess, llvm_const_array, recommends).
relation_op(randaccess, on_the_fly, unsupported).
%AST ATTACHMENTS
attach_operator_map(none, op(seqaccess)).
attach_operator_fold(none, op(seqaccess), none).
attach_operator_list_range(impl(on_the_fly)).
attach_operator_list(impl(solid)).
attach_operator_index(op(randaccess)).
%CLUSTERS
cluster_link(VTo, VFrom):- %aliases
dfa_connection(VTo, VFrom, strong).
cluster_link(VResult, VSource):- %Operator MAP
ast_op_map(VResult, VSource, _).
cluster_root(V):-
not cluster_link(V, _);
v(V).
var_cluster(V, V):- %self referencing
cluster_root(V).
var_cluster(VRoot, VTo):- %propagation down the tree
cluster_link(VTo, VFrom);
var_cluster(VRoot, VFrom).
%ALGORITHM
-impl_fulfill(OP, IMPL):-
relation_op(OP, IMPL, unsupported).
impl_fulfill(OP, IMPL, SCORE):-
SCORE = #sum{SCORE1, (OP, IMPL, RL): relation_op(OP, IMPL, RL), relation_score(RL, SCORE1)};
not -impl_fulfill(OP, IMPL);
op(OP); impl(IMPL).
-impl_fulfill_cluster(Var0, Impl):-
var_cluster(Var0, Var_Any);
bind(Var_Any, op(Op));
-impl_fulfill(Op, Impl).
impl_fulfill_cluster(VAR0, IMPL, Score):-
Score = #sum{SCORE, (OP, IMPL, VAR_ANY): impl_fulfill(OP, IMPL, SCORE), var_cluster(VAR0, VAR_ANY), bind(VAR_ANY, op(OP))};
bind(VAR0, impl(IMPL));
cluster_root(VAR0);
not -impl_fulfill_cluster(VAR0, IMPL).
%OUTPUT
containers_impl(V, Impl):-
containers_impl(VRoot, Impl);
var_cluster(VRoot, V).
containers_impl(V, solid(Size)):-
impl_fulfill_cluster(V, solid, _);
ast_op_list(V, Size);
cluster_root(V).
containers_impl(V, on_the_fly):-
impl_fulfill_cluster(V, on_the_fly, _);
ast_op_list_range(V);
cluster_root(V).
%optimization
% #maximize {SCORE, (VAR0, IMPL) : impl_fulfill_cluster(VAR0, IMPL, SCORE)}.
#show var_cluster/2.
#show impl_fulfill_cluster/3.

Event Timeline