Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
HACKE-RC committed Sep 28, 2023
2 parents 85f586d + 7eb65ef commit b072a27
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
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.
10 changes: 10 additions & 0 deletions tests/Seven/output/Main.jack.vm
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
11 changes: 11 additions & 0 deletions tests/Square/output/Main.jack.vm
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
298 changes: 298 additions & 0 deletions tests/Square/output/Square.jack.vm
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
Loading

0 comments on commit b072a27

Please sign in to comment.