%#include "control-context.lp". function(a;b;c). scope(0..2). %general cfa_parent(0, function(a)). cfa_parent(1, function(b)). cfa_parent(2, function(c)). cfa_call(0, c). cfa_call(1, c). %additional keys(key0; key1). data(key0, x). data(key0, y). data(key1, m). data(key1, n). bind_scope(0, keys(key0), strong). bind_scope(1, keys(key1), strong). %bind_scope(0, a, strong). %bind_scope(0, b, strong). %bind_scope(1, a, strong). %bind_scope(1, c, strong). bind_scope(2, set(X), Options):- bind_scope(2, keys(Key), Options), data(Key, X). %nested scope propagation: bind_scope(Scope, Context, Info) :- bind_scope(ScopeParent, Context, Info), cfa_parent(Scope, scope(ScopeParent)). %strong inter-function propagation: bind_scope(Scope, Context,strong) :- bind_scope(ScopeParent, Context, strong): cfa_call(ScopeParent, FnCurrent); cfa_parent(Scope, function(FnCurrent)); cfa_call(_, FnCurrent); bind_scope(_, Context, strong); scope(Scope). %weak inter-function propagation bind_scope(Scope, Context, weak(ScopeParent)):- not bind_scope(Scope, Context, strong), bind_scope(ScopeParent, Context, strong), cfa_call(ScopeParent, FnCurrent), cfa_parent(Scope, function(FnCurrent)). bind_scope(Scope, Context, weak(Id)):- nbind_scope(Scope, Context, strong), bind_scope(ScopeParent, Context, weak(Id)), cfa_call(ScopeParent, FnCurrent), cfa_parent(Scope, function(FnCurrent)). %make decisions bind_scope_decision(Scope, loop(Subject), Scope):- cfa_contextloop(Scope, Subject), demand_dependency(loop(Subject), X), bind_scope(Scope, X, strong). bind_scope_decision(Scope, loop(Subject), Scope):- cfa_call(Scope, FnChild), bind_function_demand(FnChild, loop(Subject)), demand_dependency(loop(Subject), X), bind_scope(Scope, X, strong). %demand % bind_scope_demand(Scope, loop(Subject)):- cfa_contextloop(Scope, Subject), not bind_scope_decision(Scope, loop(Subject), _). %nested scope demand propagation bind_scope_demand(Scope, Subject):- bind_scope_demand(ScopeChild, Subject), cfa_parent(ScopeChild, scope(Scope)). bind_function_demand(Fn, Subject):- bind_scope_demand(Scope, Subject), cfa_parent(Scope, function(Fn)). %inter-function propagation demand bind_scope_demand(Scope, Subject):- cfa_call(Scope, FnChild), bind_function_demand(FnChild, Subject), not bind_scope_decision(Scope, Subject, _). % GENERATED DECLARATIONS FOR DECISION DEPENDENCIES % -- cfa_contextloop(Scope, $set) => demand_dependency(loop(set), X) :- bind_scope($ScopeId, X = $set(_), weak(_)). demand_dependency(loop(set), X) :- bind_scope(2, X, weak(_)), X = set(_). % -- rule($Conditon, %Result) => demand_dependency(loop(X), $Condition) :- demand_dependency(loop(X), $Result) demand_dependency(loop(X), keys(Key)) :- demand_dependency(loop(X), set(Y)), bind_scope(_, keys(Key), _). cfa_contextloop(2, set). #show bind_scope/3.