176 Commits

Author SHA1 Message Date
38bf825134 feat: add effects to JS backend and fix code generation bugs
Phase 2 of JS backend: implement effect handlers in runtime

Effects added:
- Console: print, readLine, readInt
- Random: int, bool, float
- Time: now, sleep
- Http: get, post, postJson (async with fetch)

Bug fixes:
- Fix if-else with blocks executing both branches (use if-else
  statement instead of ternary for branches with statements)
- Fix main function being called twice when top-level let binding
  already invokes it
- Fix List module operations incorrectly treated as effect operations

New tests:
- test_js_random_int
- test_js_random_bool
- test_js_random_float
- test_js_time_now

All 19 JS backend tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:34:07 -05:00
ce4344810d test: add comprehensive integration tests for JS backend
Add 10 integration tests that compile Lux to JavaScript and verify
correct execution in Node.js:

- test_js_factorial: Recursion and effects
- test_js_fibonacci: Classic recursive algorithm
- test_js_adt_and_pattern_matching: Custom ADTs with match
- test_js_option_type: Built-in Option type handling
- test_js_closures: Closure creation and variable capture
- test_js_higher_order_functions: Functions as values
- test_js_list_operations: List.map, List.foldl
- test_js_pipe_operator: Pipe (|>) operator
- test_js_records: Record literal and field access
- test_js_string_concatenation: String operations

Also fix List module operations being incorrectly treated as effects
by adding special-case handling in EffectOp emission.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:28:07 -05:00
10ff8dc6ad feat: add JavaScript backend for browser/Node.js compilation
Implement Phase 1 of the browser/frontend plan with a complete JS
code generator that compiles Lux programs to JavaScript:

- Basic types: Int, Float, Bool, String, Unit → JS primitives
- Functions and closures → native JS functions with closure capture
- Pattern matching → if/else chains with tag checks
- ADT definitions → tagged object constructors
- Built-in types (Option, Result) → Lux.Some/None/Ok/Err helpers
- Effects → handler objects passed as parameters
- List operations → Array methods (map, filter, reduce, etc.)
- Top-level let bindings and run expressions

CLI usage:
  lux compile app.lux --target js -o app.js
  lux compile app.lux --target js --run

Tested with factorial, datatypes, functional, tailcall, and hello
examples - all producing correct output when run in Node.js.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 21:22:43 -05:00
9f9543a881 docs: add website and JS/WASM backend plans
Website Plan (docs/WEBSITE_PLAN.md):
- Research from Elm, Gleam, Rust, Go, Elixir, Zig websites
- Messaging strategy: "Effects you can see, tests you can trust"
- Section structure: Hero, Problem, Solution (3 pillars), Examples
- Self-hosting goal: Build lux-lang.org in Lux itself

JS/WASM Backend Plan (docs/JS_WASM_BACKEND_PLAN.md):
- Type mappings: Lux types → JavaScript equivalents
- Code generation examples for functions, closures, ADTs, effects
- 6-phase implementation: Core → StdLib → Effects → DOM → CLI → WASM
- New Dom effect for browser manipulation
- Timeline: 11-15 weeks for full support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 16:32:39 -05:00
42fef80a47 feat: add comprehensive benchmark suite with multi-language comparison
Add benchmarks comparing Lux against 7 languages:
- Rust, C, Go (compiled)
- Node.js, Bun (JavaScript JIT)
- Python (interpreted)

Benchmarks:
- Fibonacci (fib 35): recursive function calls
- Prime counting (10k): loops and conditionals
- Sum loop (10M): tight numeric loops
- Ackermann (3,10): deep recursion
- Selection sort (1k): sorting algorithm
- List operations (10k): map/filter/fold with closures

Results show Lux:
- Matches C and Rust performance
- 2-5x faster than Go
- 7-15x faster than Node.js
- 10-285x faster than Python

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 16:17:06 -05:00
f099b9fc90 fix: resolve all cargo compiler warnings
- Fix unused import std::io::Read in interpreter.rs by using qualified call
- Add #[allow(dead_code)] to CGenError.span (kept for future error reporting)
- Add #[allow(dead_code)] to local_vars field (planned for free variable analysis)
- Add #[allow(dead_code)] to unbox_value and emit_all_scope_cleanup methods

