1
0
forked from alex-eg/sex

define an empty lambda as an empty function

A lifted function with no body was a declaration of one, and nothing
defined it, so the program did not link.
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent b3d7decc6b
commit 94f41b5fad
5 changed files with 45 additions and 10 deletions

View File

@@ -441,6 +441,13 @@
(test-assert "and its code names it, a definition needing one before C23"
(emits? (in-fn "(var c (closure ((int) (int)) int) (closure ((int) (b int)) int () (return b)))")
"int ƛu0, int b)"))
;; a lifted function with no body was a declaration of one, and
;; nothing defined it
(test-assert "an empty lambda is an empty function"
(emits? "(fn f () void (var g (fn () void) (lambda () void)))"
"static void λ0_f (void) {}"))
(test-assert "so is an empty closure's code"
(emits? (in-fn "(var c (closure () void) (closure () void ()))") "(void * ƛe) {}"))
;; the call helper would have to forward the rest, which C cannot
(test-assert "a closure cannot be variadic"
(reports? (in-fn "(var c _ (closure ((n int) ...) int () (return n)))")

View File

@@ -13,7 +13,8 @@
"From a bare fn: 20 42 7"
"Captured array: 6 3, still 6"
"Captured const: 6"
"Unnamed parameter: 2")
"Unnamed parameter: 2"
"Empty bodies: called")
(return 0)
;;; A closure is a code pointer beside its captures, so what this
@@ -139,4 +140,10 @@
(var second (closure ((int) (int)) int) (closure ((int) (b int)) int () (return b)))
(printf "Unnamed parameter: %d\n" (second 1 2))
(var nothing (closure () void) (closure () void ()))
(var nothing-either (fn () void) (lambda () void))
(nothing)
(nothing-either)
(printf "Empty bodies: called\n")
(return 0))