home / skills / plurigrid / asi / jank-llvm

jank-llvm skill

/skills/jank-llvm

This skill helps you compile Clojure-like code to native LLVM with seamless C++ interop and runtime optimizations.

npx playbooks add skill plurigrid/asi --skill jank-llvm

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
7.0 KB
---
name: jank-llvm
description: Jank - Clojure dialect targeting LLVM with seamless C++ interoperability
trit: 1
metadata:
  interface_ports:
  - References
  - Related Skills
  - GF(3) Triads
  - Integration with
---
# Jank LLVM Skill

> jank-lang/jank: A Clojure dialect hosted on LLVM with native C++ interop

**Trit**: +1 (PLUS) - Forward compilation to native code

## Overview

Jank is a Clojure dialect that:
- **Targets LLVM** for native machine code generation
- **Seamless C++ interop** via `c++/` namespace
- **JIT compilation** with clang::Interpreter
- **Load native libraries** (.o, .dylib, .so)
- **Persistent data structures** like Clojure

## Architecture

```
┌─────────────────────────────────────────────────────────────────────────┐
│                         JANK COMPILATION PIPELINE                        │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                          │
│  Source Code                                                             │
│      │                                                                   │
│      ▼                                                                   │
│  ┌─────────┐     ┌──────────┐     ┌──────────┐     ┌─────────────┐     │
│  │  Lexer  │ ──► │  Parser  │ ──► │ Analyzer │ ──► │ LLVM Codegen│     │
│  └─────────┘     └──────────┘     └──────────┘     └──────┬──────┘     │
│                                                           │             │
│                                                           ▼             │
│                                                    ┌──────────────┐     │
│                                                    │ Optimization │     │
│                                                    │    Passes    │     │
│                                                    └──────┬───────┘     │
│                                                           │             │
│                                                           ▼             │
│                                                    ┌──────────────┐     │
│                                                    │     JIT      │     │
│                                                    │  Execution   │     │
│                                                    └──────────────┘     │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘
```

## C++ Interoperability

### Calling C++ from Jank
```clojure
;; Access C++ namespaces with c++/ prefix
(c++/std.cout "Hello from C++!")

;; Use chrono
(def duration (c++/std.chrono.milliseconds 100))

;; Call C++ functions
(c++/my.namespace.my-function arg1 arg2)
```

### Name Mangling
Jank automatically handles:
- `kebab-case` → `snake_case`
- Namespace dots → C++ `::`
- Symbol escaping for special characters

### Loading Native Code
```clojure
;; Load object file
(native-load "/path/to/mylib.o")

;; Load dynamic library
(native-load "/path/to/mylib.dylib")  ; macOS
(native-load "/path/to/mylib.so")     ; Linux
```

## C++ REPL Mode

```bash
jank cpp_repl

# Now you can evaluate C++ directly:
cpp> #include <iostream>
cpp> std::cout << "Hello from C++ REPL!" << std::endl;
Hello from C++ REPL!
```

## LLVM Optimization Passes

Jank applies these optimization passes:
- `InstCombinePass` - Instruction combining
- `ReassociatePass` - Reassociate expressions
- `GVNPass` - Global value numbering
- `SimplifyCFGPass` - Simplify control flow

## Unique Features

### 1. Persistent Data Structures
```clojure
;; Just like Clojure
(def m {:a 1 :b 2})
(def m2 (assoc m :c 3))
;; m is unchanged, m2 has :c
```

### 2. Native Performance
- No JVM startup overhead
- Direct machine code execution
- C++ level performance for hot paths

### 3. Ray Tracer Example
```clojure
;; From jank examples - demonstrates performance
(ns ray-tracer)

(defn render [width height]
  (for [y (range height)
        x (range width)]
    (compute-pixel x y)))
```

## Build from Source

```bash
git clone https://github.com/jank-lang/jank.git
cd jank

# Requires LLVM 17+, Clang
mkdir build && cd build
cmake ..
make -j$(nproc)
```

---

## End-of-Skill Interface

## Integration with Interaction Entropy

```clojure
;; Track jank compilations
(def JANK_DB "~/.jank/interactions.duckdb")

(defn log-compilation [source-file llvm-ir-size opt-level]
  {:file source-file
   :ir-size llvm-ir-size
   :optimization opt-level
   :entropy-bits (* 2.0 (Math/log llvm-ir-size))
   :trit 1  ; PLUS - forward compilation
   :timestamp (System/currentTimeMillis)})
```

