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

Refactor pageSize in PageMemory and workersSlice #133

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
5 changes: 1 addition & 4 deletions src/components/MemoryPreview/PageMemory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export const MemoryTable = ({ data, addressStart }: { addressStart: number; data
export const PageMemory = ({ onPageChange }: { onPageChange: (page: number) => void }) => {
// TODO: get the memory for all of them and compare results
const memory = useSelector(selectMemoryForFirstWorker);
console.log({
memory,
});

console.log("memort", memory?.meta);
return (
<div>
<div className="flex w-full">
Expand Down
15 changes: 10 additions & 5 deletions src/store/workers/workersSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { RootState } from "@/store";
import { CurrentInstruction, ExpectedState } from "@/types/pvm.ts";
import { setIsDebugFinished } from "@/store/debugger/debuggerSlice.ts";
import { Commands, PvmTypes } from "@/packages/web-worker/worker.ts";
import { Commands, PvmTypes, TargetOnMessageParams } from "@/packages/web-worker/worker.ts";
import PvmWorker from "@/packages/web-worker/worker?worker&inline";

// TODO: remove this when found a workaround for BigInt support in JSON.stringify
Expand Down Expand Up @@ -115,7 +115,7 @@ export const initAllWorkers = createAsyncThunk("workers/initAllWorkers", async (
},
});

const messageHandler = (event: MessageEvent) => {
const messageHandler = (event: MessageEvent<TargetOnMessageParams>) => {
if (event.data.command === Commands.STEP) {
const { state, isFinished } = event.data.payload;

Expand All @@ -134,8 +134,8 @@ export const initAllWorkers = createAsyncThunk("workers/initAllWorkers", async (
}

if (event.data.command === Commands.MEMORY_SIZE) {
console.log("Memory size:", event.data.payload.memorySize);
dispatch(setPageSize(event.data.payload.memorySize));
const pageSize = event.data.payload.memorySize as number;
dispatch(setPageSize({ pageSize, id: worker.id }));
}
if (event.data.command === Commands.MEMORY_PAGE) {
dispatch(
Expand Down Expand Up @@ -218,7 +218,7 @@ export const continueAllWorkers = createAsyncThunk("workers/continueAllWorkers",
isBreakpoint: boolean;
}) => void,
) => {
const messageHandler = (event: MessageEvent) => {
const messageHandler = (event: MessageEvent<TargetOnMessageParams>) => {
if (event.data.command === Commands.STEP) {
const { state, isRunMode, isFinished } = event.data.payload;
const currentState = getState() as RootState;
Expand All @@ -238,6 +238,10 @@ export const continueAllWorkers = createAsyncThunk("workers/continueAllWorkers",
dispatch(setIsDebugFinished(true));
}

if (state.pc === undefined) {
throw new Error("Program counter is undefined");
}

resolve({
isFinished,
state,
Expand Down Expand Up @@ -402,6 +406,7 @@ const workers = createSlice({
};
},
) => {
console.log("action", action);
const memory = getWorker(state, action.payload.id)?.memory;
if (!memory) {
return;
Expand Down
Loading