diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/Dispatcher.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/Dispatcher.kt index 70c0876b..db2e554a 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/Dispatcher.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/Dispatcher.kt @@ -37,11 +37,11 @@ class Dispatcher (val ruleIndex: RuleIndex) { } /** - * Create new empty [DispatchFringe] ready to accept constraints. + * Create new empty [DispatchingFront] ready to accept constraints. */ - fun fringe() = DispatchFringe() + fun front() = DispatchingFront() - inner class DispatchFringe { + inner class DispatchingFront { private var ruletag2probe: PersMap @@ -54,7 +54,7 @@ class Dispatcher (val ruleIndex: RuleIndex) { } } - private constructor(pred: DispatchFringe, matching: Iterable) { + private constructor(pred: DispatchingFront, matching: Iterable) { this.ruletag2probe = pred.ruletag2probe matching.forEach { probe -> this.ruletag2probe = ruletag2probe.put(probe.rule().tag(), probe) @@ -62,7 +62,7 @@ class Dispatcher (val ruleIndex: RuleIndex) { } } - private constructor(pred: DispatchFringe, consumedMatch: RuleMatchEx) { + private constructor(pred: DispatchingFront, consumedMatch: RuleMatchEx) { this.ruletag2probe = pred.ruletag2probe pred.ruletag2probe[consumedMatch.rule().tag()]?.let { this.ruletag2probe = ruletag2probe.put(consumedMatch.rule().tag(), it.consume(consumedMatch)) @@ -75,20 +75,20 @@ class Dispatcher (val ruleIndex: RuleIndex) { fun matches() : Iterable = allMatches /** - * Returns a new [DispatchFringe] instance that is "expanded" with matches corresponding to the + * Returns a new [DispatchingFront] instance that is "expanded" with matches corresponding to the * specified active constraint occurrence. */ - fun expand(activated: Occurrence) = DispatchFringe(this, + fun expand(activated: Occurrence) = DispatchingFront(this, ruleIndex.forOccurrenceWithMask(activated).mapNotNull { (rule, mask) -> ruletag2probe[rule.tag()]?.expand(activated, mask) ruletag2probe[rule.tag()]?.expand(activated, mask) }) /** - * Returns a new [DispatchFringe] instance that is "contracted": all matches corresponding to the + * Returns a new [DispatchingFront] instance that is "contracted": all matches corresponding to the * specified discarded constraint occurrence are eliminated. */ - fun contract(discarded: Occurrence) = DispatchFringe(this, + fun contract(discarded: Occurrence) = DispatchingFront(this, ruleIndex.forOccurrence(discarded).mapNotNull { rule -> ruletag2probe[rule.tag()] }.map { probe -> @@ -99,7 +99,7 @@ class Dispatcher (val ruleIndex: RuleIndex) { * Serves to indicate that the specified [RuleMatchEx] has been processed (consumed) and has to * be excluded from any further "match" set returned by [matches]. */ - internal fun consume(matchRule: RuleMatchEx) = DispatchFringe(this, matchRule) + internal fun consume(ruleMatch: RuleMatchEx) = DispatchingFront(this, ruleMatch) } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt index 310b587f..7567d108 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt @@ -31,7 +31,7 @@ interface RuleMatchingProbe { fun matches(): Collection - fun consume(matchRule: RuleMatchEx): RuleMatchingProbe + fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe fun expand(occ: Occurrence): RuleMatchingProbe diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt index 49cd3f63..46b34b3c 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt @@ -40,7 +40,7 @@ internal class ControllerImpl ( private val session: EvaluationSession = EvaluationSession.current() - private var dispatchFringe = Dispatcher(ruleIndex).fringe() + private var dispatchFront = Dispatcher(ruleIndex).front() // FIXME move to context private val frameStack = FrameStack(storeView) @@ -87,10 +87,10 @@ internal class ControllerImpl ( trace.reactivate(active) } - val activatedFringe = dispatchFringe.expand(active) - this.dispatchFringe = activatedFringe + val activatedFront = dispatchFront.expand(active) + this.dispatchFront = activatedFront - val outState = activatedFringe.matches().toList().fold(inState) { state, match -> + val outState = activatedFront.matches().toList().fold(inState) { state, match -> // TODO: paranoid check. should be isAlive() instead // FIXME: move this check elsewhere if (state.operational && active.stored && match.allStored()) @@ -139,11 +139,11 @@ internal class ControllerImpl ( } } - this.dispatchFringe = dispatchFringe.consume(match) + this.dispatchFront = dispatchFront.consume(match) trace.trigger(match) match.forEachReplaced {occ -> - this.dispatchFringe = dispatchFringe.contract(occ) + this.dispatchFront = dispatchFront.contract(occ) frameStack.current.store.discard(occ) trace.discard(occ) } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt index 42b177fa..f042ddc2 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt @@ -348,7 +348,7 @@ internal class ReteRuleMatcherImpl(val rule: Rule) : RuleMatcher { override fun matches(): Collection = generations.last().matches() - override fun consume(matchRule: RuleMatchEx): RuleMatchingProbe { + override fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt index 921c5616..f64567b4 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt @@ -43,12 +43,12 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup, fun lookupRule(): Rule = ruleLookup.lookupRuleByTag(tag) ?: throw IllegalStateException("can't lookup rule by tag: '${tag}'") override fun probe(): RuleMatchingProbe = - RuleMatchFringe(listOf(MatchNode(emptySubst())), + RuleMatchFront(listOf(MatchNode(emptySubst())), Sets.of(), Sets.of(), 0) - inner class RuleMatchFringe(private val nodes: List, + inner class RuleMatchFront(private val nodes: List, private val seenOccurrences: PersSet>, private val consumedSignatures: PersSet?>>, private val genId: Int) : RuleMatchingProbe @@ -58,22 +58,22 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup, override fun matches(): Collection = nodes .filter { it is ActiveMatchNode && it.complete && it.genId == genId } - .map { (it as ActiveMatchNode).toMatchRule() } + .map { (it as ActiveMatchNode).toRuleMatch() } - override fun consume(matchRule: RuleMatchEx): RuleMatchingProbe = - RuleMatchFringe(nodes, + override fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe = + RuleMatchFront(nodes, seenOccurrences, - consumedSignatures.add(matchRule.signature()), + consumedSignatures.add(ruleMatch.signature()), genId) override fun expand(occ: Occurrence): RuleMatchingProbe = expand(occ, bitSetOfOnes(head.size)) /** - * Expands the fringe by creating new leaf nodes that match the occurrence. + * Expands the front by creating new leaf nodes that match the occurrence. * Mask specifies possible slots for the occurrence. */ - override fun expand(occ: Occurrence, mask: BitSet): RuleMatchFringe { + override fun expand(occ: Occurrence, mask: BitSet): RuleMatchFront { val reactivated = seenOccurrences.contains(IdWrapper(occ)) val newSeen = if (reactivated) seenOccurrences else seenOccurrences.add(IdWrapper(occ)) val newNodes = ArrayList(nodes) @@ -86,12 +86,12 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup, .forEach { newNodes.add(it) } } - return RuleMatchFringe(newNodes, newSeen, consumedSignatures, genId + 1) + return RuleMatchFront(newNodes, newSeen, consumedSignatures, genId + 1) } - override fun contract(occ: Occurrence): RuleMatchFringe { + override fun contract(occ: Occurrence): RuleMatchFront { val newNodes = nodes.mapNotNull { it.unrelatedOrNull(occ) } - return RuleMatchFringe(newNodes, seenOccurrences, consumedSignatures, genId + 1) + return RuleMatchFront(newNodes, seenOccurrences, consumedSignatures, genId + 1) } } @@ -171,7 +171,7 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup, foldUntilNull(this) { acc, rn -> if (rn.occurrence === occ) null else acc } - fun toMatchRule(): RuleMatchImpl { + fun toRuleMatch(): RuleMatchImpl { val matched: Array = fold(arrayOfNulls(head.size)) { arr, rn -> arr[rn.headIndex] = rn.occurrence; arr diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationTrace.java b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationTrace.java index 0f3b5b13..62139ff4 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationTrace.java +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationTrace.java @@ -36,15 +36,15 @@ public interface EvaluationTrace { default void discard(ConstraintOccurrence occurrence) {} - default void trying(RuleMatch matchRule) {} + default void trying(RuleMatch ruleMatch) {} - default void reject(RuleMatch matchRule) {} + default void reject(RuleMatch ruleMatch) {} - default void trigger(RuleMatch matchRule) {} + default void trigger(RuleMatch ruleMatch) {} - default void retry(RuleMatch matchRule) {} + default void retry(RuleMatch ruleMatch) {} - default void finish(RuleMatch matchRule) {} + default void finish(RuleMatch ruleMatch) {} default void tell(PredicateInvocation invocation) {} diff --git a/reactor/Test/test/TestRuleMatcher.kt b/reactor/Test/test/TestRuleMatcher.kt index 142978ec..6551f4dd 100644 --- a/reactor/Test/test/TestRuleMatcher.kt +++ b/reactor/Test/test/TestRuleMatcher.kt @@ -545,7 +545,7 @@ class TestRuleMatcher { constraint("qux") )))) { - with(Dispatcher(RuleIndex(handlers)).fringe()) { + with(Dispatcher(RuleIndex(handlers)).front()) { expand(occurrence("foo")) }.apply { matches().count() shouldBe 0 }.run { @@ -587,7 +587,7 @@ class TestRuleMatcher { constraint("qux") )))) { - with(Dispatcher(RuleIndex(handlers)).fringe()) { + with(Dispatcher(RuleIndex(handlers)).front()) { expand(occurrence("foo")) }.apply { matches().count() shouldBe 0 }.run { @@ -656,7 +656,7 @@ class TestRuleMatcher { constraint("qux") )))) { - with(Dispatcher(RuleIndex(handlers)).fringe()) { + with(Dispatcher(RuleIndex(handlers)).front()) { expand(occurrence("blin")) }.apply { matches().count() shouldBe 0 }.run { @@ -706,7 +706,7 @@ class TestRuleMatcher { constraint("qux") )))) { - with(Dispatcher(RuleIndex(handlers)).fringe()) { + with(Dispatcher(RuleIndex(handlers)).front()) { expand(occurrence("foo")) }.apply { matches().count() shouldBe 0 }.run { @@ -759,7 +759,7 @@ class TestRuleMatcher { )))) { val bar = occurrence("bar") - with(Dispatcher(RuleIndex(handlers)).fringe()) { + with(Dispatcher(RuleIndex(handlers)).front()) { expand(occurrence("foo")) }.apply { matches().count() shouldBe 0 }.run {