interpreter: exec exit actions

This commit is contained in:
Joeri Exelmans 2025-10-07 17:58:25 +02:00
parent b9327d2eb0
commit 2b73da9387
2 changed files with 37 additions and 11 deletions

View file

@ -22,7 +22,8 @@ text.highlight {
}
.selecting {
fill: rgba(0, 0, 255, 0.2);
fill: blue;
fill-opacity: 0.2;
stroke-width: 1px;
stroke:black;
stroke-dasharray: 7 6;
@ -36,7 +37,7 @@ text.highlight {
}
.rountangle:hover {
/* stroke: darkcyan; */
/* stroke: blue; */
/* stroke-opacity: 0.2; */
/* fill: #eee; */
/* stroke-width: 4px; */
@ -67,7 +68,7 @@ text.highlight {
stroke-width: 16px;
}
.lineHelper:hover {
stroke: darkcyan;
stroke: blue;
stroke-opacity: 0.2;
cursor: grab;
}
@ -78,7 +79,7 @@ text.highlight {
stroke-width: 16px;
}
.pathHelper:hover {
stroke: darkcyan;
stroke: blue;
stroke-opacity: 0.2;
cursor: grab;
}
@ -88,7 +89,7 @@ text.highlight {
fill: rgba(0, 0, 0, 0);
}
.circleHelper:hover {
fill: darkcyan;
fill: blue;
fill-opacity: 0.2;
cursor: grab;
}
@ -136,7 +137,7 @@ text.selected, text.selected:hover {
font-weight: 600;
}
text:hover {
fill: darkcyan;
fill: blue;
/* cursor: grab; */
}

View file

@ -20,19 +20,25 @@ type ActionScope = {
raised: RaisedEvents,
};
export function enter(state: ConcreteState, rt: ActionScope): ({mode: Mode} & ActionScope) {
type EnteredScope = { mode: Mode } & ActionScope;
export function enter(state: ConcreteState, rt: ActionScope): EnteredScope {
let {environment, raised} = rt;
// execute entry actions
for (const action of state.entryActions) {
({environment, raised} = execAction(action, {environment, raised}));
}
if (state.kind === "and") {
// enter children...
const mode: {[uid:string]: Mode} = {};
if (state.kind === "and") {
for (const child of state.children) {
let childMode;
({mode: childMode, environment, raised} = enter(child, {environment, raised}));
mode[child.uid] = childMode;
}
return { mode, environment, raised };
}
else if (state.kind === "or") {
const mode: {[uid:string]: Mode} = {};
@ -41,10 +47,29 @@ export function enter(state: ConcreteState, rt: ActionScope): ({mode: Mode} & Ac
let childMode;
({mode: childMode, environment, raised} = enter(child, {environment, raised}));
mode[child.uid] = childMode;
}
}
return { mode, environment, raised };
}
export function exit(state: ConcreteState, rt: EnteredScope): ActionScope {
let {mode, environment, raised} = rt;
// exit all active children...
for (const [childUid, childMode] of Object.entries(mode)) {
const child = state.children.find(child => child.uid === childUid);
if (child) {
({environment, raised} = exit(child, {mode: childMode, environment, raised}));
}
throw new Error("should never reach here");
}
// execute exit actions
for (const action of state.exitActions) {
({environment, raised} = execAction(action, {environment, raised}));
}
return {environment, raised};
}
export function execAction(action: Action, rt: ActionScope): ActionScope {