-
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.
Refactored so that functions can be declared before the statements th…
…at comprise them. Manually tested that var declaration counting is working
- Loading branch information
Isaiah Becker-Mayer
committed
Apr 7, 2021
1 parent
570f5f2
commit 6792483
Showing
11 changed files
with
4,097 additions
and
69 deletions.
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
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,2 @@ | ||
# ignore the files we generate with the compiler | ||
Main.vm |
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,23 @@ | ||
function Array.new 0 | ||
push argument 0 | ||
push constant 0 | ||
gt | ||
not | ||
if-goto IF_TRUE0 | ||
goto IF_FALSE0 | ||
label IF_TRUE0 | ||
push constant 2 | ||
call Sys.error 1 | ||
pop temp 0 | ||
label IF_FALSE0 | ||
push argument 0 | ||
call Memory.alloc 1 | ||
return | ||
function Array.dispose 0 | ||
push argument 0 | ||
pop pointer 0 | ||
push pointer 0 | ||
call Memory.deAlloc 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,102 @@ | ||
function Keyboard.init 0 | ||
push constant 0 | ||
return | ||
function Keyboard.keyPressed 0 | ||
push constant 24576 | ||
call Memory.peek 1 | ||
return | ||
function Keyboard.readChar 2 | ||
push constant 0 | ||
call Output.printChar 1 | ||
pop temp 0 | ||
label WHILE_EXP0 | ||
push local 1 | ||
push constant 0 | ||
eq | ||
push local 0 | ||
push constant 0 | ||
gt | ||
or | ||
not | ||
if-goto WHILE_END0 | ||
call Keyboard.keyPressed 0 | ||
pop local 0 | ||
push local 0 | ||
push constant 0 | ||
gt | ||
if-goto IF_TRUE0 | ||
goto IF_FALSE0 | ||
label IF_TRUE0 | ||
push local 0 | ||
pop local 1 | ||
label IF_FALSE0 | ||
goto WHILE_EXP0 | ||
label WHILE_END0 | ||
call String.backSpace 0 | ||
call Output.printChar 1 | ||
pop temp 0 | ||
push local 1 | ||
call Output.printChar 1 | ||
pop temp 0 | ||
push local 1 | ||
return | ||
function Keyboard.readLine 5 | ||
push constant 80 | ||
call String.new 1 | ||
pop local 3 | ||
push argument 0 | ||
call Output.printString 1 | ||
pop temp 0 | ||
call String.newLine 0 | ||
pop local 1 | ||
call String.backSpace 0 | ||
pop local 2 | ||
label WHILE_EXP0 | ||
push local 4 | ||
not | ||
not | ||
if-goto WHILE_END0 | ||
call Keyboard.readChar 0 | ||
pop local 0 | ||
push local 0 | ||
push local 1 | ||
eq | ||
pop local 4 | ||
push local 4 | ||
not | ||
if-goto IF_TRUE0 | ||
goto IF_FALSE0 | ||
label IF_TRUE0 | ||
push local 0 | ||
push local 2 | ||
eq | ||
if-goto IF_TRUE1 | ||
goto IF_FALSE1 | ||
label IF_TRUE1 | ||
push local 3 | ||
call String.eraseLastChar 1 | ||
pop temp 0 | ||
goto IF_END1 | ||
label IF_FALSE1 | ||
push local 3 | ||
push local 0 | ||
call String.appendChar 2 | ||
pop local 3 | ||
label IF_END1 | ||
label IF_FALSE0 | ||
goto WHILE_EXP0 | ||
label WHILE_END0 | ||
push local 3 | ||
return | ||
function Keyboard.readInt 2 | ||
push argument 0 | ||
call Keyboard.readLine 1 | ||
pop local 0 | ||
push local 0 | ||
call String.intValue 1 | ||
pop local 1 | ||
push local 0 | ||
call String.dispose 1 | ||
pop temp 0 | ||
push local 1 | ||
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,17 @@ | ||
// This file is part of www.nand2tetris.org | ||
// and the book "The Elements of Computing Systems" | ||
// by Nisan and Schocken, MIT Press. | ||
// File name: projects/11/Seven/Main.jack | ||
|
||
/** | ||
* Computes the value of 1 + (2 * 3) and prints the result | ||
* at the top-left of the screen. | ||
*/ | ||
class Main { | ||
|
||
function void main() { | ||
do Output.printInt(1 + (2 * 3)); | ||
return; | ||
} | ||
|
||
} |
Oops, something went wrong.