From f0baaa4de5aa50cfe09789720d125e78fe76fcc9 Mon Sep 17 00:00:00 2001 From: David Souther Date: Sun, 29 Jan 2023 08:39:46 -0800 Subject: [PATCH] Redact solution files, to move to an off-repo integration test. (#186) Redact solution files, to move to an off-repo integration test. Retains solutions to unit test simulator code. --- projects/src/loader.ts | 2 +- projects/src/project_03/05_ram64.ts | 2 + projects/src/solutions/project_01/01_not.ts | 9 -- projects/src/solutions/project_01/03_or.ts | 9 -- projects/src/solutions/project_01/04_xor.ts | 11 -- projects/src/solutions/project_01/05_mux.ts | 10 -- projects/src/solutions/project_01/06_dmux.ts | 9 -- projects/src/solutions/project_01/07_not16.ts | 24 ----- projects/src/solutions/project_01/09_or16.ts | 22 ---- projects/src/solutions/project_01/10_mux16.ts | 22 ---- .../src/solutions/project_01/11_mux4way16.ts | 13 --- .../src/solutions/project_01/13_dmux4way.ts | 23 ---- .../src/solutions/project_01/14_dmux8way.ts | 51 --------- .../src/solutions/project_01/15_or8way.ts | 13 --- .../src/solutions/project_02/01_half_adder.ts | 9 -- .../src/solutions/project_02/02_full_adder.ts | 31 ------ projects/src/solutions/project_02/03_add16.ts | 31 ------ projects/src/solutions/project_02/04_inc16.ts | 32 ------ .../solutions/project_02/05_alu_no_stat.ts | 39 ------- projects/src/solutions/project_02/06_alu.ts | 46 -------- .../src/solutions/project_03/02_register.ts | 22 ---- projects/src/solutions/project_03/03_pc.ts | 19 ---- projects/src/solutions/project_03/04_ram8.ts | 43 -------- projects/src/solutions/project_03/05_ram64.ts | 43 -------- .../src/solutions/project_03/06_ram512.ts | 43 -------- projects/src/solutions/project_03/07_ram4k.ts | 43 -------- .../src/solutions/project_03/08_ram16k.ts | 31 ------ .../src/solutions/project_05/01_memory.ts | 60 ----------- projects/src/solutions/project_05/02_cpu.ts | 89 --------------- .../src/solutions/project_05/03_computer.ts | 28 ----- projects/src/{solutions => testing}/index.ts | 0 projects/src/testing/project_01/01_not.ts | 1 + .../project_01/02_and.ts | 0 projects/src/testing/project_01/03_or.ts | 1 + projects/src/testing/project_01/04_xor.ts | 1 + projects/src/testing/project_01/05_mux.ts | 1 + projects/src/testing/project_01/06_dmux.ts | 1 + projects/src/testing/project_01/07_not16.ts | 1 + .../project_01/08_and16.ts | 0 projects/src/testing/project_01/09_or16.ts | 1 + projects/src/testing/project_01/10_mux16.ts | 1 + .../src/testing/project_01/11_mux4way16.ts | 1 + .../project_01/12_mux8way16.ts | 0 .../src/testing/project_01/13_dmux4way.ts | 1 + .../src/testing/project_01/14_dmux8way.ts | 1 + projects/src/testing/project_01/15_or8way.ts | 1 + .../project_01/index.ts | 0 .../src/testing/project_02/01_half_adder.ts | 1 + .../src/testing/project_02/02_full_adder.ts | 1 + projects/src/testing/project_02/03_add16.ts | 1 + projects/src/testing/project_02/04_inc16.ts | 1 + .../src/testing/project_02/05_alu_no_stat.ts | 1 + projects/src/testing/project_02/06_alu.ts | 1 + .../project_02/index.ts | 0 .../project_03/01_bit.ts | 0 .../src/testing/project_03/02_register.ts | 1 + projects/src/testing/project_03/03_pc.ts | 1 + projects/src/testing/project_03/04_ram8.ts | 1 + projects/src/testing/project_03/05_ram64.ts | 1 + projects/src/testing/project_03/06_ram512.ts | 1 + projects/src/testing/project_03/07_ram4k.ts | 1 + projects/src/testing/project_03/08_ram16k.ts | 1 + .../project_03/index.ts | 0 projects/src/testing/project_05/01_memory.ts | 1 + projects/src/testing/project_05/02_cpu.ts | 1 + .../src/testing/project_05/03_computer.ts | 1 + .../project_05/index.ts | 0 simulator/src/chip/builtins/all.test.ts | 19 ++-- simulator/src/projects/all.test.ts | 101 ++++++++++-------- 69 files changed, 91 insertions(+), 886 deletions(-) delete mode 100644 projects/src/solutions/project_01/01_not.ts delete mode 100644 projects/src/solutions/project_01/03_or.ts delete mode 100644 projects/src/solutions/project_01/04_xor.ts delete mode 100644 projects/src/solutions/project_01/05_mux.ts delete mode 100644 projects/src/solutions/project_01/06_dmux.ts delete mode 100644 projects/src/solutions/project_01/07_not16.ts delete mode 100644 projects/src/solutions/project_01/09_or16.ts delete mode 100644 projects/src/solutions/project_01/10_mux16.ts delete mode 100644 projects/src/solutions/project_01/11_mux4way16.ts delete mode 100644 projects/src/solutions/project_01/13_dmux4way.ts delete mode 100644 projects/src/solutions/project_01/14_dmux8way.ts delete mode 100644 projects/src/solutions/project_01/15_or8way.ts delete mode 100644 projects/src/solutions/project_02/01_half_adder.ts delete mode 100644 projects/src/solutions/project_02/02_full_adder.ts delete mode 100644 projects/src/solutions/project_02/03_add16.ts delete mode 100644 projects/src/solutions/project_02/04_inc16.ts delete mode 100644 projects/src/solutions/project_02/05_alu_no_stat.ts delete mode 100644 projects/src/solutions/project_02/06_alu.ts delete mode 100644 projects/src/solutions/project_03/02_register.ts delete mode 100644 projects/src/solutions/project_03/03_pc.ts delete mode 100644 projects/src/solutions/project_03/04_ram8.ts delete mode 100644 projects/src/solutions/project_03/05_ram64.ts delete mode 100644 projects/src/solutions/project_03/06_ram512.ts delete mode 100644 projects/src/solutions/project_03/07_ram4k.ts delete mode 100644 projects/src/solutions/project_03/08_ram16k.ts delete mode 100644 projects/src/solutions/project_05/01_memory.ts delete mode 100644 projects/src/solutions/project_05/02_cpu.ts delete mode 100644 projects/src/solutions/project_05/03_computer.ts rename projects/src/{solutions => testing}/index.ts (100%) create mode 100644 projects/src/testing/project_01/01_not.ts rename projects/src/{solutions => testing}/project_01/02_and.ts (100%) create mode 100644 projects/src/testing/project_01/03_or.ts create mode 100644 projects/src/testing/project_01/04_xor.ts create mode 100644 projects/src/testing/project_01/05_mux.ts create mode 100644 projects/src/testing/project_01/06_dmux.ts create mode 100644 projects/src/testing/project_01/07_not16.ts rename projects/src/{solutions => testing}/project_01/08_and16.ts (100%) create mode 100644 projects/src/testing/project_01/09_or16.ts create mode 100644 projects/src/testing/project_01/10_mux16.ts create mode 100644 projects/src/testing/project_01/11_mux4way16.ts rename projects/src/{solutions => testing}/project_01/12_mux8way16.ts (100%) create mode 100644 projects/src/testing/project_01/13_dmux4way.ts create mode 100644 projects/src/testing/project_01/14_dmux8way.ts create mode 100644 projects/src/testing/project_01/15_or8way.ts rename projects/src/{solutions => testing}/project_01/index.ts (100%) create mode 100644 projects/src/testing/project_02/01_half_adder.ts create mode 100644 projects/src/testing/project_02/02_full_adder.ts create mode 100644 projects/src/testing/project_02/03_add16.ts create mode 100644 projects/src/testing/project_02/04_inc16.ts create mode 100644 projects/src/testing/project_02/05_alu_no_stat.ts create mode 100644 projects/src/testing/project_02/06_alu.ts rename projects/src/{solutions => testing}/project_02/index.ts (100%) rename projects/src/{solutions => testing}/project_03/01_bit.ts (100%) create mode 100644 projects/src/testing/project_03/02_register.ts create mode 100644 projects/src/testing/project_03/03_pc.ts create mode 100644 projects/src/testing/project_03/04_ram8.ts create mode 100644 projects/src/testing/project_03/05_ram64.ts create mode 100644 projects/src/testing/project_03/06_ram512.ts create mode 100644 projects/src/testing/project_03/07_ram4k.ts create mode 100644 projects/src/testing/project_03/08_ram16k.ts rename projects/src/{solutions => testing}/project_03/index.ts (100%) create mode 100644 projects/src/testing/project_05/01_memory.ts create mode 100644 projects/src/testing/project_05/02_cpu.ts create mode 100644 projects/src/testing/project_05/03_computer.ts rename projects/src/{solutions => testing}/project_05/index.ts (100%) diff --git a/projects/src/loader.ts b/projects/src/loader.ts index 02343c591..a85b7f019 100644 --- a/projects/src/loader.ts +++ b/projects/src/loader.ts @@ -9,7 +9,7 @@ export async function loadSamples(fs: FileSystem) { } export async function loadSolutions(fs: FileSystem) { - (await import("./solutions/index.js")).loadSolutions(fs); + (await import("./testing/index.js")).loadSolutions(fs); } export const loaders = { diff --git a/projects/src/project_03/05_ram64.ts b/projects/src/project_03/05_ram64.ts index 9e54171e6..cca830892 100644 --- a/projects/src/project_03/05_ram64.ts +++ b/projects/src/project_03/05_ram64.ts @@ -8,6 +8,8 @@ export const hdl = `/** CHIP RAM64 { IN in[16], load, address[6]; OUT out[16]; + + PARTS: }`; export const tst = `output-list time%S1.4.1 in%D1.6.1 load%B2.1.2 address%D2.3.2 out%D1.6.1; diff --git a/projects/src/solutions/project_01/01_not.ts b/projects/src/solutions/project_01/01_not.ts deleted file mode 100644 index 617574264..000000000 --- a/projects/src/solutions/project_01/01_not.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const sol = `// Not gate: out = not in - -CHIP Not { - IN in; - OUT out; - - PARTS: - Nand (a=in, b=in, out=out); -}`; diff --git a/projects/src/solutions/project_01/03_or.ts b/projects/src/solutions/project_01/03_or.ts deleted file mode 100644 index bedc74b85..000000000 --- a/projects/src/solutions/project_01/03_or.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const sol = `CHIP Or { - IN a, b; - OUT out; - - PARTS: - Not (in=a, out=nota); - Not (in=b, out=notb); - Nand (a=nota, b=notb, out=out); -}`; diff --git a/projects/src/solutions/project_01/04_xor.ts b/projects/src/solutions/project_01/04_xor.ts deleted file mode 100644 index ae44c8b48..000000000 --- a/projects/src/solutions/project_01/04_xor.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const sol = `CHIP XOr { - IN a, b; - OUT out; - - PARTS: - Not (in=a, out=nota); - Not (in=b, out=notb); - And (a=nota, b=b, out=and1); - And (a=a, b=notb, out=and2); - Or (a=and1, b=and2, out=out); -}`; diff --git a/projects/src/solutions/project_01/05_mux.ts b/projects/src/solutions/project_01/05_mux.ts deleted file mode 100644 index e55965e4b..000000000 --- a/projects/src/solutions/project_01/05_mux.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const sol = `CHIP Mux { - IN a, b, sel; - OUT out; - - PARTS: - Not (in=sel, out=notsel); - And (a=a, b=notsel, out=and1); - And (a=b, b=sel, out=and2); - Or (a=and1, b=and2, out=out); -}`; diff --git a/projects/src/solutions/project_01/06_dmux.ts b/projects/src/solutions/project_01/06_dmux.ts deleted file mode 100644 index fb3f2fd3e..000000000 --- a/projects/src/solutions/project_01/06_dmux.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const sol = `CHIP DMux { - IN in, sel; - OUT a, b; - - PARTS: - Not(in=sel, out=notSel); - And(a=in, b=notSel, out=a); - And(a=in, b=sel, out=b); -}`; diff --git a/projects/src/solutions/project_01/07_not16.ts b/projects/src/solutions/project_01/07_not16.ts deleted file mode 100644 index 494ebd21b..000000000 --- a/projects/src/solutions/project_01/07_not16.ts +++ /dev/null @@ -1,24 +0,0 @@ -export const sol = `// 16-bit Not gate: for i=0..15: out[i] = not in[i] - -CHIP Not16 { - IN in[16]; - OUT out[16]; - - PARTS: - Not (in=in[0], out=out[0]); - Not (in=in[1], out=out[1]); - Not (in=in[2], out=out[2]); - Not (in=in[3], out=out[3]); - Not (in=in[4], out=out[4]); - Not (in=in[5], out=out[5]); - Not (in=in[6], out=out[6]); - Not (in=in[7], out=out[7]); - Not (in=in[8], out=out[8]); - Not (in=in[9], out=out[9]); - Not (in=in[10], out=out[10]); - Not (in=in[11], out=out[11]); - Not (in=in[12], out=out[12]); - Not (in=in[13], out=out[13]); - Not (in=in[14], out=out[14]); - Not (in=in[15], out=out[15]); -}`; diff --git a/projects/src/solutions/project_01/09_or16.ts b/projects/src/solutions/project_01/09_or16.ts deleted file mode 100644 index c6460103a..000000000 --- a/projects/src/solutions/project_01/09_or16.ts +++ /dev/null @@ -1,22 +0,0 @@ -export const sol = `CHIP Or16 { - IN a[16], b[16]; - OUT out[16]; - - PARTS: - Or (a=a[0], b=b[0], out=out[0]); - Or (a=a[1], b=b[1], out=out[1]); - Or (a=a[2], b=b[2], out=out[2]); - Or (a=a[3], b=b[3], out=out[3]); - Or (a=a[4], b=b[4], out=out[4]); - Or (a=a[5], b=b[5], out=out[5]); - Or (a=a[6], b=b[6], out=out[6]); - Or (a=a[7], b=b[7], out=out[7]); - Or (a=a[8], b=b[8], out=out[8]); - Or (a=a[9], b=b[9], out=out[9]); - Or (a=a[10], b=b[10], out=out[10]); - Or (a=a[11], b=b[11], out=out[11]); - Or (a=a[12], b=b[12], out=out[12]); - Or (a=a[13], b=b[13], out=out[13]); - Or (a=a[14], b=b[14], out=out[14]); - Or (a=a[15], b=b[15], out=out[15]); -}`; diff --git a/projects/src/solutions/project_01/10_mux16.ts b/projects/src/solutions/project_01/10_mux16.ts deleted file mode 100644 index a64389363..000000000 --- a/projects/src/solutions/project_01/10_mux16.ts +++ /dev/null @@ -1,22 +0,0 @@ -export const sol = `CHIP Mux16 { - IN a[16], b[16], sel; - OUT out[16]; - - PARTS: - Mux(a=a[0], b=b[0], sel=sel, out=out[0]); - Mux(a=a[1], b=b[1], sel=sel, out=out[1]); - Mux(a=a[2], b=b[2], sel=sel, out=out[2]); - Mux(a=a[3], b=b[3], sel=sel, out=out[3]); - Mux(a=a[4], b=b[4], sel=sel, out=out[4]); - Mux(a=a[5], b=b[5], sel=sel, out=out[5]); - Mux(a=a[6], b=b[6], sel=sel, out=out[6]); - Mux(a=a[7], b=b[7], sel=sel, out=out[7]); - Mux(a=a[8], b=b[8], sel=sel, out=out[8]); - Mux(a=a[9], b=b[9], sel=sel, out=out[9]); - Mux(a=a[10], b=b[10], sel=sel, out=out[10]); - Mux(a=a[11], b=b[11], sel=sel, out=out[11]); - Mux(a=a[12], b=b[12], sel=sel, out=out[12]); - Mux(a=a[13], b=b[13], sel=sel, out=out[13]); - Mux(a=a[14], b=b[14], sel=sel, out=out[14]); - Mux(a=a[15], b=b[15], sel=sel, out=out[15]); -}`; diff --git a/projects/src/solutions/project_01/11_mux4way16.ts b/projects/src/solutions/project_01/11_mux4way16.ts deleted file mode 100644 index c7d3e0af1..000000000 --- a/projects/src/solutions/project_01/11_mux4way16.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const sol = `CHIP Mux4Way16 { - IN a[16], b[16], c[16], d[16], sel[2]; - OUT out[16]; - - PARTS: - Mux16(a=a, b=b, sel=sel[0], out=ab); - Mux16(a=c, b=d, sel=sel[0], out=cd); - Mux16(a=ab, b=cd, sel=sel[1], out=out); - -// Alternate implementation -// -// Some students make a Mux4Way chip and apply it 16 times as in Not16. -}`; diff --git a/projects/src/solutions/project_01/13_dmux4way.ts b/projects/src/solutions/project_01/13_dmux4way.ts deleted file mode 100644 index c4a679faf..000000000 --- a/projects/src/solutions/project_01/13_dmux4way.ts +++ /dev/null @@ -1,23 +0,0 @@ -export const sol = `CHIP DMux4Way { - IN in, sel[2]; - OUT a, b, c, d; - - PARTS: - DMux (in=in, sel=sel[1], a=ab, b=cd); - DMux (in=ab, sel=sel[0], a=a, b=b); - DMux (in=cd, sel=sel[0], a=c, b=d); - -// Alternate implementation, using a canonical representation. -/* - Not (in=sel[0], out=notSel0); - Not (in=sel[1], out=notSel1); - And (a=notSel1, b=notSel0, out=selA); - And (a=notSel1, b=sel[0], out=selB); - And (a=sel[1], b=notSel0, out=selC); - And (a=sel[1], b=sel[0], out=selD); - And (a=selA, b=in, out=a); - And (a=selB, b=in, out=b); - And (a=selC, b=in, out=c); - And (a=selD, b=in, out=d); -*/ -}`; diff --git a/projects/src/solutions/project_01/14_dmux8way.ts b/projects/src/solutions/project_01/14_dmux8way.ts deleted file mode 100644 index f41da2d87..000000000 --- a/projects/src/solutions/project_01/14_dmux8way.ts +++ /dev/null @@ -1,51 +0,0 @@ -export const sol = `CHIP DMux8Way { - IN in, sel[3]; - OUT a, b, c, d, e, f, g, h; - - PARTS: - // Binary tree of demultiplexors. - DMux (sel=sel[2], in=in, a=abcd, b=efgh); - DMux (sel=sel[1], in=abcd, a=ab, b=cd); - DMux (sel=sel[1], in=efgh, a=ef, b=gh); - DMux (sel=sel[0], in=ab, a=a, b=b); - DMux (sel=sel[0], in=cd, a=c, b=d); - DMux (sel=sel[0], in=ef, a=e, b=f); - DMux (sel=sel[0], in=gh, a=g, b=h); - -// Alternate implementation -// -// Replace the final two layers of the binary tree with -// 4-way demultiplexors. -/* - DMux (sel=sel[2], in=in, a=abcd, b=efgh); - DMux4Way (sel=sel[0..1], in=abcd, a=a, b=b, c=c, d=d); - DMux4Way (sel=sel[0..1], in=efgh, a=e, b=f, c=g, d=h); -*/ - -// Alternate implementation -// -// The binary tree of demultiplexors implementation with -// the demultiplexors in canonical form. -/* - Not (in=sel[0], out=notSel0); - Not (in=sel[1], out=notSel1); - Not (in=sel[2], out=notSel2); - - And (a=in, b=notSel2, out=abcd); - And (a=in, b=sel[2], out=efgh); - - And (a=abcd, b=notSel1, out=ab); - And (a=abcd, b=sel[1], out=cd); - And (a=efgh, b=notSel1, out=ef); - And (a=efgh, b=sel[1], out=gh); - - And (a=ab, b=notSel0, out=a); - And (a=ab, b=sel[0], out=b); - And (a=cd, b=notSel0, out=c); - And (a=cd, b=sel[0], out=d); - And (a=ef, b=notSel0, out=e); - And (a=ef, b=sel[0], out=f); - And (a=gh, b=notSel0, out=g); - And (a=gh, b=sel[0], out=h); -*/ -}`; diff --git a/projects/src/solutions/project_01/15_or8way.ts b/projects/src/solutions/project_01/15_or8way.ts deleted file mode 100644 index c345036b5..000000000 --- a/projects/src/solutions/project_01/15_or8way.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const sol = `CHIP Or8Way { - IN in[8]; - OUT out; - - PARTS: - Or (a=in[0], b=in[1], out=or01); - Or (a=in[2], b=in[3], out=or23); - Or (a=in[4], b=in[5], out=or45); - Or (a=in[6], b=in[7], out=or67); - Or (a=or01, b=or23, out=or0123); - Or (a=or45, b=or67, out=or4567); - Or (a=or0123, b=or4567, out=out); -}`; diff --git a/projects/src/solutions/project_02/01_half_adder.ts b/projects/src/solutions/project_02/01_half_adder.ts deleted file mode 100644 index a890f7dd6..000000000 --- a/projects/src/solutions/project_02/01_half_adder.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const sol = `CHIP HalfAdder { - IN a, b; // 1-bit inputs - OUT sum, // Right bit of a + b - carry; // Left bit of a + b - - PARTS: - Xor (a=a, b=b, out=sum); - And (a=a, b=b, out=carry); -}`; diff --git a/projects/src/solutions/project_02/02_full_adder.ts b/projects/src/solutions/project_02/02_full_adder.ts deleted file mode 100644 index 7bbb5a62b..000000000 --- a/projects/src/solutions/project_02/02_full_adder.ts +++ /dev/null @@ -1,31 +0,0 @@ -export const sol = `CHIP FullAdder { - IN a, b, c; // 1-bit inputs - OUT sum, // Right bit of a + b + c - carry; // Left bit of a + b + c - - PARTS: - HalfAdder (a=a, b=b, sum=sum1, carry=carry1); - HalfAdder (a=c, b=sum1, sum=sum, carry=carry2); - Or (a=carry1, b=carry2, out=carry); - -// Alternate implementation. -// The first implementation is the way FullAdder is described in the book. -// This implementation is elegant, but slightly less efficient. There is -// no reason to prefer either implementation over the other. -/* - HalfAdder (a=a, b=b, sum=sum1, carry=carry1); - HalfAdder (a=c, b=sum1, sum=sum, carry=carry2); - HalfAdder (a=carry1, b=carry2, out=carry); -*/ - -// Alternate implementation using less abstraction. -// Direct implementation without using half-adders, -// as mentioned in the book. -/* - Xor (a=a, b=b, out=abSum); - And (a=a, b=b, out=abCarry); - Xor (a=abSum, b=c, out=sum); - And (a=abSum, b=c, out=abcCarry); - Or (a=abCarry, b=abcCarry, out=carry); -*/ -}`; diff --git a/projects/src/solutions/project_02/03_add16.ts b/projects/src/solutions/project_02/03_add16.ts deleted file mode 100644 index a08fc6e8c..000000000 --- a/projects/src/solutions/project_02/03_add16.ts +++ /dev/null @@ -1,31 +0,0 @@ -export const sol = `CHIP Add16 { - IN a[16], b[16]; - OUT out[16]; - - PARTS: - FullAdder (a=a[0], b=b[0], sum=out[0], carry=c1); - FullAdder (a=a[1], b=b[1], c=c1, sum=out[1], carry=c2); - FullAdder (a=a[2], b=b[2], c=c2, sum=out[2], carry=c3); - FullAdder (a=a[3], b=b[3], c=c3, sum=out[3], carry=c4); - FullAdder (a=a[4], b=b[4], c=c4, sum=out[4], carry=c5); - FullAdder (a=a[5], b=b[5], c=c5, sum=out[5], carry=c6); - FullAdder (a=a[6], b=b[6], c=c6, sum=out[6], carry=c7); - FullAdder (a=a[7], b=b[7], c=c7, sum=out[7], carry=c8); - FullAdder (a=a[8], b=b[8], c=c8, sum=out[8], carry=c9); - FullAdder (a=a[9], b=b[9], c=c9, sum=out[9], carry=c10); - FullAdder (a=a[10], b=b[10], c=c10, sum=out[10], carry=c11); - FullAdder (a=a[11], b=b[11], c=c11, sum=out[11], carry=c12); - FullAdder (a=a[12], b=b[12], c=c12, sum=out[12], carry=c13); - FullAdder (a=a[13], b=b[13], c=c13, sum=out[13], carry=c14); - FullAdder (a=a[14], b=b[14], c=c14, sum=out[14], carry=c15); - FullAdder (a=a[15], b=b[15], c=c15, sum=out[15]); - -// Alternate implementation -// Both implementations are described in the text. There is no reason -// to prefer either implementation over the other. -/* - FullAdder (a=a[0], b=b[0], c=false, sum=out[0], carry=c0); - FullAdder (a=a[1], b=b[1], c=c0, sum=out[1], carry=c1); - ... -*/ -}`; diff --git a/projects/src/solutions/project_02/04_inc16.ts b/projects/src/solutions/project_02/04_inc16.ts deleted file mode 100644 index 68caf907b..000000000 --- a/projects/src/solutions/project_02/04_inc16.ts +++ /dev/null @@ -1,32 +0,0 @@ -export const sol = `CHIP Inc16 { - IN in[16]; - OUT out[16]; - - PARTS: - Add16 (a=in, b[0]=true, b[1..15]=false, out=out); - -// Alternative implementation. Unset bits are explicitly false. -// Add16 (a=in, b[0]=true, out=out); - -// Alternate implementation using less abstraction. -// The first implementation is how Inc16 is described in the text. -// This is the classical implementation. -/* - HalfAdder (a=in[0], b=true, sum=out[0], carry=c0); - HalfAdder (a=in[1], b=c0, sum=out[1], carry=c1); - HalfAdder (a=in[2], b=c1, sum=out[2], carry=c2); - HalfAdder (a=in[3], b=c2, sum=out[3], carry=c3); - HalfAdder (a=in[4], b=c3, sum=out[4], carry=c4); - HalfAdder (a=in[5], b=c4, sum=out[5], carry=c5); - HalfAdder (a=in[6], b=c5, sum=out[6], carry=c6); - HalfAdder (a=in[7], b=c6, sum=out[7], carry=c7); - HalfAdder (a=in[8], b=c7, sum=out[8], carry=c8); - HalfAdder (a=in[9], b=c8, sum=out[9], carry=c9); - HalfAdder (a=in[10],b=c9, sum=out[10], carry=c10); - HalfAdder (a=in[11],b=c10, sum=out[11], carry=c11); - HalfAdder (a=in[12],b=c11, sum=out[12], carry=c12); - HalfAdder (a=in[13],b=c12, sum=out[13], carry=c13); - HalfAdder (a=in[14],b=c13, sum=out[14], carry=c14); - HalfAdder (a=in[15],b=c14, sum=out[15]); -*/ -}`; diff --git a/projects/src/solutions/project_02/05_alu_no_stat.ts b/projects/src/solutions/project_02/05_alu_no_stat.ts deleted file mode 100644 index 3846b36b4..000000000 --- a/projects/src/solutions/project_02/05_alu_no_stat.ts +++ /dev/null @@ -1,39 +0,0 @@ -export const sol = `CHIP ALU { - IN - x[16], y[16], // 16-bit inputs - zx, // zero the x input? - nx, // negate the x input? - zy, // zero the y input? - ny, // negate the y input? - f, // compute out = x + y (if 1) or x & y (if 0) - no; // negate the out output? - - OUT - out[16]; // 16-bit output - - PARTS: - Not16(in=outbus, out=notoutbus); - Mux16(sel=no, a=outbus, b=notoutbus, out=out); - // x input processing, controlled by the 'zx' and 'nx' bits. - // When 'zx' is false, x is zeroed. 'nx' will select the negation of the - // possibly zeroed x input, and make it avaialble as 'xbus'. - Mux16 (sel=zx, a=x, b=false, out=xzero); - Not16 (in=xzero, out=notx); - Mux16 (sel=nx, a=xzero, b=notx, out=xbus); - - // y input processing, controlled by the 'zy' and 'ny' bits. - // When 'zy' is false, y is zeroed. 'ny' will select the negation of the - // possibly zeroed y input, and make it avaialble as 'ybus'. - Mux16(sel=zy, a=y, b=false, out=yzero); - Not16(in=yzero, out=noty); - Mux16(sel=ny, a=yzero, b=noty, out=ybus); - - // Compute both functions and select based on the 'f' bit - And16(a=xbus, b=ybus, out=fbusand); - Add16(a=xbus, b=ybus, out=fbusadd); - Mux16(sel=f, a=fbusand, b=fbusadd, out=outbus); - - // Output inversion, controlled by the 'no' bit - Not16(in=outbus, out=notoutbus); - Mux16(sel=no, a=outbus, b=notoutbus, out=out); -}`; diff --git a/projects/src/solutions/project_02/06_alu.ts b/projects/src/solutions/project_02/06_alu.ts deleted file mode 100644 index 3c442806c..000000000 --- a/projects/src/solutions/project_02/06_alu.ts +++ /dev/null @@ -1,46 +0,0 @@ -export const sol = `CHIP ALU { - IN - x[16], y[16], // 16-bit inputs - zx, // zero the x input? - nx, // negate the x input? - zy, // zero the y input? - ny, // negate the y input? - f, // compute out = x + y (if 1) or x & y (if 0) - no; // negate the out output? - - OUT - out[16], // 16-bit output - zr, // 1 if (out == 0), 0 otherwise - ng; // 1 if (out < 0), 0 otherwise - - PARTS: - // x input processing, controlled by the 'zx' and 'nx' bits. - // When 'zx' is false, x is zeroed. 'nx' will select the negation of the - // possibly zeroed x input, and make it avaialble as 'xbus'. - Mux16 (sel=zx, a=x, b=false, out=xzero); - Not16 (in=xzero, out=notx); - Mux16 (sel=nx, a=xzero, b=notx, out=xbus); - - // y input processing, controlled by the 'zy' and 'ny' bits. - // When 'zy' is false, y is zeroed. 'ny' will select the negation of the - // possibly zeroed y input, and make it avaialble as 'ybus'. - Mux16(sel=zy, a=y, b=false, out=yzero); - Not16(in=yzero, out=noty); - Mux16(sel=ny, a=yzero, b=noty, out=ybus); - - // Compute both functions and select based on the 'f' bit - And16(a=xbus, b=ybus, out=fbusand); - Add16(a=xbus, b=ybus, out=fbusadd); - Mux16(sel=f, a=fbusand, b=fbusadd, out=outbus); - - // Output inversion, controlled by the 'no' bit - // 'out' bit 15 is the 'ng' flag - Not16(in=outbus, out=notoutbus); - Mux16(sel=no, a=outbus, b=notoutbus, out[15]=ng, out[0..7]=zr1, out[8..15]=zr2, out=out); - - // Compute the zr and nz flags - Or8Way(in=zr1, out=zra); - Or8Way(in=zr2, out=zrb); - Or(a=zra, b=zrb, out=zror); - Not(in=zror, out=zr); -}`; diff --git a/projects/src/solutions/project_03/02_register.ts b/projects/src/solutions/project_03/02_register.ts deleted file mode 100644 index 30c947280..000000000 --- a/projects/src/solutions/project_03/02_register.ts +++ /dev/null @@ -1,22 +0,0 @@ -export const sol = `CHIP Register { - IN in[16], load; - OUT out[16]; - - PARTS: - Bit (in=in[0], load=load, out=out[0]); - Bit (in=in[1], load=load, out=out[1]); - Bit (in=in[2], load=load, out=out[2]); - Bit (in=in[3], load=load, out=out[3]); - Bit (in=in[4], load=load, out=out[4]); - Bit (in=in[5], load=load, out=out[5]); - Bit (in=in[6], load=load, out=out[6]); - Bit (in=in[7], load=load, out=out[7]); - Bit (in=in[8], load=load, out=out[8]); - Bit (in=in[9], load=load, out=out[9]); - Bit (in=in[10], load=load, out=out[10]); - Bit (in=in[11], load=load, out=out[11]); - Bit (in=in[12], load=load, out=out[12]); - Bit (in=in[13], load=load, out=out[13]); - Bit (in=in[14], load=load, out=out[14]); - Bit (in=in[15], load=load, out=out[15]); -}`; diff --git a/projects/src/solutions/project_03/03_pc.ts b/projects/src/solutions/project_03/03_pc.ts deleted file mode 100644 index 75d2deef1..000000000 --- a/projects/src/solutions/project_03/03_pc.ts +++ /dev/null @@ -1,19 +0,0 @@ -export const sol = `CHIP PC { - IN in[16], load, inc, reset; - OUT out[16]; - - PARTS: - // The internal 'self' pin tracks the current state of the PC. The 'pc' pin - // tracks the next value of the PC. Based on 'inc', 'lost', and 'reset', - // one of 'self', 'pc', and 'false' will be put on 'next' and used as the - // input value of the Register, which will always load that value and write - // its current value to 'self'. - - Inc16 (in=self, out=pc); - - Mux16 (sel=inc, a=self, b=pc, out=pin0); - Mux16 (sel=load, a=pin0, b=in, out=pin1); - Mux16 (sel=reset, a=pin1, b=false, out=next); - - Register (in=next, load=true, out=out, out=self); -}`; diff --git a/projects/src/solutions/project_03/04_ram8.ts b/projects/src/solutions/project_03/04_ram8.ts deleted file mode 100644 index eb2a212b2..000000000 --- a/projects/src/solutions/project_03/04_ram8.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const sol = `CHIP RAM8 { - IN in[16], load, address[3]; - OUT out[16]; - - PARTS: - // Demux the address to the 8 load channels - DMux8Way( - in=load, - sel=address, - a=load1, - b=load2, - c=load3, - d=load4, - e=load5, - f=load6, - g=load7, - h=load8 - ); - - // The registers proper - Register (in=in, load=load1, out=reg1); - Register (in=in, load=load2, out=reg2); - Register (in=in, load=load3, out=reg3); - Register (in=in, load=load4, out=reg4); - Register (in=in, load=load5, out=reg5); - Register (in=in, load=load6, out=reg6); - Register (in=in, load=load7, out=reg7); - Register (in=in, load=load8, out=reg8); - - // The output logic is a simple muxer - Mux8Way16( - a=reg1, - b=reg2, - c=reg3, - d=reg4, - e=reg5, - f=reg6, - g=reg7, - h=reg8, - sel=address, - out=out - ); -}`; diff --git a/projects/src/solutions/project_03/05_ram64.ts b/projects/src/solutions/project_03/05_ram64.ts deleted file mode 100644 index e70674fc7..000000000 --- a/projects/src/solutions/project_03/05_ram64.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const sol = `CHIP RAM64 { - IN in[16], load, address[6]; - OUT out[16]; - - PARTS: - // Demux the address to the 8 load channels - DMux8Way( - in=load, - sel=address[3..5], - a=load1, - b=load2, - c=load3, - d=load4, - e=load5, - f=load6, - g=load7, - h=load8 - ); - - // The child blocks - RAM8 (in=in, load=load1, address=address[0..2], out=ram1); - RAM8 (in=in, load=load2, address=address[0..2], out=ram2); - RAM8 (in=in, load=load3, address=address[0..2], out=ram3); - RAM8 (in=in, load=load4, address=address[0..2], out=ram4); - RAM8 (in=in, load=load5, address=address[0..2], out=ram5); - RAM8 (in=in, load=load6, address=address[0..2], out=ram6); - RAM8 (in=in, load=load7, address=address[0..2], out=ram7); - RAM8 (in=in, load=load8, address=address[0..2], out=ram8); - - // The output logic is a simple muxer - Mux8Way16( - a=ram1, - b=ram2, - c=ram3, - d=ram4, - e=ram5, - f=ram6, - g=ram7, - h=ram8, - sel=address[3..5], - out=out - ); -}`; diff --git a/projects/src/solutions/project_03/06_ram512.ts b/projects/src/solutions/project_03/06_ram512.ts deleted file mode 100644 index fbab2f282..000000000 --- a/projects/src/solutions/project_03/06_ram512.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const sol = `CHIP RAM512 { - IN in[16], load, address[9]; - OUT out[16]; - - PARTS: - // Demux the address to the 8 load channels - DMux8Way( - in=load, - sel=address[6..8], - a=loada, - b=loadb, - c=loadc, - d=loadd, - e=loade, - f=loadf, - g=loadg, - h=loadh - ); - - // The child blocks - RAM64 (in=in, load=loada, address=address[0..5], out=rama); - RAM64 (in=in, load=loadb, address=address[0..5], out=ramb); - RAM64 (in=in, load=loadc, address=address[0..5], out=ramc); - RAM64 (in=in, load=loadd, address=address[0..5], out=ramd); - RAM64 (in=in, load=loade, address=address[0..5], out=rame); - RAM64 (in=in, load=loadf, address=address[0..5], out=ramf); - RAM64 (in=in, load=loadg, address=address[0..5], out=ramg); - RAM64 (in=in, load=loadh, address=address[0..5], out=ramh); - - // The output logic is a simple muxer - Mux8Way16( - a=rama, - b=ramb, - c=ramc, - d=ramd, - e=rame, - f=ramf, - g=ramg, - h=ramh, - sel=address[6..8], - out=out - ); -}`; diff --git a/projects/src/solutions/project_03/07_ram4k.ts b/projects/src/solutions/project_03/07_ram4k.ts deleted file mode 100644 index 4e1c7add8..000000000 --- a/projects/src/solutions/project_03/07_ram4k.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const sol = `CHIP RAM4K { - IN in[16], load, address[12]; - OUT out[16]; - - PARTS: - // Demux the address to the 8 load channels - DMux8Way( - in=load, - sel=address[9..11], - a=load1, - b=load2, - c=load3, - d=load4, - e=load5, - f=load6, - g=load7, - h=load8 - ); - - // The child blocks - RAM512 (in=in, load=load1, address=address[0..8], out=ram1); - RAM512 (in=in, load=load2, address=address[0..8], out=ram2); - RAM512 (in=in, load=load3, address=address[0..8], out=ram3); - RAM512 (in=in, load=load4, address=address[0..8], out=ram4); - RAM512 (in=in, load=load5, address=address[0..8], out=ram5); - RAM512 (in=in, load=load6, address=address[0..8], out=ram6); - RAM512 (in=in, load=load7, address=address[0..8], out=ram7); - RAM512 (in=in, load=load8, address=address[0..8], out=ram8); - - // The output logic is a simple muxer - Mux8Way16( - a=ram1, - b=ram2, - c=ram3, - d=ram4, - e=ram5, - f=ram6, - g=ram7, - h=ram8, - sel=address[9..11], - out=out - ); -}`; diff --git a/projects/src/solutions/project_03/08_ram16k.ts b/projects/src/solutions/project_03/08_ram16k.ts deleted file mode 100644 index 3af330e71..000000000 --- a/projects/src/solutions/project_03/08_ram16k.ts +++ /dev/null @@ -1,31 +0,0 @@ -export const sol = `CHIP RAM16K { - IN in[16], load, address[14]; - OUT out[16]; - - PARTS: - // Demux the address to the 4 load channels - DMux4Way( - in=load, - sel=address[12..13], - a=load1, - b=load2, - c=load3, - d=load4 - ); - - // The child blocks - RAM4K (in=in, load=load1, address=address[0..11], out=ram1); - RAM4K (in=in, load=load2, address=address[0..11], out=ram2); - RAM4K (in=in, load=load3, address=address[0..11], out=ram3); - RAM4K (in=in, load=load4, address=address[0..11], out=ram4); - - // The output logic is a simple muxer - Mux4Way16( - a=ram1, - b=ram2, - c=ram3, - d=ram4, - sel=address[12..13], - out=out - ); -}`; diff --git a/projects/src/solutions/project_05/01_memory.ts b/projects/src/solutions/project_05/01_memory.ts deleted file mode 100644 index 496743b0b..000000000 --- a/projects/src/solutions/project_05/01_memory.ts +++ /dev/null @@ -1,60 +0,0 @@ -export const sol = `CHIP Memory { - IN in[16], load, address[15]; - OUT out[16]; - - PARTS: - DMux4Way (in=load, sel=address[13..14], a=load0, b=load1, c=loadScreen); - Or (a=load0, b=load1, out=loadRAM); - RAM16K (in=in, load=loadRAM, address=address[0..13], out=ramOut); - Screen (in=in, load=loadScreen, address=address[0..12], out=screenOut); - - // check if keyboard address - 0x6000 = 110 0000 0000 0000 - And (a=address[13], b=address[14], out=and1314); - Or8Way (in=address[0..7], out=or0to7); - Or8Way (in=address[5..12], out=or5to12); - Or (a=or0to7, b=or5to12, out=or0to12); - Not (in=or0to12, out=zero0to12); - And (a=zero0to12, b=and1314, out=keyAddress); - - // if keyboard address, output keyboard contents - Keyboard (out=key); - Mux16 (a=false, b=key, sel=keyAddress, out=keyOut); - Mux4Way16 (a=ramOut, b=ramOut, c=screenOut, d=keyOut, sel=address[13..14], out=out); - -// Alternate implementation for keyboard decoding. -/* - // check if keyboard address - 0x6000 = 110 0000 0000 0000 - // The output Mux4Way16 selects the range 0x6000 - 0x7FFF (the 1's). - // Decode xx0 0000 0000 0000 so that only 0x6000 responds within - // this range. - Or8Way (in=address[0..7], out=or0to7); - Or8Way (in[0]=or0to7, in[1..7]=address[6..12], out=or0to12); - Not (in=or0to12, out=keyAddress); - - // if keyboard address, output keyboard contents - Keyboard (out=key); - Mux16 (a=false, b=key, sel=keyAddress, out=keyOut); - - Mux4Way16 (a=ramOut, b=ramOut, c=screenOut, d=keyOut, sel=address[13..14], out=out); -*/ - - -// Alternate implementation. -// -// The book says "Access to any address>24576 (0x6000) is invalid." It can be -// argued that any access to an invalid address may return a don't-care value. -// The current keyboard value is as good a don't-care as any, so there is no -// need to decode the specific address. -// -// Some argue that this is poor engineering practice. -// Fully decoding I/O addresses should be encouraged. -/* - PARTS: - DMux4Way (in=load, sel=address[13..14], a=load0, b=load1, c=loadScreen); - Or (a=load0, b=load1, out=loadRAM); - RAM16K (in=in, load=loadRAM, address=address[0..13], out=ramOut); - Screen (in=in, load=loadScreen, address=address[0..12], out=screenOut); - Keyboard (out=keyOut); - Mux4Way16 (a=ramOut, b=ramOut, c=screenOut, d=keyOut, sel=address[13..14], out=out); -*/ -}`; diff --git a/projects/src/solutions/project_05/02_cpu.ts b/projects/src/solutions/project_05/02_cpu.ts deleted file mode 100644 index 441dfb8e2..000000000 --- a/projects/src/solutions/project_05/02_cpu.ts +++ /dev/null @@ -1,89 +0,0 @@ -export const sol = `CHIP CPU { - IN inM[16], // M value input (M = contents of RAM[A]) - instruction[16], // Instruction for execution - reset; // Signals whether to re-start the current - // program (reset==1) or continue executing - // the current program (reset==0). - - OUT outM[16], // M value output - writeM, // Write to M? - addressM[15], // Address in data memory (of M) - pc[15]; // address of next instruction - - PARTS: - - // See Figure 5.9 for a schematic of the CPU. - - // From figure 5.9, set all control bits from incoming instruction. - Not(in=instruction[15], out=aInstruction); - Mux16( - b=false, - a=instruction, - sel=aInstruction, - out[15]=cInst, - out[12]=a, - out[11]=c1, - out[10]=c2, - out[9]=c3, - out[8]=c4, - out[7]=c5, - out[6]=c6, - out[5]=d1, - out[4]=writeD, - out[3]=writeM, - out[0..2]=jump - ); - - // Register A will be filled from either the instruction line or the ALU, - // based on the aInstruction bit (bit 15 of the instruction). - Mux16(a=alu, b=instruction, sel=aInstruction, out=regA); - - // Only read 15 bits of memory address into register A. - Or(a=aInstruction, b=d1, out=setA); - ARegister(in=regA, in[15]=false, load=setA, out[0..14]=addressM, out=A); - - // D register is loaded from the ALU when d2 is set. - DRegister(in=alu, load=writeD, out=D); - - // Fill the A bus line from either the A register or Memory, based on - // instruction bit a (12). - Mux16(a=A, b=inM, sel=a, out=AM); - - // ALU control bits are mapped directly in C instructions when in c mode. - // If aInstruction is 0, c instructions are 0, and ALU will output 0. - ALU( - x=D, - y=AM, - zx=c1, nx=c2, zy=c3, ny=c4, f=c5, no=c6, - out=alu, - out=outM, - zr=zr, ng=ng - ); - - // Jump - Not(in=ng, out=nng); - Not(in=zr, out=nzr); - And(a=nng, b=nzr, out=pt); // Positive is not negative and not zero - - And(a=jump[2], b=ng, out=jlt); - And(a=jump[1], b=zr, out=jeq); - And(a=jump[0], b=pt, out=jgt); - - And(a=jgt, b=jeq, out=jge); - And(a=jlt, b=jeq, out=jle); - And(a=jgt, b=jlt, out=jne); - - Or8Way( - in[0]=jgt, - in[1]=jeq, - in[2]=jge, - in[3]=jlt, - in[4]=jne, - in[5]=jle, - out=jmpi, - ); - - And(a=jmpi, b=cInst, out=jmp); - - PC(in=A, load=jmp, reset=reset, inc=true, out[0..14]=pc); -}`; diff --git a/projects/src/solutions/project_05/03_computer.ts b/projects/src/solutions/project_05/03_computer.ts deleted file mode 100644 index 0237dd792..000000000 --- a/projects/src/solutions/project_05/03_computer.ts +++ /dev/null @@ -1,28 +0,0 @@ -export const sol = `CHIP Computer { - IN reset; - - PARTS: - CPU( - reset=reset, - inM=outM, - instruction=instruction, - outM=inM, - writeM=writeM, - addressM=addressM, - pc=pc - ); - - // ROM - ROM32K( - address=pc, - out=instruction - ); - - // RAM - Memory( - in=inM, - load=writeM, - address=addressM, - out=outM - ); -}`; diff --git a/projects/src/solutions/index.ts b/projects/src/testing/index.ts similarity index 100% rename from projects/src/solutions/index.ts rename to projects/src/testing/index.ts diff --git a/projects/src/testing/project_01/01_not.ts b/projects/src/testing/project_01/01_not.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/01_not.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_01/02_and.ts b/projects/src/testing/project_01/02_and.ts similarity index 100% rename from projects/src/solutions/project_01/02_and.ts rename to projects/src/testing/project_01/02_and.ts diff --git a/projects/src/testing/project_01/03_or.ts b/projects/src/testing/project_01/03_or.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/03_or.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/04_xor.ts b/projects/src/testing/project_01/04_xor.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/04_xor.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/05_mux.ts b/projects/src/testing/project_01/05_mux.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/05_mux.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/06_dmux.ts b/projects/src/testing/project_01/06_dmux.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/06_dmux.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/07_not16.ts b/projects/src/testing/project_01/07_not16.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/07_not16.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_01/08_and16.ts b/projects/src/testing/project_01/08_and16.ts similarity index 100% rename from projects/src/solutions/project_01/08_and16.ts rename to projects/src/testing/project_01/08_and16.ts diff --git a/projects/src/testing/project_01/09_or16.ts b/projects/src/testing/project_01/09_or16.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/09_or16.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/10_mux16.ts b/projects/src/testing/project_01/10_mux16.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/10_mux16.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/11_mux4way16.ts b/projects/src/testing/project_01/11_mux4way16.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/11_mux4way16.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_01/12_mux8way16.ts b/projects/src/testing/project_01/12_mux8way16.ts similarity index 100% rename from projects/src/solutions/project_01/12_mux8way16.ts rename to projects/src/testing/project_01/12_mux8way16.ts diff --git a/projects/src/testing/project_01/13_dmux4way.ts b/projects/src/testing/project_01/13_dmux4way.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/13_dmux4way.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/14_dmux8way.ts b/projects/src/testing/project_01/14_dmux8way.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/14_dmux8way.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_01/15_or8way.ts b/projects/src/testing/project_01/15_or8way.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_01/15_or8way.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_01/index.ts b/projects/src/testing/project_01/index.ts similarity index 100% rename from projects/src/solutions/project_01/index.ts rename to projects/src/testing/project_01/index.ts diff --git a/projects/src/testing/project_02/01_half_adder.ts b/projects/src/testing/project_02/01_half_adder.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_02/01_half_adder.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_02/02_full_adder.ts b/projects/src/testing/project_02/02_full_adder.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_02/02_full_adder.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_02/03_add16.ts b/projects/src/testing/project_02/03_add16.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_02/03_add16.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_02/04_inc16.ts b/projects/src/testing/project_02/04_inc16.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_02/04_inc16.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_02/05_alu_no_stat.ts b/projects/src/testing/project_02/05_alu_no_stat.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_02/05_alu_no_stat.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_02/06_alu.ts b/projects/src/testing/project_02/06_alu.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_02/06_alu.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_02/index.ts b/projects/src/testing/project_02/index.ts similarity index 100% rename from projects/src/solutions/project_02/index.ts rename to projects/src/testing/project_02/index.ts diff --git a/projects/src/solutions/project_03/01_bit.ts b/projects/src/testing/project_03/01_bit.ts similarity index 100% rename from projects/src/solutions/project_03/01_bit.ts rename to projects/src/testing/project_03/01_bit.ts diff --git a/projects/src/testing/project_03/02_register.ts b/projects/src/testing/project_03/02_register.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/02_register.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_03/03_pc.ts b/projects/src/testing/project_03/03_pc.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/03_pc.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_03/04_ram8.ts b/projects/src/testing/project_03/04_ram8.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/04_ram8.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_03/05_ram64.ts b/projects/src/testing/project_03/05_ram64.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/05_ram64.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_03/06_ram512.ts b/projects/src/testing/project_03/06_ram512.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/06_ram512.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_03/07_ram4k.ts b/projects/src/testing/project_03/07_ram4k.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/07_ram4k.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_03/08_ram16k.ts b/projects/src/testing/project_03/08_ram16k.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_03/08_ram16k.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_03/index.ts b/projects/src/testing/project_03/index.ts similarity index 100% rename from projects/src/solutions/project_03/index.ts rename to projects/src/testing/project_03/index.ts diff --git a/projects/src/testing/project_05/01_memory.ts b/projects/src/testing/project_05/01_memory.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_05/01_memory.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_05/02_cpu.ts b/projects/src/testing/project_05/02_cpu.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_05/02_cpu.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/testing/project_05/03_computer.ts b/projects/src/testing/project_05/03_computer.ts new file mode 100644 index 000000000..3b7d47d6d --- /dev/null +++ b/projects/src/testing/project_05/03_computer.ts @@ -0,0 +1 @@ +export const sol = `// REDACTED`; diff --git a/projects/src/solutions/project_05/index.ts b/projects/src/testing/project_05/index.ts similarity index 100% rename from projects/src/solutions/project_05/index.ts rename to projects/src/testing/project_05/index.ts diff --git a/simulator/src/chip/builtins/all.test.ts b/simulator/src/chip/builtins/all.test.ts index c9d608455..e5b743414 100644 --- a/simulator/src/chip/builtins/all.test.ts +++ b/simulator/src/chip/builtins/all.test.ts @@ -7,7 +7,6 @@ import { Cmp, CMP } from "../../languages/cmp.js"; import { HDL, HdlParse } from "../../languages/hdl.js"; import { Tst, TST } from "../../languages/tst.js"; import { ChipProjects, CHIP_PROJECTS } from "@nand2tetris/projects/index.js"; -import { ChipProjects as ChipProjectsSols } from "@nand2tetris/projects/solutions/index.js"; import { Max } from "@nand2tetris/projects/samples/hack.js"; import { compare } from "../../compare.js"; import { ChipTest } from "../../tst.js"; @@ -23,18 +22,12 @@ describe("All Projects", () => { (k) => !SKIP.has(k) ) )("Builtin %s", async (chipName) => { - let hdlFile: string = - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - ChipProjectsSols[project]?.SOLS[chipName]?.[`${chipName}.hdl`]; - const tstFile: string = - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - ChipProjects[project]?.CHIPS[chipName]?.[`${chipName}.tst`]; - const cmpFile: string = - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - ChipProjects[project]?.CHIPS[chipName]?.[`${chipName}.cmp`]; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const ChipProject = ChipProjects[project]?.CHIPS[chipName]; + let hdlFile: string = ChipProject?.[`${chipName}.hdl`]; + const tstFile: string = ChipProject?.[`${chipName}.tst`]; + const cmpFile: string = ChipProject?.[`${chipName}.cmp`]; expect(hdlFile).toBeDefined(); expect(tstFile).toBeDefined(); diff --git a/simulator/src/projects/all.test.ts b/simulator/src/projects/all.test.ts index 88b5503e6..36c7bbb5f 100644 --- a/simulator/src/projects/all.test.ts +++ b/simulator/src/projects/all.test.ts @@ -16,70 +16,77 @@ import { ASM_PROJECTS, CHIP_PROJECTS, } from "@nand2tetris/projects/index.js"; -import { ChipProjects as ChipProjectsSols } from "@nand2tetris/projects/solutions/index.js"; +import { ChipProjects as ChipProjectsSols } from "@nand2tetris/projects/testing/index.js"; import { ASM_SOLS, FILES as ASM_FILES, } from "@nand2tetris/projects/samples/project_06/index.js"; import { Max } from "@nand2tetris/projects/samples/hack.js"; +const PROJECTS = new Set(["01", "03"]); const SKIP = new Set([]); +const INCLUDE = new Set(["And", "And16", "Mux8Way16", "Bit"]); describe("Chip Projects", () => { - describe.each(Object.keys(CHIP_PROJECTS))("project %s", (project) => { - it.each( - CHIP_PROJECTS[project as keyof typeof CHIP_PROJECTS].filter( - (k) => !SKIP.has(k) - ) - )("Chip %s", async (chipName) => { - const chipProject = { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - ...ChipProjects[project]!, - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - ...ChipProjectsSols[project]!, - }; - const hdlFile = chipProject.SOLS[chipName]?.[`${chipName}.hdl`]; - const tstFile = chipProject.CHIPS[chipName]?.[`${chipName}.tst`]; - const cmpFile = chipProject.CHIPS[chipName]?.[`${chipName}.cmp`]; + describe.each(Object.keys(CHIP_PROJECTS).filter((k) => PROJECTS.has(k)))( + "project %s", + (project) => { + it.each( + CHIP_PROJECTS[project as keyof typeof CHIP_PROJECTS] + .filter((k) => !SKIP.has(k)) + .filter((k) => INCLUDE.has(k)) + )("Chip %s", async (chipName) => { + const chipProject = { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + ...ChipProjects[project]!, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + ...ChipProjectsSols[project]!, + }; + const hdlFile = chipProject.SOLS[chipName]?.[`${chipName}.hdl`]; + const tstFile = chipProject.CHIPS[chipName]?.[`${chipName}.tst`]; + const cmpFile = chipProject.CHIPS[chipName]?.[`${chipName}.cmp`]; - expect(hdlFile).toBeDefined(); - expect(tstFile).toBeDefined(); - expect(cmpFile).toBeDefined(); + expect(hdlFile).toBeDefined(); + expect(tstFile).toBeDefined(); + expect(cmpFile).toBeDefined(); - const hdl = HDL.parse(hdlFile); - expect(hdl).toBeOk(); - const tst = TST.parse(tstFile); - expect(tst).toBeOk(); + const hdl = HDL.parse(hdlFile); + expect(hdl).toBeOk(); + const tst = TST.parse(tstFile); + expect(tst).toBeOk(); - const chip = await build(Ok(hdl as Ok)); - expect(chip).toBeOk(); - const test = ChipTest.from(Ok(tst as Ok)).with(Ok(chip as Ok)); - - if (chipName === "Computer") { - test.setFileSystem( - new FileSystem( - new ObjectFileSystemAdapter({ "/samples/Max.hack": Max }) - ) + const chip = await build(Ok(hdl as Ok)); + expect(chip).toBeOk(); + const test = ChipTest.from(Ok(tst as Ok)).with( + Ok(chip as Ok) ); - } - await test.run(); + if (chipName === "Computer") { + test.setFileSystem( + new FileSystem( + new ObjectFileSystemAdapter({ "/samples/Max.hack": Max }) + ) + ); + } - const outFile = test.log(); + await test.run(); - const cmp = CMP.parse(cmpFile); - expect(cmp).toBeOk(); - const out = CMP.parse(outFile); - expect(out).toBeOk(); + const outFile = test.log(); - const diffs = compare(Ok(cmp as Ok), Ok(out as Ok)); - expect(diffs).toHaveNoDiff(); - }); - }); + const cmp = CMP.parse(cmpFile); + expect(cmp).toBeOk(); + const out = CMP.parse(outFile); + expect(out).toBeOk(); + + const diffs = compare(Ok(cmp as Ok), Ok(out as Ok)); + expect(diffs).toHaveNoDiff(); + }); + } + ); }); describe("ASM Projects", () => {