ClassicExecutionContext

data class ClassicExecutionContext(val procedure: Struct? = null, val unificator: Unificator = Unificator.default, val libraries: Runtime = Runtime.empty(), val flags: FlagStore = FlagStore.empty(), val staticKb: Theory = Theory.empty(unificator), val dynamicKb: MutableTheory = MutableTheory.empty(unificator), val operators: OperatorSet = getAllOperators(libraries, staticKb, dynamicKb).toOperatorSet(), val inputChannels: InputStore = InputStore.fromStandard(), val outputChannels: OutputStore = OutputStore.fromStandard(), val customData: CustomDataStore = CustomDataStore.empty(), val substitution: Substitution.Unifier = Substitution.empty(), val query: Struct = Truth.TRUE, val goals: Cursor<out Term> = Cursor.empty(), val rules: Cursor<out Rule> = Cursor.empty(), val primitives: Cursor<out Solve.Response> = Cursor.empty(), val startTime: TimeInstant, val maxDuration: TimeDuration = TimeDuration.MAX_VALUE, val choicePoints: ChoicePointContext? = null, val parent: ClassicExecutionContext? = null, val depth: Int = 0, val step: Long = 0, val relevantVariables: Set<Var> = emptySet()) : ExecutionContext

One frame of the :solve-classic execution-context stack: a substitution, the streams of remaining goals, candidate Rules and candidate primitive responses, plus a parent link. Frames chain into their parent rather than living in a separate stack container, so the parent chain (see pathToRoot) is the call stack -- ordinary heap-allocated data rather than native JVM/JS stack frames, which is what lets Prolog resolution of arbitrarily deep recursive programs run as an explicit, non-recursive it.unibo.tuprolog.solve.classic.fsm.State loop instead of unbounded host-language recursion.

Resolving a sub-goal (a primitive call or a rule body) pushes a new context whose parent is the current one (see it.unibo.tuprolog.solve.classic.fsm.createChild); finishing a context's goals pops back to its parent in it.unibo.tuprolog.solve.classic.fsm.StateGoalSelection. Every instance also threads through choicePoints, the sibling data structure (see ChoicePointContext) recording still-open backtracking alternatives.

Most fields mirror it.unibo.tuprolog.solve.ExecutionContext; the ones specific to the classic engine are:

Throws

if depth and parent are inconsistent (depth == 0 iff parent == null), or if startTime or maxDuration are negative.

Constructors

Link copied to clipboard
constructor(procedure: Struct? = null, unificator: Unificator = Unificator.default, libraries: Runtime = Runtime.empty(), flags: FlagStore = FlagStore.empty(), staticKb: Theory = Theory.empty(unificator), dynamicKb: MutableTheory = MutableTheory.empty(unificator), operators: OperatorSet = getAllOperators(libraries, staticKb, dynamicKb).toOperatorSet(), inputChannels: InputStore = InputStore.fromStandard(), outputChannels: OutputStore = OutputStore.fromStandard(), customData: CustomDataStore = CustomDataStore.empty(), substitution: Substitution.Unifier = Substitution.empty(), query: Struct = Truth.TRUE, goals: Cursor<out Term> = Cursor.empty(), rules: Cursor<out Rule> = Cursor.empty(), primitives: Cursor<out Solve.Response> = Cursor.empty(), startTime: TimeInstant, maxDuration: TimeDuration = TimeDuration.MAX_VALUE, choicePoints: ChoicePointContext? = null, parent: ClassicExecutionContext? = null, depth: Int = 0, step: Long = 0, relevantVariables: Set<Var> = emptySet())

Properties

Link copied to clipboard
Link copied to clipboard

The current goals entry with substitution already applied, or null if there is none left to prove.

Link copied to clipboard
open override val customData: CustomDataStore
Link copied to clipboard
val depth: Int
Link copied to clipboard
open override val dynamicKb: MutableTheory
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val flags: FlagStore
Link copied to clipboard
val goals: Cursor<out Term>
Link copied to clipboard

Whether choicePoints (or any of its ancestors) still has an alternative to backtrack into.

Link copied to clipboard
open override val inputChannels: InputStore
Link copied to clipboard

Whether this frame corresponds to an actual procedure call, i.e. should appear in logicStackTrace.

Link copied to clipboard

Whether this is the outermost frame of a resolution (i.e. it has no parent).

Link copied to clipboard
open override val libraries: Runtime
Link copied to clipboard
open override val logicStackTrace: List<Struct>
Link copied to clipboard
open override val maxDuration: TimeDuration
Link copied to clipboard
open override val operators: OperatorSet
Link copied to clipboard
open override val outputChannels: OutputStore
Link copied to clipboard
Link copied to clipboard

This frame and all its ancestors, from here up to (and including) the root, in that order.

Link copied to clipboard
Link copied to clipboard
open override val procedure: Struct?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val rules: Cursor<out Rule>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val startTime: TimeInstant
Link copied to clipboard
open override val staticKb: Theory
Link copied to clipboard
val step: Long
Link copied to clipboard
Link copied to clipboard
open override val unificator: Unificator
Link copied to clipboard

Functions

Link copied to clipboard

Attaches rules as this context's ClassicExecutionContext.rules cursor and records a matching it.unibo.tuprolog.solve.classic.ChoicePointContext.Rules onto ClassicExecutionContext.choicePoints, so the remaining candidates (if any) can be retried later on backtracking.

Link copied to clipboard
open override fun apply(sideEffect: SideEffect): ClassicExecutionContext
open override fun apply(sideEffects: Iterable<SideEffect>): ClassicExecutionContext
open override fun apply(sideEffects: Sequence<SideEffect>): ClassicExecutionContext
Link copied to clipboard

Pushes a new child frame onto the execution-context stack for the current goal, becoming its own ClassicExecutionContext.goals.

Combines createChild and appendPrimitivesAndChoicePoints: how StatePrimitiveSelection moves into a primitive call.

Link copied to clipboard

Combines createChild and appendRulesAndChoicePoints: the usual way StateRuleSelection moves into a non-tail rule call.

Link copied to clipboard
open override fun createMutableSolver(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, inputChannels: InputStore, outputChannels: OutputStore): MutableSolver
Link copied to clipboard
open override fun createSolver(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, inputChannels: InputStore, outputChannels: OutputStore): Solver
Link copied to clipboard

Whether variable is still relevant to this frame or any of its ancestors (i.e. is in relevantVariables, or occurs in this frame's currentGoal or query, or in an ancestor's). Used when popping a finished frame back to its parent (in it.unibo.tuprolog.solve.classic.fsm.StateGoalSelection) to filter the substitution handed up, discarding bindings for variables local to the finished sub-goal.

Link copied to clipboard

Last-call-optimization counterpart of createChild: reuses the current frame for the current goal (incrementing ClassicExecutionContext.depth without growing the ClassicExecutionContext.parent chain), used by StateRuleSelection for tail calls to avoid an unbounded execution-context stack.

Combines replaceWithChild and appendRulesAndChoicePoints: how StateRuleSelection moves into a last-call-optimized (tail) rule call.

Link copied to clipboard

Builds the Solve.Request passed to a Primitive's solve from this context, goal and signature, at startTime.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun update(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, operators: OperatorSet, inputChannels: InputStore, outputChannels: OutputStore, customData: CustomDataStore): ClassicExecutionContext