Easy to read
Clean def ... end blocks, for ... in loops, string interpolation ("hello #{name}"), and dot-chaining without noisy boilerplate.
Ruby-style readability. Native LLVM speed. GC when you want it, manual control when you don't.
H (.hl) compiles straight to native machine code, checks nil and types before your program runs, lets you opt into zero-GC arenas per function, and connects directly to C, C++, Objective-C, D, C#, and F#.
$ git clone https://github.com/buntatoes/h-lang.git && cd h-lang $ zig build self-host && zig build tools && ./scripts/install.sh $ hlc run examples/hello.hl
hl-lsp shares the pure-H typechecker with zero LLVM dependency.Explore real H programs — from everyday structs and safe error handling to zero-GC arenas, HTTP JSON routes, and multi-language interop.
struct Vec2
x: F64
y: F64
@[nogc]
def +(other: Vec2) -> Vec2
Vec2.new(@x + other.x, @y + other.y)
end
@[nogc]
def length_sq() -> F64
@x * @x + @y * @y
end
end
def main() -> I32
pos = Vec2.new(3.0, 4.0) + Vec2.new(1.0, -1.0)
total = 0
for i in 1..=5
total += i
end
puts("pos=(#{pos.x}, #{pos.y}) len2=#{pos.length_sq} sum=#{total}")
0
end
import result
class User
name: String
mentor: User?
def initialize(@name: String, @mentor: User? = nil)
end
end
def checked_div(a: I64, b: I64) -> Result[I64, String]
if b == 0
return Result[I64, String].err("division by zero")
end
Result[I64, String].ok(a / b)
end
def ratio(a: I64, b: I64, scale: I64) -> Result[I64, String]
q = checked_div(a, b)?
Result[I64, String].ok(q * scale)
end
def main() -> I32
ada: User? = User.new("Ada")
lin: User? = User.new("Lin", ada)
# Safe navigation (&.) + nil-coalescing (??)
mentor_name = lin&.mentor&.name ?? "none"
puts("mentor=#{mentor_name}")
# Exhaustive match on Result[I64, String]
match ratio(42, 7, 3)
when .ok(val)
puts("ratio=#{val}")
when .err(msg)
puts("error=#{msg}")
end
0
end
extern "C" def printf(fmt: Ptr[U8], ...) -> I32
@[repr(C)]
struct Packet
id: I32
score: F64
end
@[nogc]
def log_packet() -> I32
with_arena(1024) do |scratch|
pkt = scratch.alloc[Packet]() # Ptr[Packet], auto-dereferenced by '.'
pkt.id = 7
pkt.score = 98.5
# Plain literal coerces to NUL-terminated Ptr[U8] at compile time:
printf("packet id=%d score=%.1f\n", pkt.id, pkt.score)
end
0
end
def main() -> I32
log_packet()
end
import http
import json
def handle_api(req: HttpRequest) -> HttpResponse
if req.method == "GET" and req.path == "/health"
return http.ok_json(json.j_obj([
JsonField.new("status", json.j_str("ok")),
JsonField.new("lang", json.j_str("H"))
]))
end
if req.method == "POST" and req.path == "/double"
parsed = json.parse(req.body)
match parsed
when .ok(v)
n = json.obj_get_i64(v, "value") ?? 0
return http.ok_json(json.j_obj([
JsonField.new("input", json.j_int(n)),
JsonField.new("result", json.j_int(n * 2))
]))
when .err(e)
return http.bad_request("invalid json: #{e}")
end
end
http.not_found("route #{req.path} not found")
end
# Direct C ABI (also works with Zig, Rust, V, and D -betterC)
extern "C" def c_strlen(s: Ptr[U8]) -> Usize = "strlen"
# C++ classes, templates, and exceptions wrapped by hl-bindgen-cpp
import counter_bind
# Managed runtime bridges in std/interop/
import "std/interop/druntime" as druntime # GC-enabled D
import "std/interop/objc" as objc # Objective-C libobjc
import "std/interop/dotnet" as dotnet # C# & F# via CoreCLR hostfxr
def run_bridges(cfg: String, cs_dll: String) -> Void
c = Counter.new(10)
defer c.destroy()
puts("cpp=#{c.add(32)} clamp=#{counter_bind.cpp_clamp_i64(150, 0, 100)}")
host = dotnet.open(cfg)
if host != nil
defer host.close()
p = host.get_unmanaged_fn(cs_dll, "HlDotNet.MathOps, CSharpLib", "AddMul")
if p != nil
add_mul = p.as_fn[@[nogc] Fn(I64, I64, I64) -> I64]()
puts("csharp=#{add_mul(3, 4, 6)}")
end
end
end
H aims for a practical middle ground: readable enough for everyday apps and tools, predictable enough for tight loops and native libraries.
Clean def ... end blocks, for ... in loops, string interpolation ("hello #{name}"), and dot-chaining without noisy boilerplate.
nilValues cannot be nil unless their type ends in ? (like User?). The compiler checks your branches and gives you ??, &., and Result[T, E] with ?.
H compiles ahead of time to native machine code using LLVM optimizations (-O1 through -O3) — no virtual machine or interpreter at runtime.
Use garbage-collected classes when convenience matters, or switch to stack structs, scoped with_arena buffers, manual Heap allocation, and verified @[nogc] functions when you want zero pauses.
Call C libraries directly with extern "C", generate C++ wrappers with hl-bindgen-cpp, or connect to D, Objective-C, C#, and F# through built-in runtime bridges.
The H compiler, runtime, standard library, formatter, and language server are written in H itself and pass bit-for-bit fixed-point verification. A small Zig seed exists only to bootstrap on a new machine.
Measured on Linux x86_64 via benchmarks/run.sh at -O3 against C (gcc -O3) and Ruby, checking identical output checksums on every run. Lower is faster.
Sieve of Eratosthenes · count = 664,579
About 1.23x C and ~42.6x faster than Ruby. The ~2.5 ms gap to C comes from H's arena eagerly zeroing the 10 MB buffer while C's calloc requests zeroed OS pages directly.
5-body gravitational · @[nogc] value structs
Written idiomatically in H with struct Vec3 and overloaded +, -, and * operators inside with_arena. LLVM inlines the operators and keeps fields in registers.
Parse + stringify · pure-H std/json (GC)
Parses a nested JSON document into GC-managed objects and serializes it back 20,000 times using only pure-H std/json — no C JSON library underneath.
The toolchain ships with a native compiler, canonical formatter, lightweight editor language server, C++ wrapper generator, test runner, and batteries-included standard library.
Compiles .hl files and h.toml projects to native binaries via LLVM, supports hlc run, and emits -g DWARF debug info for gdb and lldb.
Provides real-time type diagnostics, hover signatures, go-to-definition, outline symbols, and completions by sharing H's pure-H typechecker with zero libLLVM dependency.
Formats H code into one clean 2-space style with --write for local editing and --check for CI pipelines.
Reads C++ headers and generates exception-safe extern "C" shims alongside idiomatic H wrapper classes and template bindings.
Discovers *_test.hl files and def test_*() functions, builds a native test binary with std/test, and reports pass/fail status.
Ready-to-use TextMate grammar, block folding, Neovim filetype setup, automatic hl-lsp attachment, and :HFormat included in editors/.
std/)std/str strings
std/math math
std/map Map & Set
std/result Result
std/json JSON
std/fs files
std/path paths
std/env env vars
std/args CLI flags
std/process processes
std/time timers
std/net TCP & UDP
std/http HTTP/1.1
std/thread threads & channels
std/test assertions
std/interop/druntime D GC
std/interop/objc libobjc
std/interop/dotnet CoreCLR
Bootstrap the self-hosted compiler once with Zig, install the standalone binaries to ~/.local, and run hlc from any folder.
$ git clone https://github.com/buntatoes/h-lang.git $ cd h-lang # Build the self-hosted H compiler, pure-H runtime, and tools $ zig build self-host $ zig build tools # Install hlc, hlfmt, hl-lsp, hl-bindgen-cpp, and std/ to ~/.local $ ./scripts/install.sh
# Ensure ~/.local/bin is in your PATH $ hlc run examples/hello.hl
# Bootstrap, self-hosting, and interop tests $ zig build test # Verify the self-hosted compiler reproduces itself bit-for-bit $ zig build fixed-point # Run the pure-H standard library and language test suite $ zig build htest