Skip to content

veera-sivarajan/boba

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boba

boba is a compiler project to learn about implementing type system, code optimization and code generation. It compiles Rust-like source code to x86-64 assembly.

Example:

fn sum(array: [i32; 5]) -> i32 {
    let mut total = 0;
    for (let mut i = 0; i < 5; i = i + 1) {
        total = total + array[i];
    }
    return total;
}

fn main() {
    let array = [1, 2, 3, 4, 5];
    let total = sum(array);
    println("Sum of {} = {}", array, total); // Sum of [1, 2, 3, 4, 5] = 15
}

Build

To build the CLI:

cargo build

NOTE: boba requires rustc version 1.70.0 or newer.

Usage

Usage: boba [OPTIONS] <FILENAME>

Arguments:
  <FILENAME>  Name of the file to be compiled

Options:
  -p, --print-ast  Print the parsed AST
  -h, --help       Print help
  -V, --version    Print version

The compiler generates a x86-64 assembly (AT&T syntax) file. Use gcc or clang to compile the assembly to an ELF executable and then run it on your system.

gcc <FILENAME>.s && ./a.out

Language Documentation

Check language documentation for details about the syntax and semantics of the language.

Example Programs

The test/ directory contains a bunch of example programs that can be compiled with this compiler.

To test the compiler against all the programs in the directory:

cargo test

NOTE: This requires gcc to be available on your $PATH.

Devlog

An attempt to document my development process:

  1. Boba Devlog #0: Compiling Pseudo-Rust to x86 Assembly
  2. Boba Devlog #1: Sliding in a Type Checker
  3. Boba Devlog #2: Compiling Arrays