diff --git a/src/statecharts/interpreter.ts b/src/statecharts/interpreter.ts index 447c64c..a412518 100644 --- a/src/statecharts/interpreter.ts +++ b/src/statecharts/interpreter.ts @@ -7,7 +7,10 @@ export function initialize(ast: Statechart): BigStepOutput { let history = new Map(); let enteredStates, environment, rest; ({enteredStates, environment, history, ...rest} = enterDefault(0, ast.root, { - environment: new Environment([new Map([["_timers", []]])]), + environment: new Environment([new Map([ + ["_timers", []], + ["_log", (str: string) => console.log(str)], + ])]), history, ...initialRaised, })); diff --git a/src/statecharts/parser.ts b/src/statecharts/parser.ts index a148b2d..790c0d2 100644 --- a/src/statecharts/parser.ts +++ b/src/statecharts/parser.ts @@ -1,4 +1,4 @@ -import { ConcreteState, HistoryState, OrState, PseudoState, Statechart, Transition } from "./abstract_syntax"; +import { ConcreteState, HistoryState, OrState, PseudoState, Statechart, stateDescription, Transition } from "./abstract_syntax"; import { Rountangle } from "./concrete_syntax"; import { isEntirelyWithin, Rect2D } from "../VisualEditor/geometry"; import { Action, EventTrigger, Expression, ParsedText } from "./label_ast"; @@ -352,6 +352,13 @@ export function parseStatechart(state: VisualEditorState, conns: Connections): [ } } + // sort children by their label + for (const state of uid2State.values()) { + if (state.kind === "and") { + state.children.sort((a, b) => stateDescription(a).localeCompare(stateDescription(b))); + } + } + return [{ root, transitions,