Skip to main content

Kale

A modern, statically-typed compiled programming language and LLVM-backed compiler pipeline written in Python, powered by uv.

Kale compiles source code (.kl) directly into LLVM Intermediate Representation (IR) with in-memory JIT execution and native standalone binary compilation via Clang / LLD.


Architecture Overview

Kale is built upon a clean, decoupled multi-stage compiler pipeline:

Source Code (.kl)
       │
       ▼
   [ Lexer ]  ──────────────► [ DiagnosticBag ]
       │                      (Errors & Warnings with line:column carets)
       ▼
 [ Syntax Tokens ]
       │
       ▼
 [ Pratt Parser ]
       │
       ▼
 [ Abstract Syntax Tree (AST) ]
       │
       ▼
 [ Semantic Analyzer / Binder ] ──► [ Lexical Scopes & Type Checking ]
       │
       ▼
 [ Bound AST / Program ]
       │
       ▼
 [ LLVM IR Emitter ] ──────────► [ In-Memory LLVM JIT Engine ] (Instant execution)
       │
       ▼
 [ Clang / LLD Native Driver ] ─► Native Executable (.exe / binary)

Compiler Subsystems

  • kale.diagnostics: Source position tracking (TextSpan, TextLocation), line mapping, and compiler diagnostics with color-coded snippets and carets.
  • kale.syntax: Non-colliding SyntaxKind tokens, robust scanner supporting multi-character operators, numbers (integer, float, exponent), strings with full escape handling, and block/line comments.
  • kale.ast: Strongly-typed AST nodes for expressions, declarations, loops, conditionals, and statements. Includes an AstPrinter for tree visualization.
  • kale.parser: Recursive descent for statements combined with Pratt parsing (operator precedence climbing) for expressions, complete with error synchronization/recovery.
  • kale.binding: Semantic analysis pass implementing hierarchical lexical scopes, variable shadowing, constant immutability, numeric promotion, and type validation.
  • kale.codegen:
    • LLVM Emitter & JIT: Generates typed LLVM IR and executes in-memory via LLVM ORC/MCJIT.
    • LLVM Driver: Invokes Clang to compile .ll into native standalone executables.
    • C Emitter: Optional fallback backend targeting standard C99.

Quick Start with uv

Installation & Environment Setup

Kale uses uv for lightning-fast environment and dependency management:

# Sync dependencies and create virtual environment instantly
uv sync

Running Programs

# Execute instantly in-memory via the LLVM JIT engine
uv run kale run examples/fibonacci.kl

# Build a native standalone executable (.exe) via Clang
uv run kale build examples/fibonacci.kl -o fib.exe
./fib.exe

# Dump generated LLVM Intermediate Representation (IR)
uv run kale dump-llvm examples/fibonacci.kl

# Typecheck and validate without compiling
uv run kale check examples/fibonacci.kl

# Inspect parsed AST tree
uv run kale dump-ast examples/fibonacci.kl

# Inspect scanned token stream
uv run kale dump-tokens examples/hello.kl

Language Features

Variables & Types

int a = 10;
double pi = 3.14159;
bool flag = true;
string greeting = "Hello, Kale!";
let deduced = 42;          // Type deduced as int
const max_users = 100;     // Read-only constant

Control Flow

// If - Else
if (a > 5) {
    print("Greater than 5");
} else {
    print("5 or less");
}

// While Loops
int i = 0;
while (i < 5) {
    print(i);
    i++;
}

// For Loops
for (int j = 0; j < 5; j++) {
    print(j);
}

Running Tests

Run the full test suite (30 unit & integration tests across diagnostics, lexer, parser, binder, LLVM emitter, JIT, and Clang driver) using uv:

uv run pytest

Release files for kale-lang 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kale-lang 0.2.0
File Size Uploaded
kale_lang-0.2.0.tar.gz 87.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kale-lang 0.2.0
File Interpreter ABI Platform
kale_lang-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 153.1 kB

Release files / kale_lang-0.2.0.tar.gz

Download URL kale_lang-0.2.0.tar.gz
Size 87.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0440f33af17829a202a4916fb6a9894621640655410c72fbf14c25ad0f8fdde2
BLAKE2b-256 checksum
How to use checksums
b11c006c661fd15a99b78cc8fe406deabdd4b40994470e382631f278fb909c56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / kale_lang-0.2.0-py3-none-any.whl

Download URL kale_lang-0.2.0-py3-none-any.whl
Size 66.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a795b3654f9d6229a10498c94aeec1ad3673ccd73893983a339d9ae47251b03
BLAKE2b-256 checksum
How to use checksums
b06e00950409a3e9a2403c93f1fdf09f3e20a53c0669185dcfef690116062828
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page