29 files changed, 341 insertions(+), 497 deletions(-)
A .gitignore
A .idea/compiler.xml
R 06/hack-assembler/.idea/encodings.xml => .idea/encodings.xml
A .idea/kotlinc.xml
A .idea/misc.xml
R 06/hack-assembler/.idea/modules.xml => .idea/modules.xml
A .idea/vcs.xml
A 06/hack-assembler/.DS_Store
M 06/hack-assembler/.gitignore
D 06/hack-assembler/.idea/.name
D 06/hack-assembler/.idea/compiler.xml
D 06/hack-assembler/.idea/copyright/profiles_settings.xml
D 06/hack-assembler/.idea/misc.xml
D 06/hack-assembler/build.gradle
D 06/hack-assembler/gradle/wrapper/gradle-wrapper.jar
D 06/hack-assembler/gradle/wrapper/gradle-wrapper.properties
D 06/hack-assembler/gradlew
D 06/hack-assembler/gradlew.bat
M 06/hack-assembler/hack-assembler.iml
A 06/hack-assembler/pom.xml
D 06/hack-assembler/settings.gradle
R 06/hack-assembler/src/main/{kotlin/assembler/Commands.kt => hackassembler/Commands.kt}
R 06/hack-assembler/src/main/{kotlin/assembler/Main.kt => hackassembler/Main.kt}
R 06/hack-assembler/src/main/{kotlin/assembler/Parser.kt => hackassembler/Parser.kt}
R 06/hack-assembler/src/main/{kotlin/assembler/translation/BinaryCodes.kt => hackassembler/translation/BinaryCodes.kt}
R 06/hack-assembler/src/main/{kotlin/assembler/translation/DefaultSymbolTable.kt => hackassembler/translation/DefaultSymbolTable.kt}
R 06/hack-assembler/src/test/{kotlin/assembler/CommandsTests.kt => hackassembler/CommandsTest.kt}
R 06/hack-assembler/src/test/{kotlin/assembler/ParserTests.kt => hackassembler/ParserTest.kt}
A nand2tetris-projects.iml
A .gitignore => .gitignore +76 -0
@@ 0,0 1,76 @@
+# Created by .ignore support plugin (hsz.mobi)
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff:
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/dictionaries
+
+# Sensitive or high-churn files:
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.xml
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+
+# Gradle:
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# CMake
+cmake-build-debug/
+cmake-build-release/
+
+# Mongo Explorer plugin:
+.idea/**/mongoSettings.xml
+
+## File-based project format:
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+### Kotlin template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
A .idea/compiler.xml => .idea/compiler.xml +16 -0
@@ 0,0 1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="CompilerConfiguration">
+ <annotationProcessing>
+ <profile name="Maven default annotation processors profile" enabled="true">
+ <sourceOutputDir name="target/generated-sources/annotations" />
+ <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+ <outputRelativeToContentRoot value="true" />
+ <module name="hack-assembler" />
+ </profile>
+ </annotationProcessing>
+ <bytecodeTargetLevel>
+ <module name="hack-assembler" target="1.5" />
+ </bytecodeTargetLevel>
+ </component>
+</project><
\ No newline at end of file
R 06/hack-assembler/.idea/encodings.xml => .idea/encodings.xml +1 -1
@@ 1,6 1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
- <file url="PROJECT" charset="UTF-8" />
+ <file url="file://$PROJECT_DIR$/06/hack-assembler" charset="UTF-8" />
</component>
</project>=
\ No newline at end of file
A .idea/kotlinc.xml => .idea/kotlinc.xml +7 -0
@@ 0,0 1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Kotlin2JsCompilerArguments">
+ <option name="sourceMapEmbedSources" />
+ <option name="sourceMapPrefix" />
+ </component>
+</project><
\ No newline at end of file
A .idea/misc.xml => .idea/misc.xml +13 -0
@@ 0,0 1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="MavenProjectsManager">
+ <option name="originalFiles">
+ <list>
+ <option value="$PROJECT_DIR$/06/hack-assembler/pom.xml" />
+ </list>
+ </option>
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/out" />
+ </component>
+</project><
\ No newline at end of file
R 06/hack-assembler/.idea/modules.xml => .idea/modules.xml +2 -1
@@ 2,7 2,8 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
- <module fileurl="file://$PROJECT_DIR$/hack-assembler.iml" filepath="$PROJECT_DIR$/hack-assembler.iml" />
+ <module fileurl="file://$PROJECT_DIR$/06/hack-assembler/hack-assembler.iml" filepath="$PROJECT_DIR$/06/hack-assembler/hack-assembler.iml" />
+ <module fileurl="file://$PROJECT_DIR$/nand2tetris-projects.iml" filepath="$PROJECT_DIR$/nand2tetris-projects.iml" />
</modules>
</component>
</project>=
\ No newline at end of file
A .idea/vcs.xml => .idea/vcs.xml +6 -0
@@ 0,0 1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="" vcs="Git" />
+ </component>
+</project><
\ No newline at end of file
A 06/hack-assembler/.DS_Store => 06/hack-assembler/.DS_Store +0 -0
M 06/hack-assembler/.gitignore => 06/hack-assembler/.gitignore +58 -43
@@ 1,31 1,32 @@
-
-# Created by https://www.gitignore.io/api/intellij,gradle
-
-### Intellij ###
+# Created by .ignore support plugin (hsz.mobi)
+### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
-.idea/workspace.xml
-.idea/tasks.xml
+.idea/**/workspace.xml
+.idea/**/tasks.xml
.idea/dictionaries
-.idea/vcs.xml
-.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
-.idea/dataSources.ids
-.idea/dataSources.xml
-.idea/dataSources.local.xml
-.idea/sqlDataSources.xml
-.idea/dynamic.xml
-.idea/uiDesigner.xml
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.xml
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
# Gradle:
-.idea/gradle.xml
-.idea/libraries
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# CMake
+cmake-build-debug/
+cmake-build-release/
# Mongo Explorer plugin:
-.idea/mongoSettings.xml
+.idea/**/mongoSettings.xml
## File-based project format:
*.iws
@@ 33,7 34,7 @@
## Plugin-specific files:
# IntelliJ
-/out/
+out/
# mpeltonen/sbt-idea plugin
.idea_modules/
@@ 41,33 42,47 @@
# JIRA plugin
atlassian-ide-plugin.xml
+# Cursive Clojure plugin
+.idea/replstate.xml
+
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
-
-### Intellij Patch ###
-# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
-
-# *.iml
-# modules.xml
-# .idea/misc.xml
-# *.ipr
-
-
-### Gradle ###
-.gradle
-build/
-
-# Ignore Gradle GUI config
-gradle-app.setting
-
-# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
-!gradle-wrapper.jar
-
-# Cache of project
-.gradletasknamecache
-
-# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
-# gradle/wrapper/gradle-wrapper.properties
+### Kotlin template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+### Maven template
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+
+# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
+!/.mvn/wrapper/maven-wrapper.jar
D 06/hack-assembler/.idea/.name => 06/hack-assembler/.idea/.name +0 -1
@@ 1,1 0,0 @@
-hack-assembler>
\ No newline at end of file
D 06/hack-assembler/.idea/compiler.xml => 06/hack-assembler/.idea/compiler.xml +0 -22
@@ 1,22 0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="CompilerConfiguration">
- <resourceExtensions />
- <wildcardResourcePatterns>
- <entry name="!?*.java" />
- <entry name="!?*.form" />
- <entry name="!?*.class" />
- <entry name="!?*.groovy" />
- <entry name="!?*.scala" />
- <entry name="!?*.flex" />
- <entry name="!?*.kt" />
- <entry name="!?*.clj" />
- <entry name="!?*.aj" />
- </wildcardResourcePatterns>
- <annotationProcessing>
- <profile default="true" name="Default" enabled="false">
- <processorPath useClasspath="true" />
- </profile>
- </annotationProcessing>
- </component>
-</project>>
\ No newline at end of file
D 06/hack-assembler/.idea/copyright/profiles_settings.xml => 06/hack-assembler/.idea/copyright/profiles_settings.xml +0 -3
@@ 1,3 0,0 @@
-<component name="CopyrightManager">
- <settings default="" />
-</component>>
\ No newline at end of file
D 06/hack-assembler/.idea/misc.xml => 06/hack-assembler/.idea/misc.xml +0 -62
@@ 1,62 0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="ClientPropertiesManager">
- <properties class="javax.swing.AbstractButton">
- <property name="hideActionText" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JComponent">
- <property name="html.disable" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JEditorPane">
- <property name="JEditorPane.w3cLengthUnits" class="java.lang.Boolean" />
- <property name="JEditorPane.honorDisplayProperties" class="java.lang.Boolean" />
- <property name="charset" class="java.lang.String" />
- </properties>
- <properties class="javax.swing.JList">
- <property name="List.isFileList" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JPasswordField">
- <property name="JPasswordField.cutCopyAllowed" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JSlider">
- <property name="Slider.paintThumbArrowShape" class="java.lang.Boolean" />
- <property name="JSlider.isFilled" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JTable">
- <property name="Table.isFileList" class="java.lang.Boolean" />
- <property name="JTable.autoStartsEdit" class="java.lang.Boolean" />
- <property name="terminateEditOnFocusLost" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JToolBar">
- <property name="JToolBar.isRollover" class="java.lang.Boolean" />
- </properties>
- <properties class="javax.swing.JTree">
- <property name="JTree.lineStyle" class="java.lang.String" />
- </properties>
- <properties class="javax.swing.text.JTextComponent">
- <property name="caretAspectRatio" class="java.lang.Double" />
- <property name="caretWidth" class="java.lang.Integer" />
- </properties>
- </component>
- <component name="EntryPointsManager">
- <entry_points version="2.0" />
- </component>
- <component name="HaskellBuildOptions">
- <ghcPath>/usr/local/bin/ghc</ghcPath>
- <cabalPath>/usr/local/bin/cabal</cabalPath>
- <stackPath>/usr/local/bin/stack</stackPath>
- </component>
- <component name="ProjectLevelVcsManager" settingsEditedManually="false">
- <OptionsSetting value="true" id="Add" />
- <OptionsSetting value="true" id="Remove" />
- <OptionsSetting value="true" id="Checkout" />
- <OptionsSetting value="true" id="Update" />
- <OptionsSetting value="true" id="Status" />
- <OptionsSetting value="true" id="Edit" />
- <ConfirmationsSetting value="0" id="Add" />
- <ConfirmationsSetting value="0" id="Remove" />
- </component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
- <output url="file://$PROJECT_DIR$/build/classes" />
- </component>
-</project>>
\ No newline at end of file
D 06/hack-assembler/build.gradle => 06/hack-assembler/build.gradle +0 -43
@@ 1,43 0,0 @@
-group 'com.macaptain'
-version '1.1'
-
-buildscript {
- ext.kotlin_version = '1.0.3'
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- }
-}
-
-apply plugin: 'idea'
-apply plugin: 'kotlin'
-apply plugin: 'application'
-
-mainClassName = "assembler.MainKt"
-
-repositories {
- mavenCentral()
-}
-
-dependencies {
- compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
- compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
- testCompile 'junit:junit:4.12'
- testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
-}
-
-run {
- if ( project.hasProperty("appArgs") ) {
- args Eval.me(appArgs)
- }
-}
-
-jar {
- manifest {
- attributes 'Main-Class': mainClassName
- }
-
- from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
-}
D 06/hack-assembler/gradle/wrapper/gradle-wrapper.jar => 06/hack-assembler/gradle/wrapper/gradle-wrapper.jar +0 -0
D 06/hack-assembler/gradle/wrapper/gradle-wrapper.properties => 06/hack-assembler/gradle/wrapper/gradle-wrapper.properties +0 -6
@@ 1,6 0,0 @@
-#Fri Jul 01 01:51:16 BST 2016
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
D 06/hack-assembler/gradlew => 06/hack-assembler/gradlew +0 -164
@@ 1,164 0,0 @@
-#!/usr/bin/env bash
-
-##############################################################################
-##
-## Gradle start up script for UN*X
-##
-##############################################################################
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
-
-warn ( ) {
- echo "$*"
-}
-
-die ( ) {
- echo
- echo "$*"
- echo
- exit 1
-}
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
-esac
-
-# For Cygwin, ensure paths are in UNIX format before anything is touched.
-if $cygwin ; then
- [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
-fi
-
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >&-
-APP_HOME="`pwd -P`"
-cd "$SAVED" >&-
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-# Determine the Java command to use to start the JVM.
-if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- if [ ! -x "$JAVACMD" ] ; then
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
- fi
-else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
- fi
- i=$((i+1))
- done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
-fi
-
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
-function splitJvmOpts() {
- JVM_OPTS=("$@")
-}
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
-
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
D 06/hack-assembler/gradlew.bat => 06/hack-assembler/gradlew.bat +0 -90
@@ 1,90 0,0 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
M 06/hack-assembler/hack-assembler.iml => 06/hack-assembler/hack-assembler.iml +31 -21
@@ 1,28 1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id="hack-assembler" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.macaptain" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/build/classes/main" />
- <output-test url="file://$MODULE_DIR$/build/classes/test" />
- <exclude-output />
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="kotlin-language" name="Kotlin">
+ <configuration version="3" platform="JVM 1.6" useProjectSettings="false">
+ <compilerSettings />
+ <compilerArguments>
+ <option name="languageVersion" value="1.2" />
+ <option name="apiVersion" value="1.2" />
+ <option name="pluginOptions">
+ <array />
+ </option>
+ <option name="pluginClasspaths">
+ <array />
+ </option>
+ </compilerArguments>
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
- <excludeFolder url="file://$MODULE_DIR$/.gradle" />
- <excludeFolder url="file://$MODULE_DIR$/build" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.0.3" level="project" />
- <orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-runtime:1.0.3" level="project" />
- <orderEntry type="library" name="Gradle: org.apache.commons:commons-io:1.3.2" level="project" />
- <orderEntry type="library" name="Gradle: commons-io:commons-io:1.3.2" level="project" />
- <orderEntry type="library" scope="TEST" name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.0.3" level="project" />
- <orderEntry type="library" scope="TEST" name="Gradle: org.jetbrains.kotlin:kotlin-test:1.0.3" level="project" />
- <orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.12" level="project" />
- <orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
+ <orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.2.21" level="project" />
+ <orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test-junit:1.2.21" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-test:1.2.21" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
+ <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
</component>
</module>=
\ No newline at end of file
A 06/hack-assembler/pom.xml => 06/hack-assembler/pom.xml +73 -0
@@ 0,0 1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.macaptain</groupId>
+ <artifactId>hack-assembler</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>com.macaptain hack-hackassembler</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <kotlin.version>1.2.21</kotlin.version>
+ <junit.version>4.12</junit.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-stdlib</artifactId>
+ <version>${kotlin.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-test-junit</artifactId>
+ <version>${kotlin.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <sourceDirectory>src/main</sourceDirectory>
+ <testSourceDirectory>src/test</testSourceDirectory>
+
+ <plugins>
+ <plugin>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-maven-plugin</artifactId>
+ <version>${kotlin.version}</version>
+ <executions>
+ <execution>
+ <id>compile</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>test-compile</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>test-compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
D 06/hack-assembler/settings.gradle => 06/hack-assembler/settings.gradle +0 -2
@@ 1,2 0,0 @@
-rootProject.name = 'hack-assembler'
-
R 06/hack-assembler/src/main/kotlin/assembler/Commands.kt => 06/hack-assembler/src/main/hackassembler/Commands.kt +5 -5
@@ 1,9 1,9 @@
-package assembler
+package hackassembler
-import assembler.translation.compMap
-import assembler.translation.destMap
-import assembler.translation.jumpMap
-import assembler.translation.toZeroPaddedBinary
+import hackassembler.translation.compMap
+import hackassembler.translation.destMap
+import hackassembler.translation.jumpMap
+import hackassembler.translation.toZeroPaddedBinary
import java.util.*
interface Command {
R 06/hack-assembler/src/main/kotlin/assembler/Main.kt => 06/hack-assembler/src/main/hackassembler/Main.kt +3 -4
@@ 1,10 1,9 @@
-package assembler
+package hackassembler
import org.apache.commons.io.FilenameUtils
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
-import java.util.*
/**
* Take an ASM file specified as command line argument args[0], parses it and writes the machine
@@ 22,7 21,7 @@ fun main(args: Array<String>) {
val parser = Parser(reader)
val codes = parser.generateMachineCodes()
- File(outFileName).printWriter().use {
- out -> codes.forEach { out.println(it) }
+ File(outFileName).printWriter().use { out ->
+ codes.forEach { out.println(it) }
}
}=
\ No newline at end of file
R 06/hack-assembler/src/main/kotlin/assembler/Parser.kt => 06/hack-assembler/src/main/hackassembler/Parser.kt +5 -6
@@ 1,7 1,7 @@
-package assembler
+package hackassembler
-import assembler.translation.MAX_MEMORY
-import assembler.translation.defaultSymbolTable
+import hackassembler.translation.MAX_MEMORY
+import hackassembler.translation.defaultSymbolTable
import java.io.BufferedReader
import java.util.*
@@ 13,7 13,7 @@ import java.util.*
class Parser(val reader: BufferedReader) {
val lines by lazy {
- reader.readLines().map{ removeWhitespace(it) }.map { removeComments(it) }
+ reader.readLines().map { removeWhitespace(it) }.map { removeComments(it) }
}
private val symbolTable by lazy {
@@ 36,8 36,7 @@ class Parser(val reader: BufferedReader) {
try {
val command = parseLine(line)
codes.add(command?.toMachineCode())
- }
- catch (e: InputMismatchException) {
+ } catch (e: InputMismatchException) {
val message = e.message
val lineNumber = idx + 1
throw InputMismatchException("Couldn't parse line number: $lineNumber: $line\n$message")
R 06/hack-assembler/src/main/kotlin/assembler/translation/BinaryCodes.kt => 06/hack-assembler/src/main/hackassembler/translation/BinaryCodes.kt +1 -1
@@ 1,4 1,4 @@
-package assembler.translation
+package hackassembler.translation
/**
* Returns a string of the integer converted to binary, left padded with 0 to be of length @length
R 06/hack-assembler/src/main/kotlin/assembler/translation/DefaultSymbolTable.kt => 06/hack-assembler/src/main/hackassembler/translation/DefaultSymbolTable.kt +1 -1
@@ 1,4 1,4 @@
-package assembler.translation
+package hackassembler.translation
const val MAX_MEMORY = 24576
R 06/hack-assembler/src/test/kotlin/assembler/CommandsTests.kt => 06/hack-assembler/src/test/hackassembler/CommandsTest.kt +10 -6
@@ 1,23 1,27 @@
-package assembler
+package hackassembler
import org.junit.Test
import kotlin.test.assertEquals
-class CommandsTests {
- @Test fun ACommandShouldConvertToValidMachineCode() {
+class CommandsTest {
+ @Test
+ fun ACommandShouldConvertToValidMachineCode() {
val actual = ACommand(address = 5).toMachineCode()
val expected = "0000000000000101"
assertEquals(expected, actual)
}
- @Test fun CCommandShouldConvertToValidMachineCode() {
- val actual = CCommand(dest="AMD", comp="D+1", jump="JEQ").toMachineCode()
+
+ @Test
+ fun CCommandShouldConvertToValidMachineCode() {
+ val actual = CCommand(dest = "AMD", comp = "D+1", jump = "JEQ").toMachineCode()
val expected = "1110011111111010"
assertEquals(expected, actual)
}
- @Test fun LCommandShouldConvertToNullMachineCode() {
+ @Test
+ fun LCommandShouldConvertToNullMachineCode() {
val actual = LCommand("FOO").toMachineCode()
val expected = null
R 06/hack-assembler/src/test/kotlin/assembler/ParserTests.kt => 06/hack-assembler/src/test/hackassembler/ParserTest.kt +24 -15
@@ 1,4 1,4 @@
-package assembler
+package hackassembler
import org.junit.Test
import java.io.BufferedReader
@@ 6,11 6,12 @@ import java.io.StringReader
import java.util.*
import kotlin.test.assertEquals
-class ParserTests {
+class ParserTest {
val FIRST_NEW_RAM_ADDRESS = 16
- @Test fun lCommandsShouldMapToRomAddresses() {
+ @Test
+ fun lCommandsShouldMapToRomAddresses() {
val asm = "(ROMADDRESS0)\n@ROMADDRESS0"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(ACommand(0)).map { it.toMachineCode() }
@@ 18,16 19,18 @@ class ParserTests {
assertEquals(expected, actual)
}
- @Test fun symbolicACommandsShouldMapToRamAddresses() {
+ @Test
+ fun symbolicACommandsShouldMapToRamAddresses() {
val asm = "@ram.address\n@ram.address"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(ACommand(FIRST_NEW_RAM_ADDRESS), ACommand(FIRST_NEW_RAM_ADDRESS))
- .map { it.toMachineCode() }
+ .map { it.toMachineCode() }
assertEquals(expected, actual)
}
- @Test fun defaultSymbolicAddressShouldMapToACommand() {
+ @Test
+ fun defaultSymbolicAddressShouldMapToACommand() {
val asm = "@LCL"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(ACommand(1)).map { it.toMachineCode() }
@@ 35,7 38,8 @@ class ParserTests {
assertEquals(expected, actual)
}
- @Test fun parseRawAddressShouldReturnACommand() {
+ @Test
+ fun parseRawAddressShouldReturnACommand() {
val asm = "@1923"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(ACommand(1923)).map { it.toMachineCode() }
@@ 43,29 47,32 @@ class ParserTests {
assertEquals(expected, actual)
}
- @Test fun parseDestCompInstructionShouldReturnCCommand() {
+ @Test
+ fun parseDestCompInstructionShouldReturnCCommand() {
val asm = "M=D"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(CCommand(dest = "M", comp = "D", jump = ""))
- .map { it.toMachineCode() }
+ .map { it.toMachineCode() }
assertEquals(expected, actual)
}
- @Test fun parseCompJumpInstructionShouldReturnCCommand() {
+ @Test
+ fun parseCompJumpInstructionShouldReturnCCommand() {
val asm = "0; JMP"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(CCommand(dest = "", comp = "0", jump = "JMP"))
- .map { it.toMachineCode() }
+ .map { it.toMachineCode() }
assertEquals(expected, actual)
}
- @Test fun parseDestCompJumpInstructionShouldReturnCCommand() {
+ @Test
+ fun parseDestCompJumpInstructionShouldReturnCCommand() {
val asm = "AM=D+1; JMP"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(CCommand(dest = "AM", comp = "D+1", jump = "JMP"))
- .map { it.toMachineCode() }
+ .map { it.toMachineCode() }
assertEquals(expected, actual)
}
@@ 76,7 83,8 @@ class ParserTests {
setUpParser(asm).generateMachineCodes()
}
- @Test fun commentsAndWhitespaceShouldBeSkipped() {
+ @Test
+ fun commentsAndWhitespaceShouldBeSkipped() {
val asm = "\n\n//Test comment\n"
val actual = setUpParser(asm).generateMachineCodes()
val expected = emptyList<String>()
@@ 84,7 92,8 @@ class ParserTests {
assertEquals(expected, actual)
}
- @Test fun inlineCommentsShouldBeSkipped() {
+ @Test
+ fun inlineCommentsShouldBeSkipped() {
val asm = "@222//Test comment"
val actual = setUpParser(asm).generateMachineCodes()
val expected = listOf(ACommand(222)).map { it.toMachineCode() }
A nand2tetris-projects.iml => nand2tetris-projects.iml +9 -0
@@ 0,0 1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$" />
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module><
\ No newline at end of file