Skip to content

Commit 64efe38

Browse files
author
Edward Palmer
committed
Add error highlighting and keep status when the VM throws.
TESTED=Added broken code and confirmed it got hit in test / normal runs.
1 parent cd2963f commit 64efe38

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

components/src/stores/vm.store.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ function reduceVMTest(
102102
try {
103103
stack = vmTest.vm.vmStack().reverse();
104104
} catch (e) {
105-
setStatus("Runtime error: Invalid stack");
105+
dispatch.current({
106+
action: "setError",
107+
payload: new Error("Runtime error: Invalid stack"),
108+
});
106109
}
107110

108111
return {
@@ -374,7 +377,7 @@ export function makeVmStore(
374377
return done;
375378
} catch (e) {
376379
setStatus(`Runtime error: ${(e as Error).message}`);
377-
dispatch.current({ action: "setValid", payload: false });
380+
dispatch.current({ action: "setError", payload: e });
378381
return true;
379382
}
380383
},
@@ -395,10 +398,11 @@ export function makeVmStore(
395398
if (animate) {
396399
dispatch.current({ action: "update" });
397400
}
401+
398402
return done;
399403
} catch (e) {
400404
setStatus(`Runtime error: ${(e as Error).message}`);
401-
dispatch.current({ action: "setValid", payload: false });
405+
dispatch.current({ action: "setError", payload: e });
402406
return true;
403407
}
404408
},

web/src/pages/vm.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,28 +252,25 @@ const VM = () => {
252252
actions.setVm(source);
253253
}}
254254
language={"vm"}
255-
highlight={
256-
state.controls.valid && state.vm.showHighlight
257-
? state.vm.highlight
258-
: undefined
259-
}
255+
highlight={state.vm.showHighlight ? state.vm.highlight : undefined}
256+
highlightType={state.controls.valid ? "highlight" : "error"}
260257
error={state.controls.error}
261258
/>
262259
</Panel>
263260
<Panel className="vm" header={<Trans>VM Structures</Trans>}>
264-
{state.controls.valid && state.vm.Stack.length > 0 && (
265-
<>
261+
<>
262+
{state.vm.Stack.length > 0 && (
266263
<VMStackFrame
267264
statics={state.vm.Statics}
268265
temp={state.vm.Temp}
269266
frame={state.vm.Stack[0]}
270267
/>
271-
<CallStack
272-
stack={state.vm.Stack}
273-
addedSysInit={state.vm.AddedSysInit}
274-
/>
275-
</>
276-
)}
268+
)}
269+
<CallStack
270+
stack={state.vm.Stack}
271+
addedSysInit={state.vm.AddedSysInit}
272+
/>
273+
</>
277274
</Panel>
278275
<Panel className="display" style={{ gridArea: "display" }}>
279276
<Screen

0 commit comments

Comments
 (0)