Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format with Prettier #195

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 66 additions & 10 deletions components/src/chips/alu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
COMMANDS_OP,
Flags,
} from "@nand2tetris/simulator/cpu/alu.js";
import { bin } from "@nand2tetris/simulator/util/twos.js";

Check failure on line 6 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

'bin' is defined but never used

export const ALUComponent = ({
A,
Expand All @@ -21,16 +21,72 @@
<div>
<span>ALU</span>
<svg width="250" height="250" xmlns="http://www.w3.org/2000/svg">
<g>
<rect x="1" y="20" height="85" width="70" fill="black" />
<rect x="1" y="145" height="85" width="70" fill="black" />
<rect x="180" y="95" height="60" width="70" fill="black" />
<polygon points="70,10 180,85 180,165 70,240 70,135 90,125 70,115" stroke="#000" fill="#6D97AB"/>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" stroke-width="0" id="svg_9" y="63" x="35" stroke="white" fill="#ffffff">{A}</text>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" id="svg_10" y="188" x="35" stroke-width="0" stroke="white" fill="#ffffff">{D}</text>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" id="svg_11" y="125" x="215" stroke-width="0" stroke="white" fill="#ffffff">{out}</text>
<text xmlSpace="preserve" text-anchor="middle" font-family="Noto Sans JP" font-size="14" id="svg_13" y="125" x="135" stroke-width="0" stroke="white" fill="#ffffff">{COMMANDS_ALU.op[op] ?? "(??)"}</text>
</g>
<g>
<rect x="1" y="20" height="85" width="70" fill="black" />
<rect x="1" y="145" height="85" width="70" fill="black" />
<rect x="180" y="95" height="60" width="70" fill="black" />
<polygon
points="70,10 180,85 180,165 70,240 70,135 90,125 70,115"
stroke="#000"
fill="#6D97AB"
/>
<text
xmlSpace="preserve"
text-anchor="middle"

Check failure on line 35 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'text-anchor' found, use 'textAnchor' instead
font-family="Noto Sans JP"

Check failure on line 36 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'font-family' found, use 'fontFamily' instead
font-size="14"

Check failure on line 37 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'font-size' found, use 'fontSize' instead
stroke-width="0"

Check failure on line 38 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'stroke-width' found, use 'strokeWidth' instead
id="svg_9"
y="63"
x="35"
stroke="white"
fill="#ffffff"
>
{A}
</text>
<text
xmlSpace="preserve"
text-anchor="middle"

Check failure on line 49 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'text-anchor' found, use 'textAnchor' instead
font-family="Noto Sans JP"

Check failure on line 50 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'font-family' found, use 'fontFamily' instead
font-size="14"

Check failure on line 51 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'font-size' found, use 'fontSize' instead
id="svg_10"
y="188"
x="35"
stroke-width="0"

Check failure on line 55 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'stroke-width' found, use 'strokeWidth' instead
stroke="white"
fill="#ffffff"
>
{D}
</text>
<text
xmlSpace="preserve"
text-anchor="middle"

Check failure on line 63 in components/src/chips/alu.tsx

View workflow job for this annotation

GitHub Actions / all

Unknown property 'text-anchor' found, use 'textAnchor' instead
font-family="Noto Sans JP"
font-size="14"
id="svg_11"
y="125"
x="215"
stroke-width="0"
stroke="white"
fill="#ffffff"
>
{out}
</text>
<text
xmlSpace="preserve"
text-anchor="middle"
font-family="Noto Sans JP"
font-size="14"
id="svg_13"
y="125"
x="135"
stroke-width="0"
stroke="white"
fill="#ffffff"
>
{COMMANDS_ALU.op[op] ?? "(??)"}
</text>
</g>
</svg>
</div>
);
14 changes: 10 additions & 4 deletions components/src/chips/visualizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export function getBuiltinVisualization(part: Chip): ReactElement | undefined {
}
}

