From 1539eb61518e82c8f7e49e8d6998cec3aaa125d6 Mon Sep 17 00:00:00 2001 From: Krystian Fras Date: Tue, 22 Oct 2024 21:01:56 +0200 Subject: [PATCH] Refactor pageSize in PageMemory and workersSlice --- src/components/MemoryPreview/PageMemory.tsx | 5 +---- src/store/workers/workersSlice.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/MemoryPreview/PageMemory.tsx b/src/components/MemoryPreview/PageMemory.tsx index c8b9f6e..4f0fe48 100644 --- a/src/components/MemoryPreview/PageMemory.tsx +++ b/src/components/MemoryPreview/PageMemory.tsx @@ -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 (
diff --git a/src/store/workers/workersSlice.ts b/src/store/workers/workersSlice.ts index bab7f3f..db6cf00 100644 --- a/src/store/workers/workersSlice.ts +++ b/src/store/workers/workersSlice.ts @@ -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 @@ -115,7 +115,7 @@ export const initAllWorkers = createAsyncThunk("workers/initAllWorkers", async ( }, }); - const messageHandler = (event: MessageEvent) => { + const messageHandler = (event: MessageEvent) => { if (event.data.command === Commands.STEP) { const { state, isFinished } = event.data.payload; @@ -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( @@ -218,7 +218,7 @@ export const continueAllWorkers = createAsyncThunk("workers/continueAllWorkers", isBreakpoint: boolean; }) => void, ) => { - const messageHandler = (event: MessageEvent) => { + const messageHandler = (event: MessageEvent) => { if (event.data.command === Commands.STEP) { const { state, isRunMode, isFinished } = event.data.payload; const currentState = getState() as RootState; @@ -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, @@ -402,6 +406,7 @@ const workers = createSlice({ }; }, ) => { + console.log("action", action); const memory = getWorker(state, action.payload.id)?.memory; if (!memory) { return;