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:
@@ -8,8 +8,8 @@
|
||||
"0 1 4 9 "
|
||||
"4"
|
||||
"42"
|
||||
"<closure of 0: 10>"
|
||||
"42"
|
||||
"<fn of 0: 10>"
|
||||
"32"
|
||||
"2 1"
|
||||
"Hello from Sex!")
|
||||
(return 0)
|
||||
@@ -47,11 +47,11 @@
|
||||
(= (. m y) (/ (+ (. a y) (. b y)) 2))
|
||||
(return m))
|
||||
|
||||
;;; The closure's type is written once, in the signature; `_' reads it
|
||||
;;; from there at every use.
|
||||
(fn make-adder ((n int)) (closure ((int)) int)
|
||||
(return (closure ((b int)) int (n)
|
||||
(return (+ n b)))))
|
||||
;;; A lambda's type is written once, in the signature; `_' reads it
|
||||
;;; from there wherever the function is called.
|
||||
(fn make-adder () (fn ((int)) int)
|
||||
(return (lambda ((b int)) int
|
||||
(return (+ b 10)))))
|
||||
|
||||
;;; A macro that asks what it was handed.
|
||||
;;;
|
||||
@@ -68,9 +68,9 @@
|
||||
;; NOTE: ,x twice -- a macro that duplicates its argument still has
|
||||
;; to think about evaluating it twice. Inference does not fix that.
|
||||
((struct point) `(printf "(%d, %d)\n" (. ,x x) (. ,x y)))
|
||||
;; a closure is a type like any other, so it dispatches like one --
|
||||
;; and `_' saves a clause per signature
|
||||
((closure _ int) `(printf "<closure of 0: %d>\n" (,x 0)))
|
||||
;; a function type is a type like any other, so it dispatches like
|
||||
;; one -- and `_' saves a clause per signature
|
||||
((fn _ int) `(printf "<fn of 0: %d>\n" (,x 0)))
|
||||
(else (error "print: don't know how to print" (type-of x)))))
|
||||
|
||||
;;; The temporary's type is the thing the macro could not write down
|
||||
@@ -136,14 +136,14 @@
|
||||
(var squares [_ 4] #(0 1 4 9))
|
||||
(print [squares 2])
|
||||
|
||||
;; A closure's type comes from the signature that produced it, and
|
||||
;; calling one needs that type and nothing else.
|
||||
(var add-10 _ (make-adder 10))
|
||||
;; A function pointer's type comes from the signature that produced
|
||||
;; it, and calling one needs that type and nothing else.
|
||||
(var add-10 _ (make-adder))
|
||||
(print (add-10 32))
|
||||
(print add-10)
|
||||
|
||||
;; ...including where it is returned, with no name in between.
|
||||
(print ((make-adder 20) 22))
|
||||
(print ((make-adder) 22))
|
||||
|
||||
;; A macro writing a declaration it could not have written before.
|
||||
(var a _ 1)
|
||||
@@ -157,12 +157,12 @@
|
||||
;;; Open questions this draft raises, to settle before Layer 2 ships:
|
||||
;;;
|
||||
;;; 1. SETTLED. `type-match' took `_' on the pattern side, so
|
||||
;;; `(closure _ int)' above is one clause rather than one per
|
||||
;;; signature, and `(* _)' and `[_ _]' say "any pointer" and "any
|
||||
;;; array". A `_' written last takes the rest, since a type's words
|
||||
;;; are spread and not nested: `(* const char)' is three elements.
|
||||
;;; Nothing destructures -- a macro body is Scheme and a type is a
|
||||
;;; list, so `(caddr (type-of x))' reads an array's length.
|
||||
;;; `(fn _ int)' above is one clause rather than one per signature,
|
||||
;;; and `(* _)' and `[_ _]' say "any pointer" and "any array". A `_'
|
||||
;;; written last takes the rest, since a type's words are spread and
|
||||
;;; not nested: `(* const char)' is three elements. Nothing
|
||||
;;; destructures -- a macro body is Scheme and a type is a list, so
|
||||
;;; `(caddr (type-of x))' reads an array's length.
|
||||
;;;
|
||||
;;; 2. SETTLED, allowed. `[_ 4]' against `#(0 1 4 9)' unifies each
|
||||
;;; element with the hole, so the element type comes from the
|
||||
|
||||
Reference in New Issue
Block a user