Skip to content

Commit

Permalink
Fix re-rendering issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Jan 23, 2025
1 parent 95c8800 commit 741a24c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@typeberry/block": "0.0.1-447d5c4",
"@typeberry/jam-host-calls": "0.0.1-459ce0b",
"@typeberry/pvm-debugger-adapter": "0.1.0-459ce0b",
"@typeberry/spectool-wasm": "0.20.5",
"@typeberry/spectool-wasm": "0.20.6",
"@uiw/react-codemirror": "^4.23.6",
"blake2b": "^2.1.4",
"class-variance-authority": "^0.7.0",
Expand Down
36 changes: 21 additions & 15 deletions src/components/ProgramLoader/Assembly.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { useCallback, useMemo, useState } from "react";
import { ProgramUploadFileOutput } from "./types";
import { InitialState } from "../../types/pvm";
import { InitialState, RegistersArray } from "../../types/pvm";
import classNames from "classnames";
import { compile_assembly, disassemble } from "@typeberry/spectool-wasm";
import { mapUploadFileInputToOutput } from "./utils";
Expand Down Expand Up @@ -116,7 +116,7 @@ export const Assembly = ({
const newInitialState = {
...initialState,
};
newInitialState.regs = output.initial.regs;
newInitialState.regs = truncateRegs(output.initial.regs);
// this is incorrect, but we would need to alter the
// assembly to include the actual data:
// pub @main: (pc)
Expand All @@ -132,9 +132,12 @@ export const Assembly = ({
if ((output.initial.pageMap?.length ?? 0) !== 0) {
newInitialState.pageMap = output.initial.pageMap;
}
// we want to keep all of the old stuff to avoid re-rendering.
output.initial = newInitialState;
onProgramLoad(output);
// if there are no changes do not re-render.
if (JSON.stringify(output.initial) !== JSON.stringify(newInitialState)) {
// we want to keep all of the old stuff to avoid re-rendering.
output.initial = newInitialState;
onProgramLoad(output);
}
setError(undefined);
} catch (e) {
if (e instanceof Error) {
Expand All @@ -157,15 +160,6 @@ export const Assembly = ({

const [error, setError] = useState<string>();
const [assembly, setAssembly] = useState(defaultAssembly);
const [isFirstCompilation, setFirstCompilation] = useState(true);

// compile the assembly for the first time
useEffect(() => {
if (isFirstCompilation) {
compile(assembly);
setFirstCompilation(false);
}
}, [compile, assembly, isFirstCompilation]);

const isError = !!error;

Expand Down Expand Up @@ -221,3 +215,15 @@ function isArrayEqual<T>(a: T[], b: T[]) {

return true;
}

function truncateRegs(regs: RegistersArray | undefined) {
if (!regs) {
return regs;
}

for (let i = 0; i < regs.length; i++) {
// currently the assembler requires that registers are provided as u32
regs[i] = regs[i] & 0xffff_ffffn;
}
return regs;
}

0 comments on commit 741a24c

Please sign in to comment.