context.lp
No OneTemporary

File Metadata

Created
Wed, Jul 8, 10:13 AM

context.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/.
%% INPUT:
%% - latex_scope_demand(Scope, Subject)
%% Initial demand from clients
%%
%% - latex_registered_subjects(Subject, PossibleDecision)
%% Clients register possible decisions for respective subjects
%%
%% - latex_fn_signature
%%
%% OUTPUT:
%% - latex_fn_demand(Fn, Subject)
%% Which functions demand hidden latex arguments
%%
%% - latex_decision(Scope, Subject, Decision)
%% Provided decisions, values for hidden latex arguments
%%
%% SIGNATURES:
%% -Subject: string
%%
% CONTEXT PROPAGATION
%===========================================================
% nested scope propagation:
bind_scope(Scope, Context, Info):-
bind_scope(ScopeParent, Context, Info);
cfa_parent(Scope, scope(ScopeParent)).
% Strong or Uniform inter-function propagation:
bind_scope(Scope, Context, Info):-
bind_scope(ScopeParent, Context, Info): cfa_call(ScopeParent, FnCurrent);
cfa_parent(Scope, function(FnCurrent)); cfa_call(_, FnCurrent);
bind_scope(_, Context, Info); 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)).
% DEMAND
%===========================================================
%demand propagations: scope level
latex_scope_demand(Scope, Subject):-
latex_scope_demand(ScopeChild, Subject);
cfa_parent(ScopeChild, scope(Scope)).
%propagation: fn level
latex_fn_demand(Fn, Subject):-
latex_scope_demand(ScopeFnBody, Subject);
cfa_parent(ScopeFnBody, function(Fn)).
latex_fn_demand_ordered(Fn, Subject, Id):-
Id= #sum{ 1, SubjLess : latex_fn_demand(Fn, SubjLess), SubjLess < Subject};
latex_fn_demand(Fn, Subject).
%propagation: inter-fn level
latex_scope_demand(Scope, Subject):-
latex_fn_demand(FnCallee, Subject);
not latex_decision(Scope, Subject, _);
cfa_call(Scope, FnCallee).
% DECISIONS
%===========================================================
latex_decision(Scope, Subject, Decision):-
latex_fn_demand(FnCallee, Subject);
bind_scope(Scope, Decision, strong);
cfa_call(Scope, FnCallee);
latex_registered_subjects(Subject, Decision).
%late decision
late((ScopeCaller, Subject), SubjectS, (AnyDecision), latex_decision(ScopeCaller, Subject, AnyDecision)):-
scope_fnbody(ScopeCaller, FnCallerBody);
latex_symbol(FnCallerBody, Subject, SubjectS);
cfa_call(ScopeCaller, FnCallee);
latex_fn_demand(FnCallee, Subject);
latex_registered_subjects(Subject, AnyDecision).
% UTILITY
%===========================================================
latex_symbol(FnBody, Topic, s(TopicsOffset + TopicId, -2, FnBody)):-
cfa_parent(FnBody, function(Fn));
latex_parameters_offset(TopicsOffset);
latex_fn_demand_ordered(Fn, Topic, TopicId).
% IMPLEMENTATION
%===========================================================
scope_fnbody(Scope, Scope):-cfa_parent(Scope, function(_)).
scope_fnbody(Scope, FnBody):-
scope_fnbody(ScopeParent, FnBody);
cfa_parent(Scope, scope(ScopeParent)).
latex_parameters_offset(1000).

Event Timeline