Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error highlighting and keep status when the VM throws. #555

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions components/src/stores/vm.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ function reduceVMTest(
try {
stack = vmTest.vm.vmStack().reverse();
} catch (e) {
setStatus("Runtime error: Invalid stack");
dispatch.current({
action: "setError",
payload: new Error("Runtime error: Invalid stack"),
});
}

return {
Expand Down Expand Up @@ -374,7 +377,7 @@ export function makeVmStore(
return done;
} catch (e) {
setStatus(`Runtime error: ${(e as Error).message}`);
dispatch.current({ action: "setValid", payload: false });
dispatch.current({ action: "setError", payload: e });
return true;
}
},
Expand All @@ -395,10 +398,11 @@ export function makeVmStore(
if (animate) {
dispatch.current({ action: "update" });
}

return done;
} catch (e) {
setStatus(`Runtime error: ${(e as Error).message}`);
dispatch.current({ action: "setValid", payload: false });
dispatch.current({ action: "setError", payload: e });
return true;
}
},
Expand Down
23 changes: 10 additions & 13 deletions web/src/pages/vm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,25 @@ const VM = () => {
actions.setVm(source);
}}
language={"vm"}
highlight={
state.controls.valid && state.vm.showHighlight
? state.vm.highlight
: undefined
}
highlight={state.vm.showHighlight ? state.vm.highlight : undefined}
highlightType={state.controls.valid ? "highlight" : "error"}
error={state.controls.error}
/>
</Panel>
<Panel className="vm" header={<Trans>VM Structures</Trans>}>
{state.controls.valid && state.vm.Stack.length > 0 && (
<>
<>
{state.vm.Stack.length > 0 && (
<VMStackFrame
statics={state.vm.Statics}
temp={state.vm.Temp}
frame={state.vm.Stack[0]}
/>
<CallStack
stack={state.vm.Stack}
addedSysInit={state.vm.AddedSysInit}
/>
</>
)}
)}
<CallStack
stack={state.vm.Stack}
addedSysInit={state.vm.AddedSysInit}
/>
</>
</Panel>
<Panel className="display" style={{ gridArea: "display" }}>
<Screen
Expand Down