forked from alex-eg/sex
walk a global's initializer like a local's
Only a local's initializer was walked, so at file scope a path was not dispatched, a lambda was never lifted, and a constructor written in place would have been left a call to nothing.
This commit is contained in:
@@ -691,6 +691,22 @@ compiles."
|
||||
(test-assert "a bare -> is not the arrow"
|
||||
(emits? (in-line "(= (-> pp x) 1)") "->(pp, x) = 1")))
|
||||
|
||||
;; A global's initializer is an expression like a local's, and walked
|
||||
;; the same way
|
||||
(test-group "global initializers"
|
||||
(test-assert "a path is dispatched on its type"
|
||||
(emits? (string-append "(struct pt ((x int)))"
|
||||
"(var a (struct pt) #((struct pt) : 1))"
|
||||
"(var q (* int) (& (. a x)))")
|
||||
"int * q = &a.x"))
|
||||
(test-assert "a lambda is lifted, and named after the global"
|
||||
(emits? "(var f (fn ((x int)) int) (lambda ((x int)) int (return x)))"
|
||||
"int (*f)(int) = λ0_f"))
|
||||
(test-assert "ahead of it"
|
||||
(let ((c (sex->c "(var f (fn ((x int)) int) (lambda ((x int)) int (return x)))")))
|
||||
(< (string-contains c "static int λ0_f (int x)")
|
||||
(string-contains c "(*f)(int) = λ0_f")))))
|
||||
|
||||
;; Toplevel forms used to be separated by a blank line unconditionally,
|
||||
;; which spread a block of adjacent typedefs over twice the lines its
|
||||
;; author wrote
|
||||
|
||||
Reference in New Issue
Block a user