Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Intermediate commit to core SCXML interpreter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeard4 committed Jun 14, 2012
1 parent c481e61 commit b554a2b
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lib/core/scxml/SCXML.js
Expand Up @@ -37,6 +37,12 @@ function getTransitionWithHigherSourceChildPriority(model) {

function SCXMLInterpreter(model, opts){
this.model = model;

//we need this, so just stick it on the model
this.model.basicStates =
model.states.filter(function(state){return state.basicDocumentOrder !== undefined;})
.sort(function(s1,s2){return s1.basicDocumentOrder - s2.basicDocumentOrder});

this.opts = opts;

//this.opts.printTrace = true;
Expand All @@ -47,7 +53,7 @@ function SCXMLInterpreter(model, opts){
this.opts.priorityComparisonFn = this.opts.priorityComparisonFn || getTransitionWithHigherSourceChildPriority(this.opts.model);
this.opts.globalEval = this.opts.globalEval || eval;

this._configuration = new this.opts.BasicStateSet();
this._configuration = new this.opts.BasicStateSet([],"basicDocumentOrder",this.model.basicStates);
this._historyValue = {};
this._innerEventQueue = [];
this._isInFinalState = false;
Expand Down Expand Up @@ -121,7 +127,7 @@ SCXMLInterpreter.prototype = {

//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
var selectedTransitionsWithTargets = new this.opts.TransitionSet(selectedTransitions.iter().filter(function(t){return t.targets;}));
var selectedTransitionsWithTargets = new this.opts.TransitionSet(selectedTransitions.iter().filter(function(t){return t.targets;}),"documentOrder",this.model.transitions);

var exitedTuple = this._getStatesExited(selectedTransitionsWithTargets),
basicStatesExited = exitedTuple[0],
Expand Down Expand Up @@ -326,8 +332,8 @@ SCXMLInterpreter.prototype = {
},

_getStatesExited : function(transitions) {
var statesExited = new this.opts.StateSet();
var basicStatesExited = new this.opts.BasicStateSet();
var statesExited = new this.opts.StateSet([],"documentOrder",this.model.states);
var basicStatesExited = new this.opts.BasicStateSet([],"basicDocumentOrder",this.model.basicStates);

transitions.iter().forEach(function(transition){
var lca = this.opts.model.getLCA(transition);
Expand All @@ -352,9 +358,9 @@ SCXMLInterpreter.prototype = {

_getStatesEntered : function(transitions) {

var statesToEnter = new this.opts.StateSet();
var basicStatesToEnter = new this.opts.BasicStateSet();
var statesProcessed = new this.opts.StateSet();
var statesToEnter = new this.opts.StateSet([],"documentOrder",this.model.states);
var basicStatesToEnter = new this.opts.BasicStateSet([],"basicDocumentOrder",this.model.basicStates);
var statesProcessed = new this.opts.StateSet([],"documentOrder",this.model.states);
var statesToProcess = [];

var processTransitionSourceAndTarget = (function(source,target){
Expand Down Expand Up @@ -434,8 +440,7 @@ SCXMLInterpreter.prototype = {
if (this.opts.onlySelectFromBasicStates) {
var states = this._configuration.iter();
} else {
var statesAndParents = new this.opts.StateSet;

var statesAndParents = new this.opts.StateSet([],"documentOrder",this.model.states);
//get full configuration, unordered
//this means we may select transitions from parents before children

Expand All @@ -458,7 +463,7 @@ SCXMLInterpreter.prototype = {
var usePrefixMatchingAlgorithm = eventNames.filter(function(name){return name.search(".");}).length;

var transitionSelector = usePrefixMatchingAlgorithm ? scxmlPrefixTransitionSelector : this.opts.transitionSelector;
var enabledTransitions = new this.opts.TransitionSet();
var enabledTransitions = new this.opts.TransitionSet([],"documentOrder",this.model.transitions);

states.forEach(function(state){
transitionSelector(state,eventNames,e).forEach(function(t){
Expand All @@ -474,7 +479,7 @@ SCXMLInterpreter.prototype = {
},

_selectPriorityEnabledTransitions : function(enabledTransitions) {
var priorityEnabledTransitions = new this.opts.TransitionSet();
var priorityEnabledTransitions = new this.opts.TransitionSet([],"documentOrder",this.model.transitions);

var tuple = this._getInconsistentTransitions(enabledTransitions),
consistentTransitions = tuple[0],
Expand All @@ -489,7 +494,10 @@ SCXMLInterpreter.prototype = {

while (!inconsistentTransitionsPairs.isEmpty()) {
enabledTransitions = new this.opts.TransitionSet(
inconsistentTransitionsPairs.iter().map(function(t){return this.opts.priorityComparisonFn(t);},this));
inconsistentTransitionsPairs.iter().map(function(t){return this.opts.priorityComparisonFn(t);},this),
,"documentOrder"
,this.model.transitions
);

tuple = this._getInconsistentTransitions(enabledTransitions);
consistentTransitions = tuple[0];
Expand All @@ -507,7 +515,7 @@ SCXMLInterpreter.prototype = {
},

_getInconsistentTransitions : function(transitions) {
var allInconsistentTransitions = new this.opts.TransitionSet();
var allInconsistentTransitions = new this.opts.TransitionSet([],"documentOrder",this.model.transitions);
var inconsistentTransitionsPairs = new this.opts.TransitionPairSet();
var transitionList = transitions.iter();

Expand Down

0 comments on commit b554a2b

Please sign in to comment.