forked from alex-eg/sex
remove closures, keep lambdas
A closure was a code pointer beside an inline environment: capture records, per-signature structs, conversion thunks and call helpers. It is gone; a lambda still lifts to an ordinary function and a (fn ...) value is still a bare code pointer. The capture budget, the environment union and the closure glyph go with it. The implementation is kept at tag 0.0.1.
This commit is contained in:
@@ -269,12 +269,12 @@ ahead of its pub forms."
|
||||
(reports? "(sum box ((inner ((x [box 2])))))" "a sum holds itself through a pointer"))
|
||||
(test-assert "though it can point at itself"
|
||||
(emits? "(sum box ((inner ((x (* box))))))" "box * x;"))
|
||||
(test-assert "a function argument becomes the closure its field holds"
|
||||
(test-assert "a function fills a function-pointer field"
|
||||
(emits? (string-append
|
||||
"(fn g ((n int)) int (return n))"
|
||||
"(sum t ((a ((k (closure ((int)) int))))))"
|
||||
"(sum t ((a ((k (fn ((int)) int))))))"
|
||||
"(fn f () t (return (t/a g)))")
|
||||
"ƛint_int_fromfn(g)"))
|
||||
"(struct tːa){g}"))
|
||||
(test-assert "a tag-only sum has no union at all"
|
||||
(not (emits? "(sum light ((red ()) (green ())))" "union")))
|
||||
(test-assert "a sum is declared once"
|
||||
@@ -308,18 +308,18 @@ ahead of its pub forms."
|
||||
").h")))
|
||||
(test-assert "a scrutinee that is not a path is read once"
|
||||
(emits? (sum-src "(match (mk) ((circle (r)) (= out r)) (else (= out 0.0)))")
|
||||
"shape ƛm0 = mk()"))
|
||||
"shape λm0 = mk()"))
|
||||
(test-assert "a path scrutinee is not copied"
|
||||
(not (emits? (sum-src "(match s ((circle (r)) (= out r)) (else (= out 0.0)))")
|
||||
"ƛm0")))
|
||||
"λm0")))
|
||||
(test-assert "unless a binder is named like a part of it"
|
||||
(emits? (sum-src "(match s ((circle (s)) (= out s)) (else (= out 0.0)))")
|
||||
"shape ƛm0 = s"))
|
||||
"shape λm0 = s"))
|
||||
(test-assert "a macro scrutinee is typed by what it expands to"
|
||||
(emits? (string-append "(defmacro (the a) a)"
|
||||
(sum-src "(match (the s) ((circle (r)) (= out r))"
|
||||
" (else (= out 0.0)))"))
|
||||
"shape ƛm0 = s"))
|
||||
"shape λm0 = s"))
|
||||
(test-assert "a typedef of a sum is matched as the sum"
|
||||
(emits? (string-append
|
||||
"(sum shape ((circle ((r int))) (empty ())))"
|
||||
@@ -392,10 +392,10 @@ ahead of its pub forms."
|
||||
(emits? (sum-src "(switch 1 (case 1 (match s ((circle (r)) (= out r))"
|
||||
" (else (= out 0.0)))))")
|
||||
"s.tag == shapeǂcircle"))
|
||||
(test-assert "and so is a closure's, wherever the closure stands"
|
||||
(emits? (sum-src "(var c (closure () int) (closure () int ((t s))"
|
||||
" (match t ((circle (r)) (return 1)) (else (return 0)))))")
|
||||
"t.tag == shapeǂcircle"))
|
||||
(test-assert "and so is a lambda's, wherever the lambda stands"
|
||||
(emits? (sum-src "(var c (fn ((shape)) int) (lambda ((v shape)) int"
|
||||
" (match v ((circle (r)) (return 1)) (else (return 0)))))")
|
||||
"v.tag == shapeǂcircle"))
|
||||
;; a pointer to one was refused, where `.' reads through one
|
||||
;; a variant with fields is a member of the sum's union, which C
|
||||
;; would not take named `int'
|
||||
|
||||
Reference in New Issue
Block a user