All 263 tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:26:21 -05:00
2960dd6538 feat: add benchmarks and enhance LSP completions/hover
Benchmarks:
- Add fib, list_ops, primes benchmarks comparing Lux vs Node.js vs Rust
- Lux matches Rust performance and is 8-30x faster than Node.js
- Add docs/benchmarks.md documenting results

LSP improvements:
- Context-aware completions (module access vs general)
- Add List, String, Option, Result, Console, Math method completions
- Add type and builtin completions
- Hover now shows type signatures and documentation for known symbols
- Hover returns formatted markdown with code blocks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:23:35 -05:00
1ca31fe985 fix: track temporary strings from toString and concat for RC cleanup
- toString now stores result in temp variable and registers for RC
- String concatenation stores result and registers for RC
- Immediately decref temporary input strings after concat to avoid leaks
- Add is_rc_temp() helper to identify RC temporary variables

This fixes the memory leak where dynamically created strings from
toString() and string concatenation were not being freed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 15:00:29 -05:00
bba94b534d feat: add FBIP debug counters to prove optimization effectiveness
Add runtime counters tracking FBIP reuse vs copy operations:
- lux_fbip_reuse_count: incremented when rc=1 allows in-place mutation
- lux_fbip_copy_count: incremented when rc>1 forces allocation

Output now shows both memory stats and FBIP stats:
  [RC] No leaks: 13 allocs, 13 frees
  [FBIP] 3 reuses, 0 copies

Rename test_no_fbip.lux to test_ownership_transfer.lux to better
reflect that ownership transfer enables FBIP even with aliases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:52:35 -05:00
25a3adf4fc test: add RC stress tests with large lists
- stress_rc.lux: Single-owner chains testing FBIP optimization
- stress_shared_rc.lux: Shared-reference chains (rc>1) forcing copy path

Both process lists of 100, 200, 500, and 1000 elements with map/filter/reverse.
Verifies no memory leaks with large data sets.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:46:21 -05:00
771512a2ec test: add FBIP and RC verification test cases
Add test cases demonstrating FBIP (Functional But In-Place) optimization:
- test_fbip_clean.lux: Basic FBIP chain (map, filter, reverse)
- test_fbip_allocs.lux: Single-owner allocation test with range/map/filter/reverse
- test_no_fbip.lux: Demonstrates shared reference forcing rc>1 path
- test_rc_comparison.lux: Comparison of FBIP vs non-FBIP allocations

All tests verify no memory leaks with the RC system.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:44:53 -05:00
4d5a975b79 feat: implement FBIP (Functional But In-Place) reuse analysis
When rc=1 at update sites, mutate in-place instead of allocating new:

List.reverse:
- Swap element pointers in-place instead of creating new list

List.take:
- Truncate list in-place, decref dropped elements

List.drop:
- Shift elements to front in-place, decref dropped elements

List.map:
- Mutate elements in-place, decref old values before storing new

List.filter:
- Filter in-place by shifting kept elements, decref filtered-out elements

All operations check LUX_RC_HEADER(list)->rc == 1 at runtime and
fall back to allocation when rc > 1 (list is shared).

This completes Phase B performance optimizations:
- B1: Last-use optimization (ownership transfer) 
- B2: Reuse analysis (FBIP) 
- B3: Drop specialization 

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:37:15 -05:00
3a22ae089f feat: add drop specialization and ownership transfer optimizations
Phase B Performance Optimizations:

Drop Specialization:
- Add specialized decref functions: lux_decref_list, lux_decref_closure,
  lux_decref_string, lux_decref_boxed
- Inline drop logic eliminates polymorphic dispatch through lux_drop
- Forward type declarations (typedef struct X_s X) for proper C ordering

Ownership Transfer (Last-Use Optimization):
- Track variable types in var_types HashMap for type inference
- When assigning let b = a where a is RC-tracked:
  - Unregister source variable from RC cleanup
  - Register destination variable instead
- Prevents double-free and eliminates unnecessary incref/decref pairs

