forked from alex-eg/sex
declare the closure environment in c99
`max_align_t' is C11 and the union goes into every unit, so a program with no closure in it stopped building under -std=c99. `unify' also bound a rigid variable one way round only.
This commit is contained in:
@@ -183,7 +183,17 @@
|
||||
(test-assert "an ordinary variable binds to it instead"
|
||||
(unify a r #f))
|
||||
;; An unsolved variable resolves to itself.
|
||||
(test-assert "it is still open" (tvar? (resolve r))))))
|
||||
(test-assert "it is still open" (tvar? (resolve r))))
|
||||
;; ...and the same the other way round: it is which side is free
|
||||
;; that decides, not which side was written first.
|
||||
(let ((r (fresh-rigid-tvar))
|
||||
(a (fresh-tvar)))
|
||||
(test-assert "rigid first binds the free one" (unify r a #f))
|
||||
(test-assert "to the parameter itself" (eq? r (resolve a))))
|
||||
(let ((r1 (fresh-rigid-tvar))
|
||||
(r2 (fresh-rigid-tvar)))
|
||||
(test-error "two parameters do not unify with each other"
|
||||
(unify r1 r2 #f)))))
|
||||
|
||||
(test-group "constraints"
|
||||
(test #t (entails? 'numeric (parse-type 'int)))
|
||||
|
||||
28
tests/sex-programs/c99.sex
Normal file
28
tests/sex-programs/c99.sex
Normal file
@@ -0,0 +1,28 @@
|
||||
(compilation "-- -std=c99 -pedantic-errors")
|
||||
(input)
|
||||
(output "c99: 42")
|
||||
(return 0)
|
||||
|
||||
;;; The closure environment is part of the ABI, so its union is declared
|
||||
;;; in every translation unit whether or not one is used. That put
|
||||
;;; whatever it was written with into every program: `max_align_t' named
|
||||
;;; the alignment in one word, and made C11 the floor for a program with
|
||||
;;; no closure in it at all.
|
||||
;;;
|
||||
;;; The widest built-ins say the same thing -- a union is aligned for the
|
||||
;;; strictest of its members -- and say it in C99.
|
||||
;;;
|
||||
;;; Closures themselves still want C11 for the `_Static_assert' that
|
||||
;;; checks the captures fit, so this program keeps clear of them.
|
||||
|
||||
(include stdio.h)
|
||||
|
||||
(struct point ((x int) (y int)))
|
||||
|
||||
(fn area ((p (struct point))) int
|
||||
(return (* (. p x) (. p y))))
|
||||
|
||||
(pub fn main () int
|
||||
(var p (struct point) #((struct point) : 6 7))
|
||||
(printf "c99: %d\n" (area p))
|
||||
(return 0))
|
||||
Reference in New Issue
Block a user