## GF(3) Triads with Jank

```
Triad 1: Native Performance
  Jank (+1) ←→ SCI (0) ←→ Scittle (-1)
  
  Interface:
    Jank: Native LLVM compilation
    SCI: Interpreted sandboxed execution
    Scittle: Browser script tags
  
  Sum: +1 + 0 + (-1) = 0 ✓

Triad 2: C++ Bridge
  Jank (+1) ←→ Joker (0) ←→ clj-kondo (-1)
  
  Interface:
    Jank: C++ interop, native code
    Joker: Go-based linting
    clj-kondo: Static analysis
  
  Sum: +1 + 0 + (-1) = 0 ✓

Triad 3: Compilation Spectrum
  Jank (+1) ←→ Babashka (0)* ←→ nbb (-1)
  
  *Babashka acts as ergodic bridge here
  Interface:
    Jank: AOT to LLVM
    Babashka: GraalVM native-image
    nbb: Node.js interpreted
  
  Sum: +1 + 0 + (-1) = 0 ✓
```

## Related Skills

- [joker-lint](file:///Users/bob/.claude/skills/joker-lint/SKILL.md) - Go-based linting
- [babashka-clj](file:///Users/bob/.claude/skills/babashka-clj/SKILL.md) - Fast scripting
- [borkdude](file:///Users/bob/.claude/skills/borkdude/SKILL.md) - Runtime selector
- [clj-kondo-3color](file:///Users/bob/.claude/skills/clj-kondo-3color/SKILL.md) - Deep linting

## References

- [jank-lang/jank](https://github.com/jank-lang/jank)
- [Jank Blog](https://jank-lang.org/blog/)
- [LLVM Documentation](https://llvm.org/docs/)


---

## Autopoietic Marginalia

> **The interaction IS the skill improving itself.**

Every use of this skill is an opportunity for worlding:
- **MEMORY** (-1): Record what was learned
- **REMEMBERING** (0): Connect patterns to other skills  
- **WORLDING** (+1): Evolve the skill based on use



*Add Interaction Exemplars here as the skill is used.*

Overview

This skill provides a Clojure-like language (Jank) that targets LLVM for native machine code generation with first-class C++ interoperability. It combines persistent Clojure-style data structures with JIT/AOT compilation, letting you run high-performance code without the JVM. Use it to call C++ namespaces, load native libraries, and iterate in a C++ REPL while preserving familiar Clojure semantics.

How this skill works

The compiler pipeline lexes, parses, and analyzes Jank source then emits LLVM IR and runs LLVM optimization passes before JIT or AOT codegen. A c++/ namespace maps Clojure-style symbols to C++ names, handling kebab→snake conversion and namespace → :: mangling. Native objects and dynamic libraries can be loaded at runtime and a C++ REPL is available for interactive evaluation.

When to use it

  • You need native performance for hot computation paths without JVM overhead.
  • You want seamless calling of existing C++ libraries from a Clojure-like language.
  • You prefer persistent immutable data structures with native code execution.
  • You want to prototype algorithms in REPL then compile to optimized machine code.
  • You need to embed or load .o/.so/.dylib artifacts into your workflow.

Best practices

  • Name C++ interop calls with c++/ prefix and follow kebab-case for predictable mangling.
  • Keep heavy numeric or inner-loop logic in functions compiled through LLVM for maximal speed.
  • Use native-load for stable binary dependencies and prefer platform-appropriate artifacts (.so, .dylib, .o).
  • Profile IR size and optimization level before AOT builds to balance build time and performance.
  • Leverage Jank’s persistent structures for safe concurrency; move mutating hot paths into native code when needed.

Example use cases

  • Ray tracer implemented in Jank for native-performance rendering loops.
  • Calling a C++ image processing library directly from Jank using c++/std and native-load.
  • Iterative algorithm development in the C++ REPL, then compiling critical routines to LLVM for deployment.
  • Embedding a small native plugin (.o) into a larger Jank application for low-latency extensions.
  • Benchmarking numeric kernels by switching between JIT and AOT builds and tuning LLVM passes.

FAQ

How do I call a C++ function from Jank?

Prefix the C++ namespace with c++/ and call symbols using kebab-case; Jank mangles names to C++ conventions automatically.

Can I load a platform-specific dynamic library?

Yes. Use native-load with the appropriate extension (.so on Linux, .dylib on macOS) to link runtime libraries into the Jank process.