forked from alex-eg/sex
name a lambda's unnamed parameters in its definition
A definition names every parameter before C23, as a closure's code already does.
This commit is contained in:
@@ -1568,8 +1568,10 @@
|
||||
(define (lift-lambda name form)
|
||||
(match form
|
||||
(('lambda arglist ret-type . body)
|
||||
(process-fn (copy-form-source! form `(fn ,name ,arglist ,ret-type
|
||||
,@(defining body)))
|
||||
(process-fn (copy-form-source!
|
||||
form
|
||||
`(fn ,name ,(named-parameters arglist) ,ret-type
|
||||
,@(defining body)))
|
||||
(list)))
|
||||
(else (sex-error form "malformed lambda" form))))
|
||||
|
||||
@@ -1935,7 +1937,8 @@
|
||||
;;; type alone gets a name nothing reads: ((int) (b int)) -> ((ƛu0 int) (b int))
|
||||
(define (named-parameters arglist)
|
||||
(map (lambda (arg index)
|
||||
(if (or (named-arg? arg) (comment-form? arg))
|
||||
(if (or (named-arg? arg) (comment-form? arg)
|
||||
(eq? arg '...) (equal? arg '(...)))
|
||||
arg
|
||||
(list (string->symbol (string-append "ƛu" (number->string index)))
|
||||
(unwrap-type arg))))
|
||||
|
||||
@@ -490,6 +490,14 @@
|
||||
(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 definition names every parameter before C23, a lambda's as a
|
||||
;; closure's code does
|
||||
(test-assert "a lambda's unnamed parameter is named in its definition"
|
||||
(emits? "(fn f () void (var g (fn ((int) (int)) int) (lambda ((int) (b int)) int (return b))))"
|
||||
"λ0_f (int ƛu0, int b)"))
|
||||
(test-assert "and a variadic one keeps its ..."
|
||||
(emits? "(fn f () void (var g (fn ((int) ...) int) (lambda ((n int) ...) int (return n))))"
|
||||
"λ0_f (int n, ...)"))
|
||||
;; a lifted function with no body was a declaration of one, and
|
||||
;; nothing defined it
|
||||
(test-assert "an empty lambda is an empty function"
|
||||
|
||||
Reference in New Issue
Block a user