Tisp is a lightweight compiler for a mini-lisp 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 proud of this name). The entire "codebase" is one file, and a little bit under 300 lines (excluding newlines and comments).
- Type system: Supports integers and floats with automatic type promotion
- Functions: Define and call functions (with recursion support)
- Control flow:
ifexpressions for conditional branchingcondfor multi-way conditionalsloopfor... looping
- Arithmetic operations:
+,-,*,/ - Comparisons:
<,>,= - Variables: Local variable definitions with
define
- C++ compiler with filesystem support
- LLVM toolchain (specifically
llc) - GCC or Clang for linking
Compile the compiler itself:
g++ -o tisp src/tisp.cppCompile a .tsp file to an executable:
tisp program.tspThis will generate an executable with the same name as the input file (minus the .tsp extension).
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
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.
- The LLVM Project - The real backbone of all these little fun projects I do.
- The Dragon Book - For foundational compiler theory, and lots on lexing and parsing.
- Wisp by Adam McDaniel - A minimal Lisp-like language built with LLVM.
- LLVM IR with the C++ API - Tutorial by Mukul Rathi
- “Hello, LLVM” - Tutorial by James Hamilton
- Awesome LLVM - A curated list of useful LLVM resources.
- Jesse Squires' Blog - A great roundup of compiler and LLVM learning materials.
- Building an Optimizing Compiler - Old, but still very good, helpful with high level design.