Skip to content
vic

am-kantox/cure-lang

Cure language compiling to BEAM with FSM primitives and Dependent types

am-kantox/cure-lang.json
{
"createdAt": "2025-10-04T11:50:04Z",
"defaultBranch": "main",
"description": "Cure language compiling to BEAM with FSM primitives and Dependent types",
"fullName": "am-kantox/cure-lang",
"homepage": null,
"language": "HTML",
"name": "cure-lang",
"pushedAt": "2025-11-26T17:54:18Z",
"stargazersCount": 79,
"topics": [],
"updatedAt": "2025-11-26T17:54:22Z",
"url": "https://github.com/am-kantox/cure-lang"
}

A strongly-typed, dependently-typed programming language for the BEAM virtual machine with built-in finite state machines, complete import system, and comprehensive standard library.

🚀 Last Updated: November 26, 2025
📦 Current Version: v0.7.0

Working import system with full module resolution
Standard library with verified runtime execution (12 modules)
Dependent types with compile-time verification
Complete compiler pipeline from source to BEAM bytecode
FSM runtime system with native BEAM integration
Type-directed optimizations (25-60% performance improvement)
Comprehensive testing infrastructure with high success rate
LSP Server with real-time diagnostics and IDE integration
SMT Solver Integration (API level - CLI integration planned)
Guard Compilation with runtime validation and optimization
Record operations with field access and update syntax

  • 🚀 Complete Import System: Full module resolution with import Module [functions] syntax
  • 📚 Working Standard Library: 12 modules (core, io, show, list, fsm, result, pair, vector, string, math, system, rec) with essential functions
  • 🎯 Dependent Types: Length-indexed vectors, refinement types with internal constraint representation
  • 🎆 Finite State Machines: Arrow-based transition syntax (State1 --> |event| State2) compiling to BEAM behaviors
  • ⚡ Type-Directed Optimizations: Monomorphization, function specialization, inlining (25-60% improvement)
  • 🏗️ BEAM Integration: Native compilation to BEAM bytecode with OTP compatibility
  • 🔧 Pattern Matching: Match expressions with guards and dependent type constraints
  • 📊 Complete Testing Infrastructure: Comprehensive test suites covering all compiler stages
  • 🔌 LSP Server: Language Server Protocol implementation with real-time diagnostics and hover info
  • ⚙️ Guard Compilation: Dependent type guard validation with runtime optimization
  • 🧮 SMT Integration: Z3/CVC5 solver integration at API level (CLI integration planned)
  • 📝 Record Operations: Field access (record.field) and update syntax (Record{base | field: value})
  • Control Flow: Match expressions with pattern guards (note: if-then-else not implemented)
  • String Operations: Concatenation with <> operator, charlist literals with Unicode curly quotes
  • List Operations: Cons operator | for pattern matching [h | t]
  • SMT-Based Constraint Solving: Z3/CVC5 integration at API level for type constraints
  • Error Handling: Result/Option types from standard library
  • CLI & Build System: Complete development toolchain with wrapper scripts
  • IDE Integration: LSP server with real-time diagnostics and hover information
  • Enhanced Error Messages: Precise location tracking with source code snippets

📋 Planned Features (See TODO.md for details)

Section titled “📋 Planned Features (See TODO.md for details)”
  • Pipe Operator: |> for function chaining (parser support exists, needs verification)
  • Type Classes/Traits: Polymorphic interfaces with typeclass and instance keywords
  • If-Then-Else: Traditional conditional expressions
  • String Interpolation: Template-based string construction
  • Advanced FSM Syntax: Guards and actions in state transitions
  • Effect System: Computational effects tracking
  • Macro System: Compile-time code generation
cure/
├── src/
│ ├── lexer/ # Tokenization and lexical analysis
│ ├── parser/ # Syntax analysis, AST generation, and error reporting
│ ├── types/ # Dependent type system implementation
│ ├── codegen/ # BEAM bytecode generation and guard compilation
│ ├── fsm/ # Finite state machine primitives
│ ├── smt/ # SMT solver integration (Z3, CVC5)
│ ├── lsp/ # Language Server Protocol implementation
│ └── runtime/ # Runtime system integration
├── lib/ # Standard library
├── test/ # Comprehensive test suites
├── examples/ # Example programs
└── docs/ # Language specification and documentation
Terminal window
# Build the compiler
make all
# Try the FSM traffic light example
./cure examples/06_fsm_traffic_light.cure
# Run the compiled program
erl -pa _build/ebin -noshell -eval "'TrafficLightDemo':main(), init:stop()."
# Expected output:
# Starting traffic light FSM...
# Current state: red
# [Traffic light transitions through states]
# Show help
./cure --help
# Run test suite
make test

