Overview of Jai

History

  • Jonathan Blow started working on the compiler in 2014 as a C++ replacement
  • Jonathan Blow is creating a video game (still in development), with the working title of Sokoban, to test the robustness and usability of the programming language
  • Sokoban is a 3D game around 250,000 lines of Jai code
  • The closed beta started around January 2020
  • After 1 year, the beta is over 100 members
  • The compiler was around 10,000 lines of code in the initial stages of 2014
  • The compiler expanded to around 50,000 lines of code after adding the LLVM backend, macros, operator overloading, multiple return values, unions, etc.
  • The compiler jumped to around 75,000 lines of code after adding inline assembly support

Current State

  • Possible language syntax rewrite in the future
  • Most of language features nailed down, adding minor improvements
  • Working on compiler robustness, inline assembly, compiler optimization, and optimizing compilation speed
  • Language will be ready when Jonathan Blow releases Sokoban

Performance

  • The goal is to compile 1M lines of code in <1s (from scratch, without delta builds).
  • Official compilation speed of the compiler is 250,000 lines of code per second using the x64 backend, according to the CHANGELOG of beta 0.0.045 (using Sokoban as a benchmark)

Compiler Internals

  • Compiler code is proprietary, but Jonathan intends to open-source later
  • Compiler was programmed in 87,000 lines of C++ code
  • Jonathan Blow will not be self-hosting the compiler in the near future
  • Multi-threaded Job System Compiler, Lexing and Parsing Parallelized
  • Hand-written recursive descent top-down parser
  • Compiler front-end is primarily written by Jonathan Blow
  • Compiler has its own internal byte-code
  • Two compiler backends: x64 and LLVM backend
  • x64 backend was developed by Jonathan Blow and his compiler team
  • x64 backend does fast but naive code generation, without any code optimization
  • LLVM backend does better code optimization, but has slower compilation speed

Features

  • Imperative, general purpose programming language
  • Statically, strongly typed
  • Supports x86 architecture only (limited Nintendo Switch support)
  • Platforms: Windows, Ubuntu Linux (limited Mac support)
  • Compiled language as fast and optimized as C or C++ code
  • Arbitrary compile-time execution, with powerful metaprogramming features to modify your code in whatever way you want
  • Compiler gives you the compiler AST (Abstract Syntax Tree) for you to modify
  • User can access compiler through a compiler message loop
  • Parameterized structs (similar to C++ templates or Java generics, except cleaner)
  • Function polymorphism
  • Multiple return values
  • Relative Pointers
  • Operator Overloading
  • Hygienic macros
  • Syntax is not final
  • Struct of Arrays supported through #insert directives.
  • Context based allocation and Temporary Storage
  • Basic multi-threading support (threads, mutexes)
  • Inline Assembly with AVX, AVX2, AVX512 SIMD instructions support
  • Lambda Expressions (no closures)
  • Notes (similar to Java annotations)

What will NOT be in Jai

  • No Makefiles
  • No header files
  • No constructors or destructors
  • No RAII (Resource acquisition is initialization)
  • No exceptions
  • No virtual functions/design patterns/object oriented inheritance hierarchies
  • No incremental rebuilds
  • No garbage collection
  • No coroutines (e.g. no Go-style channels)
  • No package managers
  • No sum types/tagged unions