From a000308104aab27c2dde9a306f1bc654b2db4806 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 29 Nov 2017 12:30:41 +0100 Subject: first commit --- projects/10/ExpressionLessSquare/Main.jack | 36 + projects/10/ExpressionLessSquare/Main.xml | 205 +++++ projects/10/ExpressionLessSquare/MainT.xml | 109 +++ projects/10/ExpressionLessSquare/Square.jack | 99 +++ projects/10/ExpressionLessSquare/Square.xml | 967 +++++++++++++++++++++++ projects/10/ExpressionLessSquare/SquareGame.jack | 60 ++ projects/10/ExpressionLessSquare/SquareGame.xml | 544 +++++++++++++ projects/10/ExpressionLessSquare/SquareGameT.xml | 268 +++++++ projects/10/ExpressionLessSquare/SquareT.xml | 449 +++++++++++ 9 files changed, 2737 insertions(+) create mode 100644 projects/10/ExpressionLessSquare/Main.jack create mode 100644 projects/10/ExpressionLessSquare/Main.xml create mode 100644 projects/10/ExpressionLessSquare/MainT.xml create mode 100644 projects/10/ExpressionLessSquare/Square.jack create mode 100644 projects/10/ExpressionLessSquare/Square.xml create mode 100644 projects/10/ExpressionLessSquare/SquareGame.jack create mode 100644 projects/10/ExpressionLessSquare/SquareGame.xml create mode 100644 projects/10/ExpressionLessSquare/SquareGameT.xml create mode 100644 projects/10/ExpressionLessSquare/SquareT.xml (limited to 'projects/10/ExpressionLessSquare') diff --git a/projects/10/ExpressionLessSquare/Main.jack b/projects/10/ExpressionLessSquare/Main.jack new file mode 100644 index 0000000..d2c5561 --- /dev/null +++ b/projects/10/ExpressionLessSquare/Main.jack @@ -0,0 +1,36 @@ +// 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/10/ExpressionLessSquare/Main.jack + +/** Expressionless version of projects/10/Square/Main.jack. */ + +class Main { + static boolean test; // Added for testing -- there is no static keyword + // in the Square files. + + function void main() { + var SquareGame game; + let game = game; + do game.run(); + do game.dispose(); + return; + } + + function void test() { // Added to test Jack syntax that is not use in + var int i, j; // the Square files. + var String s; + var Array a; + if (i) { + let s = i; + let s = j; + let a[i] = j; + } + else { // There is no else keyword in the Square files. + let i = i; + let j = j; + let i = i | j; + } + return; + } +} diff --git a/projects/10/ExpressionLessSquare/Main.xml b/projects/10/ExpressionLessSquare/Main.xml new file mode 100644 index 0000000..6beb694 --- /dev/null +++ b/projects/10/ExpressionLessSquare/Main.xml @@ -0,0 +1,205 @@ + + class + Main + { + + static + boolean + test + ; + + + function + void + main + ( + + + ) + + { + + var + SquareGame + game + ; + + + + let + game + = + + + game + + + ; + + + do + game + . + run + ( + + + ) + ; + + + do + game + . + dispose + ( + + + ) + ; + + + return + ; + + + } + + + + function + void + test + ( + + + ) + + { + + var + int + i + , + j + ; + + + var + String + s + ; + + + var + Array + a + ; + + + + if + ( + + + i + + + ) + { + + + let + s + = + + + i + + + ; + + + let + s + = + + + j + + + ; + + + let + a + [ + + + i + + + ] + = + + + j + + + ; + + + } + else + { + + + let + i + = + + + i + + + ; + + + let + j + = + + + j + + + ; + + + let + i + = + + + i + + | + + j + + + ; + + + } + + + return + ; + + + } + + + } + diff --git a/projects/10/ExpressionLessSquare/MainT.xml b/projects/10/ExpressionLessSquare/MainT.xml new file mode 100644 index 0000000..f074ba4 --- /dev/null +++ b/projects/10/ExpressionLessSquare/MainT.xml @@ -0,0 +1,109 @@ + + class + Main + { + static + boolean + test + ; + function + void + main + ( + ) + { + var + SquareGame + game + ; + let + game + = + game + ; + do + game + . + run + ( + ) + ; + do + game + . + dispose + ( + ) + ; + return + ; + } + function + void + test + ( + ) + { + var + int + i + , + j + ; + var + String + s + ; + var + Array + a + ; + if + ( + i + ) + { + let + s + = + i + ; + let + s + = + j + ; + let + a + [ + i + ] + = + j + ; + } + else + { + let + i + = + i + ; + let + j + = + j + ; + let + i + = + i + | + j + ; + } + return + ; + } + } + diff --git a/projects/10/ExpressionLessSquare/Square.jack b/projects/10/ExpressionLessSquare/Square.jack new file mode 100644 index 0000000..33a54ad --- /dev/null +++ b/projects/10/ExpressionLessSquare/Square.jack @@ -0,0 +1,99 @@ +// 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/10/ExpressionLessSquare/Square.jack + +/** Expressionless version of projects/10/Square/Square.jack. */ + +class Square { + + field int x, y; + field int size; + + constructor Square new(int Ax, int Ay, int Asize) { + let x = Ax; + let y = Ay; + let size = Asize; + do draw(); + return x; + } + + method void dispose() { + do Memory.deAlloc(this); + return; + } + + method void draw() { + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + return; + } + + method void erase() { + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + return; + } + + method void incSize() { + if (x) { + do erase(); + let size = size; + do draw(); + } + return; + } + + method void decSize() { + if (size) { + do erase(); + let size = size; + do draw(); + } + return; + } + + method void moveUp() { + if (y) { + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + let y = y; + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + } + return; + } + + method void moveDown() { + if (y) { + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + let y = y; + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + } + return; + } + + method void moveLeft() { + if (x) { + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + let x = x; + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + } + return; + } + + method void moveRight() { + if (x) { + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + let x = x; + do Screen.setColor(x); + do Screen.drawRectangle(x, y, x, y); + } + return; + } +} diff --git a/projects/10/ExpressionLessSquare/Square.xml b/projects/10/ExpressionLessSquare/Square.xml new file mode 100644 index 0000000..ed0e6ec --- /dev/null +++ b/projects/10/ExpressionLessSquare/Square.xml @@ -0,0 +1,967 @@ + + class + Square + { + + field + int + x + , + y + ; + + + field + int + size + ; + + + constructor + Square + new + ( + + int + Ax + , + int + Ay + , + int + Asize + + ) + + { + + + let + x + = + + + Ax + + + ; + + + let + y + = + + + Ay + + + ; + + + let + size + = + + + Asize + + + ; + + + do + draw + ( + + + ) + ; + + + return + + + x + + + ; + + + } + + + + method + void + dispose + ( + + + ) + + { + + + do + Memory + . + deAlloc + ( + + + + this + + + + ) + ; + + + return + ; + + + } + + + + method + void + draw + ( + + + ) + + { + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + return + ; + + + } + + + + method + void + erase + ( + + + ) + + { + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + return + ; + + + } + + + + method + void + incSize + ( + + + ) + + { + + + if + ( + + + x + + + ) + { + + + do + erase + ( + + + ) + ; + + + let + size + = + + + size + + + ; + + + do + draw + ( + + + ) + ; + + + } + + + return + ; + + + } + + + + method + void + decSize + ( + + + ) + + { + + + if + ( + + + size + + + ) + { + + + do + erase + ( + + + ) + ; + + + let + size + = + + + size + + + ; + + + do + draw + ( + + + ) + ; + + + } + + + return + ; + + + } + + + + method + void + moveUp + ( + + + ) + + { + + + if + ( + + + y + + + ) + { + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + let + y + = + + + y + + + ; + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + } + + + return + ; + + + } + + + + method + void + moveDown + ( + + + ) + + { + + + if + ( + + + y + + + ) + { + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + let + y + = + + + y + + + ; + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + } + + + return + ; + + + } + + + + method + void + moveLeft + ( + + + ) + + { + + + if + ( + + + x + + + ) + { + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + let + x + = + + + x + + + ; + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + } + + + return + ; + + + } + + + + method + void + moveRight + ( + + + ) + + { + + + if + ( + + + x + + + ) + { + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + let + x + = + + + x + + + ; + + + do + Screen + . + setColor + ( + + + + x + + + + ) + ; + + + do + Screen + . + drawRectangle + ( + + + + x + + + , + + + y + + + , + + + x + + + , + + + y + + + + ) + ; + + + } + + + return + ; + + + } + + + } + diff --git a/projects/10/ExpressionLessSquare/SquareGame.jack b/projects/10/ExpressionLessSquare/SquareGame.jack new file mode 100644 index 0000000..2866f0d --- /dev/null +++ b/projects/10/ExpressionLessSquare/SquareGame.jack @@ -0,0 +1,60 @@ +// 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/10/ExpressionLessSquare/SquareGame.jack + +/** Expressionless version of projects/10/Square/SquareGame.jack. */ + +class SquareGame { + field Square square; + field int direction; + + constructor SquareGame new() { + let square = square; + let direction = direction; + return square; + } + + method void dispose() { + do square.dispose(); + do Memory.deAlloc(square); + return; + } + + method void moveSquare() { + if (direction) { do square.moveUp(); } + if (direction) { do square.moveDown(); } + if (direction) { do square.moveLeft(); } + if (direction) { do square.moveRight(); } + do Sys.wait(direction); + return; + } + + method void run() { + var char key; + var boolean exit; + + let exit = key; + while (exit) { + while (key) { + let key = key; + do moveSquare(); + } + + if (key) { let exit = exit; } + if (key) { do square.decSize(); } + if (key) { do square.incSize(); } + if (key) { let direction = exit; } + if (key) { let direction = key; } + if (key) { let direction = square; } + if (key) { let direction = direction; } + + while (key) { + let key = key; + do moveSquare(); + } + } + return; + } +} + diff --git a/projects/10/ExpressionLessSquare/SquareGame.xml b/projects/10/ExpressionLessSquare/SquareGame.xml new file mode 100644 index 0000000..288c6cd --- /dev/null +++ b/projects/10/ExpressionLessSquare/SquareGame.xml @@ -0,0 +1,544 @@ + + class + SquareGame + { + + field + Square + square + ; + + + field + int + direction + ; + + + constructor + SquareGame + new + ( + + + ) + + { + + + let + square + = + + + square + + + ; + + + let + direction + = + + + direction + + + ; + + + return + + + square + + + ; + + + } + + + + method + void + dispose + ( + + + ) + + { + + + do + square + . + dispose + ( + + + ) + ; + + + do + Memory + . + deAlloc + ( + + + + square + + + + ) + ; + + + return + ; + + + } + + + + method + void + moveSquare + ( + + + ) + + { + + + if + ( + + + direction + + + ) + { + + + do + square + . + moveUp + ( + + + ) + ; + + + } + + + if + ( + + + direction + + + ) + { + + + do + square + . + moveDown + ( + + + ) + ; + + + } + + + if + ( + + + direction + + + ) + { + + + do + square + . + moveLeft + ( + + + ) + ; + + + } + + + if + ( + + + direction + + + ) + { + + + do + square + . + moveRight + ( + + + ) + ; + + + } + + + do + Sys + . + wait + ( + + + + direction + + + + ) + ; + + + return + ; + + + } + + + + method + void + run + ( + + + ) + + { + + var + char + key + ; + + + var + boolean + exit + ; + + + + let + exit + = + + + key + + + ; + + + while + ( + + + exit + + + ) + { + + + while + ( + + + key + + + ) + { + + + let + key + = + + + key + + + ; + + + do + moveSquare + ( + + + ) + ; + + + } + + + if + ( + + + key + + + ) + { + + + let + exit + = + + + exit + + + ; + + + } + + + if + ( + + + key + + + ) + { + + + do + square + . + decSize + ( + + + ) + ; + + + } + + + if + ( + + + key + + + ) + { + + + do + square + . + incSize + ( + + + ) + ; + + + } + + + if + ( + + + key + + + ) + { + + + let + direction + = + + + exit + + + ; + + + } + + + if + ( + + + key + + + ) + { + + + let + direction + = + + + key + + + ; + + + } + + + if + ( + + + key + + + ) + { + + + let + direction + = + + + square + + + ; + + + } + + + if + ( + + + key + + + ) + { + + + let + direction + = + + + direction + + + ; + + + } + + + while + ( + + + key + + + ) + { + + + let + key + = + + + key + + + ; + + + do + moveSquare + ( + + + ) + ; + + + } + + + } + + + return + ; + + + } + + + } + diff --git a/projects/10/ExpressionLessSquare/SquareGameT.xml b/projects/10/ExpressionLessSquare/SquareGameT.xml new file mode 100644 index 0000000..278a8a9 --- /dev/null +++ b/projects/10/ExpressionLessSquare/SquareGameT.xml @@ -0,0 +1,268 @@ + + class + SquareGame + { + field + Square + square + ; + field + int + direction + ; + constructor + SquareGame + new + ( + ) + { + let + square + = + square + ; + let + direction + = + direction + ; + return + square + ; + } + method + void + dispose + ( + ) + { + do + square + . + dispose + ( + ) + ; + do + Memory + . + deAlloc + ( + square + ) + ; + return + ; + } + method + void + moveSquare + ( + ) + { + if + ( + direction + ) + { + do + square + . + moveUp + ( + ) + ; + } + if + ( + direction + ) + { + do + square + . + moveDown + ( + ) + ; + } + if + ( + direction + ) + { + do + square + . + moveLeft + ( + ) + ; + } + if + ( + direction + ) + { + do + square + . + moveRight + ( + ) + ; + } + do + Sys + . + wait + ( + direction + ) + ; + return + ; + } + method + void + run + ( + ) + { + var + char + key + ; + var + boolean + exit + ; + let + exit + = + key + ; + while + ( + exit + ) + { + while + ( + key + ) + { + let + key + = + key + ; + do + moveSquare + ( + ) + ; + } + if + ( + key + ) + { + let + exit + = + exit + ; + } + if + ( + key + ) + { + do + square + . + decSize + ( + ) + ; + } + if + ( + key + ) + { + do + square + . + incSize + ( + ) + ; + } + if + ( + key + ) + { + let + direction + = + exit + ; + } + if + ( + key + ) + { + let + direction + = + key + ; + } + if + ( + key + ) + { + let + direction + = + square + ; + } + if + ( + key + ) + { + let + direction + = + direction + ; + } + while + ( + key + ) + { + let + key + = + key + ; + do + moveSquare + ( + ) + ; + } + } + return + ; + } + } + diff --git a/projects/10/ExpressionLessSquare/SquareT.xml b/projects/10/ExpressionLessSquare/SquareT.xml new file mode 100644 index 0000000..cd03a1e --- /dev/null +++ b/projects/10/ExpressionLessSquare/SquareT.xml @@ -0,0 +1,449 @@ + + class + Square + { + field + int + x + , + y + ; + field + int + size + ; + constructor + Square + new + ( + int + Ax + , + int + Ay + , + int + Asize + ) + { + let + x + = + Ax + ; + let + y + = + Ay + ; + let + size + = + Asize + ; + do + draw + ( + ) + ; + return + x + ; + } + method + void + dispose + ( + ) + { + do + Memory + . + deAlloc + ( + this + ) + ; + return + ; + } + method + void + draw + ( + ) + { + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + return + ; + } + method + void + erase + ( + ) + { + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + return + ; + } + method + void + incSize + ( + ) + { + if + ( + x + ) + { + do + erase + ( + ) + ; + let + size + = + size + ; + do + draw + ( + ) + ; + } + return + ; + } + method + void + decSize + ( + ) + { + if + ( + size + ) + { + do + erase + ( + ) + ; + let + size + = + size + ; + do + draw + ( + ) + ; + } + return + ; + } + method + void + moveUp + ( + ) + { + if + ( + y + ) + { + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + let + y + = + y + ; + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + } + return + ; + } + method + void + moveDown + ( + ) + { + if + ( + y + ) + { + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + let + y + = + y + ; + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + } + return + ; + } + method + void + moveLeft + ( + ) + { + if + ( + x + ) + { + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + let + x + = + x + ; + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + } + return + ; + } + method + void + moveRight + ( + ) + { + if + ( + x + ) + { + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + let + x + = + x + ; + do + Screen + . + setColor + ( + x + ) + ; + do + Screen + . + drawRectangle + ( + x + , + y + , + x + , + y + ) + ; + } + return + ; + } + } + -- cgit v1.2.3