Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feat/compiler #483

Open
wants to merge 89 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
95131df
Init
happytomatoe Sep 24, 2024
53b5a0b
WIP
happytomatoe Sep 24, 2024
1f3b3f4
WIP
happytomatoe Sep 24, 2024
240aedc
WIP
happytomatoe Sep 25, 2024
3d6f8be
WIP
happytomatoe Sep 25, 2024
49075d7
WIP
happytomatoe Sep 25, 2024
f9dab02
Add symbol table. Add validator skeleton
happytomatoe Sep 25, 2024
029f124
Add more validations
happytomatoe Sep 26, 2024
d07a587
Add more validations
happytomatoe Sep 26, 2024
3a69078
Add unknown subroutine return type error
happytomatoe Sep 27, 2024
b541d22
Add unknown type error
happytomatoe Sep 27, 2024
ab1e0c9
Add CFG for simple cases
happytomatoe Sep 27, 2024
59f7507
Add not all pahts retun validation
happytomatoe Sep 27, 2024
730f72e
Add print binary tree function
happytomatoe Sep 28, 2024
d61c6ca
Add validations for subroutine call
happytomatoe Sep 28, 2024
2fb01eb
Add builtin functions
happytomatoe Sep 28, 2024
81193e2
Add function/method called as function/method
happytomatoe Sep 28, 2024
04d720f
Add more validations
happytomatoe Sep 28, 2024
1511c94
Add int out of range validation
happytomatoe Sep 28, 2024
c40bfdd
Add field cant be referenced in a function validation
happytomatoe Sep 28, 2024
32b91f7
this can't be referenced in a function validation
happytomatoe Sep 28, 2024
d612816
Fix bug in validation
happytomatoe Sep 29, 2024
5716258
WIP
happytomatoe Sep 29, 2024
aee5ec7
WIP
happytomatoe Sep 29, 2024
fec5790
WIP
happytomatoe Oct 3, 2024
3c1185a
WIP
happytomatoe Oct 3, 2024
af250f2
WIP
happytomatoe Oct 3, 2024
cf2c04c
WIP
happytomatoe Oct 3, 2024
ecadfb2
WIP
happytomatoe Oct 3, 2024
be5142a
WIP
happytomatoe Oct 3, 2024
1b9a348
WIP
happytomatoe Oct 3, 2024
afbf33b
WIP
happytomatoe Oct 3, 2024
faef67d
Fix lexer error handling
happytomatoe Oct 3, 2024
dd918cb
WIP
happytomatoe Oct 3, 2024
ae65cc5
WIP
happytomatoe Oct 3, 2024
694dbcd
Add compiler validate methods
happytomatoe Oct 3, 2024
6bd99b8
WIP
happytomatoe Oct 3, 2024
d67729e
WIP
happytomatoe Oct 4, 2024
375001d
WIP
happytomatoe Oct 4, 2024
a170adf
Fix bug - when creating new file there is an error
happytomatoe Oct 4, 2024
aa8a8ca
Fix incorrect error message
happytomatoe Oct 4, 2024
e8e9dd8
Merge branch 'main' of https://github.com/nand2tetris/web-ide into fe…
happytomatoe Oct 4, 2024
4a51caf
WIP
happytomatoe Oct 4, 2024
ae414f2
WIP
happytomatoe Oct 4, 2024
771c2cd
Bug fixes
happytomatoe Oct 4, 2024
d92b385
WIP
happytomatoe Oct 4, 2024
4ae5997
WIP
happytomatoe Oct 4, 2024
d5c7f27
WIP
happytomatoe Oct 4, 2024
f1c9ea3
WIP
happytomatoe Oct 4, 2024
560f043
WIP
happytomatoe Oct 8, 2024
1c0c9ab
WIP
happytomatoe Oct 8, 2024
2aba5fb
WIP
happytomatoe Oct 8, 2024
d27f391
WIP
happytomatoe Oct 8, 2024
ae9be57
WIP
happytomatoe Oct 8, 2024
1317635
WIP
happytomatoe Oct 8, 2024
06432ba
WIP
happytomatoe Oct 8, 2024
46998c6
WIP
happytomatoe Oct 8, 2024
4970648
WIP
happytomatoe Oct 8, 2024
8030509
WIP
happytomatoe Oct 8, 2024
c05caa9
WIP
happytomatoe Oct 8, 2024
074b74a
WIP
happytomatoe Oct 8, 2024
f4d54d8
WIP
happytomatoe Oct 8, 2024
c5d8243
Used string enum for tagged error types
Oct 9, 2024
dbf7d80
Fix minor bug
happytomatoe Oct 11, 2024
8681e06
WIP
happytomatoe Oct 11, 2024
6c5ec41
Change tests to use FileSystem
happytomatoe Oct 11, 2024
98f696e
WIP
happytomatoe Oct 11, 2024
12edbb1
WIP
happytomatoe Oct 11, 2024
1dfc0ce
Remove ! signs
happytomatoe Oct 11, 2024
70cbcec
WIP
happytomatoe Oct 11, 2024
30f1b9c
Format error.ts file
Oct 11, 2024
ce31d3a
WIP
happytomatoe Oct 11, 2024
bf7acd0
Fix bug in jack lexer. Fix cli for compiler
happytomatoe Oct 17, 2024
179a39c
Merge remote-tracking branch 'fork/feat/compilererrors' into feat/com…
happytomatoe Oct 17, 2024
3e35604
Fix bugs
happytomatoe Oct 17, 2024
7604ef5
Generate antlr files
happytomatoe Oct 17, 2024
773cf3d
Migrate to antlr4ng
happytomatoe Oct 20, 2024
7c154b9
WIP
happytomatoe Oct 20, 2024
4bcce0a
WIP
happytomatoe Oct 20, 2024
8b71fdb
WIP
happytomatoe Oct 20, 2024
b573d00
WIP
happytomatoe Oct 20, 2024
7924123
WIP
happytomatoe Oct 20, 2024
8afba76
WIP
happytomatoe Oct 20, 2024
2dbf34d
Fix formatting and lint errors
happytomatoe Oct 20, 2024
a68a248
WIP
happytomatoe Oct 21, 2024
a2620ec
WIP
happytomatoe Oct 22, 2024
d41d95e
WIP
happytomatoe Oct 22, 2024
078f95b
Fix bug with never ending stack increase
happytomatoe Oct 22, 2024
520ce31
Formatting
happytomatoe Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ out
npm-debug.log*
yarn-debug.log*
yarn-error.log*
**/.vscode/numbered-bookmars.json
**/.antlr
DavidSouther marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
],
"outFiles": ["${workspaceFolder}/extension/build/test/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}, {
"type": "chrome",
"request": "launch",
"name": "Test web ide",
"url": "http://localhost:3000/web-ide",
"webRoot": "${workspaceFolder}"
}
]
}
49 changes: 49 additions & 0 deletions .vscode/numbered-bookmarks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"files": [
{
"path": "simulator/src/jack/compiler.ts",
"bookmarks": [
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
},
{
"line": 160,
"column": 2
},
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
},
{
"line": -1,
"column": 0
}
]
}
]
}
3 changes: 3 additions & 0 deletions simulator/.vscode/numbered-bookmarks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files": []
}
6 changes: 5 additions & 1 deletion simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"@nand2tetris/projects": "^1.0.0",
"@nand2tetris/runner": "^1.0.0",
"@types/node": "^20.14.2",
"antlr4": "^4.13.2",
"assert": "^2.1.0",
"ohm-js": "^17.1.0",
"rxjs": "^7.8.1"
},
Expand All @@ -35,6 +37,8 @@
},
"scripts": {
"build": "tsc",
"test": "jest --verbose"
"test": "jest --verbose",
"test-w": "jest --watchAll --verbose",
"gen": "cd src/languages/grammars && antlr4 -Dlanguage=TypeScript JackLexer.g4 JackParser.g4 -o ../../jack/generated"
}
}
93 changes: 93 additions & 0 deletions simulator/src/jack/builtins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { GenericSymbol, SubroutineType } from "./symbol.js";