export function makeVisualization(chip: Chip, updateAction? : () => void): ReactElement | undefined {
export function makeVisualization(
chip: Chip,
updateAction?: () => void
): ReactElement | undefined {
if (chip instanceof ALU) {
return (
<ALUComponent
Expand Down Expand Up @@ -113,9 +116,12 @@ export function makeVisualization(chip: Chip, updateAction? : () => void): React
return vis.length > 0 ? <>{vis}</> : undefined;
}

export function makeVisualizationsWithId(chip: {
parts: Chip[];
}, updateAction? : () => void): [string, ReactElement][] {
export function makeVisualizationsWithId(
chip: {
parts: Chip[];
},
updateAction?: () => void
): [string, ReactElement][] {
return [...chip.parts]
.map((part, i): [string, ReactElement | undefined] => [
`${part.id}_${i}`,
Expand Down
8 changes: 4 additions & 4 deletions components/src/pinout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const PinoutBlock = (
enableEdit={props.enableEdit}
signed={props.displayInfo.isSigned(immPin.pin.name)}
setInputValid={props.setInputValid}
internal={props.header === "Internal pins" ? true : false }
internal={props.header === "Internal pins" ? true : false}
/>
</td>
</tr>
Expand Down Expand Up @@ -151,7 +151,7 @@ export const Pinout = ({
<tr key={immPin.pin.name}>
<td>{immPin.pin.name}</td>
<td>
<Pin pin={immPin} toggle={toggle} internal/>
<Pin pin={immPin} toggle={toggle} internal />
</td>
</tr>
))}
Expand All @@ -167,7 +167,7 @@ const Pin = ({
enableEdit = true,
signed = true,
setInputValid,
internal = false
internal = false,
}: {
pin: ImmPin;
toggle: ((pin: ChipPin, bit?: number) => void) | undefined;
Expand Down Expand Up @@ -260,7 +260,7 @@ const Pin = ({
<button
key={i}
disabled={disabled}
style={internal ? {backgroundColor: "grey"} : {}}
style={internal ? { backgroundColor: "grey" } : {}}
onClick={() => toggle?.(pin.pin, i)}
data-testid={`pin-${i}`}
>
Expand Down
2 changes: 1 addition & 1 deletion projects/src/project_05/04_screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export const hdl = `CHIP Screen {
OUT out[16];

PARTS:
}`;
}`;
2 changes: 1 addition & 1 deletion projects/src/project_05/05_keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export const hdl = `CHIP Keyboard {
OUT out[16];

PARTS:
}`;
}`;
6 changes: 3 additions & 3 deletions simulator/src/chip/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Bus implements Pin {
for (const i of range(0, this.width)) {
this.state[i] = ((voltage & (1 << i)) >> i) as Voltage;
}
this.next.forEach((n) => (n.busVoltage = this.busVoltage));
this.next.forEach((n) => (n.busVoltage = this.busVoltage));
}

get busVoltage(): number {
Expand Down Expand Up @@ -446,8 +446,8 @@ export class Chip {
for (const chip of this.parts) {
// TODO topological sort
// eval chip input busses
TRUE_BUS.next.forEach((pin) => pin.busVoltage = TRUE_BUS.busVoltage);
FALSE_BUS.next.forEach((pin) => pin.busVoltage = FALSE_BUS.busVoltage);
TRUE_BUS.next.forEach((pin) => (pin.busVoltage = TRUE_BUS.busVoltage));
FALSE_BUS.next.forEach((pin) => (pin.busVoltage = FALSE_BUS.busVoltage));
chip.eval();
// eval output busses
}
Expand Down
8 changes: 4 additions & 4 deletions simulator/src/cpu/alu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type COMMANDS_OP =
| 0b010101;

//Usefull for the visualization of the ALU
export type COMMANDS_ALU =
export type COMMANDS_ALU =
| "0"
| "1"
| "-1"
Expand All @@ -68,7 +68,7 @@ export type COMMANDS_ALU =
| "x|y";

export const COMMANDS_ALU: {
op: Record<COMMANDS_OP, COMMANDS_ALU>
op: Record<COMMANDS_OP, COMMANDS_ALU>;
} = {
op: {
0x2a: "0",
Expand All @@ -89,8 +89,8 @@ export const COMMANDS_ALU: {
0x07: "y-x",
0x00: "x&y",
0x15: "x|y",
}
}
},
};

export const COMMANDS: {
asm: Record<COMMANDS_ASM, COMMANDS_OP>;
Expand Down
13 changes: 8 additions & 5 deletions web/src/pages/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,14 @@ export const Chip = () => {
</fieldset>
);

const visualizations: [string, ReactNode][] = makeVisualizationsWithId({
parts: state.sim.chip,
}, () => {
dispatch.current({ action: "updateChip" });
});
const visualizations: [string, ReactNode][] = makeVisualizationsWithId(
{
parts: state.sim.chip,
},
() => {
dispatch.current({ action: "updateChip" });
}
);

const pinResetDispatcher = new PinResetDispatcher();

Expand Down
Loading