-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
5 changed files
with
496 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Jack Compiler | ||
Jack Programming Language Compiler written purely in C++, does not follow most of the compiler thoery and is therefore extremely complicated. | ||
The purpose of the project was for me to have fun and build something functional, it does not therefore return errors in most cases and should not be used by anyone to do real compilation. There are other compilers which follow compiler thoery and can do that much more efficiently. | ||
The purpose of the project was for me to have fun and build something functional, it does not therefore return errors in most cases, is not efficient, does not follow any guidelines, it's freestyle code and should not be used by anyone to do real compilation. There are other compilers which follow compiler thoery and can do that much more efficiently. | ||
|
||
It passes all the test given in the Nand2Tetris course and can theoritically compile any piece of jack code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function Main.main 0 | ||
push constant 2 | ||
push constant 3 | ||
call Math.multiply 2 | ||
push constant 1 | ||
add | ||
call Output.printInt 1 | ||
pop temp 0 | ||
push constant 0 | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function Main.main 1 | ||
call SquareGame.new 0 | ||
pop local 0 | ||
push local 0 | ||
call SquareGame.run 1 | ||
pop temp 0 | ||
push local 0 | ||
call SquareGame.dispose 1 | ||
pop temp 0 | ||
push constant 0 | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,298 @@ | ||
function Square.new 0 | ||
push constant 3 | ||
call Memory.alloc 1 | ||
pop pointer 0 | ||
push argument 0 | ||
pop this 0 | ||
push argument 1 | ||
pop this 1 | ||
push argument 2 | ||
pop this 2 | ||
push pointer 0 | ||
call Square.draw 1 | ||
pop temp 0 | ||
push pointer 0 | ||
return | ||
function Square.dispose 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push argument 0 | ||
call Memory.deAlloc 1 | ||
pop temp 0 | ||
push constant 0 | ||
return | ||
function Square.draw 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push constant 1 | ||
neg | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
push constant 0 | ||
return | ||
function Square.erase 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push constant 0 | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
push constant 0 | ||
return | ||
function Square.incSize 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push this 1 | ||
push this 2 | ||
add | ||
push constant 254 | ||
lt | ||
push this 0 | ||
push this 2 | ||
add | ||
push constant 510 | ||
lt | ||
and | ||
not | ||
if-goto LABEL_ELSE_1 | ||
push pointer 0 | ||
call Square.erase 1 | ||
pop temp 0 | ||
push this 2 | ||
push constant 2 | ||
add | ||
pop this 2 | ||
push pointer 0 | ||
call Square.draw 1 | ||
pop temp 0 | ||
label LABEL_ELSE_1 | ||
push constant 0 | ||
return | ||
function Square.decSize 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push this 2 | ||
push constant 2 | ||
gt | ||
not | ||
if-goto LABEL_ELSE_2 | ||
push pointer 0 | ||
call Square.erase 1 | ||
pop temp 0 | ||
push this 2 | ||
push constant 2 | ||
sub | ||
pop this 2 | ||
push pointer 0 | ||
call Square.draw 1 | ||
pop temp 0 | ||
label LABEL_ELSE_2 | ||
push constant 0 | ||
return | ||
function Square.moveUp 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push this 1 | ||
push constant 1 | ||
gt | ||
not | ||
if-goto LABEL_ELSE_3 | ||
push constant 0 | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 2 | ||
add | ||
push constant 1 | ||
sub | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
push this 1 | ||
push constant 2 | ||
sub | ||
pop this 1 | ||
push constant 1 | ||
neg | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push constant 1 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
label LABEL_ELSE_3 | ||
push constant 0 | ||
return | ||
function Square.moveDown 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push this 1 | ||
push this 2 | ||
add | ||
push constant 254 | ||
lt | ||
not | ||
if-goto LABEL_ELSE_4 | ||
push constant 0 | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push constant 1 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
push this 1 | ||
push constant 2 | ||
add | ||
pop this 1 | ||
push constant 1 | ||
neg | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 2 | ||
add | ||
push constant 1 | ||
sub | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
label LABEL_ELSE_4 | ||
push constant 0 | ||
return | ||
function Square.moveLeft 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push this 0 | ||
push constant 1 | ||
gt | ||
not | ||
if-goto LABEL_ELSE_5 | ||
push constant 0 | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 2 | ||
add | ||
push constant 1 | ||
sub | ||
push this 1 | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
push this 0 | ||
push constant 2 | ||
sub | ||
pop this 0 | ||
push constant 1 | ||
neg | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 0 | ||
push constant 1 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
label LABEL_ELSE_5 | ||
push constant 0 | ||
return | ||
function Square.moveRight 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push this 0 | ||
push this 2 | ||
add | ||
push constant 510 | ||
lt | ||
not | ||
if-goto LABEL_ELSE_6 | ||
push constant 0 | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 1 | ||
push this 0 | ||
push constant 1 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
push this 0 | ||
push constant 2 | ||
add | ||
pop this 0 | ||
push constant 1 | ||
neg | ||
call Screen.setColor 1 | ||
pop temp 0 | ||
push this 0 | ||
push this 2 | ||
add | ||
push constant 1 | ||
sub | ||
push this 1 | ||
push this 0 | ||
push this 2 | ||
add | ||
push this 1 | ||
push this 2 | ||
add | ||
call Screen.drawRectangle 4 | ||
pop temp 0 | ||
label LABEL_ELSE_6 | ||
push constant 0 | ||
return |
Oops, something went wrong.