File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
src/main/kotlin/at/ac/uibk/dps/cirrina/execution/object Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 11package at.ac.uibk.dps.cirrina.execution.`object`
22
3- class Extent private constructor(private val contexts : Array <Context >) {
3+ class Extent
4+ private constructor (
5+ private val contexts: Array <Context >,
6+ private val overlay: Map <String , Any ?> = emptyMap(),
7+ ) {
48 val high: Context ? = contexts.lastOrNull()
59
610 fun setOrCreate (name : String , value : Any? ): Int =
@@ -12,13 +16,16 @@ class Extent private constructor(private val contexts: Array<Context>) {
1216 ? : error(" variable '$name ' not found in any context" )
1317
1418 fun resolve (name : String ): Any =
15- contexts.lastOrNull { it.has(name) }?.get(name)
19+ overlay[name]
20+ ? : contexts.lastOrNull { it.has(name) }?.get(name)
1621 ? : error(" variable '$name ' not found in any context" )
1722
18- fun has (name : String ): Boolean = contexts.any { it.has(name) }
23+ fun has (name : String ): Boolean = name in overlay || contexts.any { it.has(name) }
1924
2025 fun extend (high : Context ): Extent = Extent (contexts + high)
2126
27+ fun with (overlay : Map <String , Any ?>): Extent = Extent (contexts, overlay)
28+
2229 companion object {
2330 fun empty () = Extent (emptyArray())
2431
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import TimeoutActionManager
44import at.ac.uibk.dps.cirrina.Runtime
55import at.ac.uibk.dps.cirrina.csm.Csml.EventChannel
66import at.ac.uibk.dps.cirrina.execution.`object`.StateMachine.Factory
7- import at.ac.uibk.dps.cirrina.execution.provider.ContextInMemory
87import at.ac.uibk.dps.cirrina.spec.Instance
98import at.ac.uibk.dps.cirrina.spec.StateMachine as StateMachineSpec
109import at.ac.uibk.dps.cirrina.spec.Transition as TransitionSpec
@@ -140,11 +139,7 @@ internal constructor(
140139 if (candidates.isEmpty()) return null
141140
142141 val evalExtent =
143- activeState!!
144- .extent
145- .extend(
146- ContextInMemory ().apply { event.data.forEach { create(VAR_PREFIX + it.name, it.value) } }
147- )
142+ activeState!! .extent.with (event.data.associate { VAR_PREFIX + it.name to it.value })
148143
149144 return trySelect(candidates, evalExtent)?.also {
150145 event.data.forEach { d -> extent.setOrCreate(VAR_PREFIX + d.name, d.value) }
You can’t perform that action at this time.
0 commit comments