From e233fa916684b3784845ab8a0574a17132f1c2b4 Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Mon, 13 Oct 2025 11:35:42 +0200 Subject: [PATCH] show timestamp of next timeout --- src/App/App.css | 8 +++++++- src/App/App.tsx | 32 ++++++++++++++++++++++++++----- src/VisualEditor/interpreter.ts | 5 +---- src/VisualEditor/runtime_types.ts | 6 +++++- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/App/App.css b/src/App/App.css index 0111196..ccfe175 100644 --- a/src/App/App.css +++ b/src/App/App.css @@ -40,4 +40,10 @@ details { } /* details:not(:has(details)) > summary::marker { color: white; -} */ \ No newline at end of file +} */ + +.readonlyTextBox { + width: 56; + background-color:"#eee"; + text-align: "right"; +} diff --git a/src/App/App.tsx b/src/App/App.tsx index 624ec86..2d2a744 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from "react"; import { ConcreteState, emptyStatechart, Statechart, stateDescription, Transition } from "../VisualEditor/ast"; import { handleInputEvent, initialize } from "../VisualEditor/interpreter"; +import { TimerElapseEvent, Timers } from "@/VisualEditor/runtime_types"; import { Action, Expression } from "../VisualEditor/label_ast"; import { BigStep, BigStepOutput, Environment, Mode } from "../VisualEditor/runtime_types"; import { VisualEditor } from "../VisualEditor/VisualEditor"; @@ -68,11 +69,18 @@ export function AST(props: {root: ConcreteState, transitions: Map(emptyStatechart); @@ -180,6 +188,10 @@ export function App() { setTime({kind: "paused", simtime: timestamp}); } + // timestamp of next timed transition, in simulated time + const timers: Timers = (rt[rtIdx!]?.environment.get("_timers") || []); + const nextTimedTransition: [number, TimerElapseEvent] | undefined = timers[0]; + return
@@ -188,9 +200,11 @@ export function App() {   - raise  - {[...ast.inputEvents].map(event => )} -   + {ast.inputEvents && + <>raise  + {[...ast.inputEvents].map(event => )} +   + } onChangePaused(e.target.checked, performance.now())}/> onChangePaused(!e.target.checked, performance.now())}/> @@ -200,7 +214,15 @@ export function App() { onTimeScaleChange(e.target.value, performance.now())}/>     - + + {nextTimedTransition && + <> +   + next timeout (s): + + + + }
diff --git a/src/VisualEditor/interpreter.ts b/src/VisualEditor/interpreter.ts index 2ae592d..34f4613 100644 --- a/src/VisualEditor/interpreter.ts +++ b/src/VisualEditor/interpreter.ts @@ -1,7 +1,7 @@ import { evalExpr } from "./actionlang_interpreter"; import { computeArena, ConcreteState, getDescendants, isOverlapping, OrState, Statechart, stateDescription, Transition } from "./ast"; import { Action } from "./label_ast"; -import { Environment, RaisedEvents, Mode, RT_Statechart, initialRaised, BigStepOutput } from "./runtime_types"; +import { Environment, RaisedEvents, Mode, RT_Statechart, initialRaised, BigStepOutput, TimerElapseEvent, Timers } from "./runtime_types"; export function initialize(ast: Statechart): BigStepOutput { let {enteredStates, environment, ...raised} = enterDefault(0, ast.root, { @@ -17,9 +17,6 @@ type ActionScope = { type EnteredScope = { enteredStates: Mode } & ActionScope; -type TimerElapseEvent = {state: string, timeDurMs: number}; -type Timers = [number, TimerElapseEvent][]; - export function entryActions(simtime: number, state: ConcreteState, actionScope: ActionScope): ActionScope { for (const action of state.entryActions) { (actionScope = execAction(action, actionScope)); diff --git a/src/VisualEditor/runtime_types.ts b/src/VisualEditor/runtime_types.ts index 057d973..7c974d5 100644 --- a/src/VisualEditor/runtime_types.ts +++ b/src/VisualEditor/runtime_types.ts @@ -27,9 +27,13 @@ export type RaisedEvents = { outputEvents: string[]; }; -export type Timers = Map; // transition uid -> timestamp +// export type Timers = Map; // transition uid -> timestamp export const initialRaised: RaisedEvents = { internalEvents: [], outputEvents: [], }; + +export type TimerElapseEvent = { state: string; timeDurMs: number; }; +export type Timers = [number, TimerElapseEvent][]; +