Also:
- Fix type inference for variable references in infer_expr_type
- Add is_rc_tracked() and unregister_rc_var() helper functions
- Update REFERENCE_COUNTING.md with Phase B progress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:33:50 -05:00
0c4b4e8fd0 feat: add toString, string concat, keyword escaping, and conditional RC
- Add escape_c_keyword() to mangle C reserved words (double, int, etc.)
- Implement toString() mapping to lux_int_to_string()
- Add string concatenation detection for BinaryOp::Add using lux_string_concat()
- Add is_string_expr() helper for string expression detection
- Update infer_expr_type() for toString, string concat, and if expressions
- Implement complex conditionals RC handling: use if-statements instead of
  ternaries when branches create RC values to avoid allocating unused branches

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 14:16:54 -05:00
f6569f1821 feat: implement early return handling for RC values
- Add pop_rc_scope_except() to skip decref'ing returned variables
- Block expressions now properly preserve returned RC variables
- Function returns skip cleanup for variables being returned
- Track function return types for call expression type inference
- Function calls returning RC types now register for cleanup
- Fix main() entry point to call main_lux() when present

Test result: [RC] No leaks: 17 allocs, 17 frees

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 13:53:28 -05:00
5098104aaf feat: implement ADT RC - pointer fields in algebraic data types
ADT values with pointer fields (like recursive Tree types) now properly
manage memory:

- Assign unique type tags (starting at 100) to each ADT type
- Track which ADTs have pointer fields that need cleanup
- Generate lux_drop_adt() function with per-ADT drop logic
- Allocate ADT pointer fields with lux_rc_alloc instead of malloc
- Track ADT variables with pointer fields in scope
- Emit field cleanup code at scope exit (switch on tag, decref fields)

Test results:
- ADT test: [RC] No leaks: 6 allocs, 6 frees
- List test: [RC] No leaks: 31 allocs, 31 frees
- Closure test: [RC] No leaks: 8 allocs, 8 frees
- All 263 tests pass

Remaining: early returns, complex conditionals.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 13:24:45 -05:00
397c633d51 chore: add test binaries to gitignore
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 13:14:13 -05:00
c68694294b feat: implement closure RC - environments are now memory-managed
Closures and their environments are now properly reference-counted:

- Allocate closures with lux_rc_alloc(sizeof(LuxClosure), LUX_TAG_CLOSURE)
- Allocate environments with lux_rc_alloc(sizeof(LuxEnv_N), LUX_TAG_ENV)
- Enable Lambda in expr_creates_rc_value() to track closure variables
- Add lux_decref() after List higher-order operations (map, filter, fold,
  find, any, all) to clean up inline lambdas

Test results:
- Closure test: [RC] No leaks: 8 allocs, 8 frees
- List RC test: [RC] No leaks: 31 allocs, 31 frees
- All 263 tests pass

Remaining for full memory safety: ADT RC, early returns, conditionals.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 13:14:08 -05:00
b2f4beeaa2 docs: update documentation with RC implementation status
- C_BACKEND.md: Update memory management from "Leaks" to "Scope-based RC",
  update comparison tables with Koka/Rust/Zig/Go
- LANGUAGE_COMPARISON.md: Add status column to gap tables, add RC row
- OVERVIEW.md: Add C backend RC to completed features, update limitations
- REFERENCE_COUNTING.md: Add "Path to Koka/Rust Parity" section with:
  - What we have vs what Koka/Rust have
  - Remaining work for full memory safety (~230 lines)
  - Performance optimizations for Koka parity (~600 lines)
  - Cycle detection strategy

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 13:05:17 -05:00
b1cffadc83 feat: implement automatic RC cleanup at scope exit
Add scope tracking for reference-counted variables in the C backend:

- Add RcVariable struct and rc_scopes stack to CBackend
- Track RC variables when assigned in let bindings
- Emit lux_decref() calls when scopes exit (functions, blocks)
- Add memory tracking counters (alloc/free) for leak detection
- Fix List.filter to incref elements before copying (prevents double-free)
- Handle return values by incref/decref to keep them alive through cleanup

The RC system now properly frees memory at scope exit. Verified with
test showing "[RC] No leaks: 28 allocs, 28 frees".

Remaining work: early returns, complex conditionals, closures, ADTs.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 12:55:44 -05:00
56f0fa4eaa feat: add Perceus-inspired reference counting infrastructure
Implements Phase 1-3 of the RC system for automatic memory management:

