From 78fde8454f04a9a1c771b6d38f0ca467e8de3b2f Mon Sep 17 00:00:00 2001 From: Krystian Fras Date: Sun, 15 Dec 2024 11:29:34 +0100 Subject: [PATCH] Host calls cleanup (#251) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix multi-PVM visual glitch (#241) * Don't perform multiple steps when Stepping in the UI. (#240) * Fix multi-PVM visual glitch (#243) * Modify program editor to be available only in edit mode; improve error handling (#242) * Move program code input to edit mode * Handle errors in program text editor * Allow for hex in array as a program input * Fix linter * refactor --------- Co-authored-by: Wojciech Kwiatek Co-authored-by: Tomek Drwięga --- src/App.tsx | 50 ++++++++--- src/components/DebuggerSettings/index.tsx | 4 +- src/components/HostCalls/form.tsx | 33 ++++---- src/components/HostCalls/index.tsx | 40 +++------ src/components/MemoryPreview/index.tsx | 10 ++- .../ProgramLoader/BinaryFileUpload.tsx | 2 +- src/components/ProgramLoader/Bytecode.tsx | 40 --------- src/components/ProgramLoader/Examples.tsx | 36 +++++--- src/components/ProgramLoader/Loader.tsx | 24 +----- src/components/ProgramTextLoader/index.tsx | 83 ++++++++++++++++--- src/hooks/useDebuggerActions.ts | 19 +++-- src/packages/host-calls/read.ts | 2 - .../web-worker/command-handlers/host-call.ts | 7 +- .../web-worker/command-handlers/step.ts | 4 +- src/packages/web-worker/types.ts | 2 +- src/packages/web-worker/worker.ts | 3 +- src/store/debugger/debuggerSlice.ts | 12 +-- src/store/workers/workersSlice.ts | 18 ++-- 18 files changed, 215 insertions(+), 174 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 91dab5a..cbb550a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,7 +21,12 @@ import { MobileRegisters } from "./components/MobileRegisters"; import { MobileKnowledgeBase } from "./components/KnowledgeBase/Mobile"; import { Assembly } from "./components/ProgramLoader/Assembly"; import { useAppDispatch, useAppSelector } from "@/store/hooks.ts"; -import { setClickedInstruction, setInstructionMode, setIsProgramEditMode } from "@/store/debugger/debuggerSlice.ts"; +import { + setClickedInstruction, + setInstructionMode, + setIsProgramEditMode, + setIsProgramInvalid, +} from "@/store/debugger/debuggerSlice.ts"; import { MemoryPreview } from "@/components/MemoryPreview"; import { DebuggerControlls } from "./components/DebuggerControlls"; import { useDebuggerActions } from "./hooks/useDebuggerActions"; @@ -29,6 +34,7 @@ import { Loader } from "./components/ProgramLoader/Loader"; import classNames from "classnames"; import { DebuggerSettings } from "./components/DebuggerSettings"; import { HostCalls } from "./components/HostCalls"; +import { ProgramTextLoader } from "@/components/ProgramTextLoader"; const DebuggerContent = () => { const dispatch = useAppDispatch(); @@ -37,7 +43,7 @@ const DebuggerContent = () => { program, initialState, isProgramEditMode, - isAsmError, + isProgramInvalid, programPreviewResult, clickedInstruction, instructionMode, @@ -74,18 +80,37 @@ const DebuggerContent = () => { return ( <> - +
{!program.length && } {!!program.length && ( <> {isProgramEditMode && ( -
- +
+ {instructionMode === InstructionMode.ASM ? ( + + ) : ( + { + if (error) { + dispatch(setIsProgramInvalid(true)); + } + + if (!error && program) { + debuggerActions.handleProgramLoad({ + initial: initialState, + program: program || [], + name: "custom", + }); + } + }} + /> + )}
)} @@ -146,7 +171,6 @@ const DebuggerContent = () => {
@@ -160,7 +184,7 @@ const DebuggerContent = () => { variant="link" size="icon" className={!program.length ? "invisible" : "visible"} - disabled={!program.length || isAsmError} + disabled={!program.length || isProgramInvalid} title="Edit the code" onClick={() => { if (isProgramEditMode) { @@ -182,7 +206,7 @@ const DebuggerContent = () => { }; function App() { - const { pvmInitialized, initialState, program } = useAppSelector((state) => state.debugger); + const { pvmInitialized } = useAppSelector((state) => state.debugger); return ( <> @@ -212,7 +236,7 @@ function App() { ) : (
- +
)} diff --git a/src/components/DebuggerSettings/index.tsx b/src/components/DebuggerSettings/index.tsx index 768a0a6..f0c826a 100644 --- a/src/components/DebuggerSettings/index.tsx +++ b/src/components/DebuggerSettings/index.tsx @@ -30,7 +30,7 @@ export const DebuggerSettings = () => { Debugger Settings -

+

Number of batched steps To speed up execution PVMs can run multiple steps internally after clicking "Run". This may lead to @@ -48,7 +48,7 @@ export const DebuggerSettings = () => { value={debuggerState.stepsToPerform} /> -

+
diff --git a/src/components/HostCalls/form.tsx b/src/components/HostCalls/form.tsx index 7338bda..b5a7e4e 100644 --- a/src/components/HostCalls/form.tsx +++ b/src/components/HostCalls/form.tsx @@ -5,8 +5,8 @@ import { hash, bytes } from "@typeberry/jam-host-calls"; import { Storage } from "@/packages/web-worker/types"; import { useEffect, useState } from "react"; import { logger } from "@/utils/loggerService"; -import { setHasHostCallOpen, setIsDebugFinished, setStorage } from "@/store/debugger/debuggerSlice"; -import { handleHostCall, setAllWorkersStorage, stepAllWorkers } from "@/store/workers/workersSlice"; +import { setHasHostCallOpen, setStorage } from "@/store/debugger/debuggerSlice"; +import { setAllWorkersStorage } from "@/store/workers/workersSlice"; import { useAppDispatch, useAppSelector } from "@/store/hooks"; const parseJSONToStorage = (value: { [key: string]: string }) => { @@ -22,13 +22,13 @@ const parseJSONToStorage = (value: { [key: string]: string }) => { return parsedValue; }; -export const HostCallsForm = () => { +export const HostCallsForm = (props: { onAfterSubmit?: () => void }) => { const { storage } = useAppSelector((state) => state.debugger); const dispatch = useAppDispatch(); const [inputValue, setInputValue] = useState(); useEffect(() => { - setInputValue(storage ? JSON.stringify(Object.fromEntries(storage)) : ""); + setInputValue(storage ? JSON.stringify(Object.fromEntries(storage.entries())) : ""); }, [storage]); const onSubmit = async () => { @@ -38,7 +38,7 @@ export const HostCallsForm = () => { dispatch(setStorage(parsedValue)); await dispatch(setAllWorkersStorage()).unwrap(); dispatch(setHasHostCallOpen(false)); - await dispatch(handleHostCall()).unwrap(); + props.onAfterSubmit?.(); // dispatch(setIsDebugFinished(false)); // await dispatch(stepAllWorkers()).unwrap(); @@ -50,7 +50,10 @@ export const HostCallsForm = () => { return (
Storage Value - Lorem ipsum + + Set storage for read & write host calls. Confirm empty, if you want to process. Storage can be modified by + running program. +