export const builtInTypes = ["int", "boolean", "char"];
interface Range {
min: number;
max: number;
}
export const intRange = { min: -32768, max: 32767 } as Range;
happytomatoe marked this conversation as resolved.
Show resolved Hide resolved
//TODO: should we convert this to symbols?
const builtInFunctionsToArgCount: Record<string, number> = {
"Array.dispose": 0,
//TODO: what is this?
DavidSouther marked this conversation as resolved.
Show resolved Hide resolved
// "Array.init": 0,
"Array.new": 1,
"Keyboard.init": 0,
"Keyboard.keyPressed": 0,
"Keyboard.readChar": 0,
"Keyboard.readInt": 1,
"Keyboard.readLine": 1,
"Math.abs": 1,
"Math.divide": 2,
//TODO: what is this ?
// "Math.init": 0,
"Math.max": 2,
"Math.min": 2,
"Math.multiply": 2,
"Math.sqrt": 1,
"Memory.alloc": 1,
"Memory.deAlloc": 1,
// "Memory.init": 0,
"Memory.peek": 1,
"Memory.poke": 2,
"Output.backSpace": 0,
// "Output.init": 0,
"Output.moveCursor": 2,
"Output.printChar": 1,
"Output.printInt": 1,
"Output.println": 0,
"Output.printString": 1,
"Screen.clearScreen": 0,
"Screen.drawCircle": 3,
"Screen.drawLine": 4,
"Screen.drawPixel": 2,
"Screen.drawRectangle": 4,
// "Screen.init": 0,
"Screen.setColor": 1,
"String.appendChar": 1,
"String.backSpace": 0,
"String.charAt": 2,
"String.dispose": 0,
"String.doubleQuote": 0,
"String.eraseLastChar": 0,
// "String.init": 0,
"String.intValue": 0,
"String.length": 0,
"String.new": 1,
"String.newLine": 0,
"String.setCharAt": 1,
"String.setInt": 1,
"Sys.error": 1,
"Sys.halt": 0,
"Sys.wait": 1,
};
const builtInClasses = [
happytomatoe marked this conversation as resolved.
Show resolved Hide resolved
"Array",
"Keyboard",
"Math",
"Memory",
"Output",
"Screen",
"String",
"Sys",
];
const builtInClassesRecord = builtInClasses.reduce(
(acc, elem) => ({
...acc,
[elem]: {} as GenericSymbol,
}),
{} as Record<string, GenericSymbol>,
);

export const builtInSymbols = Object.keys(builtInFunctionsToArgCount).reduce(
(acc, elem) => ({
...acc,
[elem]: {
subroutineInfo: {
paramsCount: builtInFunctionsToArgCount[elem],
type: SubroutineType.Function,
},
} as GenericSymbol,
}),
builtInClassesRecord,
);
Loading
Loading