Prerequisites: Erlang/OTP 20+, Make, Unix-like environment

Terminal window
# Clone and build
git clone <repository>
cd cure
make all
# Verify installation
./cure --version
# Run tests
make test

The Cure compiler includes a comprehensive CLI for compiling .cure files to BEAM bytecode.

Basic usage:

Terminal window
cure [OPTIONS] <input-file>

Key options:

  • -o, --output <file>: Specify output file
  • -d, --output-dir <dir>: Set output directory
  • --verbose: Enable detailed output
  • --no-type-check: Skip type checking

See [docs/CLI_USAGE.md]!(docs/CLI_USAGE.md) for complete documentation.

module ListDemo do
export [demo/0]
import Std.List [map, filter, fold]
import Std.IO [print]
def demo(): Unit =
let numbers = [1, 2, 3, 4, 5]
# Map operation
let doubled = map(numbers, fn(x) -> x * 2 end)
print("Doubled: " <> show(doubled))
# Filter operation
let evens = filter(numbers, fn(x) -> x % 2 == 0 end)
print("Evens: " <> show(evens))
# Fold operation
let sum = fold(numbers, 0, fn(x, acc) -> acc + x end)
print("Sum: " <> show(sum))
end
module ResultDemo do
export [safe_divide/2]
import Std.Result [ok, error, map, and_then]
def safe_divide(a: Int, b: Int): Result(Int, String) =
match b do
0 -> error("Division by zero")
_ -> ok(a / b)
end
def compute(): Result(Int, String) =
and_then(safe_divide(10, 2), fn(x) ->
map(safe_divide(x, 0), fn(y) -> y * 2 end)
end)
end
module Guards do
export [classify/1]
def classify(x: Int): Atom =
match x do
n when n < 0 -> :negative
0 -> :zero
n when n > 0 -> :positive
end
end
module TrafficLight do
export [create/0, next/1]
import Std.FSM [fsm_new, fsm_send, fsm_stop]
import Std.Pair [pair]
# Define FSM with arrow-based transitions
fsm TrafficLight do
initial: :red
:red --> |:timer| :green
:green --> |:timer| :yellow
:yellow --> |:timer| :red
:green --> |:emergency| :red
end
def create(): FSM(TrafficLight) =
fsm_new(TrafficLight, :red)
def next(fsm: FSM(TrafficLight)): FSM(TrafficLight) =
fsm_send(fsm, pair(:timer, unit()))
end
module Records do
export [demo/0]
record Person do
name: String
age: Int
email: String
end
def demo(): Unit =
let person = Person{name: "Alice", age: 30, email: "alice@example.com"}
# Field access
let name = person.name
# Record update (immutable)
let older = Person{person | age: 31}
print("Name: " <> name)
print("New age: " <> show(older.age))
end

See the examples/ directory for working code:

  • 01_list_basics.cure - List operations and standard library functions
  • 02_result_handling.cure - Error handling with Result type
  • 03_option_type.cure - Optional values with Option type
  • 04_pattern_guards.cure - Pattern matching with guard clauses
  • 05_recursion.cure - Recursive functions and tail call optimization
  • 06_fsm_traffic_light.cure - Complete FSM implementation

Complete & Functional (~85% Core Features)

Section titled “✅ Complete & Functional (~85% Core Features)”
  • Lexical Analysis: Complete tokenizer with position tracking and error recovery
  • Parsing: Full AST generation with recursive descent parsing and comprehensive error handling
  • Type System: Dependent type checking with refinement types (internal constraint representation)
  • Type Optimization: Monomorphization, specialization, inlining, dead code elimination (25-60% performance gain)
  • FSM System: Arrow-based FSM syntax compiling to BEAM behaviors with runtime operations
  • Code Generation: BEAM bytecode generation with debug information and OTP compatibility
  • Standard Library: 12 working modules (core, io, show, list, fsm, result, pair, vector, string, math, system, rec)
  • Record Operations: Field access and update syntax fully implemented
  • Pattern Matching: Match expressions with guards and dependent type constraints
  • CLI & Build System: Complete development toolchain with wrapper scripts
  • Testing Infrastructure: Comprehensive test suites covering lexer, parser, types, FSM, codegen
  • LSP Server: Language server with real-time diagnostics and hover information
  • SMT Integration: Z3/CVC5 solver integration at API level

