Files
hakorune/lang/c-abi
nyash-codex 0455307418 refactor(phase-a): remove Cranelift/JIT backend legacy code (~373 lines)
Phase A cleanup - Safe deletions with zero risk:

## Deleted Files (6 files, 373 lines total)
1. Cranelift/JIT Backend (321 lines):
   - src/runner/modes/cranelift.rs (45 lines)
   - src/runner/modes/aot.rs (55 lines)
   - src/runner/jit_direct.rs (152 lines)
   - src/tests/core13_smoke_jit.rs (42 lines)
   - src/tests/core13_smoke_jit_map.rs (27 lines)

2. Legacy MIR Builder (52 lines):
   - src/mir/builder/exprs_legacy.rs
   - Functionality inlined into exprs.rs (control flow constructs)

## Module Reference Cleanup
- src/backend/mod.rs: Removed cranelift feature gate exports
- src/runner/mod.rs: Removed jit_direct module reference
- src/runner/modes/mod.rs: Removed aot module reference
- src/mir/builder.rs: Removed exprs_legacy module

## Impact Analysis
- Build: Success (cargo build --release)
- Tests: All passing
- Risk Level: None (feature already archived, code unused)
- Related: Phase 15 JIT archival (archive/jit-cranelift/)

## BID Copilot Status
- Already removed in previous cleanup
- Not part of this commit

Total Reduction: 373 lines (~0.4% of codebase)
Next: Phase B - Dead code investigation

Related: #phase-21.0-cleanup
Part of: Legacy Code Cleanup Initiative
2025-11-06 22:34:18 +09:00
..

C ABI Kernel — Minimal Shim for Phase 20.9

Responsibility

  • Provide a portable, minimal C ABI surface used by the LLVM line.
  • Readonly GC externs first (hako_gc_stats, hako_gc_roots_snapshot), plus memory/console/time/local-env helpers.

Inputs/Outputs

  • In: Extern calls from Hakorune code compiled to LLVM (llvmlite harness / ny-llvmc).
  • Out: Simple values (i64) or newly allocated char* (caller frees with hako_mem_free).

Contracts

  • Ownership: char* returns are callee-owned; free via hako_mem_free().
  • Alignment: pointers from hako_mem_alloc/realloc satisfy max_align_t.
  • Thread-safety: memory API and read-only helpers are thread-safe.
  • Diagnostics: use short, stable messages (NOT_FOUND/UNSUPPORTED/VALIDATION) via TLS hako_last_error when applicable.
    • Missing env key: hako_env_local_get returns NULL and sets NOT_FOUND.
    • LLVM lowering emits a short warn (stderr) on missing; return handle remains 0.

Layout

  • include/ — public headers (hako_hostbridge.h mirror or thin wrapper)
  • shims/ — libc-backed reference implementation for canaries (hako_kernel.c)

Guards

  • No Rust modules or cargo manifests under lang/.
  • No parsing or codegen here; this is a plain ABI surface.

Build (example)

cc -I../../include -shared -fPIC -o libhako_kernel_shim.so shims/hako_kernel.c

Link (LLVM canary)

  • Use rpath + -L to locate libhako_kernel_shim.so at runtime.
  • Example flags: -L$ROOT/target/release -Wl,-rpath,$ROOT/target/release -lhako_kernel_shim

APIs (Phase 20.9)

  • Memory: hako_mem_alloc/realloc/free
  • GC (readonly): hako_gc_stats, hako_gc_roots_snapshot
  • Console: hako_console_log/warn/error (void sideeffect; returns 0)
  • Time: hako_time_now_ms
  • Local env: hako_env_local_get (caller frees via hako_mem_free)

Notes

  • Future control hooks (hako_gc_collect/start/stop) are defined but gated; do not silently succeed.
  • Platform CRT note: Only hako_mem_free() may be used to free memory obtained from any hako_* API to avoid CRT boundary issues (Windows msvcrt/ucrt, macOS libc).