Skip to content

Commit

Permalink
Add host calls for 64bits
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian50 committed Jan 9, 2025
1 parent 1df7d6d commit 09bb592
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 40 deletions.
25 changes: 12 additions & 13 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"@radix-ui/react-tooltip": "^1.1.2",
"@reduxjs/toolkit": "^2.2.8",
"@tanstack/react-virtual": "^3.10.9",
"@typeberry/block": "^0.0.1-1a02906",
"@typeberry/jam-host-calls": "0.0.1-f33d167",
"@typeberry/pvm-debugger-adapter": "0.1.0-dc28f3f",
"@typeberry/block": "^0.0.1-b25856a",
"@typeberry/jam-host-calls": "0.0.1-b25856a",
"@typeberry/pvm-debugger-adapter": "0.1.0-b25856a",
"@typeberry/spectool-wasm": "0.18.0",
"@uiw/react-codemirror": "^4.23.6",
"blake2b": "^2.1.4",
Expand Down
25 changes: 5 additions & 20 deletions src/components/HostCalls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,20 @@ import { TrieInput } from "./trie-input";
import { Button } from "../ui/button";
import { setHasHostCallOpen, setStorage } from "@/store/debugger/debuggerSlice";
import { useEffect, useState } from "react";
import { CurrentInstruction, DebuggerEcalliStorage } from "@/types/pvm";
import { ArgumentType } from "@typeberry/pvm-debugger-adapter";
import { DebuggerEcalliStorage } from "@/types/pvm";
import { isSerializedError } from "@/store/utils";

const isEcalliWriteOrRead = (currentInstruction: CurrentInstruction) => {
return (
currentInstruction &&
"args" in currentInstruction &&
currentInstruction.args.type === ArgumentType.ONE_IMMEDIATE &&
(currentInstruction.args.immediateDecoder.getSigned() === 2 ||
currentInstruction.args.immediateDecoder.getSigned() === 3)
);
const isEcalliWriteOrRead = (exitArg?: number) => {
return exitArg === 2 || exitArg === 3;
};
export const HostCalls = () => {
const dispatch = useAppDispatch();
const { storage, hasHostCallOpen, programPreviewResult } = useAppSelector((state) => state.debugger);
const { storage, hasHostCallOpen } = useAppSelector((state) => state.debugger);
const firstWorker = useAppSelector((state) => state.workers?.[0]);
const currentInstruction = firstWorker?.currentInstruction;

const [newStorage, setNewStorage] = useState<DebuggerEcalliStorage | null>();
const [error, setError] = useState<string>();
const previousInstruction =
programPreviewResult[
programPreviewResult.findIndex(
(instruction) => instruction.instructionCode === currentInstruction?.instructionCode,
) - 1
];

const isOnEcalli = previousInstruction && isEcalliWriteOrRead(previousInstruction);
const isOnEcalli = isEcalliWriteOrRead(firstWorker?.exitArg);

useEffect(() => {
setNewStorage(storage);
Expand Down
2 changes: 1 addition & 1 deletion src/components/HostCalls/trie-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const TrieInput = ({ onChange, initialRows }: TrieInputProps) => {
newRows[index].key = value;

newRows[index].keyHash =
!value || is32BytesHex(value) ? value : hash.hashBytes(bytes.BytesBlob.blobFromString(value)).toString();
!value || is32BytesHex(value) ? value : hash.blake2b.hashBytes(bytes.BytesBlob.blobFromString(value)).toString();
modifyRows(newRows);
};

Expand Down
6 changes: 3 additions & 3 deletions src/store/workers/workersSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
toPvmStorage,
} from "../utils";
import { chunk, inRange, isNumber } from "lodash";
import { isInstructionError, isOneImmediateArgs } from "@/types/type-guards";
import { isInstructionError } from "@/types/type-guards";
import { nextInstruction } from "@/packages/web-worker/pvm.ts";

// TODO: remove this when found a workaround for BigInt support in JSON.stringify
Expand Down Expand Up @@ -281,8 +281,8 @@ export const handleHostCall = createAsyncThunk("workers/handleHostCall", async (

if (
!instructionEnriched ||
isInstructionError(instructionEnriched) ||
!isOneImmediateArgs(instructionEnriched.args)
isInstructionError(instructionEnriched)
// !isOneImmediateArgs(instructionEnriched.args)
) {
throw new Error("Invalid host call instruction");
}
Expand Down

0 comments on commit 09bb592

Please sign in to comment.