Skip to content

Commit

Permalink
Merge branch 'main' into td-bblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Dec 6, 2024
2 parents 4bcbbce + 7de6085 commit c984e97
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/components/DebuggerControlls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const DebuggerControlls = () => {
}

dispatch(setIsProgramEditMode(false));
await dispatch(refreshPageAllWorkers()).unwrap();
} catch (error) {
if (error instanceof Error || isSerializedError(error)) {
setError(error.message);
Expand Down
30 changes: 30 additions & 0 deletions src/components/ProgramLoader/Examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ const programs: {
memory: [],
gas: 100000n,
},
gameOfLife: {
program: [
0, 0, 128, 222, 62, 1, 3, 255, 0, 62, 1, 11, 255, 0, 62, 1, 19, 255, 0, 62, 1, 18, 255, 0, 62, 1, 9, 255, 0, 5,
176, 0, 4, 1, 255, 17, 2, 17, 1, 7, 17, 8, 166, 0, 4, 2, 255, 17, 2, 34, 1, 7, 18, 8, 241, 35, 19, 8, 8, 35, 3, 5,
47, 2, 51, 128, 0, 11, 52, 18, 68, 1, 15, 20, 1, 14, 44, 21, 2, 25, 50, 21, 3, 21, 5, 8, 7, 21, 3, 6, 5, 11, 2,
51, 128, 26, 3, 255, 0, 5, 205, 2, 51, 128, 26, 3, 5, 198, 4, 5, 2, 52, 128, 0, 2, 68, 255, 11, 70, 18, 102, 1, 8,
101, 5, 2, 68, 2, 11, 70, 18, 102, 1, 8, 101, 5, 2, 68, 247, 11, 70, 18, 102, 1, 8, 101, 5, 2, 68, 16, 11, 70, 18,
102, 1, 8, 101, 5, 2, 68, 1, 11, 70, 18, 102, 1, 8, 101, 5, 2, 68, 254, 11, 70, 18, 102, 1, 8, 101, 5, 2, 68, 240,
11, 70, 18, 102, 1, 8, 101, 5, 2, 68, 2, 11, 70, 18, 102, 1, 8, 101, 5, 5, 117, 255, 4, 1, 17, 2, 19, 128, 0, 11,
18, 16, 50, 2, 17, 1, 7, 17, 64, 69, 255, 5, 240, 33, 132, 16, 146, 9, 153, 72, 138, 18, 17, 69, 137, 82, 69, 74,
82, 146, 146, 148, 164, 36, 37, 41, 73, 73, 26, 149, 16,
],
regs: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
pc: 0,
pageMap: [
{
address: 0,
length: 4096,
"is-writable": true,
},
],
memory: [],
gas: 10_000_000n,
},
branch: {
program: [0, 0, 16, 4, 7, 210, 4, 7, 39, 210, 4, 6, 0, 4, 7, 239, 190, 173, 222, 17, 6],
regs: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand Down Expand Up @@ -81,6 +105,12 @@ export const Examples = ({ onProgramLoad }: { onProgramLoad: (val: ProgramUpload
Fibonacci sequence
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="gameOfLife" id="option-gameOfLife" />
<Label htmlFor="option-gameOfLife" className="cursor-pointer">
Conway's Game of Life
</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="branch" id="option-branch" />
<Label htmlFor="option-branch" className="cursor-pointer">
Expand Down
21 changes: 15 additions & 6 deletions src/store/workers/workersSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,30 +242,35 @@ export const continueAllWorkers = createAsyncThunk("workers/continueAllWorkers",
throw new Error("Program counter is undefined");
}

const isBreakpoint = debuggerState.breakpointAddresses.includes(state.pc);

logger.info("Response from worker:", {
isFinished,
state,
isRunMode,
debuggerHit: debuggerState.breakpointAddresses.includes(state.pc),
debuggerHit: isBreakpoint,
});

if (isBreakpoint) {
dispatch(setIsRunMode(false));
}

return {
isFinished,
state,
isRunMode,
isBreakpoint: debuggerState.breakpointAddresses.includes(state.pc),
isBreakpoint,
};
}),
);

const allSame = responses.every(
(response) => JSON.stringify(response.state) === JSON.stringify(responses[0].state),
const { workers } = getState() as RootState;
const allSame = workers.every(
({ currentState }) => JSON.stringify(currentState) === JSON.stringify(workers[0].currentState),
);

const allFinished = responses.every((response) => response.isFinished);

const allRunning = responses.every((response) => response.isRunMode);

const anyBreakpoint = responses.some((response) => response.isBreakpoint);

if (allFinished) {
Expand All @@ -276,6 +281,8 @@ export const continueAllWorkers = createAsyncThunk("workers/continueAllWorkers",
dispatch(setIsRunMode(false));
}

await dispatch(refreshPageAllWorkers());

if (debuggerState.isRunMode && allSame && !allFinished && allRunning && !anyBreakpoint) {
await stepAllWorkersAgain();
}
Expand Down Expand Up @@ -351,6 +358,8 @@ export const stepAllWorkers = createAsyncThunk("workers/stepAllWorkers", async (

const allFinished = responses.every((response) => response.isFinished);

await dispatch(refreshPageAllWorkers());

if (allFinished) {
dispatch(setIsDebugFinished(true));
}
Expand Down

0 comments on commit c984e97

Please sign in to comment.