Skip to content

Commit

Permalink
Nand2Tetris Sofware Suite
Browse files Browse the repository at this point in the history
  • Loading branch information
icmor committed May 13, 2024
0 parents commit 6ba1b1e
Show file tree
Hide file tree
Showing 153 changed files with 5,951 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tools/Assembler.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@echo off

rem $Id: Assembler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
rem [email protected]

setlocal
if not "%2"=="" goto :USAGE
if "%~1"=="/?" (
:USAGE
echo Usage:
echo Assembler Starts the assembler in interactive mode.
echo Assembler FILE[.asm] Assembles FILE.asm to FILE.hack.
exit -b
)
if not "%~1"=="" (
set "_arg1=%~f1"
)
pushd "%~dp0"
if "%~1"=="" (
start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^
HackAssemblerMain
) else (
echo Assembling "%_arg1%"
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Compilers.jar;bin/lib/AssemblerGUI.jar;bin/lib/TranslatorsGUI.jar" ^
HackAssemblerMain "%_arg1%"
)
popd
32 changes: 32 additions & 0 deletions tools/Assembler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env sh

# $Id: Assembler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
# [email protected]

# User's CDPATH can interfere with cd in this script
unset CDPATH
# Get the true name of this script
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
dir="$PWD"
cd "`dirname "$script"`"
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
then
echo "Usage:"
echo " `basename "$0"` Starts the assembler in interactive mode."
echo " `basename "$0"` FILE[.asm] Assembles FILE.asm to FILE.hack."
elif [ $# -eq 0 ]
then
# Run assembler in interactive mode
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain &
else
# Convert arg1 to an absolute path and run assembler with arg1.
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
then
arg1="$1"
else
arg1="${dir}/$1"
fi
echo Assembling "$arg1"
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Compilers.jar:bin/lib/AssemblerGUI.jar:bin/lib/TranslatorsGUI.jar" HackAssemblerMain "$arg1"
fi

29 changes: 29 additions & 0 deletions tools/CPUEmulator.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@echo off

rem $Id: CPUEmulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $
rem [email protected]

setlocal
if not "%2"=="" goto :USAGE
if "%~1"=="/?" (
:USAGE
echo Usage:
echo CPUEmulator Starts the CPU Emulator in interactive mode.
echo CPUEmulator FILE.tst Starts the CPU Emulator and runs the FILE.tst
echo test script. The success/failure message
echo is printed to the command console.
exit -b
)
if not "%~1"=="" (
set "_arg1=%~f1"
)
pushd "%~dp0"
if "%~1"=="" (
start javaw -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
CPUEmulatorMain
) else (
rem echo Running "%_arg1%"
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
CPUEmulatorMain "%_arg1%"
)
popd
33 changes: 33 additions & 0 deletions tools/CPUEmulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env sh

# $Id: CPUEmulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
# [email protected]

# User's CDPATH can interfere with cd in this script
unset CDPATH
# Get the true name of this script
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
dir="$PWD"
cd "`dirname "$script"`"
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
then
echo "Usage:"
echo " `basename "$0"` Starts the CPU Emulator in interactive mode."
echo " `basename "$0"` FILE.tst Starts the CPU Emulator and runs the File.tst"
echo " test script. The success/failure message"
echo " is printed to the command console."
elif [ $# -eq 0 ]
then
# Run CPU emulator in interactive mode
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" CPUEmulatorMain &
else
# Convert arg1 to an absolute path and run CPU emulator with arg1
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
then
arg1="$1"
else
arg1="${dir}/$1"
fi
# echo Running "$arg1"
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" CPUEmulatorMain "$arg1"
fi
30 changes: 30 additions & 0 deletions tools/HardwareSimulator.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@echo off

rem $Id: HardwareSimulator.bat,v 1.3 2014/05/10 00:52:43 marka Exp $
rem [email protected]

setlocal
if not "%2"=="" goto :USAGE
if "%~1"=="/?" (
:USAGE
echo Usage:
echo HardwareSimulator Starts the Hardware Simulator in
echo interactive mode.
echo HardwareSimulator FILE.tst Starts the Hardware Simulator and runs the
echo FILE.tst test script. The success/failure
echo message is printed to the command console.
exit -b
)
if not "%~1"=="" (
set "_arg1=%~f1"
)
pushd "%~dp0"
if "%~1"=="" (
start javaw -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
HardwareSimulatorMain
) else (
rem echo Running "%_arg1%"
java -classpath "%CLASSPATH%;.;bin/classes;bin/lib/Hack.jar;bin/lib/HackGUI.jar;bin/lib/Simulators.jar;bin/lib/SimulatorsGUI.jar;bin/lib/Compilers.jar" ^
HardwareSimulatorMain "%_arg1%"
)
popd
34 changes: 34 additions & 0 deletions tools/HardwareSimulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env sh

# $Id: HardwareSimulator.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
# [email protected]

# User's CDPATH can interfere with cd in this script
unset CDPATH
# Get the true name of this script
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
dir="$PWD"
cd "`dirname "$script"`"
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
then
echo "Usage:"
echo " `basename "$0"` Starts the Hardware Simulator in"
echo " interactive mode."
echo " `basename "$0"` FILE.tst Starts the Hardware Simulator and runs the"
echo " FILE.tst test script. The success/failure"
echo " message is printed to the command console."
elif [ $# -eq 0 ]
then
# Run hardware simulator in interactive mode
java -classpath "${CLASSPATH}:bin/classes:BuiltIn:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" HardwareSimulatorMain &
else
# Convert arg1 to an absolute path and run hardware simulator with arg1
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
then
arg1="$1"
else
arg1="${dir}/$1"
fi
# echo Running "$arg1"
java -classpath "${CLASSPATH}:bin/classes:BuiltIn:bin/lib/Hack.jar:bin/lib/HackGUI.jar:bin/lib/Simulators.jar:bin/lib/SimulatorsGUI.jar:bin/lib/Compilers.jar" HardwareSimulatorMain "$arg1"
fi
26 changes: 26 additions & 0 deletions tools/JackCompiler.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@echo off

rem $Id: JackCompiler.bat,v 1.2 2014/05/10 00:52:43 marka Exp $
rem [email protected]

setlocal
if not "%2"=="" goto :USAGE
if "%~1"=="/?" (
:USAGE
echo Usage:
echo JackCompiler Compiles all .jack files in the current
echo working directory.
echo JackCompiler DIRECTORY Compiles all .jack files in DIRECTORY.
echo JackCompiler FILE.jack Compiles FILE.jack to FILE.vm.
exit -b
)
if not "%~1"=="" (
set "_arg1=%~f1"
) else (
set "_arg1=%CD%"
)
pushd "%~dp0"
echo Compiling "%_arg1%"
java -classpath "%CLASSPATH%;bin/classes;bin/lib/Hack.jar;bin/lib/Compilers.jar" ^
Hack.Compiler.JackCompiler "%_arg1%"
popd
35 changes: 35 additions & 0 deletions tools/JackCompiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh

# $Id: JackCompiler.sh,v 1.1 2014/06/17 21:14:01 marka Exp $
# [email protected]

# User's CDPATH can interfere with cd in this script
unset CDPATH
# Get the true name of this script
script="`test -L "$0" && readlink -n "$0" || echo "$0"`"
dir="$PWD"
cd "`dirname "$script"`"
if [ \( $# -gt 1 \) -o \( "$1" = "-h" \) -o \( "$1" = "--help" \) ]
then
echo "Usage:"
echo " `basename "$0"` Compiles all .jack files in the current"
echo " working directory."
echo " `basename "$0"` DIRECTORY Compiles all .jack files in DIRECTORY."
echo " `basename "$0"` FILE.jack Compiles FILE.jack to FILE.vm."
else
if [ $# -eq 0 ]
then
# Use current directory as arg1
arg1="$dir"
else
# Convert arg1 to an absolute path
if [ `echo "$1" | sed -e "s/\(.\).*/\1/"` = / ]
then
arg1="$1"
else
arg1="$dir/$1"
fi
fi
echo Compiling "$arg1"
java -classpath "${CLASSPATH}:bin/classes:bin/lib/Hack.jar:bin/lib/Compilers.jar" Hack.Compiler.JackCompiler "$arg1"
fi
23 changes: 23 additions & 0 deletions tools/OS/Array.vm
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
102 changes: 102 additions & 0 deletions tools/OS/Keyboard.vm
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
Loading

0 comments on commit 6ba1b1e

Please sign in to comment.