Implementing EvaluationSession
This commit is contained in:
parent
50332e1e56
commit
e07f608b04
|
|
@ -2,9 +2,11 @@
|
|||
<library name="org.jetbrains.kotlin:kotlin-runtime:1.0.0-beta-2423" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-runtime:1.0.0-beta-2423" />
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../../../DotFolder/M2/repository/org/jetbrains/kotlin/kotlin-runtime/1.0.0-beta-2423/kotlin-runtime-1.0.0-beta-2423.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-runtime/1.0.0-beta-2423/kotlin-runtime-1.0.0-beta-2423.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<SOURCES>
|
||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-runtime-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="API" exported="" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="org.jetbrains.kotlin:kotlin-runtime:1.0.0-beta-2423" level="project" />
|
||||
<orderEntry type="library" name="org.jetbrains.kotlin:kotlin-runtime:1.0.0-beta-2423" level="project" />
|
||||
<orderEntry type="library" name="com.intellij:annotations:12.0" level="project" />
|
||||
<orderEntry type="library" name="com.github.andrewoma.dexx:dexx-collections:0.2" level="project" />
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import jetbrains.mps.logic.reactor.constraint.*
|
||||
import jetbrains.mps.logic.reactor.predicate.ReactorSessionSolver
|
||||
import jetbrains.mps.logic.reactor.program.EvaluationSession
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
|
||||
private class ReactorEvaluationSession(val sessionSolver: SessionSolver) : EvaluationSession() {
|
||||
|
||||
class Config : EvaluationSession.Config() {
|
||||
|
||||
val myPredicateSymbols = ArrayList<PredicateSymbol>()
|
||||
val myParameters = HashMap<String, Any?>()
|
||||
var myComputingTracer : ComputingTracer? = null
|
||||
|
||||
override fun withPredicates(vararg predicateSymbols: PredicateSymbol): EvaluationSession.Config {
|
||||
myPredicateSymbols.addAll(Arrays.asList(* predicateSymbols))
|
||||
return this
|
||||
}
|
||||
|
||||
override fun withTrace(computingTracer: ComputingTracer?): EvaluationSession.Config {
|
||||
myComputingTracer = computingTracer
|
||||
return this
|
||||
}
|
||||
|
||||
override fun withParam(key: String, param: Any?): EvaluationSession.Config {
|
||||
myParameters.put(key, param)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun start(): EvaluationSession {
|
||||
var session = ourBackend.ourSession.get()
|
||||
if (session != null) throw IllegalStateException("session already active")
|
||||
|
||||
val predicateSymbols = myPredicateSymbols.toArray<PredicateSymbol>(arrayOfNulls(myPredicateSymbols.size))
|
||||
val sessionSolver = ReactorSessionSolver()
|
||||
sessionSolver.init(myComputingTracer, * predicateSymbols)
|
||||
|
||||
session = ReactorEvaluationSession(sessionSolver)
|
||||
ourBackend.ourSession.set(session)
|
||||
return session
|
||||
}
|
||||
}
|
||||
|
||||
override fun sessionSolver(): SessionSolver? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun constraintSymbols(): MutableIterable<ConstraintSymbol>? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun constraintOccurrences(): MutableIterable<ConstraintOccurrence>? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun constraintOccurrences(symbol: ConstraintSymbol?): MutableIterable<ConstraintOccurrence>? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
private class Backend : EvaluationSession.Backend {
|
||||
|
||||
val ourSession = ThreadLocal<ReactorEvaluationSession>()
|
||||
|
||||
override fun current(): EvaluationSession = ourSession.get() ?: throw IllegalStateException("no session")
|
||||
|
||||
override fun createConfig(): EvaluationSession.Config = Config()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ourBackend = Backend()
|
||||
|
||||
fun init() {
|
||||
setBackend(ourBackend)
|
||||
}
|
||||
|
||||
fun deinit () {
|
||||
clearBackend(ourBackend)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package jetbrains.mps.logicl.reactor.core
|
||||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
/**
|
||||
* @author Fedor Isakov
|
||||
|
|
@ -12,15 +12,16 @@ import java.util.*
|
|||
import java.util.Collections.*
|
||||
|
||||
|
||||
class ReactorPlanningSession(val name: String) : PlanningSession() {
|
||||
class ReactorPlanningSession(val name: String, val sessionSolver: SessionSolver) : PlanningSession() {
|
||||
|
||||
class FactoryImpl : PlanningSession.Factory {
|
||||
override fun create(name: String): PlanningSession = ReactorPlanningSession(name)
|
||||
class FactoryImpl : Factory {
|
||||
override fun create(name: String, sessionSolver: SessionSolver): PlanningSession =
|
||||
ReactorPlanningSession(name, sessionSolver)
|
||||
}
|
||||
|
||||
private val myRules = ArrayList<Rule>()
|
||||
|
||||
private val myRegistry = ConstraintRegistry()
|
||||
private val myRegistry = ConstraintRegistry(sessionSolver)
|
||||
|
||||
override fun name(): String = name
|
||||
|
||||
|
|
@ -61,9 +62,10 @@ class ReactorPlanningSession(val name: String) : PlanningSession() {
|
|||
clearFactory(ourFactory)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ConstraintRegistry {
|
||||
private class ConstraintRegistry(val sessionSolver: SessionSolver) {
|
||||
|
||||
private val myConstraintArgTypes = HashMap<ConstraintSymbol, List<Class<*>>>()
|
||||
|
||||
|
|
@ -93,7 +95,7 @@ private class ConstraintRegistry {
|
|||
}
|
||||
}
|
||||
}
|
||||
is Predicate -> {
|
||||
is Predicate -> {
|
||||
// nothing
|
||||
}
|
||||
else -> throw InvalidConstraintException("unknown item: ${item}")
|
||||
|
|
@ -103,7 +105,7 @@ private class ConstraintRegistry {
|
|||
fun introduce(item: AndItem) {
|
||||
when(item) {
|
||||
is Constraint -> myConstraintArgTypes.put(item.symbol(), item.argumentTypes())
|
||||
is Predicate -> myPredicateSolvers.put(item.symbol(), item.solverClass())
|
||||
is Predicate -> myPredicateSolvers.put(item.symbol(), sessionSolver.solverClass(item.symbol()))
|
||||
else -> throw InvalidConstraintException("unknown item: ${item}")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package jetbrains.mps.logic.reactor.predicate
|
||||
|
||||
import jetbrains.mps.logic.reactor.constraint.*
|
||||
|
||||
/**
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
class ReactorSessionSolver : SessionSolver() {
|
||||
|
||||
override fun solverClass(predicateSymbol: PredicateSymbol?): Class<out Queryable>? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override fun registerSymbol(predicateSymbol: PredicateSymbol, computingTracer: ComputingTracer?) {
|
||||
when (predicateSymbol) {
|
||||
|
||||
}
|
||||
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import jetbrains.mps.logic.reactor.program.PlanningSession
|
||||
import jetbrains.mps.logic.reactor.rule.InvalidConstraintException
|
||||
import jetbrains.mps.logic.reactor.rule.InvalidRuleException
|
||||
import jetbrains.mps.logicl.reactor.core.ReactorPlanningSession
|
||||
import jetbrains.mps.logic.reactor.core.ReactorPlanningSession
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
|
|
@ -23,12 +23,11 @@ class Simple {
|
|||
}
|
||||
|
||||
@Before fun beforeTest() {
|
||||
session = PlanningSession.newSession("test")
|
||||
session = PlanningSession.newSession("test", null)
|
||||
}
|
||||
|
||||
lateinit var session:PlanningSession
|
||||
|
||||
|
||||
@Test fun empty() {
|
||||
session.addRules(ArrayList())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue