Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into editable-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
netalondon committed Feb 26, 2024
2 parents 6601bc3 + 5beae4a commit 325a68e
Show file tree
Hide file tree
Showing 74 changed files with 10,176 additions and 4,096 deletions.
4 changes: 1 addition & 3 deletions components/src/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ function getDiffs(cmpData: Cmp, outData: Cmp): Diff[] {
for (let j = 0; j < Math.max(cmpI.length, outI.length); j++) {
const cmpJ = cmpI[j] ?? "";
const outJ = outI[j] ?? "";
if (
!(cmpJ?.trim().match(/^\*+$/) !== null || outJ?.trim() === cmpJ?.trim())
) {
if (!(cmpJ?.trim().match(/^\*+$/) !== null || outJ === cmpJ)) {
diffs.push({ row: i, col: j, expected: cmpJ, given: outJ });
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/src/stores/chip.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export function makeChipStore(
return false;
}

test = ChipTest.from(Ok(tst)).with(chip).reset();
test = ChipTest.from(Ok(tst), setStatus).with(chip).reset();
test.setFileSystem(fs);
dispatch.current({ action: "updateTestStep" });
return true;
Expand Down
5 changes: 2 additions & 3 deletions projects/src/project_01/01_not.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ export const cmp = `|in |out|
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Not.hdl
// File name: projects/1/Not.hdl
/**
* Not gate:
* if (in == 0) out = 1, else out = 0
* if (in) out = 0, else out = 1
*/
CHIP Not {
IN in;
OUT out;
Expand Down
6 changes: 3 additions & 3 deletions projects/src/project_01/02_and.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And.hdl
/**
// File name: projects/1/And.hdl
/**
* And gate:
* if ((a == 1) and (b == 1)) out = 1, else out = 0
* if (a and b) out = 1, else out = 0
*/
CHIP And {
IN a, b;
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/03_or.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export const cmp = `| a | b |out|
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or.hdl
// File name: projects/1/Or.hdl
/**
* Or gate:
* if ((a == 1) or (b == 1)) out = 1, else out = 0
* if (a or b) out = 1, else out = 0
*/
CHIP Or {
IN a, b;
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/04_xor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export const cmp = `| a | b |out|
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Xor.hdl
// File name: projects/1/Xor.hdl
/**
* Exclusive-or gate:
* out = (not(a) and b) or (a and not(b))
* if ((a and Not(b)) or (Not(a) and b)) out = 1, else out = 0
*/
CHIP Xor {
IN a, b;
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/05_mux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const cmp = `| a | b |sel|out|
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux.hdl
// File name: projects/1/Mux.hdl
/**
* Multiplexor:
* if (sel == 0) out = a, else out = b
* if (sel = 0) out = a, else out = b
*/
CHIP Mux {
IN a, b, sel;
Expand Down
8 changes: 4 additions & 4 deletions projects/src/project_01/06_dmux.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux.hdl
/**
// File name: projects/1/DMux.hdl
/**
* Demultiplexor:
* [a, b] = [in, 0] if sel == 0
* [0, in] if sel == 1
* [a, b] = [in, 0] if sel = 0
* [0, in] if sel = 1
*/
CHIP DMux {
IN in, sel;
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/08_and16.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/And16.hdl
// File name: projects/1/And16.hdl
/**
* 16-bit bitwise And gate:
* 16-bit And gate:
* for i = 0, ..., 15:
* out[i] = a[i] And b[i]
*/
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/09_or16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export const cmp = `| a | b | out |
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or16.hdl
// File name: projects/1/Or16.hdl
/**
* 16-bit bitwise Or gate:
* 16-bit Or gate:
* for i = 0, ..., 15:
* out[i] = a[i] Or b[i]
*/
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/10_mux16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const cmp = `| a | b |sel| out
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux16.hdl
// File name: projects/1/Mux16.hdl
/**
* 16-bit multiplexor:
* for i = 0, ..., 15:
* if (sel == 0) out[i] = a[i], else out[i] = b[i]
* if (sel = 0) out[i] = a[i], else out[i] = b[i]
*/
CHIP Mux16 {
IN a[16], b[16], sel;
Expand Down
10 changes: 5 additions & 5 deletions projects/src/project_01/11_mux4way16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const cmp = `| a | b | c |
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux4Way16.hdl
// File name: projects/1/Mux4Way16.hdl
/**
* 4-way 16-bit multiplexor:
* out = a if sel == 00
* b if sel == 01
* c if sel == 10
* d if sel == 11
* out = a if sel = 00
* b if sel = 01
* c if sel = 10
* d if sel = 11
*/
CHIP Mux4Way16 {
IN a[16], b[16], c[16], d[16], sel[2];
Expand Down
14 changes: 9 additions & 5 deletions projects/src/project_01/12_mux8way16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ export const cmp = `| a | b | c |
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Mux8Way16.hdl
// File name: projects/1/Mux8Way16.hdl
/**
* 8-way 16-bit multiplexor:
* out = a if sel == 000
* b if sel == 001
* ...
* h if sel == 111
* out = a if sel = 000
* b if sel = 001
* c if sel = 010
* d if sel = 011
* e if sel = 100
* f if sel = 101
* g if sel = 110
* h if sel = 111
*/
CHIP Mux8Way16 {
IN a[16], b[16], c[16], d[16],
Expand Down
10 changes: 5 additions & 5 deletions projects/src/project_01/13_dmux4way.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux4Way.hdl
// File name: projects/1/DMux4Way.hdl
/**
* 4-way demultiplexor:
* [a, b, c, d] = [in, 0, 0, 0] if sel == 00
* [0, in, 0, 0] if sel == 01
* [0, 0, in, 0] if sel == 10
* [0, 0, 0, in] if sel == 11
* [a, b, c, d] = [in, 0, 0, 0] if sel = 00
* [0, in, 0, 0] if sel = 01
* [0, 0, in, 0] if sel = 10
* [0, 0, 0, in] if sel = 11
*/
CHIP DMux4Way {
IN in, sel[2];
Expand Down
14 changes: 9 additions & 5 deletions projects/src/project_01/14_dmux8way.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/DMux8Way.hdl
// File name: projects/1/DMux8Way.hdl
/**
* 8-way demultiplexor:
* [a, b, c, d, e, f, g, h] = [in, 0, 0, 0, 0, 0, 0, 0] if sel == 000
* [0, in, 0, 0, 0, 0, 0, 0] if sel == 001
* ...
* [0, 0, 0, 0, 0, 0, 0, in] if sel == 111
* [a, b, c, d, e, f, g, h] = [in, 0, 0, 0, 0, 0, 0, 0] if sel = 000
* [0, in, 0, 0, 0, 0, 0, 0] if sel = 001
* [0, 0, in, 0, 0, 0, 0, 0] if sel = 010
* [0, 0, 0, in, 0, 0, 0, 0] if sel = 011
* [0, 0, 0, 0, in, 0, 0, 0] if sel = 100
* [0, 0, 0, 0, 0, in, 0, 0] if sel = 101
* [0, 0, 0, 0, 0, 0, in, 0] if sel = 110
* [0, 0, 0, 0, 0, 0, 0, in] if sel = 111
*/
CHIP DMux8Way {
IN in, sel[3];
Expand Down
2 changes: 1 addition & 1 deletion projects/src/project_01/15_or8way.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const cmp = `| in |out|
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/01/Or8Way.hdl
// File name: projects/1/Or8Way.hdl
/**
* 8-way Or gate:
* out = in[0] Or in[1] Or ... Or in[7]
Expand Down
4 changes: 2 additions & 2 deletions projects/src/project_01/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function resetFiles(fs: FileSystem): Promise<void> {

export async function resetTests(fs: FileSystem): Promise<void> {
await fs.pushd("/projects/01");
await resetBySuffix(fs, CHIPS, "tst");
await resetBySuffix(fs, CHIPS, "cmp");
await resetBySuffix(fs, CHIPS, ".tst");
await resetBySuffix(fs, CHIPS, ".cmp");
await fs.popd();
}
19 changes: 12 additions & 7 deletions projects/src/project_02/01_half_adder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/HalfAdder.hdl
// File name: projects/2/HalfAdder.hdl
/**
* Computes the sum of two bits.
*/
Expand All @@ -13,12 +13,17 @@ CHIP HalfAdder {
PARTS:
//// Replace this comment with your code.
}`;
export const cmp = `| a | b | sum | carry |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |`;
export const tst = `output-list a%B3.1.3 b%B3.1.3 sum%B3.1.3 carry%B3.1.3;
export const cmp = `| a | b |sum|car|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |`;
export const tst = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/2/HalfAdder.tst
output-list a b sum carry;
set a 0,
set b 0,
Expand Down
27 changes: 16 additions & 11 deletions projects/src/project_02/02_full_adder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/FullAdder.hdl
// File name: projects/2/FullAdder.hdl
/**
* Computes the sum of three bits.
*/
Expand All @@ -13,16 +13,21 @@ CHIP FullAdder {
PARTS:
//// Replace this comment with your code.
}`;
export const cmp = `| a | b | c | sum | carry |
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |`;
export const tst = `output-list a%B3.1.3 b%B3.1.3 c%B3.1.3 sum%B3.1.3 carry%B3.1.3;
export const cmp = `| a | b | c |sum|carry|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |`;
export const tst = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/2/FullAdder.tst
output-list a b c sum carry%B2.1.2;
set a 0,
set b 0,
Expand Down
9 changes: 7 additions & 2 deletions projects/src/project_02/03_add16.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/Add16.hdl
// File name: projects/2/Add16.hdl
/**
* 16-bit adder: Adds two 16-bit two's complement values.
* The most significant carry bit is ignored.
Expand All @@ -20,7 +20,12 @@ export const cmp = `| a | b | out |
| 1010101010101010 | 0101010101010101 | 1111111111111111 |
| 0011110011000011 | 0000111111110000 | 0100110010110011 |
| 0001001000110100 | 1001100001110110 | 1010101010101010 |`;
export const tst = `output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
export const tst = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/2/Add16.tst
output-list a%B1.16.1 b%B1.16.1 out%B1.16.1;
set a %B0000000000000000,
set b %B0000000000000000,
Expand Down
9 changes: 7 additions & 2 deletions projects/src/project_02/04_inc16.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const hdl = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/Inc16.hdl
// File name: projects/2/Inc16.hdl
/**
* 16-bit incrementer:
* out = in + 1
Expand All @@ -19,7 +19,12 @@ export const cmp = `| in | out |
| 0000000000000101 | 0000000000000110 |
| 1111111111111011 | 1111111111111100 |
`;
export const tst = `output-list in%B1.16.1 out%B1.16.1;
export const tst = `// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/2/Inc16.tst
output-list in%B1.16.1 out%B1.16.1;
set in %B0000000000000000, // in = 0
eval,
Expand Down
Loading

0 comments on commit 325a68e

Please sign in to comment.