-
-
- Edit program code bytes
-
+
- {isProgramInvalid && {programError || "Program is not valid"}}
);
diff --git a/src/hooks/useDebuggerActions.ts b/src/hooks/useDebuggerActions.ts
index fba3f45..b23c838 100644
--- a/src/hooks/useDebuggerActions.ts
+++ b/src/hooks/useDebuggerActions.ts
@@ -6,7 +6,7 @@ import {
setBreakpointAddresses,
setClickedInstruction,
setInitialState,
- setIsProgramInvalid,
+ setIsAsmError,
setIsDebugFinished,
setIsRunMode,
setProgram,
@@ -80,20 +80,11 @@ export const useDebuggerActions = () => {
const handleProgramLoad = useCallback(
async (data?: ProgramUploadFileOutput) => {
if (data) {
- const response = await startProgram({ ...data.initial, status: Status.OK }, data.program);
- if (
- (
- response as unknown as {
- error: string;
- }
- )?.error
- ) {
- dispatch(setIsProgramInvalid(true));
- } else {
- dispatch(setIsProgramInvalid(false));
- }
+ await startProgram({ ...data.initial, status: Status.OK }, data.program);
+
+ dispatch(setIsAsmError(false));
} else {
- dispatch(setIsProgramInvalid(true));
+ dispatch(setIsAsmError(true));
}
},
[startProgram, dispatch],
diff --git a/src/packages/host-calls/read.ts b/src/packages/host-calls/read.ts
index 1cc9eb2..10ac5dc 100644
--- a/src/packages/host-calls/read.ts
+++ b/src/packages/host-calls/read.ts
@@ -9,6 +9,8 @@ export class ReadAccounts implements read.Accounts {
public readonly data: Storage = new Map();
read(_serviceId: block.ServiceId, hash: hash.Blake2bHash): Promise
{
+ console.log(this.data);
+
const d = this.data.get(hash.toString());
if (d === undefined) {
throw new Error(`Unexpected call to read with ${hash}`);
diff --git a/src/packages/web-worker/command-handlers/host-call.ts b/src/packages/web-worker/command-handlers/host-call.ts
index a4da4f6..28b722d 100644
--- a/src/packages/web-worker/command-handlers/host-call.ts
+++ b/src/packages/web-worker/command-handlers/host-call.ts
@@ -9,7 +9,7 @@ import { tryAsServiceId } from "@typeberry/block";
type HostCallParams = {
pvm: PvmApiInterface | null;
hostCallIdentifier: HostCallIdentifiers;
- storage: Storage | null;
+ storage?: Storage;
};
type ExecuteParams = Parameters;
type RegistersType = ExecuteParams[1];
@@ -31,8 +31,7 @@ const hostCall = async ({
if (hostCallIdentifier === HostCallIdentifiers.READ) {
const readAccounts = new ReadAccounts(storage);
const jamHostCall = new read.Read(readAccounts);
- // TODO the types are the same, but exported from different packages and lost track of the type
- jamHostCall.currentServiceId = tryAsServiceId(0x30303030) as unknown as typeof jamHostCall.currentServiceId;
+ jamHostCall.currentServiceId = tryAsServiceId(0x30303030) as any;
await jamHostCall.execute(
pvm.getInterpreter().getGasCounter(),
@@ -56,7 +55,7 @@ export const runHostCall = async ({ pvm, hostCallIdentifier, storage }: HostCall
throw new Error("PVM is uninitialized.");
}
- if (storage === null) {
+ if (!storage) {
throw new Error("Storage is uninitialized.");
}
diff --git a/src/packages/web-worker/command-handlers/step.ts b/src/packages/web-worker/command-handlers/step.ts
index 74a9d88..17073e7 100644
--- a/src/packages/web-worker/command-handlers/step.ts
+++ b/src/packages/web-worker/command-handlers/step.ts
@@ -15,7 +15,7 @@ export type StepResponse = {
error?: unknown;
result: CurrentInstruction | object;
state: ExpectedState;
- exitArg: number;
+ exitArg?: number;
isFinished: boolean;
};
@@ -49,6 +49,6 @@ export const runStep = async ({ pvm, program, stepsToPerform, storage }: StepPar
const data = await step({ pvm, program, stepsToPerform, storage });
return { status: CommandStatus.SUCCESS, ...data };
} catch (error) {
- return { status: CommandStatus.ERROR, error, isFinished: true, result: {}, state: {}, exitArg: 0 };
+ return { status: CommandStatus.ERROR, error, isFinished: true, result: {}, state: {}, exitArg: null };
}
};
diff --git a/src/packages/web-worker/types.ts b/src/packages/web-worker/types.ts
index a512560..59ca23d 100644
--- a/src/packages/web-worker/types.ts
+++ b/src/packages/web-worker/types.ts
@@ -30,7 +30,7 @@ export type WorkerResponseParams = CommonWorkerResponseParams &
| { command: Commands.STOP; payload: { isRunMode: boolean } }
| { command: Commands.MEMORY; payload: { memoryChunk: Uint8Array } }
| { command: Commands.SET_STORAGE }
- | { command: Commands.HOST_CALL }
+ | { command: Commands.HOST_CALL; payload: { hostCallIdentifier: HostCallIdentifiers; storage: Storage } }
);
type CommonWorkerRequestParams = { messageId: string };
diff --git a/src/packages/web-worker/worker.ts b/src/packages/web-worker/worker.ts
index ed197a3..7e67c7f 100644
--- a/src/packages/web-worker/worker.ts
+++ b/src/packages/web-worker/worker.ts
@@ -104,14 +104,13 @@ onmessage = async (e: MessageEvent) => {
messageId: e.data.messageId,
});
} else if (e.data.command === Commands.HOST_CALL) {
- await commandHandlers.runHostCall({
+ const data = await commandHandlers.runHostCall({
pvm,
hostCallIdentifier: e.data.payload.hostCallIdentifier,
storage,
});
postTypedMessage({
- status: CommandStatus.SUCCESS,
command: Commands.HOST_CALL,
messageId: e.data.messageId,
});
diff --git a/src/store/debugger/debuggerSlice.ts b/src/store/debugger/debuggerSlice.ts
index b5b3d0d..f02b057 100644
--- a/src/store/debugger/debuggerSlice.ts
+++ b/src/store/debugger/debuggerSlice.ts
@@ -5,12 +5,12 @@ import { RootState } from "@/store";
import { Storage } from "@/packages/web-worker/types";
export interface DebuggerState {
- isProgramInvalid: boolean;
breakpointAddresses: number[];
clickedInstruction: CurrentInstruction | null;
hasHostCallOpen: boolean;
initialState: ExpectedState;
instructionMode: InstructionMode;
+ isAsmError: boolean;
isDebugFinished: boolean;
isProgramEditMode: boolean;
isRunMode: boolean;
@@ -32,7 +32,7 @@ const initialState: DebuggerState = {
gas: 10000n,
},
isProgramEditMode: false,
- isProgramInvalid: false,
+ isAsmError: false,
isRunMode: false,
isStepMode: false,
hasHostCallOpen: false,
@@ -59,8 +59,8 @@ const debuggerSlice = createSlice({
setIsProgramEditMode(state, action) {
state.isProgramEditMode = action.payload;
},
- setIsProgramInvalid(state, action) {
- state.isProgramInvalid = action.payload;
+ setIsAsmError(state, action) {
+ state.isAsmError = action.payload;
},
setIsRunMode(state, action) {
state.isRunMode = action.payload;
@@ -99,12 +99,12 @@ const debuggerSlice = createSlice({
});
export const {
- setIsProgramInvalid,
setBreakpointAddresses,
setClickedInstruction,
setHasHostCallOpen,
setInitialState,
setInstructionMode,
+ setIsAsmError,
setIsDebugFinished,
setIsProgramEditMode,
setIsRunMode,
@@ -119,7 +119,7 @@ export const {
export const selectProgram = (state: RootState) => state.debugger.program;
export const selectInitialState = (state: RootState) => state.debugger.initialState;
export const selectIsProgramEditMode = (state: RootState) => state.debugger.isProgramEditMode;
-export const selectIsProgramInvalid = (state: RootState) => state.debugger.isProgramInvalid;
+export const selectIsAsmError = (state: RootState) => state.debugger.isAsmError;
export const selectIsRunMode = (state: RootState) => state.debugger.isRunMode;
export const selectProgramPreviewResult = (state: RootState) => state.debugger.programPreviewResult;
export const selectBreakpointAddresses = (state: RootState) => state.debugger.breakpointAddresses;
diff --git a/src/store/workers/workersSlice.ts b/src/store/workers/workersSlice.ts
index c8482b9..3c3c0dc 100644
--- a/src/store/workers/workersSlice.ts
+++ b/src/store/workers/workersSlice.ts
@@ -265,13 +265,15 @@ export const handleHostCall = createAsyncThunk("workers/handleHostCall", async (
payload: { hostCallIdentifier: worker.exitArg as HostCallIdentifiers },
});
- if ((getState() as RootState).debugger.isRunMode) {
- dispatch(continueAllWorkers());
- }
+ // if (resp) {
+ if (getState().debugger.isRunMode) {
+ dispatch(continueAllWorkers());
+ }
+ // }
- if (hasCommandStatusError(resp)) {
- throw resp.error;
- }
+ // if (hasCommandStatusError(resp)) {
+ // throw resp.error;
+ // }
}),
);
@@ -349,9 +351,7 @@ export const stepAllWorkers = createAsyncThunk("workers/stepAllWorkers", async (
command: Commands.STEP,
payload: {
program: new Uint8Array(debuggerState.program),
- // NOTE [ToDr] Despite settings "batched steps", when
- // the user clicks "Step" we want just single step to happen.
- stepsToPerform: 1,
+ stepsToPerform: debuggerState.stepsToPerform,
},
});