- Add LuxRcHeader with refcount and type tag for all heap objects
- Add lux_rc_alloc, lux_incref, lux_decref, and lux_drop functions
- Update list allocation to use RC (lux_list_new uses lux_rc_alloc)
- List operations (concat, reverse, take, drop) now incref shared elements
- Update boxing functions (box_int, box_bool, box_float) to use RC
- String operations (concat, int_to_string, readLine) return RC strings
- File and HTTP operations return RC-managed strings

The infrastructure is ready for automatic decref insertion at scope exit
(Phase 4) and closure RC (Phase 5) in future work.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 12:27:54 -05:00
2a2c6d2760 feat: add Http effect to C backend
Implement HTTP client using POSIX sockets:
- Http.get(url) - GET request
- Http.post(url, body) - POST request
- Http.put(url, body) - PUT request
- Http.delete(url) - DELETE request

Features:
- Self-contained implementation (no libcurl dependency)
- URL parsing for host, port, and path
- HTTP/1.1 protocol with Connection: close
- Response body extraction

All Http operations use evidence passing for handler customization.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 12:14:06 -05:00
3c7d72f663 feat: add Random, Time, and File effects to C backend
New effects with evidence passing support:

Random effect:
- int(min, max) - random integer in range
- float() - random float 0-1
- bool() - random boolean

Time effect:
- now() - milliseconds since epoch
- sleep(ms) - pause execution

File effect:
- read(path) - read file contents
- write(path, content) - write file
- append(path, content) - append to file
- exists(path) - check if file exists
- delete(path) - delete file
- isDir(path) - check if directory
- mkdir(path) - create directory

Also fixed:
- Function calls as statements now properly emit in generated C
- Return type inference for all effect operations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 12:08:25 -05:00
52cb38805a feat: complete evidence threading in C backend
C backend now fully threads evidence through effectful function calls:

- Track effectful functions via effectful_functions HashSet
- Add has_evidence flag to track context during code generation
- Add LuxEvidence* ev parameter to effectful function signatures
- Transform effect operations to use ev->console->print() when evidence available
- Update function calls to pass evidence (ev or &default_evidence)
- Update main entry point to pass &default_evidence

Generated code now uses zero-cost evidence passing:
  void greet_lux(LuxEvidence* ev) {
      ev->console->print(ev->console->env, "Hello!");
  }

This completes the evidence passing implementation for both interpreter
(O(1) HashMap lookup) and C backend (direct function pointer calls).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 11:58:26 -05:00
ce4ab45651 feat: implement evidence passing for O(1) effect handler lookup
Interpreter changes:
- Add evidence HashMap for O(1) handler lookup instead of O(n) stack search
- Update eval_run to manage evidence when entering/exiting run blocks
- Modify handle_effect to use evidence.get() instead of stack iteration

C backend infrastructure:
- Add handler structs (LuxConsoleHandler, LuxStateHandler, LuxReaderHandler)
- Add LuxEvidence struct containing pointers to all handlers
- Add default handlers that delegate to built-in implementations
- Add Console.readLine built-in implementation

Documentation:
- Create docs/EVIDENCE_PASSING.md explaining design and implementation
- Update docs/C_BACKEND.md with current progress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 11:52:00 -05:00
909dbf7a97 feat: add list support to C backend and improve compile workflow
C Backend Lists:
- Add LuxList type (dynamic array with void* boxing)
- Implement all 16 list operations: length, isEmpty, concat, reverse,
  range, take, drop, head, tail, get, map, filter, fold, find, any, all
- Higher-order operations generate inline loops with closure calls
- Fix unique variable names to prevent redefinition errors

Compile Command:
- `lux compile file.lux` now produces a binary (like rustc, go build)
- Add `--emit-c` flag to output C code instead
- Binary name derived from source filename (foo.lux -> ./foo)
- Clean up temp files after compilation

Documentation:
- Create docs/C_BACKEND.md with full strategy documentation
- Document compilation pipeline, runtime types, limitations
- Compare with Koka, Rust, Zig, Go, Nim, OCaml approaches
- Outline future roadmap (evidence passing, Perceus RC)
- Fix misleading doc comment (remove false Perceus claim)
- Update OVERVIEW.md and ROADMAP.md to reflect list completion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 11:02:26 -05:00
d284ee58a8 feat: add pattern variable binding to C backend
Implements full pattern matching with variable binding for the C backend:

