Skip to content

cooper-ross/tisp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tisp - Tiny Lisp Compiler

Tisp is a lightweight compiler for a lisp-like programming language that compiles to LLVM IR, then generates native code through the LLVM toolchain. The shortcut for a tisp file is .tsp, like teaspoon (so pround of this name). The entire "codebase" is one file, and a little bit under 300 lines (excluding newlines and comments).

Features

  • Type system: Supports integers and floating-point numbers with automatic type promotion
  • Functions: Define and call functions (with recursion support)
  • Control flow:
    • if expressions for conditional branching
    • cond for multi-way conditionals
    • loop for iteration
  • Arithmetic operations: +, -, *, /
  • Comparisons: <, >, =
  • Variables: Local variable definitions with define
  • LLVM backend: Compiles to LLVM IR, then to native code

Requirements

  • C++ compiler with filesystem support
  • LLVM toolchain (specifically llc)
  • GCC or Clang for linking

Building

Compile the compiler itself:

g++ -o tisp src/tisp.cpp

Usage

Basic Usage

Compile a .tsp file to an executable:

tisp program.tsp

This will generate an executable with the same name as the input file (without the .tsp extension).

Command-Line Options

Usage: tisp <input.tsp> [options]

Options:
  -o <output>   Specify output executable name
  --emit-ir     Emit LLVM IR only (.ll)
  --emit-asm    Emit assembly only (.s)
  --emit-obj    Emit object file only (.o)
  --verbose     Preserve all intermediate files
  --help        Show this help message
  --version     Show version information

How It Works

  1. Lexing & Parsing: The compiler tokenizes and parses the source code into an abstract syntax tree
  2. IR Generation: Generates LLVM Intermediate Representation (IR)
  3. Optimization: Uses llc -O2 to optimize and convert IR to assembly
  4. Linking: Links the assembly code with GCC or Clang to produce a native executable

License

This project is provided as-is for all purposes, and was really just for my own fun - it's pretty bad code, and really not practical, but if you want to use it, it's yours. Feel free to use, modify, and distribute as you wish.

Acknowledgments

About

A tiny lisp-like compiler written in C++ (less than 300 lines) though it does use the LLVM toolchain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages