Permalink
Browse files

Added interpreter support and tests for targetless transitions (a.k.a…

…. static reactions, described in statemate/rhapsody).
  • Loading branch information...
1 parent 558be15 commit c729cb768fe8c7606364171fa45c0b726eea093a @jbeard4 committed Feb 20, 2012
@@ -138,8 +138,11 @@ define ["util/set/ArraySet","scxml/state-kinds-enum","scxml/event","util/reduce"
if @opts.printTrace then logger.trace("sorted transitions: ", selectedTransitions)
- [basicStatesExited,statesExited] = @_getStatesExited(selectedTransitions)
- [basicStatesEntered,statesEntered] = @_getStatesEntered(selectedTransitions)
+ #we only want to enter and exit states from transitions with targets
+ #filter out targetless transitions here - we will only use these to execute transition actions
+ selectedTransitionsWithTargets = new @opts.TransitionSet (t for t in selectedTransitions.iter() when t.targets)
+ [basicStatesExited,statesExited] = @_getStatesExited selectedTransitionsWithTargets
+ [basicStatesEntered,statesEntered] = @_getStatesEntered selectedTransitionsWithTargets
if @opts.printTrace then logger.trace("basicStatesExited " , basicStatesExited)
if @opts.printTrace then logger.trace("basicStatesEntered " , basicStatesEntered)
@@ -434,11 +437,13 @@ define ["util/set/ArraySet","scxml/state-kinds-enum","scxml/event","util/reduce"
#this would be parameterizable
# -> Transition Consistency: Small-step consistency: Source/Destination Orthogonal
# -> Interrupt Transitions and Preemption: Non-preemptive
- _conflicts: (t1,t2) -> not @_isArenaOrthogonal(t1,t2)
+ _conflicts: (t1,t2) -> not @_isArenaOrthogonal t1,t2
_isArenaOrthogonal: (t1,t2) ->
- t1LCA = @opts.model.getLCA(t1)
- t2LCA = @opts.model.getLCA(t2)
+ #if {t1,t2}.targets is blank, then t1 and t2 are targetless transitions, a.k.a. "static reactions" in statemate/rhapsody vocabulary
+ #we treat their source state as the arena
+ t1LCA = if t1.targets then @opts.model.getLCA(t1) else t1.source
+ t2LCA = if t2.targets then @opts.model.getLCA(t2) else t2.source
isOrthogonal = @opts.model.isOrthogonalTo t1LCA,t2LCA
if @opts.printTrace
logger.trace "transition LCAs",t1LCA.id,t2LCA.id
@@ -97,7 +97,7 @@ define ["scxml/model"],(model) ->
for t in state.transitions
t.source = idToStateMap[t.source]
- t.targets = (idToStateMap[stateId] for stateId in t.targets)
+ t.targets = t.targets and (idToStateMap[stateId] for stateId in t.targets)
json.root = idToStateMap[json.root]
@@ -101,7 +101,7 @@ define ["scxml/state-kinds-enum"],(stateKinds) ->
#generate LCAs on transitions
if genLCA
- for transition in transitions
+ for transition in transitions when transition.targets
source = idToStateMap[transition.source]
targets = (idToStateMap[target] for target in transition.targets)
if not source
@@ -153,6 +153,7 @@ define ["scxml/state-kinds-enum"],(stateKinds) ->
attributes = n1
children = node[2..]
else
+ attributes = {}
children = node[1..]
if filterText
@@ -163,7 +164,7 @@ define ["scxml/state-kinds-enum"],(stateKinds) ->
transformTransitionNode = (transitionNode,parentState,genDepth,genAncestors,genDescendants,genLCA) ->
[tagName,attributes,children] = deconstructNode transitionNode,true
- if attributes.event then uniqueEvents[attributes.event] = true #track unique events
+ if attributes?.event then uniqueEvents[attributes.event] = true #track unique events
transition =
documentOrder : transitions.length
@@ -172,7 +173,7 @@ define ["scxml/state-kinds-enum"],(stateKinds) ->
cond : attributes.cond
event : attributes.event
actions : (transformActionNode child for child in children)
- targets : attributes.target.trim().split(/\s+/)
+ targets : attributes?.target?.trim().split(/\s+/) #this will either be a list, or undefined
transitions.push transition
@@ -0,0 +1,12 @@
+{
+ "initialConfiguration" : ["a"],
+ "events" : [
+ {
+ "event" : { "name" : "t" },
+ "nextConfiguration" : ["done"]
+ }
+ ]
+}
+
+
+
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<scxml
+ xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ profile="ecmascript">
+
+ <datamodel>
+ <data id="i" expr="0"/>
+ </datamodel>
+
+ <state id="a">
+ <transition target="b" event="t"/>
+ </state>
+
+ <state id="b">
+ <transition target="done" cond="i === 100"/>
+ <transition>
+ <assign location="i" expr="i + 1"/>
+ </transition>
+ </state>
+
+ <state id="done"/>
+
+</scxml>
@@ -0,0 +1,17 @@
+{
+ "initialConfiguration" : ["a"],
+ "events" : [
+ {
+ "event" : { "name" : "foo" },
+ "nextConfiguration" : ["a"]
+ },
+ {
+ "event" : { "name" : "bar" },
+ "nextConfiguration" : ["done"]
+ }
+ ]
+}
+
+
+
+
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<scxml
+ xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ profile="ecmascript">
+
+ <datamodel>
+ <data id="i" expr="1"/>
+ </datamodel>
+
+ <state id="A">
+ <transition event="foo">
+ <assign location="i" expr="i * 2"/>
+ </transition>
+
+ <state id="a">
+ <transition event="bar">
+ <assign location="i" expr="Math.pow(i,3)"/>
+ </transition>
+ </state>
+
+ <transition target="done" cond="i === 8"/>
+ </state>
+
+ <state id="done"/>
+
+</scxml>
+
@@ -0,0 +1,18 @@
+{
+ "initialConfiguration" : ["a"],
+ "events" : [
+ {
+ "event" : { "name" : "foo" },
+ "nextConfiguration" : ["a"]
+ },
+ {
+ "event" : { "name" : "bar" },
+ "nextConfiguration" : ["done"]
+ }
+ ]
+}
+
+
+
+
+
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<scxml
+ xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ profile="ecmascript">
+
+ <datamodel>
+ <data id="i" expr="1"/>
+ </datamodel>
+
+ <state id="A">
+ <transition event="foo">
+ <assign location="i" expr="i * 2"/>
+ </transition>
+ <transition event="bar">
+ <assign location="i" expr="Math.pow(i,3)"/>
+ </transition>
+
+ <state id="a">
+ <transition event="foo">
+ <assign location="i" expr="i + 2"/>
+ </transition>
+ </state>
+
+ <transition target="done" cond="i === 27"/>
+ </state>
+
+ <state id="done"/>
+
+</scxml>
+
+
@@ -0,0 +1,19 @@
+{
+ "initialConfiguration" : ["a1","b1","c"],
+ "events" : [
+ {
+ "event" : { "name" : "foo" },
+ "nextConfiguration" : ["a2","b2","c"]
+ },
+ {
+ "event" : { "name" : "bar" },
+ "nextConfiguration" : ["done"]
+ }
+ ]
+}
+
+
+
+
+
+
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<scxml
+ xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ profile="ecmascript">
+
+ <datamodel>
+ <data id="i" expr="1"/>
+ </datamodel>
+
+ <parallel id="p">
+
+ <transition target="done" cond="i === 100"/>
+
+ <transition event="bar">
+ <assign location="i" expr="i * 20"/>
+ <log expr="i"/>
+ </transition>
+
+ <state id="a">
+ <state id="a1">
+ <transition event="foo" target="a2">
+ <assign location="i" expr="i * 2"/>
+ <log expr="i"/>
+ </transition>
+ </state>
+
+ <state id="a2">
+ </state>
+ </state>
+
+ <state id="b">
+ <state id="b1">
+ <transition event="foo" target="b2">
+ <assign location="i" expr="Math.pow(i,3)"/>
+ <log expr="i"/>
+ </transition>
+ </state>
+
+ <state id="b2">
+ </state>
+ </state>
+
+ <state id="c">
+ <transition event="foo">
+ <assign location="i" expr="i - 3"/>
+ <log expr="i"/>
+ </transition>
+ </state>
+
+ </parallel>
+
+ <state id="done"/>
+
+</scxml>
+
+
+

0 comments on commit c729cb7

Please sign in to comment.