- Extract variable bindings from patterns (Var, Constructor, Tuple, Record)
- Infer C types for bound variables using variant field type tracking
- Handle recursive ADTs with pointer fields and heap allocation
- Dereference pointer bindings automatically for value semantics

Key implementation details:
- variant_to_type: Maps variant names to parent type for tag generation
- variant_field_types: Maps (type, variant) to field types for inference
- Recursive type fields use Type* pointers with malloc/memcpy
- Pattern bindings dereference pointers to maintain value semantics

Examples that now work:
- match opt { Some(x) => x, None => 0 }
- match tree { Leaf(n) => n, Node(l, r) => sum(l) + sum(r) }

Updates documentation to reflect C backend progress.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 04:23:44 -05:00
6ec1f3bdbb feat: add closure support to C backend
Implement closures/lambdas in the C code generator:

- Add LuxClosure struct (env pointer + function pointer)
- Add ClosureInfo to track closure metadata during generation
- Implement free variable analysis to find captured variables
- Generate environment structs for each lambda's captured vars
- Generate lambda implementation functions
- Support indirect closure calls via function pointer casting
- Track functions returning closures for proper type inference

Example: fn(x) => x + n compiles to a LuxEnv struct holding n,
a lambda_N function taking env + x, and closure allocation code.

Limitations: No memory management (closures leak), types
mostly hardcoded to LuxInt.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 03:53:38 -05:00
67437b8273 feat: replace Cranelift JIT with C backend
Remove Cranelift JIT compiler and expose the existing C backend as the
compilation target. Generated C code can be compiled with GCC/Clang.

Changes:
- Remove cranelift-* dependencies from Cargo.toml
- Delete src/compiler.rs (565 lines of Cranelift code)
- Add compile_to_c() function with -o and --run flags
- Fix C backend name mangling (main -> main_lux) to avoid conflicts
- Update CLI help text and documentation

Usage:
  lux compile <file.lux>           # Output C to stdout
  lux compile <file.lux> -o out.c  # Write to file
  lux compile <file.lux> --run     # Compile and execute

C backend supports: functions, basic types, operators, if/then/else,
records, enums, Console.print. Future work: closures, lists, patterns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 03:37:35 -05:00
8c7354131e docs: update documentation to match current implementation
- SKILLS.md: Update roadmap phases with actual completion status
  - Phase 0-1 complete, Phase 2-5 partial, resolved design decisions
- OVERVIEW.md: Add HttpServer, Test effect, JIT to completed features
- ROADMAP.md: Add HttpServer, Process, Test effects to done list
- VISION.md: Update Phase 2-3 tables with current status
- guide/05-effects.md: Add Time, HttpServer, Test to effects table
- guide/09-stdlib.md: Add HttpServer, Time, Test effect docs
- reference/syntax.md: Fix interpolation syntax, remove unsupported literals
- testing.md: Add native Test effect documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 02:56:42 -05:00
c81349d82c fix: resolve all stress test bugs
- Record equality: add Record case to values_equal in interpreter
- Invalid escapes: error on unknown escape sequences in lexer
- Unknown effects: validate effect names in check_function with suggestions
- Circular types: add DFS cycle detection in check_type_cycles
- Parser: require | for enum variants, enabling proper type alias syntax

