% 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 container(solid; onthefly; llvm_const_array). access(serial; rand). relation(recommends; satisfied; unsupported). score(-1..1). %DOMAIN FACTS relation_score( unsupported, -1; satisfied, 0; recommends, 1 ). relation_access( serial, onthefly, recommends; rand, llvm_const_array, recommends; rand, onthefly, unsupported ). %AST ATTACHMENTS attach_operator_map(none, access(serial)). attach_operator_fold(none, access(serial), none). attach_operator_list_range(container(onthefly)). attach_operator_list(container(solid)). attach_operator_index(access(rand)). %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); access(OP); container(IMPL). -impl_fulfill_cluster(Var0, Impl):- var_cluster(Var0, Var_Any); bind(Var_Any, access(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, access(OP))}; bind(VAR0, container(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, onthefly):- impl_fulfill_cluster(V, onthefly, _); 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.