Skip to content
Browse files

Updated interpreter and optimizations to support scxml prefix name ma…

…tching.
  • Loading branch information...
1 parent 85f7baa commit 9edc430f4de060069d406c9e78f58f3f0691a2da @jbeard4 committed Feb 21, 2012
View
25 src/main/coffeescript/optimization/class.coffee
@@ -29,7 +29,7 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
if transitionsForEvent.length
classStr += """
this['#{event.name}'] = function(evaluator){
- var toReturn = []
+ var toReturn = [];
var transitions = #{initializer.arrayToIdentifierListString transitionsForEvent};
for(var i = 0,l=transitions.length; i < l; i++){
var transition = transitions[i];
@@ -39,14 +39,14 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
}
return toReturn.length ? toReturn : #{if state.parent then "instances['#{state.parent.id}']['#{event.name}'](evaluator)" else "null"};
- }
+ };
"""
defaultTransitionsForEvent = (initializer.transitionToVarLabel transition for transition in state.transitions when not transition.event)
if defaultTransitionsForEvent.length
classStr += """
this['#{DEFAULT_EVENT_NAME}'] = function(evaluator){
- var toReturn = []
+ var toReturn = [];
var transitions = #{initializer.arrayToIdentifierListString defaultTransitionsForEvent };
for(var i = 0,l=transitions.length; i < l; i++){
var transition = transitions[i];
@@ -56,7 +56,7 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
}
return toReturn.length ? toReturn : #{if state.parent then "instances['#{state.parent.id}']['#{DEFAULT_EVENT_NAME}'](evaluator)" else "null"};
- }
+ };
"""
else
#root state
@@ -66,7 +66,7 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
classStr += """
}
- }
+ };
"""
classStr += if state.parent then "o['#{state.id}'].prototype = instances['#{state.parent.id}'];" else ""
classStr += """
@@ -93,21 +93,24 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
for(var j = 0; j < eventNames.length; j++){
var eventName = eventNames[j];
- var transitions = stateClassNameList[state.documentOrder][eventName](evaluator);
- if(transitions){
- toReturn = toReturn.concat(transitions);
- }
+ var method = stateClassNameList[state.documentOrder][eventName];
+ if(method){
+ var transitions = method(evaluator);
+ if(transitions){
+ toReturn = toReturn.concat(transitions);
+ }
+ }
}
}else{
//default events
toReturn = toReturn.concat(stateClassNameList[state.documentOrder]['#{DEFAULT_EVENT_NAME}'](evaluator) || []);
}
return toReturn;
- }
+ };
"""
toReturn = initializer.genOuterInitializerStr scxmlJson,toReturn
- toReturn = if asyncModuleDef then "define(function(){return #{toReturn};});" else toReturn
+ toReturn = if asyncModuleDef then "define(function(){return #{toReturn}});" else toReturn
if beautify then js_beautify toReturn else toReturn
View
2 src/main/coffeescript/optimization/initializer.coffee
@@ -28,7 +28,7 @@ define ->
toReturn += """
#{innerFnStr}
- }
+ };
"""
transitionFilterString : """
View
8 src/main/coffeescript/optimization/state-table.coffee
@@ -81,9 +81,11 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
for(var j = 0; j < eventNames.length; j++){
var eventName = eventNames[j];
var enumeratedEvent = eventMap[eventName];
- var eventId = enumeratedEvent.documentOrder;
+ if(enumeratedEvent){
+ var eventId = enumeratedEvent.documentOrder;
- transitions = transitions.concat(stateTransitionTable[state.documentOrder][eventId] || []);
+ transitions = transitions.concat(stateTransitionTable[state.documentOrder][eventId] || []);
+ }
}
}else{
//default events
@@ -94,6 +96,6 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
};
"""
- toReturn = if asyncModuleDef then "define(function(){return #{toReturn};});" else toReturn
+ toReturn = if asyncModuleDef then "define(function(){return #{toReturn}});" else toReturn
if beautify then js_beautify toReturn else toReturn
View
9 src/main/coffeescript/optimization/switch.coffee
@@ -17,7 +17,7 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
(scxmlJson,beautify=true,asyncModuleDef=true) ->
toReturn = """
return function(state,eventNames,evaluator){
- var toReturn = [],transitions=[];
+ var transitions=[];
if(eventNames.length){
for(var j = 0; j < eventNames.length; j++){
@@ -42,11 +42,13 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
"""
toReturn += """
+ default : break;
}
break;\n
"""
toReturn += """
+ default : break;
}
}
@@ -65,16 +67,17 @@ define ["optimization/initializer","lib/beautify"],(initializer,js_beautify)->
toReturn += """
+ default : break;
}
}
#{initializer.transitionFilterString}
- }
+ };
"""
toReturn = initializer.genOuterInitializerStr scxmlJson,toReturn
- toReturn = if asyncModuleDef then "define(function(){return #{toReturn};});" else toReturn
+ toReturn = if asyncModuleDef then "define(function(){return #{toReturn}});" else toReturn
if beautify then js_beautify toReturn else toReturn
View
12 src/main/coffeescript/scxml/SCXML.coffee
@@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-define ["util/set/ArraySet","scxml/state-kinds-enum","scxml/event","util/reduce","scxml/setup-default-opts","logger"],(ArraySet,stateKinds,Event,reduce,setupDefaultOpts,logger) ->
+
+
+define ["util/set/ArraySet","scxml/state-kinds-enum","scxml/event","util/reduce","scxml/setup-default-opts","scxml/scxml-dynamic-name-match-transition-selector","logger"],(ArraySet,stateKinds,Event,reduce,setupDefaultOpts,scxmlPrefixTransitionSelector,logger) ->
#imports
@@ -373,10 +375,14 @@ define ["util/set/ArraySet","scxml/state-kinds-enum","scxml/event","util/reduce"
eventNames = (event.name for event in eventSet.iter())
+ usePrefixMatchingAlgorithm = (name for name in eventNames when "." in name).length
+
+ transitionSelector = if usePrefixMatchingAlgorithm then scxmlPrefixTransitionSelector else @opts.transitionSelector
+
#debugger
enabledTransitions = new @opts.TransitionSet
for state in states
- for t in @opts.transitionSelector state,eventNames,e
+ for t in transitionSelector state,eventNames,e
enabledTransitions.add t
if @opts.printTrace then logger.trace("allTransitionsForEachState",allTransitionsForEachState)
@@ -484,7 +490,7 @@ define ["util/set/ArraySet","scxml/state-kinds-enum","scxml/event","util/reduce"
#External Event Communication: Asynchronous
gen: (e) ->
- logger.trace("received event ", e)
+ #logger.trace("received event ", e)
if not e?.name
throw new Error "gen must be passed an event object."
View
2 src/main/coffeescript/test-harness/optimization-harness.coffee
@@ -34,7 +34,7 @@ define ["scxml/json2model","scxml/json2extra-model", "test-harness/harness", "sc
tableTransOpt = tableTransitionOpts[i] model.transitions,model.events
optArgs = {
- "default transition lookup" : {transitionSelector:defaultTransitionSelector()}
+ "default transition lookup" : {transitionSelector:defaultTransitionSelector}
"class-transition-lookup" : {transitionSelector:classTransOpt,onlySelectFromBasicStates:true}
"switch-transition-lookup" : {transitionSelector:switchTransOpt}
"table-transition-lookup" : {transitionSelector:tableTransOpt}

0 comments on commit 9edc430

Please sign in to comment.
Something went wrong with that request. Please try again.