Skip to content

Commit

Permalink
handle primitives side effects in classic FSM
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jun 23, 2020
1 parent a7ba467 commit e60f7a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ data class ClassicExecutionContext(
)
}

override fun apply(sideEffect: SideEffect): ClassicExecutionContext {
return super.apply(sideEffect) as ClassicExecutionContext
}

override fun apply(sideEffects: Iterable<SideEffect>): ClassicExecutionContext {
return super.apply(sideEffects) as ClassicExecutionContext
}

override fun apply(sideEffects: Sequence<SideEffect>): ClassicExecutionContext {
return super.apply(sideEffects) as ClassicExecutionContext
}

override fun toString(): String {
return "ClassicExecutionContext(" +
"query=$query, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ import it.unibo.tuprolog.utils.Cursor

internal data class StatePrimitiveExecution(override val context: ClassicExecutionContext) : AbstractState(context) {

private fun ClassicExecutionContext.copyFromCurrentPrimitive(goals: Cursor<out Term>? = null,
parentProcedure: Boolean = false,
substitution: Substitution? = null): ClassicExecutionContext {
return copy(
private fun ClassicExecutionContext.copyFromCurrentPrimitive(
goals: Cursor<out Term>? = null,
parentProcedure: Boolean = false,
substitution: Substitution? = null
): ClassicExecutionContext {
val ctx = primitives.current?.let { apply(it.sideEffects) } ?: this
return ctx.copy(
goals = goals ?: this.goals,
procedure = if (parentProcedure) parent?.procedure else procedure,
primitives = Cursor.empty(),
libraries = primitives.current?.libraries ?: libraries,
flags = primitives.current?.flags ?: flags,
staticKb = primitives.current?.staticKb ?: staticKb,
dynamicKb = primitives.current?.dynamicKb ?: dynamicKb,
operators = primitives.current?.operators ?: operators,
inputChannels = primitives.current?.inputChannels ?: inputChannels,
outputChannels = primitives.current?.outputChannels ?: outputChannels,
substitution = (substitution ?: this.substitution) as Substitution.Unifier,
step = nextStep()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ sealed class Solve {
) = Response(
Solution.Yes(query, substitution),
sideEffectManager,
*sideEffects
*sideEffects
)

/** Creates a new failed [Response] to this Request */
Expand Down

0 comments on commit e60f7a0

Please sign in to comment.