diff --git a/core/containers.lp b/core/containers.lp index 63b7269..8a46e89 100644 --- a/core/containers.lp +++ b/core/containers.lp @@ -1,58 +1,41 @@ -%defines - impl(solid; on_the_fly; linked_list). - op(seqaccess; randaccess). - - relation(recommends; satisfied; unsupported). - relation_score(satisfied, 0). - relation_score(recommends, 1). - relation_score(unsupported, -1). - score(-1..1). +%1. Domain definitions: + impl(solid; on_the_fly; linked_list). + op(seqaccess; randaccess). + relation(recommends; satisfied; unsupported). -%domain facts: + relation_score(satisfied, 0). + relation_score(recommends, 1). + score(0..1). + +%2. Domain facts: relation_op(seqaccess, on_the_fly, recommends). - relation_op(randaccess, solid, recommends). relation_op(randaccess, on_the_fly, unsupported). -%dfa analysis: -%scheme: dfa_connection(Vto, Vfrom, proto); -%-- dfa_connection(VTo, VFrom, alias); -%-- dfa_connection(VFormal, VActual, arg); -%-- dfa_connection(VActual, VFormal, ret) - -%compilation: -%-- - -%domain rules: - %aliases: - var_origin(VAR) :- not dfa_connection(VAR, _, alias), v(VAR). - var_alias(VAR0, VAR_TO) :- dfa_connection(VAR_TO, VAR0, alias), var_origin(VAR0). - var_alias(VAR0, VAR_TO2) :- dfa_connection(VAR_TO2, VAR_TO1, alias), var_alias(VAR0, VAR_TO1). - var_alias(VAR0, VAR0):- var_origin(VAR0). - - %prototypes: - var_proto(V0, Vproto) :- var_origin(V0); var_origin(Vproto); var_alias(Vproto, Vp); dfa_connection(V0, Vp, proto). - - %implementations: - -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)} - ; op(OP); impl(IMPL); not -impl_fulfill(OP, IMPL). - - -var_impl_fulfill(Var0, Impl) :- var_alias(Var0, Var_Any); bind(Var_Any, op(Op)); -impl_fulfill(Op, Impl). - var_impl_fulfill(VAR0, IMPL, Score) :- - Score = #sum{SCORE, (OP, IMPL, VAR_ANY): impl_fulfill(OP, IMPL, SCORE), var_alias(VAR0, VAR_ANY), bind(VAR_ANY, op(OP))} - ; bind(VAR0, impl(IMPL)); var_origin(VAR0); not -var_impl_fulfill(VAR0, IMPL). - - %transfunction implementation: - %bind(Vactual, op(Op)) :- var_alias(Vformal, V1); bind(V1, op(Op)); dfa_connection(Vformal, Vactual, arg); op(Op). - - %bind(Vactual, op(Op)) :- var_alias(VO, Vformal); var_alias(VO, V); bind(V, op(Op)); dfa_connection(Vactual,Vformal, ret); op(Op). - % --uncomment to add possible implementations(impl) to an actual var - %bind(Vres, op(Op)) :- var_alias(VO, VA); bind(VA, op(Op)); dfa_connection(VArg,VO, result); op(Op). + bind(X, impl(solid)):- bind(X, dfa_operator(list)). + bind(X, impl(on_the_fly)):- bind(X, dfa_operator(list)). -%optimization -% #maximize {SCORE, (VAR0, IMPL) : var_impl_fulfill(VAR0, IMPL, SCORE)}. + bind(X, op(seqaccess)) :- bind(X, dfa_operator(loop_fold)). + bind(X, op(randaccess)) :- bind(X, dfa_operator(index)). + +%5. Manual input + +%2. Supplies + +%4. Best implemetation search: + score(op(OP), IMPL, SCORE):- SCORE = #sum{SCORE1, SCORE1: relation_score(RL, SCORE1), relation_op(OP, IMPL, RL)}; op(OP); impl(IMPL); not relation_op(OP, IMPL, unsupported). + {score(v(VAR), IMPL, SCORE)}:- score(op(OP), IMPL, SCORE); bind(VAR, op(OP)); bind(VAR, impl(IMPL)). + :- 2{score(v(VAR), IMPL, SCORE): v(VAR)}. + + #maximize { SCORE, (VAR, SCORE): score(v(VAR), _, SCORE) }. + +%5. Output + %resolution(var, impl) + -#show var_alias/2. -#show var_impl_fulfill/3. -#show proto_alias2. +%1. DFA input + v(a). + bind(a, dfa_operator(list)). + bind(a, dfa_operator(loop_fold)). + + diff --git a/problems/code-containers-impl.lp b/problems/code-containers-impl.lp deleted file mode 100644 index fb5941d..0000000 --- a/problems/code-containers-impl.lp +++ /dev/null @@ -1,50 +0,0 @@ -%defines - impl(llvm_array; 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). - -%dfa analysis: - dfa_connection((5,0),(4,0),strong). - v((5,0)). %c c = b : [num]; - v((3,0)). %a2 a2 = [1 .. 100] : [num]; - v((4,0)). %b b = loop map (a1 -> el: num) : [num] - v((2,0)). %a1 a1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] : [num]; - -%compilation: - bind((5,0), op(randaccess)). - bind((4,0),impl(llvm_array)). - bind((3,0),impl(on_the_fly)). - bind((3,0),op(seqaccess)). - bind((2,0),op(seqaccess)). - bind((2,0),impl(llvm_const_array)). - -%domain rules: - -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)} - ; op(OP); impl(IMPL); not -impl_fulfill(OP, IMPL). - - cluster_root(VAR) :- not dfa_connection(VAR, _, strong), v(VAR). - var_cluster(VAR0, VAR_TO) :- dfa_connection(VAR_TO, VAR0, strong), cluster_root(VAR0). - var_cluster(VAR0, VAR_TO2) :- dfa_connection(VAR_TO2, VAR_TO1, strong), var_cluster(VAR0, VAR_TO1). - var_cluster(VAR0, VAR0):- cluster_root(VAR0). - - -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). - -%optimization: -% #maximize {SCORE, (VAR0, IMPL) : impl_fulfill_cluster(VAR0, IMPL, SCORE)}. - -#show var_cluster/2. -#show impl_fulfill_cluster/3. \ No newline at end of file