Skip to content

Instantly share code, notes, and snippets.

@rpbeltran
Last active September 11, 2017 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpbeltran/23f78fe865ac95d1e7a0c02f7ee9b2c5 to your computer and use it in GitHub Desktop.
Save rpbeltran/23f78fe865ac95d1e7a0c02f7ee9b2c5 to your computer and use it in GitHub Desktop.
A build system for testing HDL files for the NAND2TETRIS Hardware Simulator
// Build System for Nand2Tetris HDL Test Files
{
// This says what command to run by default ( should work for OSX and linux )
"cmd": ["../tools/HardwareSimulator.sh", "$file"],
"windows": {
// This says what command to run if you use windows
"cmd": ["../tools/HardwareSimulator", "$file"]
},
// Remove or comment this line to disable use with Build System "Automatic"
"selector": "source.tst",
// Sets the working path to that of the current file
"working_dir": "${file_path:${folder}}",
// Not strictly necessary, just being explicit
"encoding": "utf-8"
}
@rpbeltran
Copy link
Author

rpbeltran commented Sep 11, 2017

Usage Guide

Follow this guide to set up building for Sublime Text 2 or 3. If you encounter any difficulty setting this up, drop a comment here and I'll try to fix it. Currently only tested on OSX, but pretty confident about support for Linux and Windows.

Expected File Structure and Nand2Tertris Tools

First, the build system assumes that your files for NAND2TETRIS projects are all in a common directory along with the tools provided by Nand2Tetris, which has the following structure:

tools
.... your tool files
project folder (named whatever )
.... your project files
project folder (named whatever )
.... your project files
project folder (named whatever )
.... your project files

I can add support for modifying this file structure by setting a custom path for the build script, or for using tools added to the system path if this really bothers anybody, or you can just modify the proper "cmd" line in the build system for your OS if you feel comfortable doing this yourself.

Adding a new Build System to Sublime Text

To add the build system to Sublime Text either download the file and move it to your local Sublime Packages folder, or if you don't know where that is, just follow these steps:

  1. Click on Tools > Build System > New Build System and a new file should open. (Note: It is possible that this is located somewhere slightly different on Windows and/or Linux? I'm not sure.)
  2. Copy and paste the code from this repository into the file
  3. Save the file, and it should default to the correct directory. What you title the file before the extension is the way it will appear in the menu. Make sure the extension is .sublime-build.

Now look in the list of build systems under Tools > Build System and see if it's there. If not, you may have to restart Sublime Text once before it appears.

Usage

This build system will run tst files and show you the output. While viewing a tst file, you may run the build by following these steps:

  1. Click on Tools > Build System > Nand2Tetris_Hardware_tst to set the current build system
  2. Click on Tools > Build or use the shortcut Command + b ( I think it is ctrl + b for windows)
  3. An output console should appear on the bottom of your window with the output of your build.

Reading the Output

The output messages are exactly what you would see if you run the Hardware Simulator through terminal or cmd (which is really all we are doing).

A build of a successful circuit should output something like:

End of script - Comparison ended successfully
[Finished in 0.1s]

A build of a circuit which did not pass all tests should a=output something like:

Comparison failure at line 4
[Finished in 0.2s with exit code 255]

Note: The given line number in this case corresponds to the first entry in the provided cmp file which did not pass

A build of a test script which is syntactically malformed

In script /Users/ryanbeltran/Documents/school/CSCE 312/Project_1/And.tst, Line 1, too many arguments

Note: line number corresponds to line number in your tst file, and the message which follows should sum up the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment