This initiative aims to enhance the Jack programming language by providing a robust set of data structures and utility functions. Jack, being a low-level object-oriented language, lacks a comprehensive standard library found in more mature languages like Java or Python. Our custom standard library addresses this gap, enabling developers to write more efficient and effective code.
This library includes the following features:
- List: A dynamic array that can grow or shrink in size.
- Vector: A resizable array providing efficient index-based access.
- Queue: A first-in-first-out (FIFO) data structure.
- Priority Queue (pQueue): A queue where each element has a priority, and higher priority elements are dequeued first.
- Matrix: A two-dimensional array supporting matrix operations.
- Binary Search Tree (BST): A tree structure that maintains elements in sorted order.
- Hash Table: A data structure that maps keys to values for efficient lookups.
- Set: A collection of unique elements.
- Bubble Sort: A simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
- Insertion Sort: A sorting algorithm that builds the final sorted array one item at a time.
- Selection Sort: A sorting algorithm that repeatedly selects the smallest (or largest) remaining item and moves it to the correct position.
- Quick Sort: A highly efficient sorting algorithm that uses a divide-and-conquer approach
- String Comparison: Compares two strings lexicographically.
- toUppercase: Converts all characters in a string to uppercase.
- toLowercase: Converts all characters in a string to lowercase.
- String Reversal: Reverses the characters in a string.
- Greatest Common Divisor (GCD): Computes the largest number that divides two integers without leaving a remainder.
- Exponentiation: Raises a number to the power of an exponent.
- Finding the Hypotenuse of a Triangle: Calculates the hypotenuse of a right-angled triangle using the Pythagorean theorem.
- Cube Root Calculation: Computes the cube root of a number.
To use the Jack Standard Library, you need:
- The Jack compiler and virtual machine (VM).
- Basic understanding of the Jack programming language.
- Jack Compiler and VM Emulator: Ensure you have the Jack compiler and VM emulator installed. These are typically provided as part of the NAND2Tetris software suite.
- Jack Code: Make sure you have your Jack code files ready.
Create your Jack code file(s) with a .jack extension. For example, you might have a file named Main.jack.
-
Open the Jack Compiler: Open the Jack compiler. This can be done using the command line or the graphical interface provided by NAND2Tetris.
-
Select the Directory: Choose the directory where your
.jackfiles are located. The compiler will process all.jackfiles in the selected directory. -
Compile the Code: Start the compilation process. The compiler will convert the Jack code into VM code, generating
.vmfiles.
If you are using the command line, navigate to the directory containing your Jack files and run:
JackCompiler Main.jackThis will generate a Main.vm file in the same directory.
-
Open the VM Emulator: Open the VM emulator provided by NAND2Tetris.
-
Load the VM Code: In the VM emulator, load the
.vmfile(s) generated by the compiler.- Click on the "Load Program" button.
- Navigate to the directory containing the
.vmfiles. - Select the appropriate
.vmfile(s). For example, selectBubbleSort.vmandMain.vm.
-
Configure the VM Emulator: Ensure the VM emulator is set up correctly. You may need to configure the memory, CPU, and other settings based on your program requirements.
-
Run the VM Code: Start the execution of the VM code.
-
You can step through the code line by line using the "Step" button.
-
Use the "Run" button to execute the code continuously.
-
- Step: Executes one VM instruction at a time.
- Run: Continuously runs the VM code until it completes or is manually paused.
- Pause: Pauses the execution of the VM code.
- Reset: Resets the VM emulator to its initial state.
- Load the
BubbleSort.vmandMain.vmfile. - Configure any necessary initial settings.
- Click "Run" to execute the program.
- Observe the output and debug as needed.
- Use the VM emulator’s debugging tools to inspect the state of the stack, memory, and registers.
- Verify the program's output and behavior.
- Adjust and recompile your Jack code as necessary to achieve the desired results.
By following these steps, you can effectively compile and run all the Jack programs, leveraging the custom standard library to enhance the programming capabilities in the Jack environment.
-
Clone the repository to your local machine:
git clone https://github.com/your-repository/jack-standard-library.git
-
Navigate to the project directory:
cd jack-standard-library -
Compile the Jack files using the Jack compiler.
After compiling the Jack files, you can include the necessary modules in your Jack programs. Here are examples of how to use some of the provided features:
class Main {
function void main() {
var List myList;
let myList = List.new();
do myList.add(5);
do myList.add(10);
do myList.remove(0);
let myList.get(0);
return;
}
}
class Main {
function void main() {
var Array myArray;
var int size;
let size = 5;
let myArray = Array.new(size);
let myArray[0] = 5;
let myArray[1] = 3;
let myArray[2] = 8;
let myArray[3] = 4;
let myArray[4] = 2;
do Sort.bubbleSort(myArray, size);
return;
}
}
Detailed documentation for each data structure and utility function is available in the docs directory. It includes descriptions, method signatures, and usage examples.
We welcome contributions to the Jack Standard Library! If you have a feature request, find a bug, or want to add a new data structure or utility function, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature
- Make your changes.
- Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature/YourFeature
- Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
We would like to thank the Jack programming language community for their support and contributions. Your feedback and collaboration are invaluable in making this project a success.
By building and utilizing this standard library, we aim to significantly expand the capabilities of the Jack programming language, providing developers with essential tools for efficient programming. We hope this project serves as a valuable resource for the Jack community. Happy coding!
|
Dharsini Sri B |
Jothika K |
Kaniska M |
Chanjhana Elango |