ensure all numeric values preserve across session

This commit is contained in:
Rachel Powers
2024-04-20 10:58:42 -07:00
parent e4d42d69a5
commit 29d7a10f47
8 changed files with 131 additions and 78 deletions

View File

@@ -36,6 +36,7 @@ import "@shoelace-style/shoelace/dist/components/icon/icon.js";
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js";
import {
displayNumber,
parseIntWithHexOrBinary,
parseNumber,
structuralEqual,
@@ -274,7 +275,7 @@ export class VMDeviceCard extends VMDeviceMixin(BaseElement) {
return html` <sl-input
id="${inputIdBase}${name}"
key="${name}"
value="${field.value}"
value="${displayNumber(field.value)}"
size="small"
@sl-change=${this._handleChangeField}
>
@@ -334,8 +335,14 @@ export class VMDeviceCard extends VMDeviceMixin(BaseElement) {
<div class="slot-fields">
${fields.map(
([name, field], _index, _fields) => html`
<sl-input id="${inputIdBase}${name}" slotIndex=${slotIndex} key="${name}" value="${field.value}" size="small"
@sl-change=${this._handleChangeSlotField}>
<sl-input
id="${inputIdBase}${name}"
slotIndex=${slotIndex}
key="${name}"
value="${displayNumber(field.value)}"
size="small"
@sl-change=${this._handleChangeSlotField}
>
<span slot="prefix">${name}</span>
<sl-copy-button slot="suffix" from="${inputIdBase}${name}.value"></sl-copy-button>
<span slot="suffix">${field.field_type}</span>
@@ -1023,7 +1030,7 @@ export class VmDeviceTemplate extends BaseElement {
return html`
<sl-input
key="${name}"
value="${field.value}"
value="${displayNumber(field.value)}"
size="small"
@sl-change=${this._handleChangeField}
?disabled=${name === "PrefabHash"}

View File

@@ -137,7 +137,7 @@ class VirtualMachine extends EventTarget {
const attempt = Date.now().toString(16);
const ic = this._ics.get(id);
const prog = progs.get(id);
if (ic && prog) {
if (ic && prog && ic.code !== prog) {
try {
console.time(`CompileProgram_${id}_${attempt}`);
this.ics.get(id)!.setCodeInvalid(progs.get(id)!);

View File

@@ -9,7 +9,7 @@ import "@shoelace-style/shoelace/dist/components/tooltip/tooltip.js";
import "@shoelace-style/shoelace/dist/components/input/input.js";
import { RegisterSpec } from "ic10emu_wasm";
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js";
import { parseNumber } from "../utils";
import { displayNumber, parseNumber } from "../utils";
@customElement("vm-ic-registers")
export class VMICRegisters extends VMActiveICMixin(BaseElement) {
@@ -47,16 +47,6 @@ export class VMICRegisters extends VMActiveICMixin(BaseElement) {
}
protected render() {
// const inputTypeFromVal = (val: number) => { if (val === Number.NEGATIVE_INFINITY || val === Number.POSITIVE_INFINITY || Number.isNaN(val)) { return "text"; } else { return "number"; } };
const displayVal = (val: number) => {
if (Number.POSITIVE_INFINITY === val) {
return "∞";
} else if (Number.NEGATIVE_INFINITY === val) {
return "-∞";
} else {
return val.toString();
}
};
const registerAliases: [string, number][] = (
(
[...(this.aliases ?? [])].filter(
@@ -83,7 +73,7 @@ export class VMICRegisters extends VMActiveICMixin(BaseElement) {
</div>
<sl-input
type="text"
value="${displayVal(val)}"
value="${displayNumber(val)}"
size="small"
class="reg-input"
@sl-change=${this._handleCellChange}

View File

@@ -8,7 +8,7 @@ import "@shoelace-style/shoelace/dist/components/icon/icon.js";
import "@shoelace-style/shoelace/dist/components/tooltip/tooltip.js";
import "@shoelace-style/shoelace/dist/components/input/input.js";
import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js";
import { parseNumber } from "../utils";
import { displayNumber, parseNumber } from "../utils";
@customElement("vm-ic-stack")
export class VMICStack extends VMActiveICMixin(BaseElement) {
@@ -44,15 +44,6 @@ export class VMICStack extends VMActiveICMixin(BaseElement) {
}
protected render() {
const displayVal = (val: number) => {
if (Number.POSITIVE_INFINITY === val) {
return "∞";
} else if (Number.NEGATIVE_INFINITY === val) {
return "-∞";
} else {
return val.toString();
}
};
const sp = this.registers![16];
return html`
@@ -67,7 +58,7 @@ export class VMICStack extends VMActiveICMixin(BaseElement) {
</div>
<sl-input
type="text"
value="${displayVal(val)}"
value="${displayNumber(val)}"
size="small"
class="stack-input ${sp === index ? "stack-pointer" : ""}"
@sl-change=${this._handleCellChange}