From 42d4c747693a22f2040d3cab1af7ad837634fb12 Mon Sep 17 00:00:00 2001 From: Krystian Fras Date: Sun, 15 Dec 2024 11:29:55 +0100 Subject: [PATCH] Revert "Host calls cleanup (#251)" This reverts commit 78fde8454f04a9a1c771b6d38f0ca467e8de3b2f. --- 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, 174 insertions(+), 215 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index cbb550a..91dab5a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,12 +21,7 @@ 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, - setIsProgramInvalid, -} from "@/store/debugger/debuggerSlice.ts"; +import { setClickedInstruction, setInstructionMode, setIsProgramEditMode } from "@/store/debugger/debuggerSlice.ts"; import { MemoryPreview } from "@/components/MemoryPreview"; import { DebuggerControlls } from "./components/DebuggerControlls"; import { useDebuggerActions } from "./hooks/useDebuggerActions"; @@ -34,7 +29,6 @@ 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(); @@ -43,7 +37,7 @@ const DebuggerContent = () => { program, initialState, isProgramEditMode, - isProgramInvalid, + isAsmError, programPreviewResult, clickedInstruction, instructionMode, @@ -80,37 +74,18 @@ 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", - }); - } - }} - /> - )} +
+
)} @@ -171,6 +146,7 @@ const DebuggerContent = () => {
@@ -184,7 +160,7 @@ const DebuggerContent = () => { variant="link" size="icon" className={!program.length ? "invisible" : "visible"} - disabled={!program.length || isProgramInvalid} + disabled={!program.length || isAsmError} title="Edit the code" onClick={() => { if (isProgramEditMode) { @@ -206,7 +182,7 @@ const DebuggerContent = () => { }; function App() { - const { pvmInitialized } = useAppSelector((state) => state.debugger); + const { pvmInitialized, initialState, program } = useAppSelector((state) => state.debugger); return ( <> @@ -236,7 +212,7 @@ function App() { ) : (
- +
)} diff --git a/src/components/DebuggerSettings/index.tsx b/src/components/DebuggerSettings/index.tsx index f0c826a..768a0a6 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 b5a7e4e..7338bda 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, setStorage } from "@/store/debugger/debuggerSlice"; -import { setAllWorkersStorage } from "@/store/workers/workersSlice"; +import { setHasHostCallOpen, setIsDebugFinished, setStorage } from "@/store/debugger/debuggerSlice"; +import { handleHostCall, setAllWorkersStorage, stepAllWorkers } 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 = (props: { onAfterSubmit?: () => void }) => { +export const HostCallsForm = () => { const { storage } = useAppSelector((state) => state.debugger); const dispatch = useAppDispatch(); const [inputValue, setInputValue] = useState(); useEffect(() => { - setInputValue(storage ? JSON.stringify(Object.fromEntries(storage.entries())) : ""); + setInputValue(storage ? JSON.stringify(Object.fromEntries(storage)) : ""); }, [storage]); const onSubmit = async () => { @@ -38,7 +38,7 @@ export const HostCallsForm = (props: { onAfterSubmit?: () => void }) => { dispatch(setStorage(parsedValue)); await dispatch(setAllWorkersStorage()).unwrap(); dispatch(setHasHostCallOpen(false)); - props.onAfterSubmit?.(); + await dispatch(handleHostCall()).unwrap(); // dispatch(setIsDebugFinished(false)); // await dispatch(stepAllWorkers()).unwrap(); @@ -50,10 +50,7 @@ export const HostCallsForm = (props: { onAfterSubmit?: () => void }) => { return (
Storage Value - - Set storage for read & write host calls. Confirm empty, if you want to process. Storage can be modified by - running program. - + Lorem ipsum