📋 Missing Critical Features (~15% - See TODO.md)

Section titled “📋 Missing Critical Features (~15% - See TODO.md)”
  • Pipe Operator: |> for function chaining (parser recognizes, needs implementation verification)
  • Type Classes/Traits: Polymorphic interfaces with typeclass/instance keywords not recognized
  • If-Then-Else: Traditional conditional expressions (currently only match expressions)
  • String Interpolation: Template-based string construction (AST exists, implementation unclear)
  • Advanced FSM Syntax: Guards and actions in state transitions
  • CLI SMT Integration: Command-line options for SMT solver (API works, CLI planned)

🏗️ Future Features (Research/Experimental)

Section titled “🏗️ Future Features (Research/Experimental)”
  • Effect System: Computational effects tracking and management
  • Macro System: Compile-time code generation and metaprogramming
  • Linear Types: Resource management and memory safety
  • Gradual Typing: Mixed static/dynamic typing for Erlang interoperability
  • Distributed FSMs: Cross-node state machine coordination
  • Package Manager: Dependency management and distribution
  • Small files (<100 lines): <1 second
  • Medium projects (1K-10K lines): 5-30 seconds
  • Large projects (100K+ lines): 30-300 seconds with incremental compilation
  • Function calls: ~10ns overhead (after type-directed optimization)
  • FSM events: ~1μs including message passing
  • Type checking: Zero runtime overhead (compile-time only)
  • Memory usage: Comparable to equivalent Erlang code
  • Optimization impact: 25-60% performance improvement over unoptimized code

Comprehensive documentation is available in the docs/ directory:

  • [LANGUAGE_SPEC.md]!(docs/LANGUAGE_SPEC.md) - Complete language specification
  • [TYPE_SYSTEM.md]!(docs/TYPE_SYSTEM.md) - Dependent types and type system details
  • [FSM_USAGE.md]!(docs/FSM_USAGE.md) - Finite state machine guide
  • [FEATURE_REFERENCE.md]!(docs/FEATURE_REFERENCE.md) - Quick reference for all language features
  • [STD_SUMMARY.md]!(docs/STD_SUMMARY.md) - Standard library module documentation
  • [TODO.md]!(docs/TODO.md) - Missing features and future work
  • [EDITOR_SETUP.md]!(docs/EDITOR_SETUP.md) - IDE configuration for Cure development
  • [DEPENDENT_TYPES_GUIDE.md]!(docs/DEPENDENT_TYPES_GUIDE.md) - User guide to dependent types with SMT verification
  • [DEPENDENT_TYPES_DESIGN.md]!(docs/DEPENDENT_TYPES_DESIGN.md) - Design document and implementation details
  • [TYPECLASS_RESOLUTION.md]!(docs/TYPECLASS_RESOLUTION.md) - ✨ Typeclass method lookup and instance registry system (NEW)
  • [SMT_SOLVER_ADVANCED.md]!(docs/SMT_SOLVER_ADVANCED.md) - ✨ CVC5 solver, Z3 simplification, S-expression parsing (NEW)
  • [smt_simplification.md]!(docs/smt_simplification.md) - SMT-based constraint simplification and optimization
  • [dependent_types_demo.cure]!(examples/dependent_types_demo.cure) - Comprehensive examples showcasing compile-time verification

Cure is a research and educational project demonstrating advanced programming language concepts in a practical, BEAM-compatible implementation.

Contributions welcome! Priority areas (see TODO.md):

  • Pipe operator implementation - Complete |> integration
  • Type classes/traits - Polymorphic interface system
  • If-then-else expressions - Traditional control flow
  • Standard library expansion - More utility functions
  • String interpolation - Template-based strings
  • Developer tooling - Enhanced IDE support
  • Documentation and examples - More learning resources

To be determined based on project direction and community needs.