import React, { useId, useState } from "react";
import {
ArrowRight,
Info,
BookOpen,
Lightbulb,
Warning,
} from "@phosphor-icons/react";
import { Markdown } from "./Markdown.jsx";
import {
parseLearningBlock,
translateAddress,
} from "./shared/learning-blocks.js";
function AddressTranslation({ block }) {
const [address, setAddress] = useState(block.address),
[draft, setDraft] = useState(String(block.address)),
[activeRole, setActiveRole] = useState(null);
const uid = useId(),
max = block.pageSize * block.mappings.length - 1;
const result = translateAddress(address, block.pageSize, block.mappings);
const change = (value) => {
const n = Number(value);
setDraft(value);
if (value !== "" && Number.isSafeInteger(n) && n >= 0 && n <= max)
setAddress(n);
};
const update = (n) => {
setAddress(n);
setDraft(String(n));
};
const part = (role) => ({
onMouseEnter: () => setActiveRole(role),
onMouseLeave: () => setActiveRole(null),
onFocus: () => setActiveRole(role),
onBlur: () => setActiveRole(null),
});
return (
{block.mappings.length} virtual pages
Byte {result.offset}{" "}
within the frame
Virtual address
{block.pageSize.toLocaleString("en-US")} bytes per page
Page table
Physical address
{result.frame === null ? (
This learning block has invalid data.
{code}