All 265 tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 02:45:52 -05:00
07a35f1829 docs: add stress test findings with identified bugs and gaps
Documents findings from systematic testing of parser, typechecker, and REPL:
- 5 critical bugs (record equality, invalid escapes, unknown effects, etc.)
- Parser missing features (hex literals, list patterns, guard clauses)
- Poor error messages for common mistakes
- REPL issues (:type doesn't show type, interpolation syntax)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 02:20:41 -05:00
ee9acce6ec feat: add Test effect and native testing framework
- Add Test effect with operations: assert, assertEqual, assertNotEqual,
  assertTrue, assertFalse, fail
- Implement Test effect handlers in interpreter with TestResults tracking
- Add values_equal method for comparing Value types in tests
- Update lux test command to discover and run test_* functions
- Create example test files: test_math.lux, test_lists.lux
- Add TESTING_DESIGN.md documentation
- Fix AST mismatches in C backend and compiler.rs for compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 01:20:30 -05:00
9a42a7f540 wip: compile to c 2026-02-14 00:12:28 -05:00
d9be70b021 fix: improve JIT compiler error messages
Show specific expression type when JIT compilation fails, e.g.:
- "Unsupported in JIT: String literal"
- "Effect operation 'Console.print' - effects are not supported in JIT"
- "ADT constructor 'Success' - algebraic data types are not supported in JIT"

This helps users understand exactly which expression is blocking
JIT compilation instead of a generic "Unsupported expression type".

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 23:36:18 -05:00
6ace4dea01 feat: add integration tests and lint script for examples
- Add 30 integration tests that verify all examples and projects
  parse and type-check correctly
- Add scripts/lint-examples.sh for quick pre-commit validation
- Tests will catch regressions like missing `run ... with {}` syntax
  or broken escape sequences

Run with: cargo test example_tests
Or quick check: ./scripts/lint-examples.sh

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 23:35:22 -05:00
f5fe7d5335 fix: fix examples to use working patterns
- behavioral.lux: use verifiable behavioral patterns (abs for idempotent)
- behavioral_types.lux: use simpler verified patterns, proper main invocation
- schema_evolution.lux: simplify to runtime schema ops, fix record access
- jit_test.lux: add proper main function with console output

All examples now parse and run correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 23:31:21 -05:00
cdc4f47272 fix: fix REST API and HTTP server examples
- Fix string interpolation issues: escape curly braces with \{ and \}
  since unescaped { triggers string interpolation
- Fix effectful function invocation: use "let _ = run main() with {}"
  instead of bare "main()" calls
- Use inline record types instead of type aliases (structural typing)
- Fix flake.nix to show build progress instead of suppressing output

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 23:11:51 -05:00
5edd8aea77 feat: add lux to PATH on shell entry
- Build release binary when entering nix shell
- Add target/release to PATH automatically
- Update shell help to show lux commands

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 22:22:08 -05:00
705bd57e81 docs: add demos and update documentation for new features
Documentation:
- Update IMPLEMENTATION_PLAN.md with current status (222 tests)
- Update feature comparison table (Schema Evolution, Behavioral Types: )
- Add HttpServer to built-in effects list
- Update OVERVIEW.md with working behavioral types examples

Demo Programs:
- examples/schema_evolution.lux - Version annotations, constraints, runtime ops
- examples/behavioral_types.lux - pure, deterministic, commutative, idempotent, total

Sample Project:
- projects/rest-api/ - Full REST API demo with:
  - Task CRUD endpoints
  - Pattern matching router
  - JSON serialization
  - Effect-tracked request handling

Tests:
- Add behavioral type tests (pure, deterministic, commutative, idempotent, total)
- 227 tests passing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 22:14:55 -05:00
086552b7a4 feat: add schema evolution type system integration and HTTP server effect
Schema Evolution:
- Preserve version info in type resolution (Type::Versioned)
- Track versioned type declarations in typechecker
- Detect version mismatches at compile time (@v1 vs @v2 errors)
- Support @v2+ (at least) and @latest version constraints
- Store migrations for future auto-migration support
- Fix let bindings to preserve declared type annotations

HTTP Server Effect:
- Add HttpServer effect with listen, accept, respond, respondWithHeaders, stop
- Implement blocking request handling via tiny_http
- Request record includes method, path, body, headers
- Add http_server.lux example with routing via pattern matching
- Add type-checking test for HttpServer effect

Tests: 222 passing (up from 217)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 22:06:31 -05:00
554a1e7c3e feat: expose JIT compiler via CLI command
Add `lux compile <file>` command that compiles and runs Lux code using
the Cranelift JIT compiler. Includes --benchmark flag for timing.

- Add compile_file() function in main.rs
- Add jit_test.lux example with fib(30) + factorial(10)
- Update VISION.md status

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 21:16:39 -05:00
26546f9a6a docs: update documentation to reflect actual implementation status
Many features were documented as "missing" or "planned" but are actually
working: generics, string interpolation, File/HTTP/Random/Time effects,
JSON parsing, module system, and JIT CLI integration.

Updated IMPLEMENTATION_PLAN.md, OVERVIEW.md with accurate status.
Added ROADMAP.md (use-case-targeted) and LANGUAGE_COMPARISON.md.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 21:12:24 -05:00
730112a917 feat: add stress test projects and testing documentation
- Add String.fromChar function to convert Char to String
- Create four stress test projects demonstrating Lux features:
  - json-parser: recursive descent parsing with Char handling
  - markdown-converter: string manipulation and ADTs
  - todo-app: list operations and pattern matching
  - mini-interpreter: AST evaluation and environments
- Add comprehensive testing documentation (docs/testing.md)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 18:53:27 -05:00
a6eb349d59 feat: improve editor tooling and fix warnings
Neovim improvements:
- Add tree-sitter text objects for functions, types, blocks
- Add folding support
- Enhanced REPL integration (toggle, send line/selection)
- New commands: LuxCheck, LuxReplToggle, LuxSend
- Better keybindings with localleader

VS Code extension:
- Full syntax highlighting with TextMate grammar
- LSP client integration
- 20+ snippets for common patterns
- Commands: run, format, check, REPL
- Keybindings and context menu

Fixes:
- Fix all cargo warnings with #[allow(dead_code)] annotations
- Clean up unused variables

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 18:23:55 -05:00
ebc0bdb109 feat: improve error messages with context lines
- Show 2 lines of context before and after errors (dimmed)
- Fix guessing_game.lux to be non-interactive for testing
- Use binary search simulation to demonstrate game logic

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 18:13:57 -05:00
719bc77243 feat: add Console.readLine and Console.readInt, guessing game project
Add readLine and readInt operations to the Console effect for interactive
input. Create a number guessing game project demonstrating ADTs, pattern
matching, effects, and game state management.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 17:58:00 -05:00
44f88afcf8 docs: add comprehensive language documentation
Documentation structure inspired by Rust Book, Elm Guide, and others:

Guide (10 chapters):
- Introduction and setup
- Basic types (Int, String, Bool, List, Option, Result)
- Functions (closures, higher-order, composition)
- Data types (ADTs, pattern matching, records)
- Effects (the core innovation)
- Handlers (patterns and techniques)
- Modules (imports, exports, organization)
- Error handling (Fail, Option, Result)
- Standard library reference
- Advanced topics (traits, generics, optimization)

Reference:
- Complete syntax reference

Tutorials:
- Calculator (parsing, evaluation, REPL)
- Dependency injection (testing with effects)
- Project ideas (16 projects by difficulty)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 17:43:41 -05:00
9ee7148d24 feat: add module import examples and standard library
Module system was already implemented - this adds examples and stdlib:

examples/modules/:
- math_utils.lux: Reusable math functions (square, cube, factorial)
- string_utils.lux: String utilities (repeat, exclaim, greet)
- main.lux: Basic module import example
- main_selective.lux: Selective imports {fn1, fn2}
- main_wildcard.lux: Wildcard imports (module.*)
- use_stdlib.lux: Using the standard library

std/:
- prelude.lux: Core utilities (identity, compose, flip, not, and, or)
- io.lux: I/O helpers (println, readLine, debug)
- option.lux: Option utilities (some, none, map, flatMap, filter)
- result.lux: Result utilities (ok, err, mapOk, mapErr)

Import syntax supports:
- import path/to/module       (access as module.fn)
- import path/to/module as x  (access as x.fn)
- import path/to/module.{a,b} (access as a, b directly)
- import path/to/module.*     (all exports directly)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 17:28:23 -05:00
0b5abece5f feat: add comprehensive example programs
Standard examples (examples/standard/):
- hello_world: Basic effect usage
- fizzbuzz: Classic programming exercise
- factorial: Recursive and tail-recursive versions
- primes: Prime number generation
- guessing_game: Interactive Random + Console effects
- stdlib_demo: Demonstrates List, String, Option, Math modules

Showcase examples (examples/showcase/):
- ask_pattern: Resumable effects for config/environment
- custom_logging: Custom effect with handler
- early_return: Fail effect for clean error handling
- effect_composition: Combining multiple effects
- higher_order: Closures and function composition
- pattern_matching: ADTs and exhaustive matching

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 17:25:04 -05:00