From 45cfc6f1f8bb738c9af03a893819df3324f21696 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Wed, 22 Oct 2025 11:15:33 +0200 Subject: [PATCH] add _log function to environment + enable explicit order of orthogonal regions --- src/statecharts/interpreter.ts | 5 ++++- src/statecharts/parser.ts | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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,