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:
@@ -6,7 +6,6 @@
|
||||
"decayed: 2 2 there"
|
||||
"unsigned wins either way: 4294967295 4294967295"
|
||||
"toplevel: 1 2.5 hi 12"
|
||||
"closure in place: 5"
|
||||
"a type is not a call: 7"
|
||||
"radix literals: 224 5 128"
|
||||
"a double reaches C whole: 1"
|
||||
@@ -35,9 +34,6 @@
|
||||
(var s _ "hi")
|
||||
(var a _ (+ 3 (* 3 3)))
|
||||
|
||||
(fn make-adder ((k int)) (closure ((int)) int)
|
||||
(return (closure ((b int)) int (k) (return (+ k b)))))
|
||||
|
||||
(pub fn main () int
|
||||
(var x int 6)
|
||||
(var y int 3)
|
||||
@@ -80,14 +76,9 @@
|
||||
|
||||
(printf "toplevel: %d %g %s %d\n" n d s a)
|
||||
|
||||
;; a closure literal is its own type, so it can be called where it is
|
||||
;; written, the way a lambda already could
|
||||
(printf "closure in place: %d\n"
|
||||
((closure ((v int)) int () (return v)) 5))
|
||||
|
||||
;; a `fn' type's parameter list looks exactly like a call; with a
|
||||
;; closure named `f' in scope it used to be read as one
|
||||
(var f (closure ((int)) int) (make-adder 1))
|
||||
;; function named `f' in scope it used to be read as one
|
||||
(var f (fn ((int)) int) (lambda ((v int)) int (return (+ v 1))))
|
||||
(var fp (fn ((f int) (g int)) int) area)
|
||||
(printf "a type is not a call: %d\n" (f 6))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user