99f68e89fa
Every fn-value is now a `ptr` to a closure pair `{ ptr thunk, ptr env }`,
not a raw fn-pointer. Top-level fns get an auto-generated adapter
`@ail_<m>_<f>_adapter(ptr %_env, params...)` that ignores env and
forwards to the real fn, plus a static closure constant
`@ail_<m>_<f>_clos = { @adapter, null }`. References to a fn as a
value return the closure-pair address.
Indirect calls now GEP the thunk + env slots, load both, and call
`thunk(env, args...)`. Direct calls to statically-known callees stay
on the original fast path (no adapter).
This is the ABI groundwork for Iter 8b lambdas: a captured-env closure
will reuse the same value shape, just with a non-null env produced by
malloc.
Tests: 48 still green. IR snapshots refreshed (every fn now carries an
adapter + static closure pair). Iter 7's hof.ail.json prints 42
unchanged — `apply(inc, 41)` now hands `@ail_hof_inc_clos` to apply,
which unpacks and indirect-calls as designed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
29 lines
640 B
LLVM
29 lines
640 B
LLVM
; AILang generated workspace; entry: hello
|
|
source_filename = "hello.ail"
|
|
target triple = "<NORMALIZED>"
|
|
|
|
@.str_hello_str_0 = private unnamed_addr constant [15 x i8] c"Hello, AILang.\00", align 1
|
|
|
|
declare i32 @printf(ptr, ...)
|
|
declare i32 @puts(ptr)
|
|
declare ptr @malloc(i64)
|
|
|
|
@ail_hello_main_clos = private unnamed_addr constant { ptr, ptr } { ptr @ail_hello_main_adapter, ptr null }
|
|
define i8 @ail_hello_main() {
|
|
entry:
|
|
call i32 @puts(ptr @.str_hello_str_0)
|
|
ret i8 0
|
|
}
|
|
|
|
define i8 @ail_hello_main_adapter(ptr %_env) {
|
|
entry:
|
|
%r = call i8 @ail_hello_main()
|
|
ret i8 %r
|
|
}
|
|
|
|
|
|
define i32 @main() {
|
|
call i8 @ail_hello_main()
|
|
ret i32 0
|
|
}
|