Garbage is a low-level programming language compiler developed as a capstone project. It targets AArch64 assembly for MacOS on Apple Silicon (M1/M2/M3) processors.
- Compiles Garbage language to AArch64 assembly
- Supports direct assembly and linking
- Includes a run mode for immediate execution
- VSCode syntax highlighting extension available
- Assembly visualization tool (VizWiz) for debugging
- MacOS with Apple Silicon (M1/M2/M3)
- Zig compiler (for building the compiler)
Note: The required assembler and linker typically come pre-installed on MacOS.
-
Clone the repository:
git clone https://github.com/yourusername/garbage-compiler.git cd garbage-compiler -
Build the compiler using Zig:
zig build
The Garbage compiler supports two modes: compile and run.
To compile a Garbage source file to assembly:
./garbage --compile path/to/your/source.trash
This will generate an assembly file (source.asm) and an executable in the same directory as the source file.
To compile and immediately run a Garbage program:
./garbage --run path/to/your/source.trash
This will compile the source file, generate the executable, and run it, displaying the output.
Here's a simple "Hello, World!" program in Garbage:
// docs/hello_world.trash
say a: [14]u8 = "hello, world!\n"
@print_buf(a, 14)
To compile and run this program:
./garbage --run hello_world.trash
src
├── ast
│ ├── node.zig
│ ├── parser.zig
│ └── program.zig
├── codegen
│ └── codegen.zig
├── compiler.zig
├── lexer
│ ├── lexer.zig
│ ├── test.zig
│ └── tokens.zig
├── main.zig
├── syntax_test.zig
└── test_ast.zig
main.zig: The entry point of the compilercompiler.zig: Contains the core compilation logicast/: Handles Abstract Syntax Tree (AST) generation and parsingcodegen/: Generates AArch64 assembly from the ASTlexer/: Handles lexical analysis and tokenization
VizWiz is an assembly visualization tool designed to aid in debugging Garbage programs. You can access it at https://vizwiz.netlify.app.
A syntax highlighting extension for Visual Studio Code is available to enhance the development experience with Garbage.
To install it just search for this: vscode:extension/marketplace.visualstudio.com/items?itemName=0xfaa.garbage-syntax
Or search for garbage-syntax in vscode extensions tab.
Contributions to the Garbage compiler are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
