Skip to content

Commit

Permalink
Add stop on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
wkwiatek committed Nov 13, 2024
1 parent a2313c6 commit 167be91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
38 changes: 28 additions & 10 deletions src/components/DebuggerControlls/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RefreshCcw, Play, StepForward } from "lucide-react";
import { RefreshCcw, Play, StepForward, Pause } from "lucide-react";
import { LoadingSpinner } from "../LoadingSpinner";
import { ProgramLoader } from "../ProgramLoader";
import { Button } from "../ui/button";
Expand Down Expand Up @@ -82,6 +82,10 @@ export const DebuggerControlls = () => {
dispatch(refreshPageAllWorkers());
};

const handlePauseProgram = async () => {
dispatch(setIsRunMode(false));
};

return (
<div className="col-span-12 md:col-span-6 max-sm:order-2 flex align-middle max-sm:justify-between mb-3">
<div className="md:mr-3">
Expand All @@ -104,18 +108,32 @@ export const DebuggerControlls = () => {
<RefreshCcw className="w-3.5 md:mr-1.5" />
<span className="hidden md:block">Reset</span>
</Button>
<Button
className="md:mr-3"
onClick={handleRunProgram}
disabled={isDebugFinished || !pvmInitialized || isProgramEditMode || isLoading || !!error}
>
{isLoading ? <LoadingSpinner className="w-3.5 md:mr-1.5" size={20} /> : <Play className="w-3.5 md:mr-1.5" />}
<span className="hidden md:block">Run</span>
</Button>
{!isDebugFinished && isRunMode ? (
<Button className="md:mr-3" onClick={handlePauseProgram}>
<Pause className="w-3.5 md:mr-1.5" />
<span className="hidden md:block">Stop</span>
</Button>
) : (
<Button
className="md:mr-3"
onClick={handleRunProgram}
disabled={isDebugFinished || !pvmInitialized || isProgramEditMode || isLoading || !!error}
>
{isLoading ? <LoadingSpinner className="w-3.5 md:mr-1.5" size={20} /> : <Play className="w-3.5 md:mr-1.5" />}
<span className="hidden md:block">Run</span>
</Button>
)}
<Button
className="md:mr-3"
onClick={onNext}
disabled={isDebugFinished || !pvmInitialized || isProgramEditMode || isLoading || !!error}
disabled={
(!isDebugFinished && isRunMode) ||
isDebugFinished ||
!pvmInitialized ||
isProgramEditMode ||
isLoading ||
!!error
}
>
{isLoading ? (
<LoadingSpinner className="w-3.5 md:mr-1.5" size={20} />
Expand Down
8 changes: 6 additions & 2 deletions src/store/workers/workersSlice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSlice, createAsyncThunk, isRejected } from "@reduxjs/toolkit";
import { RootState } from "@/store";
import { CurrentInstruction, ExpectedState } from "@/types/pvm.ts";
import { setIsDebugFinished, setIsStepMode } from "@/store/debugger/debuggerSlice.ts";
import { setIsDebugFinished, setIsRunMode, setIsStepMode } from "@/store/debugger/debuggerSlice.ts";
import PvmWorker from "@/packages/web-worker/worker?worker&inline";
import { SupportedLangs } from "@/packages/web-worker/utils.ts";
import { virtualTrapInstruction } from "@/utils/virtualTrapInstruction.ts";
Expand Down Expand Up @@ -256,7 +256,11 @@ export const continueAllWorkers = createAsyncThunk("workers/continueAllWorkers",
dispatch(setIsDebugFinished(true));
}

if (allSame && !allFinished && allRunning && !anyBreakpoint) {
if (!allSame) {
dispatch(setIsRunMode(false));
}

if (debuggerState.isRunMode && allSame && !allFinished && allRunning && !anyBreakpoint) {
await stepAllWorkersAgain();
}
};
Expand Down

0 comments on commit 167be91

Please sign in to comment.