PrologExecutionContext

data class PrologExecutionContext(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: PrologExecutionContext? = null, val depth: Int = 0, val step: Long = 0, val relevantGoals: RelevantGoals? = null, val trimmedSize: Int = 0, val inlined: Boolean = false, val scoped: Boolean = false, val theoryIndexes: TheoryIndexes = TheoryIndexes()) : ExecutionContext

One frame of the :solve-prolog 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.argumentation.core.engine.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.argumentation.core.engine.fsm.createChild); finishing a context's goals pops back to its parent in it.unibo.tuprolog.argumentation.core.engine.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 prolog engine are:

  • query/goals: the original query, and the cursor over the goals still to be proven in this frame.

  • rules/primitives: the still-untried candidate clauses/primitive responses for the current goal, i.e. the frame's own view of the choicePoints entry recorded for it (if any).

  • choicePoints: the head of the choice-point queue as seen from this frame -- see ChoicePointContext.

  • parent/depth: the enclosing frame and this frame's distance from the root (depth == 0, isRoot).

  • step: a monotonically increasing counter of state-machine transitions, used to keep PrologSolver's currentContext in sync with resolution progress and to detect it.unibo.tuprolog.solve.exception.TimeOutExceptions.

  • relevantGoals: the goals selected so far in this frame, whose variables are still of interest, used to trim substitutions of variables local to a finished sub-goal when popping back to parent (see isVariableInteresting); trimmedSize is the size of the substitution when it was last trimmed.

  • inlined: whether this frame solves the goal of an Inlining, against libraries of its own; scoped: whether this frame or one above does (so that its libraries are not the ones of the whole resolution).

  • theoryIndexes: the indexes of the immutable theories, kept by the solver and shared with the solvers the resolution creates (see TheoryIndexes).

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: PrologExecutionContext? = null, depth: Int = 0, step: Long = 0, relevantGoals: RelevantGoals? = null, trimmedSize: Int = 0, inlined: Boolean = false, scoped: Boolean = false, theoryIndexes: TheoryIndexes = TheoryIndexes())

Properties

Link copied to clipboard
Link copied to clipboard
val currentGoal: Term?

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
open val elapsedTime: TimeDuration
Link copied to clipboard
open val endTime: TimeInstant
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
Link copied to clipboard
open override val inputChannels: InputStore
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 (arg2p: built when needed, rather than for each of the contexts, one or more per resolution step).

Link copied to clipboard
val primitives: Cursor<out Solve.Response>
Link copied to clipboard
open override val procedure: Struct?
Link copied to clipboard
val query: Struct
Link copied to clipboard
Link copied to clipboard
open val remainingTime: TimeDuration
Link copied to clipboard
val rules: Cursor<out Rule>
Link copied to clipboard
Link copied to clipboard
open val standardError: OutputChannel<String>
Link copied to clipboard
open val standardInput: InputChannel<String>
Link copied to clipboard
open val standardOutput: OutputChannel<String>
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
open override val substitution: Substitution.Unifier
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val unificator: Unificator
Link copied to clipboard
open val warnings: OutputChannel<Warning>

Functions

Link copied to clipboard

Records a it.unibo.tuprolog.argumentation.core.engine.ChoicePointContext.Rules onto PrologExecutionContext.choicePoints whose alternatives resolve the current goal of this context on backtracking (arg2p): for the frames whose first alternative is not a clause (see ControlConstruct)

Link copied to clipboard

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

Link copied to clipboard
open override fun apply(sideEffect: SideEffect): PrologExecutionContext
open override fun apply(sideEffects: Iterable<SideEffect>): PrologExecutionContext
open override fun apply(sideEffects: Sequence<SideEffect>): PrologExecutionContext
Link copied to clipboard
fun PrologExecutionContext.createChild(currentGoal: Struct = this.currentGoal!!.castToStruct()): PrologExecutionContext

Pushes a new child frame onto the execution-context stack for the current goal, becoming its own PrologExecutionContext.goals (arg2p: currentGoal is the current goal with the substitution applied, when the caller already has it)

Link copied to clipboard
fun PrologExecutionContext.createChildAppendingRulesAndChoicePoints(rules: Cursor<out Rule>, currentGoal: Struct = this.currentGoal!!.castToStruct()): PrologExecutionContext

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
fun isVariableInteresting(variable: Var): Boolean

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

Link copied to clipboard
fun PrologExecutionContext.replaceWithChild(currentGoal: Struct = this.currentGoal!!.castToStruct()): PrologExecutionContext

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

fun PrologExecutionContext.replaceWithChildAppendingRulesAndChoicePoints(rules: Cursor<out Rule>, currentGoal: Struct = this.currentGoal!!.castToStruct()): PrologExecutionContext

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

Link copied to clipboard
fun PrologExecutionContext.skipThrow(): ExecutionContext

The context an error raised in this one is reported in: the nearest one that is not throw/1

Link copied to clipboard
fun PrologExecutionContext.toRequest(goal: Struct, signature: Signature, startTime: TimeInstant): Solve.Request<PrologExecutionContext>

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): PrologExecutionContext