Skip to content

Commit

Permalink
Merge pull request #68 from FluffyLabs/instructions-fixes
Browse files Browse the repository at this point in the history
Instructions fixes
  • Loading branch information
krystian50 authored Aug 17, 2024
2 parents 22c25e0 + 9477016 commit aa0ff05
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/components/Instructions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Table, TableRow, TableBody, TableCell } from "@/components/ui/table.tsx
import { mapInstructionsArgsByType, valueToNumeralSystem } from "./utils";
import classNames from "classnames";
import { InstructionMode } from "@/components/Instructions/types.ts";
import { NumeralSystemContext } from "@/context/NumeralSystem.tsx";
import { NumeralSystem, NumeralSystemContext } from "@/context/NumeralSystem.tsx";
import { useContext, useMemo } from "react";
import { isEqual, omit } from "lodash";
import { CurrentInstruction } from "@/types/pvm";
Expand Down Expand Up @@ -46,13 +46,15 @@ export const Instructions = ({
}
let counter = 0;
return programPreviewResult?.map((result) => {
const addressVal = valueToNumeralSystem(counter, numeralSystem);
const isHex = numeralSystem === NumeralSystem.HEXADECIMAL;
const valInNumeralSystem = isHex ? `${(counter >>> 0).toString(16)}` : counter.toString();
const address = (
<div>
{[...Array(8 - addressVal.length)].map(() => (
<span className="text-gray-400">0</span>
{isHex && <span className="opacity-20">0x</span>}
{[...Array(8 - (isHex ? 2 : 0) - valInNumeralSystem.length)].map(() => (
<span className="opacity-20">0</span>
))}
<span>{addressVal}</span>
<span>{valInNumeralSystem}</span>
</div>
);
if ("args" in result) {
Expand All @@ -74,9 +76,7 @@ export const Instructions = ({
{programRow.instructionBytes && (
<span className="text-gray-500">
{[...programRow.instructionBytes]
?.map((byte) =>
valueToNumeralSystem(byte, numeralSystem).padStart(numeralSystem ? 2 : 3, "0"),
)
?.map((byte) => valueToNumeralSystem(byte, numeralSystem, numeralSystem ? 2 : 3))
.join(" ")}
</span>
)}
Expand All @@ -85,7 +85,7 @@ export const Instructions = ({
{instructionMode === InstructionMode.ASM && (
<>
<TableCell className="p-1.5">
<span className="uppercase font-bold">{programRow.address}</span>
<span className="uppercase">{programRow.address}</span>
</TableCell>
<TableCell className="p-1.5">
<span className="uppercase font-bold">{programRow.name}</span>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Instructions/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NumeralSystem } from "@/context/NumeralSystem.tsx";
import { ArgumentType } from "@/packages/pvm/pvm/args-decoder/argument-type";

export const valueToNumeralSystem = (value: number, numeralSystem: NumeralSystem): string => {
return numeralSystem === NumeralSystem.HEXADECIMAL ? `0x${(value >>> 0).toString(16)}` : value.toString();
export const valueToNumeralSystem = (value: number, numeralSystem: NumeralSystem, padStartVal?: number): string => {
return numeralSystem === NumeralSystem.HEXADECIMAL
? `0x${(value >>> 0).toString(16).padStart(padStartVal || 0, "0")}`
: value.toString().padStart(padStartVal || 0, "0");
};

export const mapInstructionsArgsByType = (args: any, numeralSystem: NumeralSystem) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Registers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const Registers = ({
<div
className={classNames({
"flex-[3]": true,
"text-gray-300": currentState.regs?.[regNo] === 0,
"opacity-20": currentState.regs?.[regNo] === 0,
})}
>
{valueToNumeralSystem(currentState.regs?.[regNo] ?? 0, numeralSystem)}
Expand Down
3 changes: 3 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
overflow: hidden;
}

0 comments on commit aa0ff05

Please sign in to comment.