fix: C backend struct ordering enables native compilation

The LuxList struct body was defined after functions that used it,
causing "invalid use of incomplete typedef" errors. Moved struct
definition earlier, right after the forward declaration.

Compiled Lux now works and achieves C-level performance:
- Lux (compiled): 0.030s
- C (gcc -O3): 0.028s
- Rust: 0.041s
- Zig: 0.046s

Updated benchmark documentation with accurate measurements for
both compiled and interpreted modes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-16 05:14:49 -05:00
parent 0cf8f2a4a2
commit 8a001a8f26
3 changed files with 126 additions and 141 deletions

View File

@@ -426,6 +426,13 @@ impl CBackend {
self.writeln("// Closure representation: env pointer + function pointer");
self.writeln("struct LuxClosure_s { void* env; void* fn_ptr; };");
self.writeln("");
self.writeln("// List struct body (typedef declared above)");
self.writeln("struct LuxList_s {");
self.writeln(" void** elements;");
self.writeln(" int64_t length;");
self.writeln(" int64_t capacity;");
self.writeln("};");
self.writeln("");
self.writeln("// === Reference Counting Infrastructure ===");
self.writeln("// Perceus-inspired RC system for automatic memory management.");
self.writeln("// See docs/REFERENCE_COUNTING.md for details.");
@@ -1378,17 +1385,8 @@ impl CBackend {
self.writeln(" .process = &default_process_handler");
self.writeln("};");
self.writeln("");
self.writeln("// === List Types ===");
self.writeln("");
self.writeln("// LuxList struct body (typedef declared earlier for drop specialization)");
self.writeln("struct LuxList_s {");
self.writeln(" void** elements;");
self.writeln(" int64_t length;");
self.writeln(" int64_t capacity;");
self.writeln("};");
self.writeln("");
// Note: Option type is already defined earlier (before handler structs)
self.writeln("");
self.writeln("// === List Operations ===");
self.writeln("// (LuxList struct defined earlier, before string functions)");
// Emit specialized decref implementations (now that types are defined)
self.emit_specialized_decref_implementations();