Skip to content
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
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@reduxjs/toolkit": "^2.2.8",
"@tanstack/react-virtual": "^3.10.9",
"@typeberry/block": "0.0.1-447d5c4",
"@typeberry/jam-host-calls": "0.0.1-459ce0b",
"@typeberry/pvm-debugger-adapter": "0.1.0-83a3aec",
"@typeberry/jam-host-calls": "0.0.1-fece159",
"@typeberry/pvm-debugger-adapter": "0.1.0-fece159",
"@typeberry/spectool-wasm": "0.20.8",
"@uiw/react-codemirror": "^4.23.6",
"blake2b": "^2.1.4",
Expand Down
10 changes: 4 additions & 6 deletions src/components/ProgramTextLoader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { bytes } from "@typeberry/block";
import { logger } from "@/utils/loggerService";
import { useAppSelector } from "@/store/hooks.ts";
import { selectIsProgramInvalid } from "@/store/debugger/debuggerSlice.ts";
import { ProgramEdit } from "../ProgramEdit";

const parseArrayLikeString = (input: string): (number | string)[] => {
// Remove the brackets and split the string by commas
Expand All @@ -15,7 +16,7 @@ const parseArrayLikeString = (input: string): (number | string)[] => {

// Process each item
return items.map((item) => {
if (/^(?:0x)?[0-9a-fA-F]+$/i.test(item)) {
if (/^0x[0-9a-fA-F]+$/i.test(item)) {
return parseInt(item, 16);
} else if (!isNaN(Number(item))) {
return Number(item);
Expand Down Expand Up @@ -72,7 +73,6 @@ export const ProgramTextLoader = ({
const parseTest = newInput.replace(/0x([a-fA-F0-9]+)/g, '"0x$1"');
// Parse it just to check if it's a valid JSON
JSON.parse(parseTest);

const parsedJson = parseArrayLikeString(newInput);
const programArray = parsedJson.filter((item) => typeof item === "number") as number[];

Expand All @@ -93,11 +93,9 @@ export const ProgramTextLoader = ({
};

return (
<div className="h-full">
<div className="h-full flex flex-col">
<ProgramEdit startSlot={<small>Edit program code bytes</small>} />
<div className={classNames("h-full flex-auto flex gap-1 flex-col")}>
<p className="pb-2 mb-1">
<small>Edit program code bytes</small>
</p>
<Textarea
autoFocus
className={classNames("w-full flex-auto font-mono text-base border-2 rounded-md", {
Expand Down
35 changes: 29 additions & 6 deletions src/pages/DebuggerContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAppDispatch, useAppSelector } from "@/store/hooks.ts";
import { useDebuggerActions } from "@/hooks/useDebuggerActions.ts";
import { useCallback, useRef } from "react";
import { CurrentInstruction } from "@/types/pvm.ts";
import { CurrentInstruction, RegistersArray } from "@/types/pvm.ts";
import { setClickedInstruction, setIsProgramInvalid } from "@/store/debugger/debuggerSlice.ts";
import { InitialLoadProgramCTA } from "@/components/InitialLoadProgramCTA";
import { InstructionMode } from "@/components/Instructions/types.ts";
Expand All @@ -14,6 +14,7 @@ import { MemoryPreview } from "@/components/MemoryPreview";
// import { KnowledgeBase } from "@/components/KnowledgeBase";
import { MobileKnowledgeBase } from "@/components/KnowledgeBase/Mobile.tsx";
import { HostCalls } from "@/components/HostCalls";
import { Program } from "@typeberry/pvm-debugger-adapter";

const DebuggerContent = () => {
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -80,12 +81,34 @@ const DebuggerContent = () => {
dispatch(setIsProgramInvalid(true));
}

function tryAsSpi(program: number[]) {
try {
const { code, memory, registers } = Program.fromSpi(
new Uint8Array(program),
new Uint8Array(),
);
const regs = Array.from(registers.getAllU64()) as RegistersArray;
return {
program: Array.from(code) || [],
initial: { ...initialState, regs, mem: memory },
name: "custom",
};
} catch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make try a bit more minimal? I guess the only thing that is expected to throw is Program.fromSpi, isn't it?

return null;
}
}

if (!error && program) {
debuggerActions.handleProgramLoad({
initial: initialState,
program: program || [],
name: "custom",
});
const maybeSpi = tryAsSpi(program.slice());
if (maybeSpi) {
debuggerActions.handleProgramLoad(maybeSpi);
} else {
debuggerActions.handleProgramLoad({
initial: initialState,
program: program || [],
name: "custom",
});
}
}
}}
/>
Expand Down
Loading