Repository navigation
Tooling and LSP
The H toolchain ships with the hlc compiler CLI (including a built-in test runner and DWARF debug support), a canonical source formatter (hlfmt), a zero-LLVM semantic Language Server Protocol server (hl-lsp), a C++ binding generator (hl-bindgen-cpp), a standalone install script (scripts/install.sh), and VS Code / Neovim editor integrations under editors/.
Usage: hlc [build|run|test] [file.hl|dir] [-g] [-c] [-o <out>] [-O0|-O1|-O2|-O3]
[-I <dir>] [--emit-llvm] [--run] [-l<lib>] [-L<dir>] [<extra.o>] [--runtime <path>]
| Subcommand | Behavior |
|---|---|
build (default) |
Compiles input .hl file, directory (<dir>/main.hl), or h.toml project into a native executable |
run (or --run / -r) |
Compiles to a temporary binary (or -o <out>), executes it, deletes the temporary binary, and propagates its exit code |
test |
Discovers *_test.hl files and def test_*() functions, compiles and runs a native test harness with std/test
|
| Flag | Description |
|---|---|
-o <path> |
Output executable or object file path (defaults to stripping .hl from entry path, or name from h.toml) |
-c |
Emit a native object file (.o) without invoking the linker (used to compile runtime/hl_runtime.hl) |
-g |
Emit DWARF v4 debug info via LLVM DIBuilder and pass -g to gcc; defaults optimization level to -O0 (skipping LLVMRunPasses) unless -O* is explicitly supplied |
-O0, -O1, -O2, -O3
|
Optimization level (default -O2, or -O0 when -g is set without an explicit -O*). Runs LLVM's LLVMRunPasses with default<O1>, default<O2>, or default<O3> when opt_level > 0, and skips IR optimization passes at -O0
|
-I <dir> / -I<dir>
|
Adds an extra module import search directory (repeatable) |
--emit-llvm |
Verify the LLVM module and print textual LLVM IR to stdout without emitting an object file |
--runtime <path> |
Explicit path to runtime object/archive. By default, hlc auto-detects libhl_runtime_h.o relative to $H_HOME / /proc/self/exe before falling back to zig-out/lib/libhl_runtime.a
|
-l<lib>, -L<dir>, -Wl,..., *.o, *.a
|
Forwarded to the gcc link step (which always links -lgc -lm -lpthread) |
-h, --help
|
Print usage text and exit 0
|
hlc works from any working directory by locating std/ and libhl_runtime_h.o relative to its own executable path (/proc/self/exe -> <exe_dir>/../share/h for installed binaries, <exe_dir>/../.. for repo builds), via the $H_HOME environment variable, or via -I <dir>.
The frozen Zig bootstrap seed (zig-out/bin/hlc) implements only the minimal flag subset (<file.hl>, run, -o, --runtime, --emit-llvm, -O0..-O3, -l, -L) needed to compile compiler/main.hl once. All full CLI subcommands, -g, -c, -I, h.toml ([dependencies]), and new language features live exclusively in the self-hosted compiler (hlc / hlc-pure).
Passing -g activates Codegen.enable_debug():
- Emits module metadata flags
Debug Info Version = 3andDwarf Version = 4. - Creates a
DICompileUnit(producer"hlc") and aDIFileper loaded module. - Attaches a
DISubprogramto every emitted H function and method. - Updates the builder's current
DILocation(LLVMSetCurrentDebugLocation2) as statements are emitted. - Registers function parameters (
LLVMDIBuilderCreateParameterVariable) and local variables (LLVMDIBuilderCreateAutoVariable) viaLLVMDIBuilderInsertDeclareRecordAtEnd. - Defaults to
-O0(skippingLLVMRunPasses) and passes-gtogccwhen linking sogdbandlldbresolve source file names, line numbers, stack frames, and local values cleanly:
hlc -g examples/chaining_fn.hl -o chaining_fn
gdb ./chaining_fnhlc test [path] automates unit testing:
- Defaults to
testswhenpathis omitted. - Accepts either a single
.hlfile or a directory containing*_test.hlfiles. - Parses each file with
LexerandParserto collect all top-level functions matchingtest_*with zero parameters and zero type parameters. - Synthesizes a temporary H harness importing
std/testand the test file, runsTypeChecker+Codegen, executes the compiled test binary, prints per-testPASS/FAILand check counts, and exits1on failure.
hlc test tests/
hlc test tests/http_and_ergonomics_test.hl -gtools/hlfmt.hl (hlfmt) formats .hl source files according to canonical H style:
# Format to stdout
hlfmt examples/vec2.hl
# Rewrite files in place
hlfmt --write src/main.hl src/util.hl
# CI check mode (exits 1 if any file differs from canonical formatting)
hlfmt --check compiler/*.hl std/*.hl-
Indentation: 2 spaces per block level (
def,mut def,struct,class,enum,interface,if/elsif/else,unless,while,for,do ... end). -
matchalignment:whenandelsearms align with their enclosingmatch, while arm bodies indent one level deeper. -
Multi-line continuation: Lines starting with
.or&.indent one extra level; open parenthesized lists indent inner lines by current parenthesis nesting depth while closing)dedents cleanly. -
String/comment awareness: Token scanning ignores keywords inside strings, character literals, and
#comments, and preserves single-line closures (fn(x: I64) -> I64 do x * 2 end). - Whitespace hygiene: Strips trailing whitespace, collapses consecutive blank lines to at most one, and ensures a single trailing newline.
tools/hl_lsp.hl (hl-lsp) implements a JSON-RPC 2.0 Language Server over stdio (Content-Length framing). Because compiler/typecheck.hl is written in pure H with zero LLVM dependency, hl-lsp imports the exact same frontend and typechecker modules as hlc (compiler/token.hl, compiler/lexer.hl, compiler/ast.hl, compiler/parser.hl, and compiler/typecheck.hl) while linking zero libLLVM (~218 KB standalone binary).
| Method | Behavior |
|---|---|
initialize |
Advertises textDocumentSync: 1 (full sync), documentSymbolProvider, definitionProvider, hoverProvider, completionProvider (trigger character .), and server info hl-lsp 0.1.0
|
textDocument/didOpen, didChange, didClose
|
Maintains an in-memory document map (StrMap), loads imported modules via LspLoader (supporting relative paths, std/, and $H_HOME/std/), runs TypeChecker.check_modules, and publishes multi-diagnostic semantic and type errors (type mismatches, nil safety & Bool?, @[nogc] violations, match exhaustiveness, interface bounds, missing fields/methods) alongside lexer/parser errors via textDocument/publishDiagnostics
|
textDocument/documentSymbol |
Returns outline symbols for interface, enum, struct, class, Type.method, and top-level def declarations |
textDocument/definition |
Jumps to the declaration line of top-level functions, structs/classes, methods, enums, and interfaces in the open document |
textDocument/hover |
Displays formatted Markdown h signatures (@[nogc], mut def, generic type parameters & bounds, parameter types, return type) and field/method/variant counts |
textDocument/completion |
Suggests H keywords, built-in types, and all functions, structs, classes, enums, and interfaces parsed from the current document |
shutdown, exit
|
Clean protocol shutdown (exit returns 0 after shutdown, 1 otherwise) |
./scripts/install.sh [--prefix=<dir>] [--no-build]Installs hlc, hlfmt, hl-lsp, and hl-bindgen-cpp to $PREFIX/bin (default $HOME/.local/bin) and installs libhl_runtime_h.o plus std/ (and std/interop/) to $PREFIX/share/h/.
Contains a TextMate grammar (syntaxes/h.tmLanguage.json), language-configuration.json (comment toggling, bracket/quote pairs, do/end block folding), and package.json:
- Copy or symlink
editors/vscodeinto~/.vscode/extensions/h-language/. - Reload VS Code for
.hlsyntax highlighting and block folding. - Install
hl-lspvia./scripts/install.shand connect it with any generic stdio LSP extension for language IDh.
Drop editors/neovim/h.lua into ~/.config/nvim/after/plugin/h.lua (or require() it from init.lua). It automatically configures:
-
.hl->hfiletype detection - 2-space indentation (
shiftwidth = 2,tabstop = 2,expandtab = true) and# %scomments - Automatic
hl-lspattachment viavim.lsp.startrooted ath.tomlor.git -
:HFormatuser command runninghlfmt --writeand reloading the buffer
tools/hl_bindgen_cpp.hl (hl-bindgen-cpp) generates extern "C" C++ shims and H wrapper bindings:
hl-bindgen-cpp <header.hpp> \
--out-cpp <shim.cpp> \
--out-hl <bindings.hl> \
[--inst <fn>:<cpp_type>]See Foreign Interop for details on exception boundaries, template instantiation directives, and generated class wrappers.
build.zig automatically probes llvm-config-23, llvm-config-22, llvm-config-21, llvm-config-20, llvm-config-19, and llvm-config to discover the installed LLVM major version and library directory. Override manually with -Dllvm-lib=<name> and -Dllvm-libdir=<dir>.
| Command | Dependencies | Outputs / Action |
|---|---|---|
zig build |
— | Builds zig-out/bin/hlc (frozen Zig bootstrap seed) and zig-out/lib/libhl_runtime.a (C seed runtime) |
zig build test |
zig build |
Runs src/tests.zig: bootstrap checks, native execution tests, fixed-point self-hosting verification, pure-H runtime verification, and C++/D/Objective-C/.NET interop tests |
zig build self-host |
zig build |
Builds zig-out/bin/hlc-self, compiles runtime/hl_runtime.hl -> zig-out/lib/libhl_runtime_h.o, and builds zig-out/bin/hlc-pure
|
zig build fixed-point |
zig build self-host |
Compiles compiler/ with hlc-pure into zig-out/bin/hlc-pure2 and verifies bit-for-bit equality via cmp
|
zig build tools |
zig build self-host |
Compiles zig-out/bin/hl-bindgen-cpp, zig-out/bin/hlfmt, and zig-out/bin/hl-lsp (zero LLVM) using hlc-pure + libhl_runtime_h.o
|
zig build htest |
zig build self-host |
Runs ./zig-out/bin/hlc-pure test tests/ --runtime zig-out/lib/libhl_runtime_h.o
|
Next: Compiler Architecture