Web-Ide mit aufgenommen

This commit is contained in:
Riwoldt
2026-04-09 14:14:56 +02:00
parent 64816c45cc
commit 15cfaf332d
489 changed files with 186891 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.vsix
+12
View File
@@ -0,0 +1,12 @@
..
build
node_modules
src
tsconfig*
views
!out
out/**/*.map
!fileicons
!languages
!LICENSE
!package.json
+12
View File
@@ -0,0 +1,12 @@
MIT License
Copyright 2022 David Souther et al
This software is based on Stefano Volpe's 'Nand2Tetris Tools'. Please check [here](https://github.com/foxyseta/nand-ide/blob/master/LICENSE) for further information.
This software is based on Aviv Yaish's 'NAND IDE'. Please check [here](https://github.com/AvivYaish/nand-ide/blob/master/LICENSE) for further information.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+19
View File
@@ -0,0 +1,19 @@
# NAND2Tetris VSCode Extension
This extension adds a NAND2Tetris side panel to VSCode.
The side panel allows interacting with .HDl files and chips.
## Developing the extension
1. Open this project in VSCode.
2. Select "Run Extension" from the "Run and Debug" panel
3. Click "Run" or press F5.
4. In the debug VSCode window, open the [Project Files](https://github.com/nand2tetris/projects).
5. Open an HDL file, for instance, demo/Xor.hdl
6. The NAND2TETRIS: HDL CHIP view should be open in the side panel.
- If it is not, try `NAND2Tetris: Focus on HDL Chip View` in the command pallette.
## References
- [Your first extension](https://code.visualstudio.com/api/get-started/your-first-extension)
@@ -0,0 +1,42 @@
{
"iconDefinitions": {
"_hdl": {
"iconPath": "./images/hdl.svg"
},
"_tst": {
"iconPath": "./images/tst.svg"
},
"_cmp-out": {
"iconPath": "./images/cmp-out.svg"
},
"_hack": {
"iconPath": "./images/hack.svg"
},
"_vm": {
"iconPath": "./images/vm.svg"
},
"_jack": {
"iconPath": "./images/jack.svg"
}
},
"fileExtensions": {
"hdl": "_hdl",
"tst": "_tst",
"cmp": "_cmp-out",
"out": "_cmp-out",
"asm": "_asm",
"hack": "_hack",
"vm": "_vm",
"jack": "_jack"
},
"languageIds": {
"hdl": "_hdl",
"tst": "_tst",
"cmp": "_cmp-out",
"out": "_cmp-out",
"asm": "_asm",
"hack": "_hack",
"vm": "_vm",
"jack": "_jack"
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g style="transform: translate(20%, 10%) scale(80%)">
<g style="stroke: #777; fill:none; stroke-width: 20px; stroke-linejoin: round; stroke-linecap: round">
<path d="M10,10 H500 V500 H10 z M10,120 H500 M10,240 H500 M10,370 H500 M170,120 V500 M340,120 V500" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 428 B

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g style="transform: translate(20%, 10%) scale(80%)">
<g style="stroke: #777; fill:none; stroke-width: 40px; stroke-linejoin: round; stroke-linecap: round">
<path d="M106,20 h100 v180 h-100 z" />
<path d="M292,292 h100 v180 h-100 z" />
<path d="M296,60 l40,-40 v180 m-50,0 h100" />
<path d="M116,332 l40,-40 v180 m-50,0 h100" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 533 B

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g style="transform: translate(20%, 10%) scale(80%)">
<g style="stroke: #777; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 25px">
<path d="M75,75 h362 v362 h-362 z" />
<path d="M75,75 m72,0 v-60 m72,60 v-60 m72,60 v-60 m72,60 v-60" />
<path d="M75,75 m0,72 h-60 m60,72 h-60 m60,72 h-60 m60,72 h-60" />
<path d="M440,75 m0,72 h60 m-60,72 h60 m-60,72 h60 m-60,72 h60" />
<path d="M75,440 m72,0 v60 m72,-60 v60 m72,-60 v60 m72,-60 v60" />
<path d="M145,145 h215 v215 h-215 z m0,80 h70 m-70,55 h40" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 754 B

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g style="transform: translate(20%, 10%) scale(80%)">
<g style="stroke: #777; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 25px">
<path d="M12.5,12.5 h240 v120 h-120 v120 h-120 z m0,120 h20 m40,0 h0 m35,0 h25 v-120 " />
<path d="M380,132.5 h120 M255,253 h245 M12.5,376 h486 M12.5,499 h486" />
<path d="M12.5,380 v115 M132.5,380 v115 M253,255 v240 M376,132.5 v365 M500,132.5 v365 " />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 606 B

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g style="transform: translate(20%, 10%) scale(80%)">
<g style="stroke: #777; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 25px">
<path d="M12.5,12.5 h352 v485 h-352 z" />
<path d="M75,90 h75 v75 h-75 z M75,220 h75 v75 h-75 z M75,345 h75 v75 h-75 z" />
<path d="M200,90 h100 m-100,66 h100 m-100,66 h100 m-100,66 h100 m-100,66 h100 m-100,66 h100" />
<path d="M425,55 a 37.5 37.5 0 1 1 75 0 v366 l-37.5,75 l-37.5,-70 z M425,70 h75 M425,380 h75 " />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 679 B

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<g style="transform: translate(20%, 10%) scale(80%)">
<g style="stroke: #777; fill:none; stroke-width: 40px; stroke-linejoin: round; stroke-linecap: round">
<path d="M256,25 l256,124 l-256,124, l-256,-124 z" />
<path d="M0,247 l256,124 l256,-124" />
<path d="M0,355 l256,124 l256,-124" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 481 B

+51
View File
@@ -0,0 +1,51 @@
<svg version="1.1" width="32" height="32" xmlns="http://www.w3.org/2000/svg">
<style>
:root {
--outline: black;
--block: red;
--gate: cyan;
}
@media (prefers-color-scheme: dark) {
:root {
--outline: white;
--block: orange;
--gate: green;
}
}
rect, path, circle {
stroke: var(--outline);
stroke-width: 1px;
stroke-linecap: square;
}
rect.tetris {
--size: 8px;
--offset: 1.5px + calc(10px - var(--size));
fill: var(--block);
width: var(--size);
height: var(--size);
x: calc(var(--x) * var(--size) + var(--offset) - 1px);
y: calc(var(--y) * var(--size) + var(--offset) + 1px);
}
.gate {
fill: var(--gate);
}
.letter {
fill: var(--outline);
}
</style>
<rect class="tetris" style="--x: 0; --y: 2"></rect>
<rect class="tetris" style="--x: 1; --y: 2"></rect>
<rect class="tetris" style="--x: 1; --y: 1"></rect>
<rect class="tetris" style="--x: 2; --y: 1"></rect>
<path class="gate" d="M2.5,1.5 h5 a 5 5 0 0 1 0,10 h-5 v-10"></path>
<circle class="gate" cx="14.5" cy="6.5" r="2"></circle>
<path class="letter" d="M26,10 h-6 v-1 l5,-4 v-1 l-1,-1 h-2.5 l-.5,1 h-1 v-1 l1,-1 h4 l1,1 v2 l-5,4 h5 v1"></path>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

@@ -0,0 +1,57 @@
{
"If-then Statement": {
"prefix": [
"if",
"then",
"condition"
],
"body": [
"\t${1:$LINE_COMMENT D = condition}",
"\t@${2:IF_END}",
"\tD;JEQ",
"\t${0:$LINE_COMMENT code}",
"(${2:IF_END})"
],
"description": "An if-then statement."
},
"If-then-else Statement": {
"prefix": [
"if",
"then",
"else",
"elif",
"condition"
],
"body": [
"\t${1:$LINE_COMMENT D = condition}",
"\t@${2:IF_ELSE}",
"\tD;JEQ",
"\t${4:$LINE_COMMENT code}",
"\t@${3:IF_END}",
"\t0;JMP",
"(${2:IF_ELSE})",
"\t${0:$LINE_COMMENT code}",
"(${3:IF_END})"
],
"description": "An if-then-else statement."
},
"While Loop": {
"prefix": [
"repeat",
"loop",
"for",
"while"
],
"body": [
"(${1:LOOP})",
"\t${2:$LINE_COMMENT D = condition}",
"\t@${3:LOOP_END}",
"\tD;JEQ",
"\t${0:$LINE_COMMENT code}",
"\t@${1:LOOP}",
"\t0;JMP",
"(${3:LOOP_END})"
],
"description": "A while loop."
}
}
@@ -0,0 +1,111 @@
{
"fileTypes": [
"asm"
],
"name": "Hack Assembly Language",
"patterns": [
{
"include": "#declaration"
},
{
"include": "#A-instruction"
},
{
"include": "#destination"
},
{
"include": "#boolean"
},
{
"include": "#jump"
},
{
"include": "#comment"
}
],
"repository": {
"declaration": {
"patterns": [
{
"comment": "Label declaration",
"match": "\\(([^ \\/]*)\\)",
"name": "storage.type",
"captures": {
"1": {
"patterns": [
{
"comment": "Label",
"match": "[a-zA-Z\\_\\.\\$\\:]+[a-zA-Z\\_\\.\\$\\:\\d]*",
"name": "variable.other"
}
]
}
}
}
]
},
"A-instruction": {
"patterns": [
{
"comment": "@XXX instruction",
"match": "\\@([^ \\/]*)",
"name": "keyword.operator",
"captures": {
"1": {
"patterns": [
{
"match": "R10|R11|R12|R13|R14|R15|R0|R1|R2|R3|R4|R5|R6|R7|R8|R9|SP|LCL|ARG|THIS|THAT|SCREEN|KBD",
"name": "variable.language"
},
{
"comment": "A-instruction string argument",
"match": "[a-zA-Z\\_\\.\\$\\:]+[a-zA-Z\\_\\.\\$\\:\\d]*",
"name": "variable.other"
},
{
"match": "\\d+",
"name": "constant.numeric"
}
]
}
}
}
]
},
"destination": {
"patterns": [
{
"comment": "Left-hand side",
"match": "null|M|D|A|MD|AM|AD|AMD",
"name": "variable.language"
}
]
},
"jump": {
"patterns": [
{
"comment": "Jump type",
"match": "JGT|JLE|JEQ|JLT|JNE|JMP|JGE",
"name": "keyword.control"
}
]
},
"comment": {
"patterns": [
{
"comment": "Inline comment",
"begin": "\\/\\/",
"end": "\\n",
"name": "comment.line.double-slash"
},
{
"comment": "Multiline comment",
"begin": "\\/\\*",
"end": "\\*\\/",
"name": "comment.block"
}
]
}
},
"scopeName": "source.asm"
}
@@ -0,0 +1,60 @@
{
"fileTypes": [
"cmp",
"out"
],
"name": "CMP/OUT",
"patterns": [
{
"include": "#border"
},
{
"include": "#variable"
},
{
"include": "#value"
},
{
"include": "#placeholder"
}
],
"repository": {
"border": {
"patterns": [
{
"comment": "Vertical table border",
"name": "keyword.operator",
"match": "\\|"
}
]
},
"variable": {
"patterns": [
{
"comment": "The variable identifier (table header)",
"name": "support.variable",
"match": "[a-zA-Z]+"
}
]
},
"value": {
"patterns": [
{
"comment": "The value of a certain variable at a given time",
"name": "constant.numeric",
"match": "-*\\d+\\+*"
}
]
},
"placeholder": {
"patterns": [
{
"comment": "List of wildcard characters",
"name": "constant.language",
"match": "\\*+"
}
]
}
},
"scopeName": "source.cmp"
}
@@ -0,0 +1,59 @@
{
"fileTypes": ["hack"],
"name": "Hack Machine Language",
"patterns": [
{
"include": "#a"
},
{
"include": "#c"
}
],
"repository": {
"a": {
"patterns": [
{
"comment": "0-value",
"begin": "\\b0",
"end": "\\b",
"name": "comment",
"patterns": [
{
"comment": "value",
"match": "[01]{15}\\b",
"name": "constant.numeric"
}
]
}
]
},
"c": {
"patterns": [
{
"comment": "1-??-a-comp-dest-jump",
"match": "\\b1[01]{2}([01]{1})([01]{6})([01]{3})([01]{3})\\b",
"name": "comment",
"captures": {
"1": {
"comment": "control",
"name": "keyword.control"
},
"2": {
"comment": "op",
"name": "keyword.operarator"
},
"3": {
"comment": "dest",
"name": "variable.language"
},
"4": {
"comment": "jump",
"name": "keyword.control"
}
}
}
]
}
},
"scopeName": "source.hack"
}
@@ -0,0 +1,264 @@
{
"CHIP Class": {
"body": [
"CHIP $1 {",
" IN $2;",
" OUT $3;",
"",
" PARTS:",
" $4",
"}"
],
"description": "Create CHIP class.\n",
"prefix": "CHIP"
},
"Chip Add16": {
"body": [
"Add16(a=$1, b=$2, out=$3);"
],
"description": [
"* Adds two 16-bit values.\n* The most significant carry bit is ignored.\n"
],
"prefix": "Add16"
},
"Chip ALU": {
"body": [
"ALU(x=$1, y=$2, zx=$3, nx=$4, zy=$5, ny=$6, f=$7, no=$8, out=$9, zr=$10, ng=$11);"
],
"description": [
"* the ALU manipulates the x and y.\n"
],
"prefix": "ALU"
},
"Chip And": {
"body": [
"And(a=$1, b=$2, out=$3);"
],
"description": "* And gate:\n* out = 1 if (a == 1 and b == 1)\n* 0 otherwise\n",
"prefix": "And"
},
"Chip And16": {
"body": [
"And16(a=$1, b=$2, out=$3);"
],
"description": "* 16-bit bitwise And:\n* for i = 0..15: out[i] = (a[i] and b[i])\n",
"prefix": "And16"
},
"Chip ARegister": {
"body": [
"ARegister(in=$1, load=$2, out=$3);"
],
"description": "* A 16-Bit register called \"A Register\"\n",
"prefix": "ARegister"
},
"Chip Bit": {
"body": [
"Bit(in=$1, load=$2, out=$3);"
],
"description": "* 1-bit register:\n* If load[t] == 1 then out[t+1] = in[t]\n* else out does not change (out[t+1] = out[t])\n",
"prefix": "Bit"
},
"Chip DFF": {
"body": [
"DFF(in=$1, out=$2);"
],
"description": "* Data Flip-flop:\n* out(t) = in(t-1)\n* where t is the current time unit, or clock cycle.\n",
"prefix": "DFF"
},
"Chip DMux": {
"body": [
"DMux(in=$1, sel=$2, a=$3, b=$4);"
],
"description": "* Demultiplexor:\n* {a, b} = {in, 0} if sel == 0\n* {0, in} if sel == 1\n",
"prefix": "DMux"
},
"Chip DMux4Way": {
"body": [
"DMux4Way(in=$1, sel=$2, a=$3, b=$4, c=$5, d=$6);"
],
"description": "* 4-way demultiplexor:\n* {a, b, c, d} = {in, 0, 0, 0} if sel == 00\n* {0, in, 0, 0} if sel == 01\n* {0, 0, in, 0} if sel == 10\n* {0, 0, 0, in} if sel == 11\n",
"prefix": "DMux4Way"
},
"Chip DMux8Way": {
"body": [
"DMux8Way(in=$1, sel=$2, a=$3, b=$4, c=$5, d=$6, e=$7, f=$8, g=$9, h=$10);"
],
"description": "* 8-way demultiplexor:\n* {a, b, c, d, e, f, g, h} = {in, 0, 0, 0, 0, 0, 0, 0} if sel == 000\n* {0, in, 0, 0, 0, 0, 0, 0} if sel == 001\n* etc.\n* {0, 0, 0, 0, 0, 0, 0, in} if sel == 111\n",
"prefix": "DMux8Way"
},
"Chip DRegister": {
"body": [
"DRegister(in=$1, load=$2, out=$3);"
],
"description": "* A 16-Bit register called \"D Register\"\n",
"prefix": "DRegister"
},
"Chip FullAdder": {
"body": [
"FullAdder(a=$1, b=$2, c=$3, sum=$4, carry=$5);"
],
"description": "* Full adder:\n* Computes sum, the least significant bit of a + b + c, and carry, the most significant bit of a + b + c.\n",
"prefix": "FullAdder"
},
"Chip HalfAdder": {
"body": [
"HalfAdder(a=$1, b=$2, sum=$3, carry=$4);"
],
"description": "* Half adder:\n* Computes sum, the least significnat bit of a + b, and carry, the most significnat bit of a + b.\n",
"prefix": "HalfAdder"
},
"Chip Inc16": {
"body": [
"Inc16(in=$1, out=$2);"
],
"description": "* 16-bit incrementer:\n* out = in + 1 (arithmetic addition)\n",
"prefix": "Inc16"
},
"Chip Keyboard": {
"body": [
"Keyboard(out=$1);"
],
"description": "* The keyboard (memory map).\n* Outputs the code of the currently pressed key\n",
"prefix": "Keyboard"
},
"Chip Mux": {
"body": [
"Mux(a=$1, b=$2, sel=$3, out=$4);"
],
"description": "* Multiplexor:\n* If sel == 1 then out = b else out = a.\n",
"prefix": "Mux"
},
"Chip Mux16": {
"body": [
"Mux16(a=$1, b=$2, sel=$3, out=$4);"
],
"description": "* 16-bit multiplexor:\n* for i = 0..15 out[i] = a[i] if sel == 0\n* b[i] if sel == 1\n",
"prefix": "Mux16"
},
"Chip Mux4Way16": {
"body": [
"Mux4Way16(a=$1, b=$2, c=$3, d=$4, sel=$5, out=$6);"
],
"description": "* 4-way 16-bit multiplexor:\n* out = a if sel == 00\n* b if sel == 01\n* c if sel == 10\n* d if sel == 11\n",
"prefix": "Mux4Way16"
},
"Chip Mux8Way16": {
"body": [
"Mux8Way16(a=$1, b=$2, c=$3, d=$4, e=$5, f=$6, g=$7, h=$8, sel=$9, out=$10);"
],
"description": "* 8-way 16-bit multiplexor:\n* out = a if sel == 000\n* b if sel == 001\n* etc.\n* h if sel == 111\n",
"prefix": "Mux8Way16"
},
"Chip Nand": {
"body": [
"Nand(a=$1, b=$2, out=$3);"
],
"description": "* Nand gate:\n* out = a Nand b.\n",
"prefix": "Nand"
},
"Chip Not": {
"body": [
"Not(in=$1, out=$2);"
],
"description": "* Not gate:\n* out = not in\n",
"prefix": "Not"
},
"Chip Not16": {
"body": [
"Not16(in=$1, out=$2);"
],
"description": "* 16-bit Not:\n* for i=0..15: out[i] = not in[i]\n",
"prefix": "Not16"
},
"Chip Or": {
"body": [
"Or(a=$1, b=$2, out=$3);"
],
"description": "* Or gate:\n* out = 1 if (a == 1 or b == 1)\n* 0 otherwise\n",
"prefix": "Or"
},
"Chip Or16": {
"body": [
"Or16(a=$1, b=$2, out=$3);"
],
"description": "* 16-bit bitwise Or gate:\n* for i = 0..15 out[i] = a[i] or b[i].\n",
"prefix": "Or16"
},
"Chip Or8Way": {
"body": [
"Or8Way(in=$1, out=$2);"
],
"description": "* 8-way Or\n* out = (in[0] or in[1] or ... or in[7])\n",
"prefix": "Or8Way"
},
"Chip PC": {
"body": [
"PC(in=$1, load=$2, inc=$3, reset=$4, out=$5);"
],
"description": "* A 16-bit counter with load and reset control bits.\n* if (reset[t] == 1) out[t+1] = 0\n* else if (load[t] == 1) out[t+1] = in[t]\n* else if (inc[t] == 1) out[t+1] = out[t] + 1 (integer addition)\n* else out[t+1] = out[t]\n",
"prefix": "PC"
},
"Chip RAM16K": {
"body": [
"RAM16K(in=$1, load=$2, address=$3, out=$4);"
],
"description": "* Memory of 16K registers, each 16 bit-wide. Out holds the value stored at the memory location specified by address.\n* If load==1, then the in value is loaded into the memory location specified by address (the loaded value will be emitted to out from the next time step onward).\n",
"prefix": "RAM16K"
},
"Chip RAM4K": {
"body": [
"RAM4K(in=$1, load=$2, address=$3, out=$4);"
],
"description": "* Memory of 4K registers, each 16 bit-wide. Out holds the value stored at the memory location specified by address.\n* If load==1, then the in value is loaded into the memory location specified by address (the loaded value will be emitted to out from the next time step onward).\n",
"prefix": "RAM4K"
},
"Chip RAM512": {
"body": [
"RAM512(in=$1, load=$2, address=$3, out=$4);"
],
"description": "* Memory of 512 registers, each 16 bit-wide. Out holds the value stored at the memory location specified by address.\n* If load==1, then the in value is loaded into the memory location specified by address (the loaded value will be emitted to out from the next time step onward).\n",
"prefix": "RAM512"
},
"Chip RAM64": {
"body": [
"RAM64(in=$1, load=$2, address=$3, out=$4);"
],
"description": "* Memory of 64 registers, each 16 bit-wide. Out holds the value stored at the memory location specified by address.\n* If load==1, then the in value is loaded into the memory location specified by address (the loaded value will be emitted to out from the next time step onward).\n",
"prefix": "RAM64"
},
"Chip RAM8": {
"body": [
"RAM8(in=$1, load=$2, address=$3, out=$4);"
],
"description": "* Memory of 8 registers, each 16 bit-wide. Out holds the value stored at the memory location specified by address.\n* If load==1, then the in value is loaded into the memory location specified by address (the loaded value will be emitted to out from the next time step onward).\n",
"prefix": "RAM8"
},
"Chip Register": {
"body": [
"Register(in=$1, load=$2, out=$3);"
],
"description": "* 16-bit register:\n* If load[t] == 1 then out[t+1] = in[t]\n* else out does not change\n",
"prefix": "Register"
},
"Chip ROM32K": {
"body": [
"ROM32K(address=$1, out=$2);"
],
"description": "* Read-Only memory (ROM) of 16K registers, each 16-bit wide.\n* The chip is designed to facilitate data read, as follows:\n* out(t) = ROM32K[address(t)](t)\n",
"prefix": "ROM32K"
},
"Chip Screen": {
"body": [
"Screen(in=$1, load=$2, address=$3, out=$4);"
],
"description": "* The Screen (memory map).\n* Functions exactly like a 16-bit 8K RAM:\n* 1. out(t)=Screen[address(t)](t)\n* 2. If load(t-1) then Screen[address(t-1)](t)=in(t-1)\n",
"prefix": "Screen"
},
"Chip Xor": {
"body": [
"Xor(a=$1, b=$2, out=$3);"
],
"description": "* Exclusive-or gate:\n* out = !(a == b).\n",
"prefix": "Xor"
}
}
@@ -0,0 +1,75 @@
{
"fileTypes": [
"hdl"
],
"name": "HDL",
"patterns": [
{
"comment": "Block comment",
"begin": "\\/\\*",
"end": "\\*\\/",
"name": "comment.block.hdl"
},
{
"comment": "Line comment",
"begin": "\\/\\/",
"end": "\\n",
"name": "comment.line.hdl"
},
{
"comment": "keywords",
"name": "keyword.hdl",
"match": "IN|OUT|PARTS|BUILTIN"
},
{
"comment": "true, false",
"name": "constant.language.hdl",
"match": "true|false"
},
{
"comment": "bus index",
"captures": {
"1": {
"name": "constant.numeric.hdl"
}
},
"match": "\\[([\\d]+)\\]"
},
{
"comment": ".. in bus slicing",
"captures": {
"1": {
"name": "constant.numeric.hdl"
}
},
"match": "\\[(\\d+\\.{2}\\d+)\\]"
},
{
"comment": "chip name",
"name": "storage.type.hdl",
"match": "CHIP"
},
{
"comment": "inner chip",
"captures": {
"1": {
"name": "entity.name.function.hdl"
}
},
"match": "([\\w\\d\\_]+)\\s*\\("
},
{
"comment": "inner chip inputs and outputs",
"captures": {
"1": {
"name": "variable.parameter.hdl"
},
"2": {
"name": "constant.numeric.hdl"
}
},
"match": "([\\w\\d\\_]+)\\s*(\\[.+\\])*="
}
],
"scopeName": "source.hdl"
}
@@ -0,0 +1,32 @@
{
"Class": {
"prefix": [
"class",
"struct"
],
"body": [
"class ${1:Name} {",
"\t${0:$LINE_COMMENT attributes and methods}",
"}"
],
"description": "A class interface."
},
"Function/method": {
"prefix": [
"function",
"method",
"procedure",
"void",
"int",
"String",
"Array",
"Char"
],
"body": [
"${1|function,method|} ${2:void} ${3:name} (${4:$BLOCK_COMMENT_START arguments $BLOCK_COMMENT_END}) {",
"\t${0:$LINE_COMMENT code}",
"}"
],
"description": "A function/method definition."
}
}
@@ -0,0 +1,122 @@
{
"fileTypes": [
"jack"
],
"name": "Jack Language",
"patterns": [
{
"include": "#keyword"
},
{
"include": "#constant"
},
{
"include": "#declaration"
},
{
"include": "#comment"
}
],
"repository": {
"keyword": {
"patterns": [
{
"comment": "Keyword related to flow control",
"match": "\\b(if|else|while|do|return)\\b",
"name": "keyword.control"
},
{
"comment": "Miscellaneous keyword",
"match": "\\blet\\b",
"name": "keyword.other"
}
]
},
"constant": {
"patterns": [
{
"comment": "Numeric constant",
"name": "constant.numeric",
"match": "\\b[0-9]+\\b"
},
{
"comment": "String literal",
"begin": "\\\"",
"end": "\\\"",
"name": "string.quoted.double",
"patterns": [
{
"comment": "Escape characters",
"match": "\\\\.",
"name": "constant.character.escape"
}
]
},
{
"comment": "Language constant",
"name": "constant.language",
"match": "\\b(true|false|null|this)\\b"
}
]
},
"declaration": {
"patterns": [
{
"comment": "Class declaration",
"match": "\\bclass\\b",
"name": "storage.type"
},
{
"comment": "Variable declaration",
"name": "storage.type",
"match": "\\b(field|static|var)\\s+(\\w+)\\b",
"captures": {
"1": {
"name": "storage.modifier"
},
"2": {
"name": "storage.type"
}
}
},
{
"comment": "Function declaration",
"begin": "\\b(constructor|function|method)\\s+([A-Za-z_][A-Za-z_0-9]*)\\s+([A-Za-z_][A-Za-z_0-9]*)\\s*\\(",
"end": "\\)",
"match": "meta.function",
"beginCaptures": {
"1": {
"name": "storage.modifier"
},
"2": {
"name": "storage.type"
}
},
"patterns": [
{
"match": "\\s*([A-Za-z_][A-Za-z_0-9]*)\\s+(?=[A-Za-z_][A-Za-z_0-9]*)\\b",
"name": "storage.type"
}
]
}
]
},
"comment": {
"patterns": [
{
"comment": "Inline comment",
"begin": "\\/\\/",
"end": "\\n",
"name": "comment.line.double-slash"
},
{
"comment": "Multiline comment",
"begin": "\\/\\*",
"end": "\\*\\/",
"name": "comment.block"
}
]
}
},
"scopeName": "source.jack"
}
@@ -0,0 +1,28 @@
{
"comments": {
"lineComment": "//",
"blockComment": ["/*", "*/"]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
@@ -0,0 +1,16 @@
{
"Repeat Loop": {
"prefix": [
"repeat",
"loop",
"while",
"for"
],
"body": [
"repeat ${1:iterations} {",
"\t${0:$LINE_COMMENT code",
"}"
],
"description": "A repeat loop."
}
}
@@ -0,0 +1,59 @@
{
"fileTypes": [
"tst"
],
"name": "TST",
"patterns": [
{
"include": "#instruction"
},
{
"include": "#comment"
}
],
"repository": {
"instruction": {
"patterns": [
{
"comment": "Everything which is not a comment is a function",
"begin": "\\b",
"end": "(,|;)",
"patterns": [
{
"comment": "Every actual instruction starts with a function",
"name": "support.function",
"match": "(output-file|compare-to|output-list|set|eval|output|load)\\b"
},
{
"comment": "A single bit",
"name": "constant.numeric",
"match": "\\s(1|0)|%B(\\d|\\.)+"
},
{
"comment": "Filename with a known extension",
"name": "string.interpolated",
"match": "\\w+\\.(hdl|out|cmp)"
}
]
}
]
},
"comment": {
"patterns": [
{
"comment": "Inline comment",
"begin": "\\/\\/",
"end": "\\n",
"name": "comment.line.double-slash"
},
{
"comment": "Multiline comment",
"begin": "\\/\\*",
"end": "\\*\\/",
"name": "comment.block"
}
]
}
},
"scopeName": "source.tst"
}
@@ -0,0 +1,63 @@
{
"If-then Statement": {
"prefix": [
"if",
"then",
"condition"
],
"body": [
"\t${1:$LINE_COMMENT not-condition}",
"\tif-goto\t${2:if_end}",
"\t${0:$LINE_COMMENT code}",
"label\t\t${2:IF_END}"
],
"description": "An if-then statement."
},
"If-then-else Statement": {
"prefix": [
"if",
"then",
"else",
"elif",
"condition"
],
"body": [
"\t${1:$LINE_COMMENT not-condition}",
"\tif-goto\t${2:if_else}",
"\t${3:$LINE_COMMENT code}",
"\tgoto\t${4:if_end}",
"label\t\t${2:if_else}",
"\t${0:$LINE_COMMENT code}",
"label\t\t${4:if_end}"
],
"description": "An if-then-else statement."
},
"While Loop": {
"prefix": [
"repeat",
"loop",
"for",
"while"
],
"body": [
"label\t\t${1:loop}",
"\t${2:$LINE_COMMENT not condition}",
"\tif-goto\t${3:loop_end}",
"\t${4:$LINE_COMMENT code}",
"\tgoto\t${1:loop}",
"label\t\t${3:loop_end}"
],
"description": "A while loop."
},
"Function": {
"prefix": [
"function",
"procedure"
],
"body": [
"function ${TM_FILENAME/(.*)\\..+$/$1/}.${1:name} ${2:0}",
"\t${0:$LINE_COMMENT code}"
],
"description": "A function definition."
}
}
@@ -0,0 +1,134 @@
{
"fileTypes": [
"vm"
],
"name": "Virtual Machine Language",
"patterns": [
{
"include": "#arithmetic-command"
},
{
"include": "#memory-access-command"
},
{
"include": "#program-flow-command"
},
{
"include": "#function-calling-command"
},
{
"include": "#comment"
}
],
"repository": {
"arithmetic-command": {
"patterns": [
{
"comment": "Performs arithmetic and logical operations on the stack.",
"match": "\\b(add|sub|neg|eq|gt|lt|and|or|not|shiftleft|shiftright)\\b",
"name": "keyword.operator"
}
]
},
"memory-access-command": {
"patterns": [
{
"comment": "Transfers data between the stack and virtual memory segments.",
"match": "\\b(push|pop)\\s+([^ \\/]*)\\s+(\\d+)\\b",
"name": "keyword.operator",
"captures": {
"2": {
"patterns": [
{
"comment": "Segment",
"match": "[a-zA-Z\\_\\.\\$\\:]+[a-zA-Z\\_\\.\\$\\:\\d]*",
"name": "storage.type"
}
]
},
"3": {
"patterns": [
{
"comment": "Location",
"match": "\\d+",
"name": "constant.numeric"
}
]
}
}
}
]
},
"program-flow-command": {
"patterns": [
{
"comment": "Facilitates conditional and unconditional branching operations.",
"match": "\\b(label|goto|if-goto)\\s+([^ \\/]*)\\b",
"name": "keyword.control",
"captures": {
"2": {
"patterns": [
{
"comment": "Label",
"match": "[a-zA-Z\\_\\.\\$\\:]+[a-zA-Z\\_\\.\\$\\:\\d]*",
"name": "entity.name.section"
}
]
}
}
}
]
},
"function-calling-command": {
"patterns": [
{
"comment": "Defines/calls functions.",
"match": "\\b(function|call)\\s+([^ \\/]*)\\s+(\\w+)\\b",
"name": "keyword.control",
"captures": {
"2": {
"patterns": [
{
"comment": "Function name",
"match": "[a-zA-Z\\_\\.\\$\\:]+[a-zA-Z\\_\\.\\$\\:\\d]*",
"name": "entity.name.function"
}
]
},
"3": {
"patterns": [
{
"comment": "Number of local variables/arguments passed",
"match": "\\d+",
"name": "constant.numeric"
}
]
}
}
},
{
"comment": "Returns from functions.",
"match": "return",
"name": "keyword.control"
}
]
},
"comment": {
"patterns": [
{
"comment": "Inline comment",
"begin": "\\/\\/",
"end": "\\n",
"name": "comment.line.double-slash"
},
{
"comment": "Multiline comment",
"begin": "\\/\\*",
"end": "\\*\\/",
"name": "comment.block"
}
]
}
},
"scopeName": "source.vm"
}
+261
View File
@@ -0,0 +1,261 @@
{
"name": "@nand2tetris/vscode",
"version": "0.0.0",
"private": true,
"description": "NAND2Tetris IDE features for VSCode",
"author": "David Souther <davidsouther@gmail.com>",
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/davidsouther/nand2tetris.git"
},
"homepage": "https://davidsouther.github.io/nand2tetris",
"scripts": {
"prebuild": "shx mkdir -p out/views/hdl && cd .. && npm run build -w extension/views/hdl",
"build": "npx esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --sourcemap",
"watch": "npm run build -- --watch",
"vscode:prepublish": "npm run build",
"package": "vsce package"
},
"engines": {
"vscode": "^1.61.0"
},
"main": "./out/main.js",
"contributes": {
"commands": [
{
"command": "nand2tetris.run",
"title": "Nand2Tetris: run code",
"icon": "./images/button.png"
},
{
"command": "nand2tetris.stop",
"title": "Nand2Tetris: stop running"
},
{
"command": "nand2tetris.hardware",
"title": "Nand2Tetris: open hardware Simulator"
}
],
"configuration": {
"type": "object",
"title": "Nand2Tetris IDE",
"properties": {
"nand2tetris.showRunIconInEditorTitleMenu": {
"type": "boolean",
"default": true,
"description": "Whether to show 'Run Code' icon in editor title menu.",
"scope": "resource"
},
"nand2tetris.showTranslateIconInEditorTitleMenu": {
"type": "boolean",
"default": true,
"description": "Whether to show 'Translate Code' icon in editor title menu.",
"scope": "resource"
}
}
},
"languages": [
{
"id": "hdl",
"aliases": [
"HDL"
],
"extensions": [
".hdl"
],
"configuration": "./languages/language-configuration.json"
},
{
"id": "tst",
"aliases": [
"TST",
"TEST",
"Test",
"test"
],
"extensions": [
".tst"
],
"configuration": "./languages/language-configuration.json"
},
{
"id": "cmp",
"aliases": [
"CMP",
"cmp"
],
"extensions": [
".cmp"
]
},
{
"id": "out",
"aliases": [
"OUT",
"out"
],
"extensions": [
".out"
]
},
{
"id": "asm",
"aliases": [
"ASM",
"asm"
],
"extensions": [
".asm"
],
"configuration": "./languages/language-configuration.json"
},
{
"id": "hack",
"aliases": [
"HACK",
"hack"
],
"extensions": [
".hack"
]
},
{
"id": "vm",
"aliases": [
"VM",
"vm"
],
"extensions": [
".vm"
],
"configuration": "./languages/language-configuration.json"
},
{
"id": "jack",
"aliases": [
"JACK",
"jack"
],
"extensions": [
".jack"
],
"configuration": "./languages/language-configuration.json"
}
],
"grammars": [
{
"language": "hdl",
"scopeName": "source.hdl",
"path": "./languages/hdl.tmLanguage.json"
},
{
"language": "tst",
"scopeName": "source.tst",
"path": "./languages/tst.tmLanguage.json"
},
{
"language": "cmp",
"scopeName": "source.cmp",
"path": "./languages/cmp-out.tmLanguage.json"
},
{
"language": "out",
"scopeName": "source.out",
"path": "./languages/cmp-out.tmLanguage.json"
},
{
"language": "asm",
"scopeName": "source.asm",
"path": "./languages/asm.tmLanguage.json"
},
{
"language": "hack",
"scopeName": "source.hack",
"path": "./languages/hack.tmLanguage.json"
},
{
"language": "vm",
"scopeName": "source.vm",
"path": "./languages/vm.tmLanguage.json"
},
{
"language": "jack",
"scopeName": "source.jack",
"path": "./languages/jack.tmLanguage.json"
}
],
"snippets": [
{
"language": "hdl",
"path": "./languages/hdl.snippets.json.code-snippets"
},
{
"language": "tst",
"path": "./languages/tst.snippets.json.code-snippets"
},
{
"language": "asm",
"path": "./languages/asm.snippets.json.code-snippets"
},
{
"language": "vm",
"path": "./languages/vm.snippets.json.code-snippets"
},
{
"language": "jack",
"path": "./languages/jack.snippets.json.code-snippets"
}
],
"iconThemes": [
{
"id": "nand-ide",
"label": "Nand2Tetris IDE Icon Theme",
"path": "./fileicons/icon-theme.json"
}
],
"viewsContainers": {
"activitybar": [
{
"id": "nand2tetris",
"icon": "./fileicons/logo.svg",
"title": "NAND2Tetris"
}
]
},
"views": {
"nand2tetris": [
{
"type": "webview",
"id": "nand2tetris.hdlView",
"name": "HDL Chip"
}
]
}
},
"activationEvents": [
"onCommand:nand2tetris.hardware",
"onLanguage:cmp",
"onLanguage:hdl",
"onLanguage:out",
"onLanguage:tst"
],
"devDependencies": {
"@davidsouther/jiffies": "^2.0.6",
"@nand2tetris/simulator": "file:../simulator",
"@types/error-cause": "^1.0.1",
"@types/node": "^16.11.41",
"@types/vscode": "^1.74.0",
"@vscode/vsce": "^2.27.0",
"@vscode/webview-ui-toolkit": "^1.2.1",
"esbuild": "^0.15.18",
"ohm-js": "^17.1.0"
},
"dependencies": {
"gh-pages": "6.1.1",
"react-scripts": "5.0.1"
},
"optionalDependencies": {
"esbuild-windows-64": "^0.15.18"
}
}
+14
View File
@@ -0,0 +1,14 @@
import * as vscode from "vscode";
type Callback = Parameters<typeof vscode.commands.registerCommand>[1];
export function makeCommands(): [string, Callback][] {
const hardwareCommand: [string, Callback] = [
"nand2tetris.hardware",
async (fileUri: string) => {
console.log("Hardware Command");
},
];
return [hardwareCommand];
}
@@ -0,0 +1,6 @@
export async function hardware(fileUri: string) {
// The await eval() hack is for https://github.com/microsoft/TypeScript/issues/43329
const tst = await import("@nand2tetris/simulator/test/chiptst.js");
console.log(`Hardware for ${fileUri}`);
console.log(new tst.ChipTest());
}
+41
View File
@@ -0,0 +1,41 @@
import * as vscode from "vscode";
import * as lang from "./languages/index.js";
async function getDiagnostics(document: vscode.TextDocument) {
switch (document.languageId) {
case "cmp":
case "out":
return lang.cmp.getDiagnostics(document);
case "hdl":
return lang.hdl.getDiagnostics(document);
case "tst":
return lang.tst.getDiagnostics(document);
default:
return [];
}
}
let diagnosticCollection: vscode.DiagnosticCollection;
function getDiagnosticCollection() {
if (diagnosticCollection === undefined) {
diagnosticCollection = vscode.languages.createDiagnosticCollection();
}
return diagnosticCollection;
}
async function runDiagnostics(document: vscode.TextDocument) {
getDiagnosticCollection().delete(document.uri);
const allDiagnostics = await getDiagnostics(document);
for (const [file, diagnostics] of allDiagnostics) {
getDiagnosticCollection().set(file, diagnostics);
}
}
export function makeDiagnostics() {
vscode.workspace.textDocuments.forEach(runDiagnostics);
vscode.workspace.onDidOpenTextDocument(runDiagnostics);
vscode.workspace.onDidChangeTextDocument(async (event) => {
runDiagnostics(event.document);
});
return getDiagnosticCollection();
}
+18
View File
@@ -0,0 +1,18 @@
import * as vscode from "vscode";
import { makeCommands } from "./commands.js";
import { makeDiagnostics } from "./diagnostics.js";
import { activateHdlView } from "./views/hdl.js";
export function activate(context: vscode.ExtensionContext) {
makeCommands().forEach(([name, callback]) =>
context.subscriptions.push(vscode.commands.registerCommand(name, callback)),
);
context.subscriptions.push(makeDiagnostics());
activateHdlView(context);
}
export function deactivate() {
console.log("Deactivating extension");
}
@@ -0,0 +1,40 @@
import type { Grammar } from "ohm-js";
import {
Diagnostic,
DiagnosticSeverity,
Range,
TextDocument,
Uri,
} from "vscode";
export async function getDiagnostics(
document: TextDocument,
parser: Grammar,
): Promise<[Uri, Diagnostic[]][]> {
const parsed = parser.match(document.getText());
if (!parsed.failed()) return [];
const { line, column, message } =
/Line (?<line>\d+), col (?<column>\d+): (?<message>.*)/.exec(
parsed.shortMessage ?? "",
)?.groups ?? { line: 1, column: 1, message: "could not parse error" };
const startLineNumber = Number(line);
const endLineNumber = startLineNumber;
const startColumn = Number(column);
const restOfLine = document
.lineAt(startLineNumber)
.text.substring(startColumn - 1);
let endColumn = startColumn + (restOfLine.match(/([^\s]+)/)?.[0].length ?? 1);
if (endColumn <= startColumn) {
endColumn = startColumn + 1;
}
const range = new Range(
startLineNumber - 1,
startColumn - 1,
endLineNumber - 1,
endColumn - 1,
);
const diagnostic = new Diagnostic(range, message, DiagnosticSeverity.Error);
return [[document.uri, [diagnostic]]];
}
@@ -0,0 +1,25 @@
import type { CMP } from "@nand2tetris/simulator/languages/cmp";
import { Diagnostic, TextDocument, Uri } from "vscode";
import * as base from "./base.js";
// import { load } from "../loader.js";
let cmp: typeof CMP | undefined = undefined;
async function getCmp(): Promise<typeof CMP> {
if (cmp) return Promise.resolve(cmp);
cmp = (await import("@nand2tetris/simulator/languages/cmp.js"))
.CMP as typeof CMP;
return cmp;
}
export async function getDiagnostics(
document: TextDocument,
): Promise<[Uri, Diagnostic[]][]> {
try {
const { parser } = await getCmp();
return base.getDiagnostics(document, parser);
} catch (e) {
console.error("Failed to load tst parser", e);
return [];
}
}
@@ -0,0 +1,19 @@
import type { HDL } from "@nand2tetris/simulator/languages/hdl";
import { Diagnostic, TextDocument, Uri } from "vscode";
import * as base from "./base.js";
let hdl: typeof HDL | undefined = undefined;
async function getHdl(): Promise<typeof HDL> {
if (hdl) return Promise.resolve(hdl);
hdl = (await import("@nand2tetris/simulator/languages/hdl.js"))
.HDL as typeof HDL;
return hdl;
}
export async function getDiagnostics(
document: TextDocument,
): Promise<[Uri, Diagnostic[]][]> {
const { parser } = await getHdl();
return base.getDiagnostics(document, parser);
}
@@ -0,0 +1,5 @@
export const LANGUAGE_IDS = ["cmp", "hdl", "out", "tst"];
export * as base from "./base.js";
export * as cmp from "./cmp.js";
export * as hdl from "./hdl.js";
export * as tst from "./tst.js";
@@ -0,0 +1,23 @@
import type { TST } from "@nand2tetris/simulator/languages/tst";
import { Diagnostic, TextDocument, Uri } from "vscode";
import * as base from "./base.js";
let tst: typeof TST | undefined = undefined;
async function getTst(): Promise<typeof TST> {
if (tst) return Promise.resolve(tst);
tst = (await import("@nand2tetris/simulator/languages/tst.js"))
.TST as typeof TST;
return tst;
}
export async function getDiagnostics(
document: TextDocument,
): Promise<[Uri, Diagnostic[]][]> {
try {
const { parser } = await getTst();
return base.getDiagnostics(document, parser);
} catch (e) {
console.error("Failed to load tst parser", e);
return [];
}
}
+104
View File
@@ -0,0 +1,104 @@
import { parse } from "path";
import * as vscode from "vscode";
import { hdl as HDL } from "../languages/index.js";
export function activateHdlView(context: vscode.ExtensionContext) {
const provider = new HdlViewProvider(context.extensionUri);
vscode.window.registerWebviewViewProvider(HdlViewProvider.viewType, provider);
}
class HdlViewProvider implements vscode.WebviewViewProvider {
public static readonly viewType = "nand2tetris.hdlView";
private _hdl = "";
private _view?: vscode.WebviewView;
constructor(private readonly extensionUri: vscode.Uri) {}
public resolveWebviewView(
webviewView: vscode.WebviewView,
context: vscode.WebviewViewResolveContext,
_token: vscode.CancellationToken,
) {
this._view = webviewView;
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,
localResourceRoots: [this.extensionUri],
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(
(message: { nand2tetris: boolean; ready: boolean }) => {
if (message.nand2tetris && message.ready) {
this.updateHdl(vscode.window.activeTextEditor?.document);
}
},
);
webviewView.onDidChangeVisibility(() => {
if (this._view?.visible !== true) {
this.clearHdl();
} else {
this.updateHdl(vscode.window.activeTextEditor?.document);
}
});
vscode.window.onDidChangeActiveTextEditor((e) => {
this.updateHdl(e?.document);
});
vscode.workspace.onDidSaveTextDocument(async (document) => {
this.updateHdl(document);
});
}
clearHdl() {
this._hdl = "";
}
async updateHdl(document?: vscode.TextDocument) {
if (document?.languageId !== "hdl") return;
const hdl = document.getText();
if (this._hdl === hdl) {
return;
}
const diagnostics = await HDL.getDiagnostics(document);
if ((diagnostics[0] ?? ["", []])[1].length === 0) {
const chipName = parse(document.fileName).name;
this._view?.webview.postMessage({ nand2tetris: true, hdl, chipName });
this._hdl = hdl;
}
}
private _getHtmlForWebview(webview: vscode.Webview) {
const stylesUri = this.getUri(webview, ["hdl", "styles.css"]);
const scriptUri = this.getUri(webview, ["hdl", "main.js"]);
return /*html*/ `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="stylesheet" type="text/css" href="${stylesUri}">
<title>HDL - NAND2Tetris</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="${scriptUri}"></script>
</body>
</html>
`;
}
private getUri(webview: vscode.Webview, pathList: string[]) {
return webview.asWebviewUri(
vscode.Uri.joinPath(this.extensionUri, "out", "views", ...pathList),
);
}
}
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "build",
"rootDir": "src",
"module": "CommonJS",
"tsBuildInfoFile": "build/.tsbuildinfo"
},
"include": ["src"]
}
@@ -0,0 +1,31 @@
[role="group"] {
display: flex;
align-items: baseline;
}
[role="group"] > label:has(input[type="radio"]) {
color: var(--vscode-button-foreground);
background-color: var(--vscode-button-background);
align-self: stretch;
padding: 2px 1px;
}
[role="group"] > label:has(input[type="radio"]):first-of-type {
padding-left: 2px;
border-top-left-radius: 2px;
border-bottom-left-radius: 2px;
}
[role="group"] > label:has(input[type="radio"]):larst-of-type {
padding-right: 2px;
border-top-right-radius: 2px;
border-bottom-right-radius: 2px;
}
[role="group"] > label[aria-current="true"]:has(input[type="radio"]) {
background-color: var(--vscode-button-hoverBackground);
}
[role="group"] > label > input[type="radio"] {
display: none;
}
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
@@ -0,0 +1,46 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
@@ -0,0 +1,44 @@
{
"name": "hdl",
"version": "0.0.0",
"private": true,
"dependencies": {
"@nand2tetris/components": "0.0.0",
"@nand2tetris/simulator": "0.0.0",
"gh-pages": "6.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rewire": "^6.0.0",
"vsce": "^2.15.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.11.66",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@types/vscode-webview": "^1.57.1",
"react-scripts": "^5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "node ./scripts/build-react-no-split.js",
"postbuild": "shx cp ./build/styles.css ./build/static/js/main.js ./build/static/js/main.js.map ./build/static/js/main.js.LICENSE.txt ../../out/views/hdl",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<link rel="stylesheet" href="%PUBLIC_URL%/vars.css"></link>
<link rel="stylesheet" href="%PUBLIC_URL%/styles.css"></link>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
@@ -0,0 +1,63 @@
:root {
--font-family-monospace: var(--vscode-editor-font-family);
}
button {
font-family: var(--vscode-editor-font-family);
font-weight: var(--vscode-editor-font-weight);
font-size: var(--vscode-editor-font-size);
color: var(--vscode-button-foreground);
background-color: var(--vscode-button-background);
border: 0;
padding: 0;
width: 1rem;
}
button:hover {
background-color: var(--vscode-button-hoverBackground);
}
button[disabled] {
opacity: var(--disabled-opacity);
background-color: var(--vscode-button-hoverBackground);
}
fieldset[role="group"] {
border: 0;
padding: 0;
display: flex;
align-items: baseline;
}
fieldset[role="group"] > label[role="button"] {
/* fieldset[role="group"] > label:has(input[type="radio"]) { */
color: var(--vscode-button-foreground);
background-color: var(--vscode-button-background);
align-self: stretch;
padding: 2px 1px;
}
fieldset[role="group"] button:first-of-type,
fieldset[role="group"] > label[role="button"]:first-of-type {
/* fieldset[role="group"] > label:has(input[type="radio"]):first-of-type { */
padding-left: 2px;
border-top-left-radius: 2px;
border-bottom-left-radius: 2px;
}
fieldset[role="group"] button:last-of-type,
fieldset[role="group"] > label[role="button"]:last-of-type {
/* fieldset[role="group"] > label:has(input[type="radio"]):last-of-type { */
padding-right: 2px;
border-top-right-radius: 2px;
border-bottom-right-radius: 2px;
}
fieldset[role="group"] > label[role="button"][aria-current="true"] {
/* fieldset[role="group"] > label[aria-current="true"]:has(input[type="radio"]) { */
background-color: var(--vscode-button-hoverBackground);
}
fieldset[role="group"] > label > input[type="radio"] {
display: none;
}
@@ -0,0 +1,591 @@
:root {
--vscode-font-family: -apple-system, BlinkMacSystemFont, sans-serif;
--vscode-font-weight: normal;
--vscode-font-size: 13px;
--vscode-editor-font-family: "JetBrains Mono", "Consolas Light", "Courier New",
monospace;
--vscode-editor-font-weight: normal;
--vscode-editor-font-size: 16px;
--vscode-foreground: #cccccc;
--vscode-button-background: #0e639c;
--vscode-button-foreground: #ffffff;
--vscode-button-hoverBackground: #1177bb;
--vscode-button-separator: rgba(255, 255, 255, 0.4);
--vscode-charts-blue: #3794ff;
--vscode-charts-foreground: #cccccc;
--vscode-charts-green: #89d185;
--vscode-charts-lines: rgba(204, 204, 204, 0.5);
--vscode-charts-orange: #d18616;
--vscode-charts-purple: #b180d7;
--vscode-charts-red: #f14c4c;
--vscode-charts-yellow: #cca700;
--vscode-checkbox-background: #3c3c3c;
--vscode-checkbox-border: #3c3c3c;
--vscode-checkbox-foreground: #f0f0f0;
--vscode-commandCenter-activeBackground: rgba(90, 93, 94, 0.31);
--vscode-commandCenter-activeForeground: #cccccc;
--vscode-commandCenter-border: rgba(128, 128, 128, 0.35);
--vscode-commandCenter-foreground: #cccccc;
--vscode-debugConsole-errorForeground: #f48771;
--vscode-debugConsole-infoForeground: #3794ff;
--vscode-debugConsole-sourceForeground: #cccccc;
--vscode-debugConsole-warningForeground: #cca700;
--vscode-debugConsoleInputIcon-foreground: #cccccc;
--vscode-debugExceptionWidget-background: #420b0d;
--vscode-debugExceptionWidget-border: #a31515;
--vscode-debugIcon-breakpointCurrentStackframeForeground: #ffcc00;
--vscode-debugIcon-breakpointDisabledForeground: #848484;
--vscode-debugIcon-breakpointForeground: #e51400;
--vscode-debugIcon-breakpointStackframeForeground: #89d185;
--vscode-debugIcon-breakpointUnverifiedForeground: #848484;
--vscode-debugIcon-continueForeground: #75beff;
--vscode-debugIcon-disconnectForeground: #f48771;
--vscode-debugIcon-pauseForeground: #75beff;
--vscode-debugIcon-restartForeground: #89d185;
--vscode-debugIcon-startForeground: #89d185;
--vscode-debugIcon-stepBackForeground: #75beff;
--vscode-debugIcon-stepIntoForeground: #75beff;
--vscode-debugIcon-stepOutForeground: #75beff;
--vscode-debugIcon-stepOverForeground: #75beff;
--vscode-debugIcon-stopForeground: #f48771;
--vscode-debugTokenExpression-boolean: #4e94ce;
--vscode-debugTokenExpression-error: #f48771;
--vscode-debugTokenExpression-name: #c586c0;
--vscode-debugTokenExpression-number: #b5cea8;
--vscode-debugTokenExpression-string: #ce9178;
--vscode-debugTokenExpression-value: rgba(204, 204, 204, 0.6);
--vscode-debugToolBar-background: #333333;
--vscode-debugView-exceptionLabelBackground: #6c2022;
--vscode-debugView-exceptionLabelForeground: #cccccc;
--vscode-debugView-stateLabelBackground: rgba(136, 136, 136, 0.27);
--vscode-debugView-stateLabelForeground: #cccccc;
--vscode-debugView-valueChangedHighlight: #569cd6;
--vscode-descriptionForeground: rgba(204, 204, 204, 0.7);
--vscode-diffEditor-diagonalFill: rgba(204, 204, 204, 0.2);
--vscode-diffEditor-insertedLineBackground: rgba(155, 185, 85, 0.2);
--vscode-diffEditor-insertedTextBackground: rgba(156, 204, 44, 0.2);
--vscode-diffEditor-removedLineBackground: rgba(255, 0, 0, 0.2);
--vscode-diffEditor-removedTextBackground: rgba(255, 0, 0, 0.2);
--vscode-disabledForeground: rgba(204, 204, 204, 0.5);
--vscode-dropdown-background: #3c3c3c;
--vscode-dropdown-border: #3c3c3c;
--vscode-dropdown-foreground: #f0f0f0;
--vscode-editor-background: #1e1e1e;
--vscode-editor-findMatchBackground: #515c6a;
--vscode-editor-findMatchHighlightBackground: rgba(234, 92, 0, 0.33);
--vscode-editor-findRangeHighlightBackground: rgba(58, 61, 65, 0.4);
--vscode-editor-focusedStackFrameHighlightBackground: rgba(
122,
189,
122,
0.3
);
--vscode-editor-foldBackground: rgba(38, 79, 120, 0.3);
--vscode-editor-foreground: #d4d4d4;
--vscode-editor-hoverHighlightBackground: rgba(38, 79, 120, 0.25);
--vscode-editor-inactiveSelectionBackground: #3a3d41;
--vscode-editor-inlineValuesBackground: rgba(255, 200, 0, 0.2);
--vscode-editor-inlineValuesForeground: rgba(255, 255, 255, 0.5);
--vscode-editor-lineHighlightBorder: #282828;
--vscode-editor-linkedEditingBackground: rgba(255, 0, 0, 0.3);
--vscode-editor-rangeHighlightBackground: rgba(255, 255, 255, 0.04);
--vscode-editor-selectionBackground: #264f78;
--vscode-editor-selectionHighlightBackground: rgba(173, 214, 255, 0.15);
--vscode-editor-snippetFinalTabstopHighlightBorder: #525252;
--vscode-editor-snippetTabstopHighlightBackground: rgba(124, 124, 124, 0.3);
--vscode-editor-stackFrameHighlightBackground: rgba(255, 255, 0, 0.2);
--vscode-editor-symbolHighlightBackground: rgba(234, 92, 0, 0.33);
--vscode-editor-wordHighlightBackground: rgba(87, 87, 87, 0.72);
--vscode-editor-wordHighlightStrongBackground: rgba(0, 73, 114, 0.72);
--vscode-editorActiveLineNumber-foreground: #c6c6c6;
--vscode-editorBracketHighlight-foreground1: #ffd700;
--vscode-editorBracketHighlight-foreground2: #da70d6;
--vscode-editorBracketHighlight-foreground3: #179fff;
--vscode-editorBracketHighlight-foreground4: rgba(0, 0, 0, 0);
--vscode-editorBracketHighlight-foreground5: rgba(0, 0, 0, 0);
--vscode-editorBracketHighlight-foreground6: rgba(0, 0, 0, 0);
--vscode-editorBracketHighlight-unexpectedBracket\.foreground: rgba(
255,
18,
18,
0.8
);
--vscode-editorBracketMatch-background: rgba(0, 100, 0, 0.1);
--vscode-editorBracketMatch-border: #888888;
--vscode-editorBracketPairGuide-activeBackground1: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-activeBackground2: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-activeBackground3: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-activeBackground4: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-activeBackground5: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-activeBackground6: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-background1: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-background2: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-background3: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-background4: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-background5: rgba(0, 0, 0, 0);
--vscode-editorBracketPairGuide-background6: rgba(0, 0, 0, 0);
--vscode-editorCodeLens-foreground: #999999;
--vscode-editorCommentsWidget-rangeActiveBackground: rgba(55, 148, 255, 0.1);
--vscode-editorCommentsWidget-rangeActiveBorder: rgba(55, 148, 255, 0.4);
--vscode-editorCommentsWidget-rangeBackground: rgba(55, 148, 255, 0.1);
--vscode-editorCommentsWidget-rangeBorder: rgba(55, 148, 255, 0.4);
--vscode-editorCommentsWidget-resolvedBorder: rgba(204, 204, 204, 0.5);
--vscode-editorCommentsWidget-unresolvedBorder: #3794ff;
--vscode-editorCursor-foreground: #aeafad;
--vscode-editorError-foreground: #f14c4c;
--vscode-editorGhostText-foreground: rgba(255, 255, 255, 0.34);
--vscode-editorGroup-border: #444444;
--vscode-editorGroup-dropBackground: rgba(83, 89, 93, 0.5);
--vscode-editorGroup-dropIntoPromptBackground: #252526;
--vscode-editorGroup-dropIntoPromptForeground: #cccccc;
--vscode-editorGroupHeader-noTabsBackground: #1e1e1e;
--vscode-editorGroupHeader-tabsBackground: #252526;
--vscode-editorGutter-addedBackground: #487e02;
--vscode-editorGutter-background: #1e1e1e;
--vscode-editorGutter-commentRangeForeground: #37373d;
--vscode-editorGutter-deletedBackground: #f14c4c;
--vscode-editorGutter-foldingControlForeground: #c5c5c5;
--vscode-editorGutter-modifiedBackground: #1b81a8;
--vscode-editorHint-foreground: rgba(238, 238, 238, 0.7);
--vscode-editorHoverWidget-background: #252526;
--vscode-editorHoverWidget-border: #454545;
--vscode-editorHoverWidget-foreground: #cccccc;
--vscode-editorHoverWidget-highlightForeground: #2aaaff;
--vscode-editorHoverWidget-statusBarBackground: #2c2c2d;
--vscode-editorIndentGuide-activeBackground: #707070;
--vscode-editorIndentGuide-background: #404040;
--vscode-editorInfo-foreground: #3794ff;
--vscode-editorInlayHint-background: rgba(77, 77, 77, 0.8);
--vscode-editorInlayHint-foreground: #ffffff;
--vscode-editorInlayHint-parameterBackground: rgba(77, 77, 77, 0.8);
--vscode-editorInlayHint-parameterForeground: #ffffff;
--vscode-editorInlayHint-typeBackground: rgba(77, 77, 77, 0.8);
--vscode-editorInlayHint-typeForeground: #ffffff;
--vscode-editorLightBulb-foreground: #ffcc00;
--vscode-editorLightBulbAutoFix-foreground: #75beff;
--vscode-editorLineNumber-activeForeground: #c6c6c6;
--vscode-editorLineNumber-foreground: #858585;
--vscode-editorLink-activeForeground: #4e94ce;
--vscode-editorMarkerNavigation-background: #1e1e1e;
--vscode-editorMarkerNavigationError-background: #f14c4c;
--vscode-editorMarkerNavigationInfo-background: #3794ff;
--vscode-editorMarkerNavigationWarning-background: #cca700;
--vscode-editorMarkerNavigationWarning-headerBackground: rgba(
204,
167,
0,
0.1
);
--vscode-editorOverviewRuler-addedForeground: rgba(72, 126, 2, 0.6);
--vscode-editorOverviewRuler-border: rgba(127, 127, 127, 0.3);
--vscode-editorOverviewRuler-bracketMatchForeground: #a0a0a0;
--vscode-editorOverviewRuler-commonContentForeground: rgba(96, 96, 96, 0.4);
--vscode-editorOverviewRuler-currentContentForeground: rgba(
64,
200,
174,
0.5
);
--vscode-editorOverviewRuler-deletedForeground: rgba(241, 76, 76, 0.6);
--vscode-editorOverviewRuler-errorForeground: rgba(255, 18, 18, 0.7);
--vscode-editorOverviewRuler-findMatchForeground: rgba(209, 134, 22, 0.49);
--vscode-editorOverviewRuler-incomingContentForeground: rgba(
64,
166,
255,
0.5
);
--vscode-editorOverviewRuler-infoForeground: #3794ff;
--vscode-editorOverviewRuler-modifiedForeground: rgba(27, 129, 168, 0.6);
--vscode-editorOverviewRuler-rangeHighlightForeground: rgba(0, 122, 204, 0.6);
--vscode-editorOverviewRuler-selectionHighlightForeground: rgba(
160,
160,
160,
0.8
);
--vscode-editorOverviewRuler-warningForeground: #cca700;
--vscode-editorOverviewRuler-wordHighlightForeground: rgba(
160,
160,
160,
0.8
);
--vscode-editorOverviewRuler-wordHighlightStrongForeground: rgba(
192,
160,
192,
0.8
);
--vscode-editorPane-background: #1e1e1e;
--vscode-editorRuler-foreground: #5a5a5a;
--vscode-editorStickyScroll-background: #1e1e1e;
--vscode-editorStickyScrollHover-background: #2a2d2e;
--vscode-editorSuggestWidget-background: #252526;
--vscode-editorSuggestWidget-border: #454545;
--vscode-editorSuggestWidget-focusHighlightForeground: #2aaaff;
--vscode-editorSuggestWidget-foreground: #d4d4d4;
--vscode-editorSuggestWidget-highlightForeground: #2aaaff;
--vscode-editorSuggestWidget-selectedBackground: #04395e;
--vscode-editorSuggestWidget-selectedForeground: #ffffff;
--vscode-editorSuggestWidget-selectedIconForeground: #ffffff;
--vscode-editorSuggestWidgetStatus-foreground: rgba(212, 212, 212, 0.5);
--vscode-editorUnicodeHighlight-background: rgba(189, 155, 3, 0.15);
--vscode-editorUnicodeHighlight-border: #bd9b03;
--vscode-editorUnnecessaryCode-opacity: rgba(0, 0, 0, 0.67);
--vscode-editorWarning-foreground: #cca700;
--vscode-editorWhitespace-foreground: rgba(227, 228, 226, 0.16);
--vscode-editorWidget-background: #252526;
--vscode-editorWidget-border: #454545;
--vscode-editorWidget-foreground: #cccccc;
--vscode-errorForeground: #f48771;
--vscode-extensionBadge-remoteBackground: #007acc;
--vscode-extensionBadge-remoteForeground: #ffffff;
--vscode-extensionButton-prominentBackground: #0e639c;
--vscode-extensionButton-prominentForeground: #ffffff;
--vscode-extensionButton-prominentHoverBackground: #1177bb;
--vscode-extensionIcon-preReleaseForeground: #1d9271;
--vscode-extensionIcon-sponsorForeground: #d758b3;
--vscode-extensionIcon-starForeground: #ff8e00;
--vscode-extensionIcon-verifiedForeground: #3794ff;
--vscode-focusBorder: #007fd4;
--vscode-gitDecoration-addedResourceForeground: #81b88b;
--vscode-gitDecoration-conflictingResourceForeground: #e4676b;
--vscode-gitDecoration-deletedResourceForeground: #c74e39;
--vscode-gitDecoration-ignoredResourceForeground: #8c8c8c;
--vscode-gitDecoration-modifiedResourceForeground: #e2c08d;
--vscode-gitDecoration-renamedResourceForeground: #73c991;
--vscode-gitDecoration-stageDeletedResourceForeground: #c74e39;
--vscode-gitDecoration-stageModifiedResourceForeground: #e2c08d;
--vscode-gitDecoration-submoduleResourceForeground: #8db9e2;
--vscode-gitDecoration-untrackedResourceForeground: #73c991;
--vscode-icon-foreground: #c5c5c5;
--vscode-input-background: #3c3c3c;
--vscode-input-foreground: #cccccc;
--vscode-input-placeholderForeground: #a6a6a6;
--vscode-inputOption-activeBackground: rgba(0, 127, 212, 0.4);
--vscode-inputOption-activeBorder: rgba(0, 122, 204, 0);
--vscode-inputOption-activeForeground: #ffffff;
--vscode-inputOption-hoverBackground: rgba(90, 93, 94, 0.5);
--vscode-inputValidation-errorBackground: #5a1d1d;
--vscode-inputValidation-errorBorder: #be1100;
--vscode-inputValidation-infoBackground: #063b49;
--vscode-inputValidation-infoBorder: #007acc;
--vscode-inputValidation-warningBackground: #352a05;
--vscode-inputValidation-warningBorder: #b89500;
--vscode-interactive-activeCodeBorder: #3794ff;
--vscode-interactive-inactiveCodeBorder: #37373d;
--vscode-keybindingLabel-background: rgba(128, 128, 128, 0.17);
--vscode-keybindingLabel-border: rgba(51, 51, 51, 0.6);
--vscode-keybindingLabel-bottomBorder: rgba(68, 68, 68, 0.6);
--vscode-keybindingLabel-foreground: #cccccc;
--vscode-keybindingTable-headerBackground: rgba(204, 204, 204, 0.04);
--vscode-keybindingTable-rowsBackground: rgba(204, 204, 204, 0.04);
--vscode-list-activeSelectionBackground: #04395e;
--vscode-list-activeSelectionForeground: #ffffff;
--vscode-list-activeSelectionIconForeground: #ffffff;
--vscode-list-deemphasizedForeground: #8c8c8c;
--vscode-list-dropBackground: #383b3d;
--vscode-list-errorForeground: #f88070;
--vscode-list-filterMatchBackground: rgba(234, 92, 0, 0.33);
--vscode-list-focusHighlightForeground: #2aaaff;
--vscode-list-focusOutline: #007fd4;
--vscode-list-highlightForeground: #2aaaff;
--vscode-list-hoverBackground: #2a2d2e;
--vscode-list-inactiveSelectionBackground: #37373d;
--vscode-list-invalidItemForeground: #b89500;
--vscode-list-warningForeground: #cca700;
--vscode-listFilterWidget-background: #252526;
--vscode-listFilterWidget-noMatchesOutline: #be1100;
--vscode-listFilterWidget-outline: rgba(0, 0, 0, 0);
--vscode-listFilterWidget-shadow: rgba(0, 0, 0, 0.36);
--vscode-menu-background: #303031;
--vscode-menu-foreground: #cccccc;
--vscode-menu-selectionBackground: #04395e;
--vscode-menu-selectionForeground: #ffffff;
--vscode-menu-separatorBackground: #606060;
--vscode-menubar-selectionBackground: rgba(90, 93, 94, 0.31);
--vscode-menubar-selectionForeground: #cccccc;
--vscode-merge-commonContentBackground: rgba(96, 96, 96, 0.16);
--vscode-merge-commonHeaderBackground: rgba(96, 96, 96, 0.4);
--vscode-merge-currentContentBackground: rgba(64, 200, 174, 0.2);
--vscode-merge-currentHeaderBackground: rgba(64, 200, 174, 0.5);
--vscode-merge-incomingContentBackground: rgba(64, 166, 255, 0.2);
--vscode-merge-incomingHeaderBackground: rgba(64, 166, 255, 0.5);
--vscode-mergeEditor-change\.background: rgba(155, 185, 85, 0.2);
--vscode-mergeEditor-change\.word\.background: rgba(156, 204, 44, 0.2);
--vscode-mergeEditor-conflict\.handledFocused\.border: rgba(
193,
193,
193,
0.8
);
--vscode-mergeEditor-conflict\.handledUnfocused\.border: rgba(
134,
134,
134,
0.29
);
--vscode-mergeEditor-conflict\.handled\.minimapOverViewRuler: rgba(
173,
172,
168,
0.93
);
--vscode-mergeEditor-conflict\.unhandledFocused\.border: #ffa600;
--vscode-mergeEditor-conflict\.unhandledUnfocused\.border: rgba(
255,
166,
0,
0.48
);
--vscode-mergeEditor-conflict\.unhandled\.minimapOverViewRuler: #fcba03;
--vscode-mergeEditor-conflictingLines\.background: rgba(255, 234, 0, 0.28);
--vscode-minimap-errorHighlight: rgba(255, 18, 18, 0.7);
--vscode-minimap-findMatchHighlight: #d18616;
--vscode-minimap-foregroundOpacity: #000000;
--vscode-minimap-selectionHighlight: #264f78;
--vscode-minimap-selectionOccurrenceHighlight: #676767;
--vscode-minimap-warningHighlight: #cca700;
--vscode-minimapGutter-addedBackground: #487e02;
--vscode-minimapGutter-deletedBackground: #f14c4c;
--vscode-minimapGutter-modifiedBackground: #1b81a8;
--vscode-minimapSlider-activeBackground: rgba(191, 191, 191, 0.2);
--vscode-minimapSlider-background: rgba(121, 121, 121, 0.2);
--vscode-minimapSlider-hoverBackground: rgba(100, 100, 100, 0.35);
--vscode-notebook-cellBorderColor: #37373d;
--vscode-notebook-cellEditorBackground: #252526;
--vscode-notebook-cellInsertionIndicator: #007fd4;
--vscode-notebook-cellStatusBarItemHoverBackground: rgba(255, 255, 255, 0.15);
--vscode-notebook-cellToolbarSeparator: rgba(128, 128, 128, 0.35);
--vscode-notebook-editorBackground: #1e1e1e;
--vscode-notebook-focusedCellBorder: #007fd4;
--vscode-notebook-focusedEditorBorder: #007fd4;
--vscode-notebook-inactiveFocusedCellBorder: #37373d;
--vscode-notebook-selectedCellBackground: #37373d;
--vscode-notebook-selectedCellBorder: #37373d;
--vscode-notebook-symbolHighlightBackground: rgba(255, 255, 255, 0.04);
--vscode-notebookScrollbarSlider-activeBackground: rgba(191, 191, 191, 0.4);
--vscode-notebookScrollbarSlider-background: rgba(121, 121, 121, 0.4);
--vscode-notebookScrollbarSlider-hoverBackground: rgba(100, 100, 100, 0.7);
--vscode-notebookStatusErrorIcon-foreground: #f48771;
--vscode-notebookStatusRunningIcon-foreground: #cccccc;
--vscode-notebookStatusSuccessIcon-foreground: #89d185;
--vscode-notificationCenterHeader-background: #303031;
--vscode-notificationLink-foreground: #3794ff;
--vscode-notifications-background: #252526;
--vscode-notifications-border: #303031;
--vscode-notifications-foreground: #cccccc;
--vscode-notificationsErrorIcon-foreground: #f14c4c;
--vscode-notificationsInfoIcon-foreground: #3794ff;
--vscode-notificationsWarningIcon-foreground: #cca700;
--vscode-panel-background: #1e1e1e;
--vscode-panel-border: rgba(128, 128, 128, 0.35);
--vscode-panel-dropBorder: #e7e7e7;
--vscode-panelSection-border: rgba(128, 128, 128, 0.35);
--vscode-panelSection-dropBackground: rgba(83, 89, 93, 0.5);
--vscode-panelSectionHeader-background: rgba(128, 128, 128, 0.2);
--vscode-panelTitle-activeBorder: #e7e7e7;
--vscode-panelTitle-activeForeground: #e7e7e7;
--vscode-panelTitle-inactiveForeground: rgba(231, 231, 231, 0.6);
--vscode-peekView-border: #3794ff;
--vscode-peekViewEditor-background: #001f33;
--vscode-peekViewEditor-matchHighlightBackground: rgba(255, 143, 0, 0.6);
--vscode-peekViewEditorGutter-background: #001f33;
--vscode-peekViewResult-background: #252526;
--vscode-peekViewResult-fileForeground: #ffffff;
--vscode-peekViewResult-lineForeground: #bbbbbb;
--vscode-peekViewResult-matchHighlightBackground: rgba(234, 92, 0, 0.3);
--vscode-peekViewResult-selectionBackground: rgba(51, 153, 255, 0.2);
--vscode-peekViewResult-selectionForeground: #ffffff;
--vscode-peekViewTitle-background: rgba(55, 148, 255, 0.1);
--vscode-peekViewTitleDescription-foreground: rgba(204, 204, 204, 0.7);
--vscode-peekViewTitleLabel-foreground: #ffffff;
--vscode-pickerGroup-border: #3f3f46;
--vscode-pickerGroup-foreground: #3794ff;
--vscode-ports-iconRunningProcessForeground: #369432;
--vscode-problemsErrorIcon-foreground: #f14c4c;
--vscode-problemsInfoIcon-foreground: #3794ff;
--vscode-problemsWarningIcon-foreground: #cca700;
--vscode-progressBar-background: #0e70c0;
--vscode-quickInput-background: #252526;
--vscode-quickInput-foreground: #cccccc;
--vscode-quickInputList-focusBackground: #04395e;
--vscode-quickInputList-focusForeground: #ffffff;
--vscode-quickInputList-focusIconForeground: #ffffff;
--vscode-quickInputTitle-background: rgba(255, 255, 255, 0.1);
--vscode-sash-hoverBorder: #007fd4;
--vscode-scm-providerBorder: #454545;
--vscode-scrollbar-shadow: #000000;
--vscode-scrollbarSlider-activeBackground: rgba(191, 191, 191, 0.4);
--vscode-scrollbarSlider-background: rgba(121, 121, 121, 0.4);
--vscode-scrollbarSlider-hoverBackground: rgba(100, 100, 100, 0.7);
--vscode-searchEditor-findMatchBackground: rgba(234, 92, 0, 0.22);
--vscode-settings-checkboxBackground: #3c3c3c;
--vscode-settings-checkboxBorder: #3c3c3c;
--vscode-settings-checkboxForeground: #f0f0f0;
--vscode-settings-dropdownBackground: #3c3c3c;
--vscode-settings-dropdownBorder: #3c3c3c;
--vscode-settings-dropdownForeground: #f0f0f0;
--vscode-settings-dropdownListBorder: #454545;
--vscode-settings-focusedRowBackground: rgba(42, 45, 46, 0.6);
--vscode-settings-focusedRowBorder: rgba(255, 255, 255, 0.12);
--vscode-settings-headerBorder: rgba(128, 128, 128, 0.35);
--vscode-settings-headerForeground: #e7e7e7;
--vscode-settings-modifiedItemIndicator: #0c7d9d;
--vscode-settings-numberInputBackground: #3c3c3c;
--vscode-settings-numberInputForeground: #cccccc;
--vscode-settings-rowHoverBackground: rgba(42, 45, 46, 0.3);
--vscode-settings-sashBorder: rgba(128, 128, 128, 0.35);
--vscode-settings-textInputBackground: #3c3c3c;
--vscode-settings-textInputForeground: #cccccc;
--vscode-sideBar-background: #252526;
--vscode-sideBar-dropBackground: rgba(83, 89, 93, 0.5);
--vscode-sideBarSectionHeader-background: rgba(0, 0, 0, 0);
--vscode-sideBarSectionHeader-border: rgba(204, 204, 204, 0.2);
--vscode-sideBarTitle-foreground: #bbbbbb;
--vscode-sideBySideEditor-horizontalBorder: #444444;
--vscode-sideBySideEditor-verticalBorder: #444444;
--vscode-statusBar-background: #007acc;
--vscode-statusBar-debuggingBackground: #cc6633;
--vscode-statusBar-debuggingForeground: #ffffff;
--vscode-statusBar-focusBorder: #ffffff;
--vscode-statusBar-foreground: #ffffff;
--vscode-statusBar-noFolderBackground: #68217a;
--vscode-statusBar-noFolderForeground: #ffffff;
--vscode-statusBarItem-activeBackground: rgba(255, 255, 255, 0.18);
--vscode-statusBarItem-compactHoverBackground: rgba(255, 255, 255, 0.2);
--vscode-statusBarItem-errorBackground: #c72e0f;
--vscode-statusBarItem-errorForeground: #ffffff;
--vscode-statusBarItem-focusBorder: #ffffff;
--vscode-statusBarItem-hoverBackground: rgba(255, 255, 255, 0.12);
--vscode-statusBarItem-prominentBackground: rgba(0, 0, 0, 0.5);
--vscode-statusBarItem-prominentForeground: #ffffff;
--vscode-statusBarItem-prominentHoverBackground: rgba(0, 0, 0, 0.3);
--vscode-statusBarItem-remoteBackground: #16825d;
--vscode-statusBarItem-remoteForeground: #ffffff;
--vscode-statusBarItem-warningBackground: #7a6400;
--vscode-statusBarItem-warningForeground: #ffffff;
--vscode-symbolIcon-arrayForeground: #cccccc;
--vscode-symbolIcon-booleanForeground: #cccccc;
--vscode-symbolIcon-classForeground: #ee9d28;
--vscode-symbolIcon-colorForeground: #cccccc;
--vscode-symbolIcon-constantForeground: #cccccc;
--vscode-symbolIcon-constructorForeground: #b180d7;
--vscode-symbolIcon-enumeratorForeground: #ee9d28;
--vscode-symbolIcon-enumeratorMemberForeground: #75beff;
--vscode-symbolIcon-eventForeground: #ee9d28;
--vscode-symbolIcon-fieldForeground: #75beff;
--vscode-symbolIcon-fileForeground: #cccccc;
--vscode-symbolIcon-folderForeground: #cccccc;
--vscode-symbolIcon-functionForeground: #b180d7;
--vscode-symbolIcon-interfaceForeground: #75beff;
--vscode-symbolIcon-keyForeground: #cccccc;
--vscode-symbolIcon-keywordForeground: #cccccc;
--vscode-symbolIcon-methodForeground: #b180d7;
--vscode-symbolIcon-moduleForeground: #cccccc;
--vscode-symbolIcon-namespaceForeground: #cccccc;
--vscode-symbolIcon-nullForeground: #cccccc;
--vscode-symbolIcon-numberForeground: #cccccc;
--vscode-symbolIcon-objectForeground: #cccccc;
--vscode-symbolIcon-operatorForeground: #cccccc;
--vscode-symbolIcon-packageForeground: #cccccc;
--vscode-symbolIcon-propertyForeground: #cccccc;
--vscode-symbolIcon-referenceForeground: #cccccc;
--vscode-symbolIcon-snippetForeground: #cccccc;
--vscode-symbolIcon-stringForeground: #cccccc;
--vscode-symbolIcon-structForeground: #cccccc;
--vscode-symbolIcon-textForeground: #cccccc;
--vscode-symbolIcon-typeParameterForeground: #cccccc;
--vscode-symbolIcon-unitForeground: #cccccc;
--vscode-symbolIcon-variableForeground: #75beff;
--vscode-tab-activeBackground: #1e1e1e;
--vscode-tab-activeForeground: #ffffff;
--vscode-tab-activeModifiedBorder: #3399cc;
--vscode-tab-border: #252526;
--vscode-tab-inactiveBackground: #2d2d2d;
--vscode-tab-inactiveForeground: rgba(255, 255, 255, 0.5);
--vscode-tab-inactiveModifiedBorder: rgba(51, 153, 204, 0.5);
--vscode-tab-lastPinnedBorder: rgba(204, 204, 204, 0.2);
--vscode-tab-unfocusedActiveBackground: #1e1e1e;
--vscode-tab-unfocusedActiveForeground: rgba(255, 255, 255, 0.5);
--vscode-tab-unfocusedActiveModifiedBorder: rgba(51, 153, 204, 0.5);
--vscode-tab-unfocusedInactiveBackground: #2d2d2d;
--vscode-tab-unfocusedInactiveForeground: rgba(255, 255, 255, 0.25);
--vscode-tab-unfocusedInactiveModifiedBorder: rgba(51, 153, 204, 0.25);
--vscode-terminal-ansiBlack: #000000;
--vscode-terminal-ansiBlue: #2472c8;
--vscode-terminal-ansiBrightBlack: #666666;
--vscode-terminal-ansiBrightBlue: #3b8eea;
--vscode-terminal-ansiBrightCyan: #29b8db;
--vscode-terminal-ansiBrightGreen: #23d18b;
--vscode-terminal-ansiBrightMagenta: #d670d6;
--vscode-terminal-ansiBrightRed: #f14c4c;
--vscode-terminal-ansiBrightWhite: #e5e5e5;
--vscode-terminal-ansiBrightYellow: #f5f543;
--vscode-terminal-ansiCyan: #11a8cd;
--vscode-terminal-ansiGreen: #0dbc79;
--vscode-terminal-ansiMagenta: #bc3fbc;
--vscode-terminal-ansiRed: #cd3131;
--vscode-terminal-ansiWhite: #e5e5e5;
--vscode-terminal-ansiYellow: #e5e510;
--vscode-terminal-border: rgba(128, 128, 128, 0.35);
--vscode-terminal-dropBackground: rgba(83, 89, 93, 0.5);
--vscode-terminal-findMatchBackground: #515c6a;
--vscode-terminal-findMatchHighlightBackground: rgba(234, 92, 0, 0.33);
--vscode-terminal-foreground: #cccccc;
--vscode-terminal-inactiveSelectionBackground: #3a3d41;
--vscode-terminal-selectionBackground: #264f78;
--vscode-terminalCommandDecoration-defaultBackground: rgba(
255,
255,
255,
0.25
);
--vscode-terminalCommandDecoration-errorBackground: #f14c4c;
--vscode-terminalCommandDecoration-successBackground: #1b81a8;
--vscode-terminalOverviewRuler-cursorForeground: rgba(160, 160, 160, 0.8);
--vscode-terminalOverviewRuler-findMatchForeground: rgba(209, 134, 22, 0.49);
--vscode-testing-iconErrored: #f14c4c;
--vscode-testing-iconFailed: #f14c4c;
--vscode-testing-iconPassed: #73c991;
--vscode-testing-iconQueued: #cca700;
--vscode-testing-iconSkipped: #848484;
--vscode-testing-iconUnset: #848484;
--vscode-testing-message\.error\.decorationForeground: #f14c4c;
--vscode-testing-message\.error\.lineBackground: rgba(255, 0, 0, 0.2);
--vscode-testing-message\.info\.decorationForeground: rgba(
212,
212,
212,
0.5
);
--vscode-testing-peekBorder: #f14c4c;
--vscode-testing-peekHeaderBackground: rgba(241, 76, 76, 0.1);
--vscode-testing-runAction: #73c991;
--vscode-textBlockQuote-background: rgba(127, 127, 127, 0.1);
--vscode-textBlockQuote-border: rgba(0, 122, 204, 0.5);
--vscode-textCodeBlock-background: rgba(10, 10, 10, 0.4);
--vscode-textLink-activeForeground: #3794ff;
--vscode-textLink-foreground: #3794ff;
--vscode-textPreformat-foreground: #d7ba7d;
--vscode-textSeparator-foreground: rgba(255, 255, 255, 0.18);
--vscode-titleBar-activeBackground: #3c3c3c;
--vscode-titleBar-activeForeground: #cccccc;
--vscode-titleBar-inactiveBackground: rgba(60, 60, 60, 0.6);
--vscode-titleBar-inactiveForeground: rgba(204, 204, 204, 0.6);
--vscode-toolbar-activeBackground: rgba(99, 102, 103, 0.31);
--vscode-toolbar-hoverBackground: rgba(90, 93, 94, 0.31);
--vscode-tree-indentGuidesStroke: #585858;
--vscode-tree-tableColumnsBorder: rgba(204, 204, 204, 0.13);
--vscode-tree-tableOddRowsBackground: rgba(204, 204, 204, 0.04);
--vscode-welcomePage-progress\.background: #3c3c3c;
--vscode-welcomePage-progress\.foreground: #3794ff;
--vscode-welcomePage-tileBackground: #252526;
--vscode-welcomePage-tileHoverBackground: #2c2c2d;
--vscode-welcomePage-tileShadow: rgba(0, 0, 0, 0.36);
--vscode-widget-shadow: rgba(0, 0, 0, 0.36);
}
@@ -0,0 +1,22 @@
#!/usr/bin/env node
const rewire = require("rewire");
const defaults = rewire("react-scripts/scripts/build.js");
const config = defaults.__get__("config");
// Disable code splitting
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
// Disable code chunks
config.optimization.runtimeChunk = false;
// Rename main.{hash}.js to main.js
config.output.filename = "static/js/[name].js";
// Rename main.{hash}.css to main.css
config.plugins[5].options.filename = "static/css/[name].css";
config.plugins[5].options.moduleFilename = () => "static/css/main.css";
@@ -0,0 +1,160 @@
import { makeVisualizationsWithId } from "@nand2tetris/components/chips/visualizations.js";
import { Clockface } from "@nand2tetris/components/clockface.js";
import { FullPinout } from "@nand2tetris/components/pinout.js";
import { useChipPageStore } from "@nand2tetris/components/stores/chip.store.js";
import * as Not from "@nand2tetris/projects/project_01/01_not.js";
import { VSCodeButton, VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react";
import {
ReactNode,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
import { VSCodeContext } from "./vscode";
function App() {
const { state, actions, dispatch } = useChipPageStore();
const { api } = useContext(VSCodeContext);
const [hdl, setHdl] = useState(Not.hdl);
const [loaded, setLoaded] = useState(false);
const compile = useCallback(
async (hdl: string) => {
setHdl(hdl);
await actions.updateFiles({ hdl, tst: "// No test", cmp: "" });
},
[setHdl, actions],
);
const onMessage = useCallback(
(
event: MessageEvent<
Partial<{ nand2tetris: boolean; hdl: string; chipName: string }>
>,
) => {
if (!event.data?.nand2tetris) return;
if (event.data.hdl) compile(event.data.hdl ?? "");
if (event.data.chipName)
dispatch.current({
action: "updateChip",
payload: {
chipName: event.data.chipName,
},
});
setLoaded(true);
},
[compile, dispatch],
);
useEffect(() => {
window.addEventListener("message", onMessage);
return () => {
window.removeEventListener("message", onMessage);
};
}, [onMessage]);
useEffect(() => {
api.postMessage({ nand2tetris: true, ready: true });
}, [api]);
const [useBuiltin, setUseBuiltin] = useState(false);
const toggleUseBuiltin = async () => {
if (useBuiltin) {
compile(hdl);
setUseBuiltin(false);
} else {
actions.toggleBuiltin();
setUseBuiltin(true);
}
};
const clockActions = useMemo(
() => ({
toggle() {
actions.clock();
},
reset() {
actions.reset();
},
}),
[actions],
);
const chipButtons = state.controls.error ? (
<p>{state.controls.error?.message}</p>
) : (
<>
<VSCodeCheckbox onChange={toggleUseBuiltin}>Use Builtin</VSCodeCheckbox>
<fieldset role="group">
<VSCodeButton
onClick={actions.eval}
onKeyDown={actions.eval}
disabled={!state.sim.pending}
>
Eval
</VSCodeButton>
<VSCodeButton
onClick={clockActions.toggle}
style={{ maxWidth: "initial" }}
disabled={!state.sim.clocked}
>
Clock:{"\u00a0"}
<Clockface />
</VSCodeButton>
<VSCodeButton
onClick={clockActions.reset}
style={{ maxWidth: "initial" }}
disabled={!state.sim.clocked}
>
Reset
</VSCodeButton>
</fieldset>
</>
);
const visualizations: [string, ReactNode][] = makeVisualizationsWithId({
parts: state.sim.chip,
});
const pinsPanel = (
<>
<h3>Chip {state.controls.chipName}</h3>
{chipButtons}
{state.sim.invalid ? (
<p>Invalid Chip</p>
) : (
<>
<FullPinout
sim={state.sim}
toggle={actions.toggle}
setInputValid={() => {
console.log("TODO: Handle Input Valid");
}}
/>
<h4>Visualizations</h4>
{visualizations.length > 0 ? (
visualizations.map(([p, v]) => <div key={p}>{v}</div>)
) : (
<p>None</p>
)}
</>
)}
{/* DEBUG */}
<textarea style={{ display: "none" }}>{hdl}</textarea>
</>
);
return loaded ? (
pinsPanel
) : (
<>
<h3>HDL</h3>
<p>Open an HDL chip to begin</p>
</>
);
}
export default App;
@@ -0,0 +1,47 @@
import {
FileSystem,
ObjectFileSystemAdapter,
} from "@davidsouther/jiffies/lib/esm/fs.js";
import { useDialog } from "@nand2tetris/components/dialog";
import { BaseContext } from "@nand2tetris/components/stores/base.context.js";
import * as Not from "@nand2tetris/projects/project_01/01_not.js";
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import { StatusSeverity } from "@nand2tetris/components/stores/base.context";
const baseContext: BaseContext = {
fs: new FileSystem(
new ObjectFileSystemAdapter({ "projects/01/Not.hdl": Not.hdl }),
),
canUpgradeFs: false,
async upgradeFs() {},
closeFs() {},
storage: {},
status: { message: "", severity: "INFO" },
setStatus: (status: string | { message: string; severity?: StatusSeverity }): void => {
// api.postMessage({ nand2tetris: true, showMessage: status });
if (typeof status === "string") {
console.log(status);
} else {
console.log(`${status.severity}: ${status.message}`);
}
},
permissionPrompt: {} as ReturnType<typeof useDialog>,
// eslint-disable-next-line @typescript-eslint/no-empty-function
async requestPermission() {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
loadFs() {},
};
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement,
);
root.render(
<React.StrictMode>
<BaseContext.Provider value={baseContext}>
<App />
</BaseContext.Provider>
</React.StrictMode>,
);
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";
@@ -0,0 +1,6 @@
import { createContext } from "react";
import type { WebviewApi } from "vscode-webview";
const api: WebviewApi<unknown> = acquireVsCodeApi?.();
export const VSCodeContext = createContext({ api });
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"rootDir": "src"
},
"include": ["src"]
}