import { useState } from "react"; import { ConcreteState, emptyStatechart, Statechart, stateDescription, Transition } from "../VisualEditor/ast"; import { VisualEditor } from "../VisualEditor/VisualEditor"; import { RT_Statechart } from "../VisualEditor/runtime_types"; import { initialize, handleEvent } from "../VisualEditor/interpreter"; import { Action, Expression } from "../VisualEditor/label_ast"; import "../index.css"; import "./App.css"; export function ShowTransition(props: {transition: Transition}) { return <>➔ {stateDescription(props.transition.tgt)}; } export function ShowExpr(props: {expr: Expression}) { if (props.expr.kind === "literal") { return <>{props.expr.value}; } else if (props.expr.kind === "ref") { return <>{props.expr.variable}; } else if (props.expr.kind === "unaryExpr") { return <>{props.expr.operator}; } else if (props.expr.kind === "binaryExpr") { return <>{props.expr.operator}; } } export function ShowAction(props: {action: Action}) { if (props.action.kind === "raise") { return <>raise {props.action.event}; } else if (props.action.kind === "assignment") { return <>{props.action.lhs} = ;; } } export function AST(props: {root: ConcreteState, transitions: Map}) { const description = stateDescription(props.root); const outgoing = props.transitions.get(props.root.uid) || []; return
{props.root.kind}: {description} {props.root.entryActions.length>0 && props.root.entryActions.map(action =>
 entry /
) } {props.root.exitActions.length>0 && props.root.exitActions.map(action =>
 exit /
) } {props.root.children.length>0 && props.root.children.map(child => ) } {outgoing.length>0 && outgoing.map(transition => <> 
) }
} export function App() { const [ast, setAST] = useState(emptyStatechart); const [errors, setErrors] = useState<[string,string][]>([]); const [rt, setRT] = useState(null); const [paused, setPaused] = useState(true); const [timescale, setTimescale] = useState(1); function restart() { const rt = initialize(ast); console.log('runtime: ', rt); setRT(rt); } function stop() { setRT(null); } function raise(event: string) { if (rt && ast.inputEvents.has(event)) { const nextConfig = handleEvent(event, ast, ast.root, rt); setRT(nextConfig); // console.log({nextConfigs}); // if (nextConfigs.length > 0) { // if (nextConfigs.length > 1) { // console.warn('non-determinism, blindly selecting first next run-time state!'); // } // setRT(nextConfigs[0]); // } } } return
setPaused(e.target.checked)}/> setPaused(!e.target.checked)}/>
; } export default App;