This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
K1 is an experimental systems programming language that combines C-like performance with modern features like type classes (abilities), algebraic data types, pattern matching, and generics. The project is implemented in Rust with an LLVM backend and includes a self-hosted standard library written in K1.
Important: K1 is a hobby project for learning and exploration, not production-ready.
./check.sh [file] # Build compiler and run validation (skips codegen/linking if file specified)
./test.sh # Run comprehensive test suite + build test_suite and compiler binaries
./run.sh <file> # Compile and run K1 programs
./debug <file> # Debug build and launch interactive lldb with the specified file
./build_lsp.sh # Build language server# Run program with sanitizers (address, undefined behavior detection)
./.k1-out/<filename> # After building with ./debug <file>
# Non-interactive debugging (useful for automated testing)
lldb --batch -o run .k1-out/<filename>
# Non-interactive debug script (builds with sanitizers and runs)
./debug_run.sh <file> # Build with debug/sanitizers and run non-interactively# Build compiler (main binary)
cargo build --features=llvm-sys/prefer-dynamic --bin compiler
# Build test runner
cargo build --features=llvm-sys/prefer-dynamic --bin test_suite
# Build language server
cargo build --features=lsp --bin lsp
# Build GUI development environment
cargo build --features=gui --bin gui
# Build REPL
cargo build --bin repl
# Run Rust tests
cargo test# Run all K1 language tests
target/debug/test_suite
# Run specific test
target/debug/test_suite <test_name>
# Check for lint violations (no "nocommit" messages)
rg --type-add 'k1:*.k1' -c 'nocommit' -t rust -t c -t k1 .export RUST_BACKTRACE=1 # For debugging Rust panics
export RUST_LOG=info # For detailed logging
export MallocScribble=1 # For memory debugging (used in test.sh)- Location:
/src/k1/ - Pipeline: Lexer → Parser → Type Checker → LLVM Codegen
- Key modules:
lex.rs- Tokenization and lexical analysisparse.rs- AST generation with error recoverytyper.rs- Type inference, checking, and ability resolutioncodegen_llvm.rs- LLVM IR generation and optimizationvm.rs- Compile-time execution engine for static evaluationcompiler.rs- Main compilation orchestration
compiler(default) - Main K1 compilertest_suite- Comprehensive test runnerlsp- Language Server Protocol implementationgui- Development GUI (raylib-based)repl- Interactive interpreter
- Core Library:
/k1lib/core/- Memory management, collections, strings, metaprogramming - Standard Library:
/k1lib/std/- Higher-level utilities like HashMap - Self-hosted: Entire standard library is written in K1
- Location:
/test_src/suite1/ - Coverage: 79 test files covering language features, core library, error handling
- Types: Basic features, advanced features (generics, pattern matching), expected compilation failures
- Strong static typing with limited inference
- Algebraic data types via
either(sum types) andstruct(product types) - Generics with constraints through abilities (trait system)
- Anonymous structs/enums for lightweight data modeling
- Reference types with distinct pointer/reference semantics
- Pattern matching with exhaustiveness checking
- Closures with automatic capture analysis
- String interpolation using
{...}syntax with full expression support:{a.b.c()} - Backtick strings (
`string`) for easier handling of double-quotes, especially useful for compile-time codegen - Iterator protocol with
forexpressions supportingyield - Method syntax with namespaced scoping
- Pipeline operator (
|) for functional composition - Abilities (traits) for type-class abstraction
- Direct memory management with pointer operations
- Foreign Function Interface (C interop)
- Fixed-size integer types (u8/i8 through u64/i64)
- Compile-time execution via VM for metaprogramming
#metadirective for compile-time code generation and metaprogramming
/src/k1/- Rust compiler implementation/k1lib/- K1 standard library (self-hosted)/test_src/suite1/- Language test suite/dogfood/- Real-world K1 programs (Advent of Code, chess engine, etc.)
- Primary development on macOS
- Linux x86-64 via Docker cross-compilation
- Docker containerization with
Cross.tomlconfiguration
- Development builds: Use
--features=llvm-sys/prefer-dynamicfor faster iteration - Release builds: Static linking with LTO optimization enabled
- Memory debugging: Use
MallocScribble=1environment variable during testing
- Full LSP implementation available via
lspbinary - IDE integration support for syntax highlighting, completion, diagnostics
- Uses LLVM 18 via
inkwellbindings - Generates optimized machine code with debug information
- Supports compile-time execution through custom VM
- Core:
anyhow,clap,log,itertools,smallvec - Performance:
mimalloc,ahash,fxhash,string-interner - LLVM:
inkwell,llvm-sys,libffi - Optional features: LSP (
tower-lsp,tokio), GUI (raylib)