You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/05/21 19:49:10 UTC
svn commit: r947090 [4/4] - in /commons/sandbox/gsoc/2010/scxml-js/trunk: ./
lib/ lib/java/ lib/js/ lib/test-java/ lib/test-js/ src/ src/scxml/
src/scxml/cgf/ src/scxml/cgf/js/ src/scxml/cgf/util/ test/
test/kitchen_sink/ test/kitchen_sink/doc/ test/ki...
Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/switch_pattern_full.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/switch_pattern_full.js?rev=947090&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/switch_pattern_full.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/switch_pattern_full.js Fri May 21 17:49:09 2010
@@ -0,0 +1,1463 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+//runtime-specific functions
+function sortByDepthShallowToDeep(a,b){
+ return a.depth - b.depth;
+}
+
+function sortByDepthDeepToShallow(a,b){
+ return b.depth - a.depth;
+}
+
+function StatechartExecutionContext(){
+
+ var self = this; //used in the rare occasions we call public functions from inside this class
+
+
+ var AbstractState = new function(){
+ }
+
+ //top-state
+ var Root = (function(){
+ function Root(){
+ this.parent = null;
+
+ this.initial = null;
+
+ this.depth = 0;
+
+ this.id = null;
+
+ this.toString = function(){
+ return "Root"
+ }
+
+ }
+ Root.prototype = AbstractState;
+ return new Root();
+ })();
+
+ var Root_$Initial = (function(){
+ function Root_$Initial(){
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.initial = null;
+
+ this.id = 0;
+
+ this.enterAction = function(){
+ console.log("entering Root_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Root_$Initial");
+ }
+ this.toString = function(){
+ return "Root_$Initial";
+ }
+
+ }
+ Root_$Initial.prototype = Root;
+ return new Root_$Initial();
+ })();
+
+ var FinalState = (function(){
+ function FinalState(){
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.initial = null;
+
+ this.id = 1;
+
+ this.enterAction = function(){
+ console.log("entering FinalState");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting FinalState");
+ }
+
+ this.toString = function(){
+ return "FinalState";
+ }
+
+ }
+ FinalState.prototype = Root;
+ return new FinalState();
+ })();
+
+ var Compound1 = (function(){
+ function Compound1(){
+
+ this.initial = null;
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.parent.initial = this;
+
+ //FIXME: these properties are slightly problematic, as they will show up on all
+ //substates, which is probably not the semantics we want. For example, we do
+ //not want every substate to think it has a history state. This is mitigated by
+ //the fact that all of our code is generated, but still, I should be careful...
+ //and maybe not put these properties here. Just to be clear. Should probably
+ //break it out into an external property. Although I don't think we'll ever
+ //need to make dynamic checks on whether something has a history state.
+ this.historyState = null;
+
+ this.enterAction = function(){
+ console.log("entering Compound1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Compound1");
+
+ //instrument this to accomodate his history
+ this.historyState.lastConfiguration = currentConfiguration.slice(); //make a copy of the current configuration
+ }
+
+ this.toString = function(){
+ return "Compound1";
+ }
+ }
+ Compound1.prototype = Root;
+ return new Compound1();
+ })();
+
+
+ var Compound1_$Initial = (function(){
+ function Compound1_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.parent.initial = this;
+
+ this.id = 2;
+
+ this.enterAction = function(){
+ console.log("entering Compound1_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Compound1_$Initial");
+ }
+
+ this.toString = function(){
+ return "Compound1_$Initial";
+ }
+
+ }
+ Compound1_$Initial.prototype = Compound1;
+ return new Compound1_$Initial();
+ })();
+
+ var ShallowHistory = (function(){
+ function ShallowHistory(){
+ //shallow history
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.lastConfiguration = null;
+
+ this.id = 4;
+
+ this.parent = Compound1;
+
+ this.parent.historyState = this;
+
+ this.enterAction = function(){
+ console.log("entering ShallowHistory");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ShallowHistory");
+ }
+
+ this.toString = function(){
+ return "ShallowHistory";
+ }
+
+ }
+ ShallowHistory.prototype = Compound1;
+ return new ShallowHistory();
+ })();
+
+ var Basic1 = (function(){
+ function Basic1(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.id = 4;
+
+ this.enterAction = function(){
+ console.log("entering Basic1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic1");
+ }
+
+ this.toString = function(){
+ return "Basic1";
+ }
+
+ }
+ Basic1.prototype = Compound1;
+ return new Basic1();
+ })();
+
+
+ var Basic2 = (function(){
+ function Basic2(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.id = 5;
+
+ this.enterAction = function(){
+ console.log("entering Basic2");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic2");
+ }
+
+ this.toString = function(){
+ return "Basic2";
+ }
+
+ }
+ Basic2.prototype = Compound1;
+ return new Basic2();
+ })();
+
+
+ var Basic3 = (function(){
+ function Basic3(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.id = 6;
+
+ this.enterAction = function(){
+ console.log("entering Basic3");
+
+ window.setTimeout(function(){
+ self.GEN(t_after);
+ },1000);
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic3");
+ }
+
+
+ this.toString = function(){
+ return "Basic3";
+ }
+
+ }
+ Basic3.prototype = Compound1;
+ return new Basic3();
+ })();
+
+ var Parallel1 = (function(){
+ function Parallel1(){
+
+ this.initial = null;
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.enterAction = function(){
+ console.log("entering Parallel1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Parallel1");
+
+ //instrument this to accomodate his history
+ this.historyState.lastConfiguration = currentConfiguration.slice(); //make a copy of the current configuration
+ }
+
+ this.toString = function(){
+ return "Parallel1";
+ }
+
+ }
+ Parallel1.prototype = Root;
+ return new Parallel1();
+ })();
+
+
+ var DeepHistory = (function(){
+ function DeepHistory(){
+ //deep history
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.lastConfiguration = null;
+
+ this.parent = Parallel1;
+
+ this.parent.historyState = this;
+
+ this.id = 7;
+
+ this.enterAction = function(){
+ console.log("entering DeepHistory");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting DeepHistory");
+ }
+
+ this.toString = function(){
+ return "DeepHistory";
+ }
+
+ }
+ DeepHistory.prototype = Parallel1;
+ return new DeepHistory();
+ })();
+
+ var Parallel1_$Initial = (function(){
+ function Parallel1_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Parallel1;
+
+ this.parent.initial = this;
+
+ this.id = 8;
+
+ this.enterAction = function(){
+ console.log("entering Parallel1_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Parallel1_$Initial");
+ }
+
+ this.toString = function(){
+ return "Parallel1_$Initial";
+ }
+
+ }
+ Parallel1_$Initial.prototype = Parallel1;
+ return new Parallel1_$Initial();
+ })();
+
+ var ParallelRegion1 = (function(){
+ function ParallelRegion1(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion1");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion1";
+ }
+
+ this.parent = Parallel1;
+ }
+ ParallelRegion1.prototype = Parallel1;
+ return new ParallelRegion1();
+ })();
+
+
+ var ParallelRegion1_$Initial = (function(){
+ function ParallelRegion1_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 9;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion1_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion1_$Initial");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion1_$Initial";
+ }
+
+ this.parent = ParallelRegion1;
+
+ this.parent.initial = this;
+ }
+ ParallelRegion1_$Initial.prototype = ParallelRegion1;
+ return new ParallelRegion1_$Initial();
+ })();
+
+ var Basic4 = (function(){
+ function Basic4(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 10;
+
+ this.enterAction = function(){
+ console.log("entering Basic4");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic4");
+ }
+
+ this.toString = function(){
+ return "Basic4";
+ }
+
+ this.parent = Parallel1;
+ }
+ Basic4.prototype = ParallelRegion1;
+ return new Basic4();
+ })();
+
+ var Basic5 = (function(){
+ function Basic5(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 11;
+
+ this.enterAction = function(){
+ console.log("entering Basic5");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic5");
+ }
+
+ this.toString = function(){
+ return "Basic5";
+ }
+
+ this.parent = ParallelRegion1;
+ }
+ Basic5.prototype = ParallelRegion1;
+ return new Basic5();
+ })();
+
+ var ParallelRegion2 = (function(){
+ function ParallelRegion2(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion2");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion2");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion2";
+ }
+
+ this.parent = Parallel1;
+ }
+ ParallelRegion2.prototype = Parallel1;
+ return new ParallelRegion2();
+ })();
+
+
+ var ParallelRegion2_$Initial = (function(){
+ function ParallelRegion2_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.parent = ParallelRegion2;
+
+ this.parent.initial = this;
+
+ this.id = 12;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion2_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion2_$Initial");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion2_$Initial";
+ }
+ }
+ ParallelRegion2_$Initial.prototype = ParallelRegion2;
+ return new ParallelRegion2_$Initial();
+ })();
+
+ var Basic6 = (function(){
+ function Basic6(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 13;
+
+ this.enterAction = function(){
+ console.log("entering Basic6");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic6");
+ }
+
+
+ this.toString = function(){
+ return "Basic6";
+ }
+
+ this.parent = ParallelRegion2;
+ }
+ Basic6.prototype = ParallelRegion2;
+ return new Basic6();
+ })();
+
+ var Basic7 = (function(){
+ function Basic7(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 14;
+
+ this.enterAction = function(){
+ console.log("entering Basic7");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic7");
+ }
+
+ this.toString = function(){
+ return "Basic7";
+ }
+
+ this.parent = ParallelRegion2;
+ }
+ Basic7.prototype = ParallelRegion2;
+ return new Basic7();
+ })();
+
+ //this is used for glass-box testing
+ this._states = {
+ Root : Root,
+ FinalState : FinalState,
+ Compound1 : Compound1,
+ Basic1 : Basic1,
+ Basic2 : Basic2,
+ Basic3 : Basic3,
+ Parallel1 : Parallel1,
+ ParallelRegion1 : ParallelRegion1,
+ Basic4 : Basic4,
+ Basic5 : Basic5,
+ ParallelRegion2 : ParallelRegion2,
+ Basic6 : Basic6,
+ Basic7 : Basic7
+ }
+
+ //enumeration of states int id's
+ var Root_$Initial_id = 0;
+ var FinalState_id = 1;
+ var Compound1_$Initial_id = 2;
+ var ShallowHistory_id = 3;
+ var Basic1_id = 4;
+ var Basic2_id = 5;
+ var Basic3_id = 6;
+ var DeepHistory_id = 7;
+ var Parallel1_$Initial_id = 8;
+ var ParallelRegion1_$Initial_id = 9;
+ var Basic4_id = 10;
+ var Basic5_id = 11;
+ var ParallelRegion2_$Initial_id = 12;
+ var Basic6_id = 13;
+ var Basic7_id = 14;
+
+ //map from states int id's to objects
+ var STATE_INT_ID_TO_OBJECT_MAP = [Root_$Initial,
+ FinalState,
+ Compound1_$Initial,
+ ShallowHistory,
+ Basic1,
+ Basic2,
+ Basic3,
+ DeepHistory,
+ Parallel1_$Initial,
+ ParallelRegion1_$Initial,
+ Basic4,
+ Basic5,
+ ParallelRegion2_$Initial,
+ Basic6,
+ Basic7]
+
+ //enumeration of triggers
+ var $default = 0;
+ var t1 = 1;
+ var t2_7 = 2;
+ var t3 = 3;
+ var t4_9 = 4;
+ var t5 = 5
+ var t6 = 6;
+ var t8 = 7;
+ var t10 = 8;
+ var t_gen = 9;
+ var t_after = 10;
+
+ //expose them as a convenient interface as part of the API
+ this.TRIGGERS = {
+ $default : $default,
+ t1 : t1,
+ t2_7 : t2_7,
+ t3 : t3,
+ t4_9 : t4_9,
+ t5 : t5,
+ t6 : t6,
+ t8 : t8,
+ t10 : t10,
+ t_gen : t_gen,
+ t_after : t_after
+ }
+
+ //needed for debugging
+ var TRIGGER_ID_TO_NAME_MAP = [
+ "$default",
+ "t1",
+ "t2_7",
+ "t3",
+ "t4_9",
+ "t5",
+ "t6",
+ "t8",
+ "t10",
+ "t_gen",
+ "t_after"
+ ]
+
+ //transition functions
+ var Root_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ Root_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Compound1_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [Compound1_$Initial_id];
+ }
+
+ var Compound1_t2_7 = function(){
+ //the way we figure out what states we're exiting here is based on the current configuration
+ //we are able to precompute the LCS
+ //so we need to dynamically compute the set of states to be exited
+ //This is true for both parallel and non-parallel compound states.
+ //We could probably generalize this over all states (including basic states), but it may not be appropriate to do so
+ var statesExited = [];
+ var lcs = Root; //this is set at compile time!!!
+ currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lcs &&
+ statesExited.indexOf(state) == -1)
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+
+ //fire transition action
+ console.log("taking t2_7");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Parallel1.enterAction();
+ DeepHistory.enterAction();
+
+ //update configuration
+ currentConfiguration = [DeepHistory_id];
+ }
+
+ var Compound1_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ Compound1_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ ShallowHistory.enterAction();
+
+ //update configuration
+ currentConfiguration = [ShallowHistory_id];
+ }
+
+
+ var ShallowHistory_$default = function(){
+
+ //FIXME: for debugging only
+ ShallowHistory.exitAction();
+
+ //history state semantics
+ if(ShallowHistory.lastConfiguration){
+ //he is shallow history, so we only enter into the guy we left last
+ //also, we know that his parent is a non-parallel state, so we don't need to loop...
+ //although, that doesn't hurt anything really. May as well generalize, it's easier
+
+ //transition action
+ console.log("return to last shallow configuration");
+
+ var self = ShallowHistory;
+ var newConfiguration = [];
+ ShallowHistory.lastConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ //walk up the tree until we hit the parent
+ var statesEntered = [state];
+
+ for(var parent = state.parent;
+ parent != self.parent && parent != null;
+ parent = parent.parent){
+ statesEntered.push(parent);
+ }
+
+ //this is different for deep vs. shallow
+ //enter into the top guy
+ var topState = statesEntered.pop();
+
+ topState.enterAction();
+ //add this state to the current configuration.
+ //I don't remember if we had ordering semantics on the configuration.
+ //I think we did... not. If I remember correctly.
+ //this will become the updated configuration. The
+ //problem now is we need to push is initial state. So
+ //we actually do need a runtime association between the
+ //two so that we can set this configuration properly.
+
+ //use his dynamic id property
+ newConfiguration.push(topState.initial ? topState.initial.id : topState.id );
+ });
+
+ currentConfiguration = newConfiguration;
+ }else{
+ //take default transition
+ hasTakenDefaultTransition = true;
+
+ //transition action
+ console.log("taking default history transition");
+
+ //enter action
+ Basic1.enterAction();
+
+ //set the current configuration
+ currentConfiguration = [Basic1_id];
+ }
+ }
+
+
+ var Basic1_t1 = function(){
+ //exit states
+ Basic1.exitAction();
+
+ //transition action
+ console.log("taking transition t1");
+
+ //enter states
+ Basic2.enterAction();
+
+ //update configuration
+ currentConfiguration = [Basic2_id];
+ }
+
+ var Basic2_t5 = function(){
+ //exit states
+ Basic2.exitAction();
+
+ //transition action
+ console.log("Taking transition t5");
+
+ //enter states
+ Basic1.enterAction();
+
+ //update configuration
+ currentConfiguration = [Basic1_id];
+ }
+
+ var Basic2_t2_7 = function(){
+ //BECAUSE HE IS A BASIC STATE in a non-parallel region, we know what the configuration is when we start,
+ //and we know LCS, and so WE CAN GENERATE the following at compile time
+ //exit states
+ Basic2.exitAction();
+ Compound1.exitAction();
+
+ //transition action
+ console.log("taking transition t2_7")
+
+ //enter states
+ Parallel1.enterAction();
+ //default transitions
+
+ Parallel1.enterAction();
+ Parallel1_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [Parallel1_$Initial_id];
+ }
+
+
+ var Basic3_t_after = function(){
+ //exit actions
+ Basic3.exitAction();
+ Compound1.exitAction();
+
+ //transition action
+ console.log("Taking transision t_after");
+
+ //enter actions
+ FinalState.enterAction();
+
+ //update configuration
+ currentConfiguration = [FinalState_id];
+ }
+
+ var Parallel1_t4_9 = function(){
+
+ //exit states
+ var statesExited = [];
+ var lcs = Root; //this is set at compile time!!!
+ currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lcs &&
+ statesExited.indexOf(state) == -1)
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+
+ //transition action
+ console.log("taking transition t4_9");
+
+ //enter states
+ Compound1.enterAction();
+ Compound1_$Initial.enterAction();
+ Basic3.enterAction();
+
+ //update configuration
+ currentConfiguration = [Basic3_id];
+
+ //This is interesting. The compiler should know that we are exiting
+ //a parallel state, and as such, should prevent other changes from
+ //taking place in this state's orthogonal components.
+ //I can't think of a case when this would fail...
+ //Maybe something involving nested orthogonal componenets... But
+ //I feel like this would be protected by inner-transition first
+ //semantics. Very well...
+ isPreempted = true;
+ }
+
+
+ var DeepHistory_$default = function(){
+
+ //FIXME: for debugging only
+ DeepHistory.exitAction();
+
+ //history state semantics
+ if(DeepHistory.lastConfiguration){
+ //he is shallow history, so we only enter into the guy we left last
+ //also, we know that his parent is a non-parallel state, so we don't need to loop...
+ //although, that doesn't hurt anything really. May as well generalize, it's easier
+
+ //transition action
+ console.log("return to last shallow configuration");
+
+ var self = DeepHistory;
+
+ DeepHistory.lastConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ //walk up the tree until we hit the parent
+ var statesEntered = [state];
+
+ for(var parent = state.parent;
+ parent != self.parent && parent != null;
+ parent = parent.parent){
+ statesEntered.push(parent);
+ }
+
+ //this is different for deep vs. shallow
+ //enter into the top guy
+
+ var topState;
+ while(topState = statesEntered.pop()){
+ topState.enterAction();
+ }
+
+ });
+
+ currentConfiguration = DeepHistory.lastConfiguration.slice();
+ }else{
+ //take default transition
+ hasTakenDefaultTransition = true;
+
+ //transition action
+ console.log("taking default history transition");
+
+ //fire states entered
+ //this should even work in the case of history :)
+ ParallelRegion1.enterAction();
+ ParallelRegion2.enterAction();
+ ParallelRegion1_$Initial.enterAction();
+ ParallelRegion2_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [ParallelRegion1_$Initial_id, ParallelRegion2_$Initial_id];
+ }
+ }
+
+
+ var Parallel1_$Initial_$default = function(){
+
+ //take default transition
+ hasTakenDefaultTransition = true;
+
+ //transition action
+ console.log("taking default history transition");
+
+ //fire states entered
+ //this should even work in the case of history :)
+ ParallelRegion1.enterAction();
+ ParallelRegion2.enterAction();
+ ParallelRegion1_$Initial.enterAction();
+ ParallelRegion2_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [ParallelRegion1_$Initial_id, ParallelRegion2_$Initial_id];
+ }
+
+ var ParallelRegion1_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ ParallelRegion1_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Basic4.enterAction();
+
+ //update configuration
+ //FIXME: probably a much cheaper way to do this now, now that we're just using ints.
+ currentConfiguration.splice(currentConfiguration.indexOf(ParallelRegion1_$Initial_id),1,Basic4_id);
+ }
+
+ var Basic4_t3 = function(){
+ //exit states
+ Basic4.exitAction();
+
+ //transition action
+ //issue event here. just by appending to innerevents queue?
+ innerEventQueue.push(t_gen);
+
+ //enter states
+ Basic5.enterAction();
+
+ //update configuration
+ //this is a bit interesting because he's in a parallel state.
+ //we don't, at this point, have any information on what the configuration of the other parallel state is
+ //so we now have to make some decisions on:
+ // * how we want to encode the configuration
+ // * how we want to update it based on that encoding
+ // I think we should keep it as a list. We basically need to take out the current basic state, and put in
+ // the next state. We will probably, unfortunately need to make this general, which will involve some dynamic ops.
+ // Honestly, we could do both. When in a parallel state, we do this more expensive state update change.
+ // And when in a non-parallel state, we do something cheaper.
+ // We could try to make it general, so that when you exit a state, it is removed from the configuration.
+ // This would entail that we would need to include non-basic states in the configuration.
+ // OR, we say that whenever you leave a non-basic state, it is removed from the configuration. That's not bad.
+ // FIXME: with a different representation, maybe a more ordered list, we could avoid the indexOf lookup, which may be expensive
+ currentConfiguration.splice(currentConfiguration.indexOf(Basic4_id),1,Basic5_id);
+
+ }
+
+
+ var Basic5_t8 = function(){
+ //exit states
+ Basic5.exitAction();
+
+ //transition action
+
+ //enter states
+ Basic4.enterAction();
+
+ //update configuration
+ currentConfiguration.splice(currentConfiguration.indexOf(Basic5_id),1,Basic4_id);
+ }
+
+ var Basic5_t4_9 = function(){
+
+ //exit states
+ var statesExited = [];
+ var lcs = Root; //this is set at compile time!!!
+ currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lcs &&
+ statesExited.indexOf(state) == -1)
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+
+ //transition action
+ console.log("taking transition t4_9");
+
+ //enter states
+ Compound1.enterAction();
+ Compound1_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [Compound1_$Initial_id];
+
+ //This is interesting. The compiler should know that we are exiting
+ //a parallel state, and as such, should prevent other changes from
+ //taking place in this state's orthogonal components.
+ //I can't think of a case when this would fail...
+ //Maybe something involving nested orthogonal componenets... But
+ //I feel like this would be protected by inner-transition first
+ //semantics. Very well...
+ isPreempted = true;
+ }
+
+
+ var ParallelRegion2_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ ParallelRegion2_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Basic6.enterAction();
+
+ //update configuration
+ currentConfiguration.splice(currentConfiguration.indexOf(ParallelRegion2_$Initial_id),1,Basic6_id);
+ }
+
+ var Basic6_t_gen = function(){
+
+ //exit states
+ Basic6.exitAction();
+
+ //transition action
+ console.log("taking transition t_gen");
+
+ //enter states
+ Basic7.enterAction();
+
+ //update configuration
+ currentConfiguration.splice(currentConfiguration.indexOf(Basic6_id),1,Basic7_id);
+
+ }
+ //end transition function
+
+ var $nt = function(){}; //null transition
+
+ //state transition table
+ function dispatch(state,e){
+ switch(state){
+ case Root_$Initial_id :
+ switch(e){
+ case $default :
+ Root_$Initial_$default();
+ break;
+ }
+ break;
+ case FinalState_id :
+ //nothing to do
+ break;
+ case Compound1_$Initial_id:
+ switch(e){
+ case $default :
+ Compound1_$Initial_$default();
+ }
+ case ShallowHistory_id :
+ switch(e){
+ case $default :
+ ShallowHistory_$default();
+ }
+ break;
+ case Basic1_id :
+ switch(e){
+ case t1 :
+ Basic1_t1();
+ break;
+ case t2_7 :
+ Compound1_t2_7();
+ }
+ break;
+ case Basic2_id :
+ switch(e){
+ case t2_7 :
+ Basic2_t2_7();
+ break;
+ case t5 :
+ Basic2_t5();
+ }
+ break;
+ case Basic3_id :
+ switch(e){
+ case t2_7 :
+ Compound1_t2_7();
+ break;
+ case t_after :
+ Basic3_t_after();
+ }
+ break;
+ case DeepHistory_id :
+ switch(e){
+ case $default :
+ DeepHistory_$default();
+ }
+ break;
+ case Parallel1_$Initial_id :
+ switch(e){
+ case $default :
+ Parallel1_$Initial_$default();
+ }
+ break;
+ case ParallelRegion1_$Initial_id :
+ switch(e){
+ case $default :
+ ParallelRegion1_$Initial_$default();
+ }
+ break;
+ case Basic4_id :
+ switch(e){
+ case t3 :
+ Basic4_t3();
+ break;
+ case t4_9 :
+ Parallel1_t4_9();
+ }
+ break;
+ case Basic5_id :
+ switch(e){
+ case t4_9 :
+ Basic5_t4_9();
+ break;
+ case t8 :
+ Basic5_t8();
+ }
+ break;
+ case ParallelRegion2_$Initial_id :
+ switch(e){
+ case $default :
+ ParallelRegion2_$Initial_$default();
+ }
+ break;
+ case Basic6_id :
+ switch(e){
+ case t4_9 :
+ Parallel1_t4_9();
+ break;
+ case t_gen :
+ Basic6_t_gen();
+ }
+ break;
+ case Basic7_id :
+ switch(e){
+ case t4_9 :
+ Parallel1_t4_9();
+ }
+ break;
+ }
+ }
+
+ //synchronous events encoded as method calls
+ //TODO: hook up event params
+
+ this.t1 = function(){
+ if(isInStableState){
+ runToCompletion(t1);
+ }else{
+ return undefined;
+ }
+ }
+ this.t5 = function(){
+ if(isInStableState){
+ runToCompletion(t5);
+ }else{
+ return undefined;
+ }
+ }
+ this.t2_7 = function(){
+ if(isInStableState){
+ runToCompletion(t2_7);
+ }else{
+ return undefined;
+ }
+ }
+ this.t3 = function(){
+ if(isInStableState){
+ runToCompletion(t3);
+ }else{
+ return undefined;
+ }
+ }
+ this.t4_9 = function(){
+ if(isInStableState){
+ runToCompletion(t4_9);
+ }else{
+ return undefined;
+ }
+ }
+ this.t8 = function(){
+ if(isInStableState){
+ runToCompletion(t8);
+ }else{
+ return undefined;
+ }
+ }
+
+ //start static boilerplate code
+
+ //static private member variables
+ var currentConfiguration = []; //current configuration
+ var innerEventQueue = []; //inner event queue
+ var outerEventQueue = []; //outer event queue
+ var isInStableState = true;
+ var isPreempted = false;
+ var hasTakenDefaultTransition = false;
+
+
+ //initialize the statechart
+ //FIXME: do we want it to be something the user has control over?
+ //or done automatically on instantiation?
+ //right now, automatically.
+ //I guess, basically, take the transition into the initial states...
+ //in Rhapsody, events could be fired on initial transitions.
+ //In SCXML, is it possible? Maybe.
+ //Either way, you could enter into a state that has an empty transitions
+ //and that transition can have an action associated with it. So,
+ //just on initialization, you can have multiple microsteps,
+ //which may have action code associated with it.
+ this.initialize = function(){
+ Root_$Initial.enterAction();
+ currentConfiguration = [Root_$Initial_id];
+ runToCompletion();
+ mainLoop();
+ }
+
+ //static private member functions
+ function mainLoop(){
+
+ //take an event from the current outer event queue
+ if(outerEventQueue.length && isInStableState){
+ runToCompletion(outerEventQueue.shift());
+ }
+ //call back
+ window.setTimeout(function(){
+ mainLoop(); //FIXME: note that when calling mainloop this way, we won't have access to the "this" object.
+ //I don't think we ever use it though. Everything we need is private in function scope.
+ },100);
+ }
+
+ function runToCompletion(e){
+ isInStableState = false;
+
+ if(e){
+ innerEventQueue.push(e);
+ }
+
+ do{
+ //take any available default transitions
+ microstep($default);
+
+ if(!hasTakenDefaultTransition){
+
+ if(!innerEventQueue.length){
+ //we have no more generated events, and no default transitions fired, so
+ //we are done, and have run to completion
+ break;
+ }else{
+ //microstep, then dequeue next event sending in event
+ microstep(innerEventQueue.shift());
+ }
+ }else{
+ //he has taken a default transition, so reset the global variable to false and loop again
+ hasTakenDefaultTransition = false;
+ }
+
+ }while(true)
+
+ isInStableState = true;
+ }
+
+ function microstep(e){
+ //FIXME: this code isn't portable. I need to write a small wrapper
+ currentConfiguration.forEach(function(state){
+ //calling this method should handle everything, including:
+ //figuring out what are the activated transitions
+ //enterStates
+ //transitionAction
+ //exitStates
+ //FIXME: maybe pass in the event params
+ if(!isPreempted) dispatch(state,e);
+ });
+
+ //reset the isPreempted flag
+ isPreempted = false;
+ }
+
+ //this is for async communication
+ this.GEN = function(e){
+ outerEventQueue.push(e);
+ }
+
+ //this may or may not be something we want to expose, but for right now, we at least need it for testing
+ this.getCurrentConfiguration = function(){
+ //slice it to return a copy of the configuration rather than the conf itself
+ //this saves us all kinds of confusion involving references and stuff
+ return currentConfiguration.slice();
+ }
+
+
+ this.getStringifiedCurrentConfiguration = function(){
+ return currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]});
+ }
+
+ //end static boilerplate code
+
+}
+
+//static class properties
+//triggers map to method names
+//StatechartExecutionContext.TEST_TRIGGER = "testTrigger";
+
+//TODO: the execution context could also potentially just have all the
+//methods on the him, and then simply delegate the method call to method
+//calls on his current configuration. We would do this if we wanted
+//synchronous communication.
+//if we allow sync communication, then we need to add a mutex, as
+//described in Rhapsody paper.
+
+
+
Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/switch_pattern_full.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/transition_table_pattern_full.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/transition_table_pattern_full.js?rev=947090&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/transition_table_pattern_full.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/transition_table_pattern_full.js Fri May 21 17:49:09 2010
@@ -0,0 +1,1367 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+
+//runtime-specific functions
+function sortByDepthShallowToDeep(a,b){
+ return a.depth - b.depth;
+}
+
+function sortByDepthDeepToShallow(a,b){
+ return b.depth - a.depth;
+}
+
+function StatechartExecutionContext(){
+
+ var self = this; //used in the rare occasions we call public functions from inside this class
+
+
+ var AbstractState = new function(){
+ }
+
+ //top-state
+ var Root = (function(){
+ function Root(){
+ this.parent = null;
+
+ this.initial = null;
+
+ this.depth = 0;
+
+ this.id = null;
+
+ this.toString = function(){
+ return "Root"
+ }
+
+ }
+ Root.prototype = AbstractState;
+ return new Root();
+ })();
+
+ var Root_$Initial = (function(){
+ function Root_$Initial(){
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.initial = null;
+
+ this.id = 0;
+
+ this.enterAction = function(){
+ console.log("entering Root_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Root_$Initial");
+ }
+ this.toString = function(){
+ return "Root_$Initial";
+ }
+
+ }
+ Root_$Initial.prototype = Root;
+ return new Root_$Initial();
+ })();
+
+ var FinalState = (function(){
+ function FinalState(){
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.initial = null;
+
+ this.id = 1;
+
+ this.enterAction = function(){
+ console.log("entering FinalState");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting FinalState");
+ }
+
+ this.toString = function(){
+ return "FinalState";
+ }
+
+ }
+ FinalState.prototype = Root;
+ return new FinalState();
+ })();
+
+ var Compound1 = (function(){
+ function Compound1(){
+
+ this.initial = null;
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.parent.initial = this;
+
+ //FIXME: these properties are slightly problematic, as they will show up on all
+ //substates, which is probably not the semantics we want. For example, we do
+ //not want every substate to think it has a history state. This is mitigated by
+ //the fact that all of our code is generated, but still, I should be careful...
+ //and maybe not put these properties here. Just to be clear. Should probably
+ //break it out into an external property. Although I don't think we'll ever
+ //need to make dynamic checks on whether something has a history state.
+ this.historyState = null;
+
+ this.enterAction = function(){
+ console.log("entering Compound1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Compound1");
+
+ //instrument this to accomodate his history
+ this.historyState.lastConfiguration = currentConfiguration.slice(); //make a copy of the current configuration
+ }
+
+ this.toString = function(){
+ return "Compound1";
+ }
+ }
+ Compound1.prototype = Root;
+ return new Compound1();
+ })();
+
+
+ var Compound1_$Initial = (function(){
+ function Compound1_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.parent.initial = this;
+
+ this.id = 2;
+
+ this.enterAction = function(){
+ console.log("entering Compound1_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Compound1_$Initial");
+ }
+
+ this.toString = function(){
+ return "Compound1_$Initial";
+ }
+
+ }
+ Compound1_$Initial.prototype = Compound1;
+ return new Compound1_$Initial();
+ })();
+
+ var ShallowHistory = (function(){
+ function ShallowHistory(){
+ //shallow history
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.lastConfiguration = null;
+
+ this.id = 4;
+
+ this.parent = Compound1;
+
+ this.parent.historyState = this;
+
+ this.enterAction = function(){
+ console.log("entering ShallowHistory");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ShallowHistory");
+ }
+
+ this.toString = function(){
+ return "ShallowHistory";
+ }
+
+ }
+ ShallowHistory.prototype = Compound1;
+ return new ShallowHistory();
+ })();
+
+ var Basic1 = (function(){
+ function Basic1(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.id = 4;
+
+ this.enterAction = function(){
+ console.log("entering Basic1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic1");
+ }
+
+ this.toString = function(){
+ return "Basic1";
+ }
+
+ }
+ Basic1.prototype = Compound1;
+ return new Basic1();
+ })();
+
+
+ var Basic2 = (function(){
+ function Basic2(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.id = 5;
+
+ this.enterAction = function(){
+ console.log("entering Basic2");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic2");
+ }
+
+ this.toString = function(){
+ return "Basic2";
+ }
+
+ }
+ Basic2.prototype = Compound1;
+ return new Basic2();
+ })();
+
+
+ var Basic3 = (function(){
+ function Basic3(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Compound1;
+
+ this.id = 6;
+
+ this.enterAction = function(){
+ console.log("entering Basic3");
+
+ window.setTimeout(function(){
+ self.GEN(t_after);
+ },1000);
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic3");
+ }
+
+
+ this.toString = function(){
+ return "Basic3";
+ }
+
+ }
+ Basic3.prototype = Compound1;
+ return new Basic3();
+ })();
+
+ var Parallel1 = (function(){
+ function Parallel1(){
+
+ this.initial = null;
+
+ this.depth = 1;
+
+ this.parent = Root;
+
+ this.enterAction = function(){
+ console.log("entering Parallel1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Parallel1");
+
+ //instrument this to accomodate his history
+ this.historyState.lastConfiguration = currentConfiguration.slice(); //make a copy of the current configuration
+ }
+
+ this.toString = function(){
+ return "Parallel1";
+ }
+
+ }
+ Parallel1.prototype = Root;
+ return new Parallel1();
+ })();
+
+
+ var DeepHistory = (function(){
+ function DeepHistory(){
+ //deep history
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.lastConfiguration = null;
+
+ this.parent = Parallel1;
+
+ this.parent.historyState = this;
+
+ this.id = 7;
+
+ this.enterAction = function(){
+ console.log("entering DeepHistory");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting DeepHistory");
+ }
+
+ this.toString = function(){
+ return "DeepHistory";
+ }
+
+ }
+ DeepHistory.prototype = Parallel1;
+ return new DeepHistory();
+ })();
+
+ var Parallel1_$Initial = (function(){
+ function Parallel1_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.parent = Parallel1;
+
+ this.parent.initial = this;
+
+ this.id = 8;
+
+ this.enterAction = function(){
+ console.log("entering Parallel1_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Parallel1_$Initial");
+ }
+
+ this.toString = function(){
+ return "Parallel1_$Initial";
+ }
+
+ }
+ Parallel1_$Initial.prototype = Parallel1;
+ return new Parallel1_$Initial();
+ })();
+
+ var ParallelRegion1 = (function(){
+ function ParallelRegion1(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion1");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion1");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion1";
+ }
+
+ this.parent = Parallel1;
+ }
+ ParallelRegion1.prototype = Parallel1;
+ return new ParallelRegion1();
+ })();
+
+
+ var ParallelRegion1_$Initial = (function(){
+ function ParallelRegion1_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 9;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion1_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion1_$Initial");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion1_$Initial";
+ }
+
+ this.parent = ParallelRegion1;
+
+ this.parent.initial = this;
+ }
+ ParallelRegion1_$Initial.prototype = ParallelRegion1;
+ return new ParallelRegion1_$Initial();
+ })();
+
+ var Basic4 = (function(){
+ function Basic4(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 10;
+
+ this.enterAction = function(){
+ console.log("entering Basic4");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic4");
+ }
+
+ this.toString = function(){
+ return "Basic4";
+ }
+
+ this.parent = Parallel1;
+ }
+ Basic4.prototype = ParallelRegion1;
+ return new Basic4();
+ })();
+
+ var Basic5 = (function(){
+ function Basic5(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 11;
+
+ this.enterAction = function(){
+ console.log("entering Basic5");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic5");
+ }
+
+ this.toString = function(){
+ return "Basic5";
+ }
+
+ this.parent = ParallelRegion1;
+ }
+ Basic5.prototype = ParallelRegion1;
+ return new Basic5();
+ })();
+
+ var ParallelRegion2 = (function(){
+ function ParallelRegion2(){
+
+ this.initial = null;
+
+ this.depth = 2;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion2");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion2");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion2";
+ }
+
+ this.parent = Parallel1;
+ }
+ ParallelRegion2.prototype = Parallel1;
+ return new ParallelRegion2();
+ })();
+
+
+ var ParallelRegion2_$Initial = (function(){
+ function ParallelRegion2_$Initial(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.parent = ParallelRegion2;
+
+ this.parent.initial = this;
+
+ this.id = 12;
+
+ this.enterAction = function(){
+ console.log("entering ParallelRegion2_$Initial");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting ParallelRegion2_$Initial");
+ }
+
+ this.toString = function(){
+ return "ParallelRegion2_$Initial";
+ }
+ }
+ ParallelRegion2_$Initial.prototype = ParallelRegion2;
+ return new ParallelRegion2_$Initial();
+ })();
+
+ var Basic6 = (function(){
+ function Basic6(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 13;
+
+ this.enterAction = function(){
+ console.log("entering Basic6");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic6");
+ }
+
+
+ this.toString = function(){
+ return "Basic6";
+ }
+
+ this.parent = ParallelRegion2;
+ }
+ Basic6.prototype = ParallelRegion2;
+ return new Basic6();
+ })();
+
+ var Basic7 = (function(){
+ function Basic7(){
+
+ this.initial = null;
+
+ this.depth = 3;
+
+ this.id = 14;
+
+ this.enterAction = function(){
+ console.log("entering Basic7");
+ }
+
+ this.exitAction = function(){
+ console.log("exiting Basic7");
+ }
+
+ this.toString = function(){
+ return "Basic7";
+ }
+
+ this.parent = ParallelRegion2;
+ }
+ Basic7.prototype = ParallelRegion2;
+ return new Basic7();
+ })();
+
+ //this is used for glass-box testing
+ this._states = {
+ Root : Root,
+ FinalState : FinalState,
+ Compound1 : Compound1,
+ Basic1 : Basic1,
+ Basic2 : Basic2,
+ Basic3 : Basic3,
+ Parallel1 : Parallel1,
+ ParallelRegion1 : ParallelRegion1,
+ Basic4 : Basic4,
+ Basic5 : Basic5,
+ ParallelRegion2 : ParallelRegion2,
+ Basic6 : Basic6,
+ Basic7 : Basic7
+ }
+
+ //enumeration of states int id's
+ var Root_$Initial_id = 0;
+ var FinalState_id = 1;
+ var Compound1_$Initial_id = 2;
+ var ShallowHistory_id = 3;
+ var Basic1_id = 4;
+ var Basic2_id = 5;
+ var Basic3_id = 6;
+ var DeepHistory_id = 7;
+ var Parallel1_$Initial_id = 8;
+ var ParallelRegion1_$Initial_id = 9;
+ var Basic4_id = 10;
+ var Basic5_id = 11;
+ var ParallelRegion2_$Initial_id = 12;
+ var Basic6_id = 13;
+ var Basic7_id = 14;
+
+ //map from states int id's to objects
+ var STATE_INT_ID_TO_OBJECT_MAP = [Root_$Initial,
+ FinalState,
+ Compound1_$Initial,
+ ShallowHistory,
+ Basic1,
+ Basic2,
+ Basic3,
+ DeepHistory,
+ Parallel1_$Initial,
+ ParallelRegion1_$Initial,
+ Basic4,
+ Basic5,
+ ParallelRegion2_$Initial,
+ Basic6,
+ Basic7]
+
+ //enumeration of triggers
+ var $default = 0;
+ var t1 = 1;
+ var t2_7 = 2;
+ var t3 = 3;
+ var t4_9 = 4;
+ var t5 = 5
+ var t6 = 6;
+ var t8 = 7;
+ var t10 = 8;
+ var t_gen = 9;
+ var t_after = 10;
+
+ //expose them as a convenient interface as part of the API
+ this.TRIGGERS = {
+ $default : $default,
+ t1 : t1,
+ t2_7 : t2_7,
+ t3 : t3,
+ t4_9 : t4_9,
+ t5 : t5,
+ t6 : t6,
+ t8 : t8,
+ t10 : t10,
+ t_gen : t_gen,
+ t_after : t_after
+ }
+
+ //needed for debugging
+ var TRIGGER_ID_TO_NAME_MAP = [
+ "$default",
+ "t1",
+ "t2_7",
+ "t3",
+ "t4_9",
+ "t5",
+ "t6",
+ "t8",
+ "t10",
+ "t_gen",
+ "t_after"
+ ]
+
+ //transition functions
+ var Root_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ Root_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Compound1_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [Compound1_$Initial_id];
+ }
+
+ var Compound1_t2_7 = function(){
+ //the way we figure out what states we're exiting here is based on the current configuration
+ //we are able to precompute the LCS
+ //so we need to dynamically compute the set of states to be exited
+ //This is true for both parallel and non-parallel compound states.
+ //We could probably generalize this over all states (including basic states), but it may not be appropriate to do so
+ var statesExited = [];
+ var lcs = Root; //this is set at compile time!!!
+ currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lcs &&
+ statesExited.indexOf(state) == -1)
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+
+ //fire transition action
+ console.log("taking t2_7");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Parallel1.enterAction();
+ DeepHistory.enterAction();
+
+ //update configuration
+ currentConfiguration = [DeepHistory_id];
+ }
+
+ var Compound1_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ Compound1_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ ShallowHistory.enterAction();
+
+ //update configuration
+ currentConfiguration = [ShallowHistory_id];
+ }
+
+
+ var ShallowHistory_$default = function(){
+
+ //FIXME: for debugging only
+ ShallowHistory.exitAction();
+
+ //history state semantics
+ if(ShallowHistory.lastConfiguration){
+ //he is shallow history, so we only enter into the guy we left last
+ //also, we know that his parent is a non-parallel state, so we don't need to loop...
+ //although, that doesn't hurt anything really. May as well generalize, it's easier
+
+ //transition action
+ console.log("return to last shallow configuration");
+
+ var self = ShallowHistory;
+ var newConfiguration = [];
+ ShallowHistory.lastConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ //walk up the tree until we hit the parent
+ var statesEntered = [state];
+
+ for(var parent = state.parent;
+ parent != self.parent && parent != null;
+ parent = parent.parent){
+ statesEntered.push(parent);
+ }
+
+ //this is different for deep vs. shallow
+ //enter into the top guy
+ var topState = statesEntered.pop();
+
+ topState.enterAction();
+ //add this state to the current configuration.
+ //I don't remember if we had ordering semantics on the configuration.
+ //I think we did... not. If I remember correctly.
+ //this will become the updated configuration. The
+ //problem now is we need to push is initial state. So
+ //we actually do need a runtime association between the
+ //two so that we can set this configuration properly.
+
+ //use his dynamic id property
+ newConfiguration.push(topState.initial ? topState.initial.id : topState.id );
+ });
+
+ currentConfiguration = newConfiguration;
+ }else{
+ //take default transition
+ hasTakenDefaultTransition = true;
+
+ //transition action
+ console.log("taking default history transition");
+
+ //enter action
+ Basic1.enterAction();
+
+ //set the current configuration
+ currentConfiguration = [Basic1_id];
+ }
+ }
+
+
+ var Basic1_t1 = function(){
+ //exit states
+ Basic1.exitAction();
+
+ //transition action
+ console.log("taking transition t1");
+
+ //enter states
+ Basic2.enterAction();
+
+ //update configuration
+ currentConfiguration = [Basic2_id];
+ }
+
+ var Basic2_t5 = function(){
+ //exit states
+ Basic2.exitAction();
+
+ //transition action
+ console.log("Taking transition t5");
+
+ //enter states
+ Basic1.enterAction();
+
+ //update configuration
+ currentConfiguration = [Basic1_id];
+ }
+
+ var Basic2_t2_7 = function(){
+ //BECAUSE HE IS A BASIC STATE in a non-parallel region, we know what the configuration is when we start,
+ //and we know LCS, and so WE CAN GENERATE the following at compile time
+ //exit states
+ Basic2.exitAction();
+ Compound1.exitAction();
+
+ //transition action
+ console.log("taking transition t2_7")
+
+ //enter states
+ Parallel1.enterAction();
+ //default transitions
+
+ Parallel1.enterAction();
+ Parallel1_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [Parallel1_$Initial_id];
+ }
+
+
+ var Basic3_t_after = function(){
+ //exit actions
+ Basic3.exitAction();
+ Compound1.exitAction();
+
+ //transition action
+ console.log("Taking transision t_after");
+
+ //enter actions
+ FinalState.enterAction();
+
+ //update configuration
+ currentConfiguration = [FinalState_id];
+ }
+
+ var Parallel1_t4_9 = function(){
+
+ //exit states
+ var statesExited = [];
+ var lcs = Root; //this is set at compile time!!!
+ currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lcs &&
+ statesExited.indexOf(state) == -1)
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+
+ //transition action
+ console.log("taking transition t4_9");
+
+ //enter states
+ Compound1.enterAction();
+ Compound1_$Initial.enterAction();
+ Basic3.enterAction();
+
+ //update configuration
+ currentConfiguration = [Basic3_id];
+
+ //This is interesting. The compiler should know that we are exiting
+ //a parallel state, and as such, should prevent other changes from
+ //taking place in this state's orthogonal components.
+ //I can't think of a case when this would fail...
+ //Maybe something involving nested orthogonal componenets... But
+ //I feel like this would be protected by inner-transition first
+ //semantics. Very well...
+ isPreempted = true;
+ }
+
+
+ var DeepHistory_$default = function(){
+
+ //FIXME: for debugging only
+ DeepHistory.exitAction();
+
+ //history state semantics
+ if(DeepHistory.lastConfiguration){
+ //he is shallow history, so we only enter into the guy we left last
+ //also, we know that his parent is a non-parallel state, so we don't need to loop...
+ //although, that doesn't hurt anything really. May as well generalize, it's easier
+
+ //transition action
+ console.log("return to last shallow configuration");
+
+ var self = DeepHistory;
+
+ DeepHistory.lastConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ //walk up the tree until we hit the parent
+ var statesEntered = [state];
+
+ for(var parent = state.parent;
+ parent != self.parent && parent != null;
+ parent = parent.parent){
+ statesEntered.push(parent);
+ }
+
+ //this is different for deep vs. shallow
+ //enter into the top guy
+
+ var topState;
+ while(topState = statesEntered.pop()){
+ topState.enterAction();
+ }
+
+ });
+
+ currentConfiguration = DeepHistory.lastConfiguration.slice();
+ }else{
+ //take default transition
+ hasTakenDefaultTransition = true;
+
+ //transition action
+ console.log("taking default history transition");
+
+ //fire states entered
+ //this should even work in the case of history :)
+ ParallelRegion1.enterAction();
+ ParallelRegion2.enterAction();
+ ParallelRegion1_$Initial.enterAction();
+ ParallelRegion2_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [ParallelRegion1_$Initial_id, ParallelRegion2_$Initial_id];
+ }
+ }
+
+
+ var Parallel1_$Initial_$default = function(){
+
+ //take default transition
+ hasTakenDefaultTransition = true;
+
+ //transition action
+ console.log("taking default history transition");
+
+ //fire states entered
+ //this should even work in the case of history :)
+ ParallelRegion1.enterAction();
+ ParallelRegion2.enterAction();
+ ParallelRegion1_$Initial.enterAction();
+ ParallelRegion2_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [ParallelRegion1_$Initial_id, ParallelRegion2_$Initial_id];
+ }
+
+ var ParallelRegion1_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ ParallelRegion1_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Basic4.enterAction();
+
+ //update configuration
+ //FIXME: probably a much cheaper way to do this now, now that we're just using ints.
+ currentConfiguration.splice(currentConfiguration.indexOf(ParallelRegion1_$Initial_id),1,Basic4_id);
+ }
+
+ var Basic4_t3 = function(){
+ //exit states
+ Basic4.exitAction();
+
+ //transition action
+ //issue event here. just by appending to innerevents queue?
+ innerEventQueue.push(t_gen);
+
+ //enter states
+ Basic5.enterAction();
+
+ //update configuration
+ //this is a bit interesting because he's in a parallel state.
+ //we don't, at this point, have any information on what the configuration of the other parallel state is
+ //so we now have to make some decisions on:
+ // * how we want to encode the configuration
+ // * how we want to update it based on that encoding
+ // I think we should keep it as a list. We basically need to take out the current basic state, and put in
+ // the next state. We will probably, unfortunately need to make this general, which will involve some dynamic ops.
+ // Honestly, we could do both. When in a parallel state, we do this more expensive state update change.
+ // And when in a non-parallel state, we do something cheaper.
+ // We could try to make it general, so that when you exit a state, it is removed from the configuration.
+ // This would entail that we would need to include non-basic states in the configuration.
+ // OR, we say that whenever you leave a non-basic state, it is removed from the configuration. That's not bad.
+ // FIXME: with a different representation, maybe a more ordered list, we could avoid the indexOf lookup, which may be expensive
+ currentConfiguration.splice(currentConfiguration.indexOf(Basic4_id),1,Basic5_id);
+
+ }
+
+
+ var Basic5_t8 = function(){
+ //exit states
+ Basic5.exitAction();
+
+ //transition action
+
+ //enter states
+ Basic4.enterAction();
+
+ //update configuration
+ currentConfiguration.splice(currentConfiguration.indexOf(Basic5_id),1,Basic4_id);
+ }
+
+ var Basic5_t4_9 = function(){
+
+ //exit states
+ var statesExited = [];
+ var lcs = Root; //this is set at compile time!!!
+ currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]}).forEach(function(state){
+ do{
+ statesExited.push(state);
+ }while((state = state.parent) &&
+ state != lcs &&
+ statesExited.indexOf(state) == -1)
+ });
+
+ //sort by depth
+ statesExited.sort(sortByDepthDeepToShallow);
+
+ //execute actions for each of these states
+ statesExited.forEach(function(state){
+ state.exitAction();
+ });
+
+ //transition action
+ console.log("taking transition t4_9");
+
+ //enter states
+ Compound1.enterAction();
+ Compound1_$Initial.enterAction();
+
+ //update configuration
+ currentConfiguration = [Compound1_$Initial_id];
+
+ //This is interesting. The compiler should know that we are exiting
+ //a parallel state, and as such, should prevent other changes from
+ //taking place in this state's orthogonal components.
+ //I can't think of a case when this would fail...
+ //Maybe something involving nested orthogonal componenets... But
+ //I feel like this would be protected by inner-transition first
+ //semantics. Very well...
+ isPreempted = true;
+ }
+
+
+ var ParallelRegion2_$Initial_$default = function(){
+
+ hasTakenDefaultTransition = true;
+
+ //FIXME: we probably won't allow this in our compiled version,
+ //but it is useful for debugging
+ ParallelRegion2_$Initial.exitAction();
+
+ //fire transition action
+ console.log("taking default transition");
+
+ //ALL OF THE FOLLOWING IS GENERATED AT COMPILE-TIME
+
+ //fire states entered
+ //this should even work in the case of history :)
+ Basic6.enterAction();
+
+ //update configuration
+ currentConfiguration.splice(currentConfiguration.indexOf(ParallelRegion2_$Initial_id),1,Basic6_id);
+ }
+
+ var Basic6_t_gen = function(){
+
+ //exit states
+ Basic6.exitAction();
+
+ //transition action
+ console.log("taking transition t_gen");
+
+ //enter states
+ Basic7.enterAction();
+
+ //update configuration
+ currentConfiguration.splice(currentConfiguration.indexOf(Basic6_id),1,Basic7_id);
+
+ }
+ //end transition function
+
+ var $nt = function(){}; //null transition
+
+ //state transition table
+ var STATE_TRANSITION_TABLE = [
+ [Root_$Initial_$default , $nt , Compound1_$Initial_$default , ShallowHistory_$default , $nt , $nt , $nt , DeepHistory_$default , Parallel1_$Initial_$default , ParallelRegion1_$Initial_$default , $nt , $nt , ParallelRegion2_$Initial_$default , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , Basic1_t1 , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , Compound1_t2_7 , Basic2_t2_7 , Compound1_t2_7 , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , Basic4_t3 , $nt , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , Parallel1_t4_9 , Basic5_t4_9 , $nt , Parallel1_t4_9 , Parallel1_t4_9 ],
+ [$nt , $nt , $nt , $nt , $nt , Basic2_t5 , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , Basic5_t8 , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt , Basic6_t_gen , $nt ],
+ [$nt , $nt , $nt , $nt , $nt , $nt , Basic3_t_after , $nt , $nt , $nt , $nt , $nt , $nt , $nt , $nt ]
+ ]
+
+ //synchronous events encoded as method calls
+ //TODO: hook up event params
+
+ this.t1 = function(){
+ if(isInStableState){
+ runToCompletion(t1);
+ }else{
+ return undefined;
+ }
+ }
+ this.t5 = function(){
+ if(isInStableState){
+ runToCompletion(t5);
+ }else{
+ return undefined;
+ }
+ }
+ this.t2_7 = function(){
+ if(isInStableState){
+ runToCompletion(t2_7);
+ }else{
+ return undefined;
+ }
+ }
+ this.t3 = function(){
+ if(isInStableState){
+ runToCompletion(t3);
+ }else{
+ return undefined;
+ }
+ }
+ this.t4_9 = function(){
+ if(isInStableState){
+ runToCompletion(t4_9);
+ }else{
+ return undefined;
+ }
+ }
+ this.t8 = function(){
+ if(isInStableState){
+ runToCompletion(t8);
+ }else{
+ return undefined;
+ }
+ }
+
+ //start static boilerplate code
+
+ //static private member variables
+ var currentConfiguration = []; //current configuration
+ var innerEventQueue = []; //inner event queue
+ var outerEventQueue = []; //outer event queue
+ var isInStableState = true;
+ var isPreempted = false;
+ var hasTakenDefaultTransition = false;
+
+
+ //initialize the statechart
+ //FIXME: do we want it to be something the user has control over?
+ //or done automatically on instantiation?
+ //right now, automatically.
+ //I guess, basically, take the transition into the initial states...
+ //in Rhapsody, events could be fired on initial transitions.
+ //In SCXML, is it possible? Maybe.
+ //Either way, you could enter into a state that has an empty transitions
+ //and that transition can have an action associated with it. So,
+ //just on initialization, you can have multiple microsteps,
+ //which may have action code associated with it.
+ this.initialize = function(){
+ Root_$Initial.enterAction();
+ currentConfiguration = [Root_$Initial_id];
+ runToCompletion();
+ mainLoop();
+ }
+
+ //static private member functions
+ function mainLoop(){
+
+ //take an event from the current outer event queue
+ if(outerEventQueue.length && isInStableState){
+ runToCompletion(outerEventQueue.shift());
+ }
+ //call back
+ window.setTimeout(function(){
+ mainLoop(); //FIXME: note that when calling mainloop this way, we won't have access to the "this" object.
+ //I don't think we ever use it though. Everything we need is private in function scope.
+ },100);
+ }
+
+ function runToCompletion(e){
+ isInStableState = false;
+
+ if(e){
+ innerEventQueue.push(e);
+ }
+
+ do{
+ //take any available default transitions
+ microstep($default);
+
+ if(!hasTakenDefaultTransition){
+
+ if(!innerEventQueue.length){
+ //we have no more generated events, and no default transitions fired, so
+ //we are done, and have run to completion
+ break;
+ }else{
+ //microstep, then dequeue next event sending in event
+ microstep(innerEventQueue.shift());
+ }
+ }else{
+ //he has taken a default transition, so reset the global variable to false and loop again
+ hasTakenDefaultTransition = false;
+ }
+
+ }while(true)
+
+ isInStableState = true;
+ }
+
+ function microstep(e){
+ //FIXME: this code isn't portable. I need to write a small wrapper
+ currentConfiguration.forEach(function(state){
+ //calling this method should handle everything, including:
+ //figuring out what are the activated transitions
+ //enterStates
+ //transitionAction
+ //exitStates
+ //FIXME: maybe pass in the event params
+ if(!isPreempted) STATE_TRANSITION_TABLE[e][state]();
+ });
+
+ //reset the isPreempted flag
+ isPreempted = false;
+ }
+
+ //this is for async communication
+ this.GEN = function(e){
+ outerEventQueue.push(e);
+ }
+
+ //this may or may not be something we want to expose, but for right now, we at least need it for testing
+ this.getCurrentConfiguration = function(){
+ //slice it to return a copy of the configuration rather than the conf itself
+ //this saves us all kinds of confusion involving references and stuff
+ return currentConfiguration.slice();
+ }
+
+
+ this.getStringifiedCurrentConfiguration = function(){
+ return currentConfiguration.map(function(s){return STATE_INT_ID_TO_OBJECT_MAP[s]});
+ }
+
+ //end static boilerplate code
+
+}
+
+//static class properties
+//triggers map to method names
+//StatechartExecutionContext.TEST_TRIGGER = "testTrigger";
+
+//TODO: the execution context could also potentially just have all the
+//methods on the him, and then simply delegate the method call to method
+//calls on his current configuration. We would do this if we wanted
+//synchronous communication.
+//if we allow sync communication, then we need to add a mutex, as
+//described in Rhapsody paper.
+
+
Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/hand_compiled/transition_table_pattern_full.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/performanceTest.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/performanceTest.js?rev=947090&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/performanceTest.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/performanceTest.js Fri May 21 17:49:09 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+
+performanceTest = function(scConstructor,ticToc){
+
+ var d1 = new Date();
+
+ sc = new scConstructor()
+
+ sc.initialize();
+
+ sc.t1()
+
+ sc.t2_7()
+
+ sc.t3()
+
+ sc.t4_9()
+
+ sc.t5()
+
+ sc.t2_7()
+
+ sc.t8()
+
+ sc.t4_9()
+
+ var etime = new Date() - d1;
+
+ //return an array of times
+ //index 0 is initialization time
+ //FIXME: maybe way want labels for this data? Might be easier to analyze later...
+ return etime;
+}
Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/performanceTest.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/unitTest.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/unitTest.js?rev=947090&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/unitTest.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/unitTest.js Fri May 21 17:49:09 2010
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+
+dojo.require("doh.runner");
+
+//we assume statechart is imported here. should probably do registermodulepath instead
+
+(function(){
+ var sc;
+ doh.register("testKitchenSinkSuite",[
+ {
+ name:"testAll",
+ //timeout:5000,
+ setUp:function(){
+ sc = new StatechartExecutionContext()
+ sc.initialize();
+ },
+ runTest:function(){
+ var conf0 = sc.getCurrentConfiguration();
+ console.log(conf0);
+ doh.assertTrue(setwiseEqual(conf0,[sc._states.Basic1]));
+
+ console.info("sending event t1")
+ sc.t1()
+ var conf1 = sc.getCurrentConfiguration();
+ console.log(conf1);
+ doh.assertTrue(setwiseEqual(conf1,[sc._states.Basic2]));
+
+
+ console.info("sending event t2_7")
+ sc.t2_7()
+ var conf2 = sc.getCurrentConfiguration();
+ console.log(conf2);
+ doh.assertTrue(setwiseEqual(conf2,[sc._states.Basic4,sc._states.Basic6]));
+
+
+ console.info("sending event t3")
+ sc.t3()
+ var conf3 = sc.getCurrentConfiguration();
+ console.log(conf3);
+ doh.assertTrue(setwiseEqual(conf3,[sc._states.Basic5,sc._states.Basic7]));
+
+ console.info("sending event t4_9")
+ sc.t4_9()
+ var conf4 = sc.getCurrentConfiguration();
+ console.log(conf4);
+ doh.assertTrue(setwiseEqual(conf4,[sc._states.Basic2]));
+
+ console.info("sending event t5")
+ sc.t5()
+ var conf5 = sc.getCurrentConfiguration();
+ console.log(conf5);
+ doh.assertTrue(setwiseEqual(conf5,[sc._states.Basic1]));
+
+ console.info("sending event t2_7")
+ sc.t2_7()
+ var conf6 = sc.getCurrentConfiguration();
+ console.log(conf6);
+ doh.assertTrue(setwiseEqual(conf6,[sc._states.Basic5,sc._states.Basic7]));
+
+ console.info("sending event t8")
+ sc.t8()
+ var conf7 = sc.getCurrentConfiguration();
+ console.log(conf7);
+ doh.assertTrue(setwiseEqual(conf7,[sc._states.Basic4,sc._states.Basic7]));
+
+ console.info("sending event t4_9")
+ sc.t4_9()
+ var conf8 = sc.getCurrentConfiguration();
+ console.log(conf8);
+ doh.assertTrue(setwiseEqual(conf8,[sc._states.Basic3]));
+
+ //TODO: hook this up with doh.Deferred...
+ /*
+ var deferred = new doh.Deferred();
+ window.setTimeout(function(){
+ var conf9 = sc.getCurrentConfiguration();
+ console.log(conf9);
+ deferred.callback(setwiseEqual(conf9,[sc._states.FinalState]));
+ },1500);
+ return deferred;
+ */
+ },
+ tearDown:function(){
+ sc.destroy();
+ }
+ }
+ ]);
+})()
Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/scripts/unitTest.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/testHelpers.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/testHelpers.js?rev=947090&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/testHelpers.js (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/testHelpers.js Fri May 21 17:49:09 2010
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+
+//global functions used in unit testing
+
+setwiseEqual = function(A,B){
+ return dojo.every(A,function(a){
+ return dojo.some(B,function(b){
+ return a==b;
+ });
+ });
+}
Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/testHelpers.js
------------------------------------------------------------------------------
svn:eol-style = native