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:
@@ -10,11 +10,8 @@
|
||||
;;;
|
||||
;;; It also checks what only a second translation unit can check: that an
|
||||
;;; imported type reaches the type database, by expanding a macro that
|
||||
;;; reads the imported struct's fields; and that a closure type crossing
|
||||
;;; the boundary works both ways -- one built in the module and called
|
||||
;;; here, one built here and called there, through a code pointer that is
|
||||
;;; static in the other object. And that a record can cross as a handle
|
||||
;;; alone, its fields left behind and its methods still found.
|
||||
;;; reads the imported struct's fields; and that a record can cross as a
|
||||
;;; handle alone, its fields left behind and its methods still found.
|
||||
;;;
|
||||
;;; The public forms carry comments in their headers, which the reduction
|
||||
;;; to a prototype and to an extern both have to look past. And a type the
|
||||
@@ -152,7 +149,6 @@
|
||||
"text times "
|
||||
"text times "
|
||||
"mood 1"
|
||||
"closure 15 21 201"
|
||||
"vec2 7 7"
|
||||
"tally 2"
|
||||
"board 42"
|
||||
|
||||
@@ -27,13 +27,6 @@
|
||||
(var m (enum mood) grumpy)
|
||||
(printf "mood %d\n" m)
|
||||
|
||||
(var add-10 (closure ((int)) int) (make-adder 10))
|
||||
(printf "closure %d %d" (add-10 5) (apply-twice add-10 1))
|
||||
(var base int 100)
|
||||
(var here (closure ((int)) int)
|
||||
(closure ((x int)) int (base) (return (+ base x))))
|
||||
(printf " %d\n" (apply-twice here 1))
|
||||
|
||||
;; the bare record name, then the method both ways round
|
||||
(var v vec2 #(vec2 : 3 4))
|
||||
(printf "vec2 %d %d\n" (.manhattan v) (vec2/manhattan (& v)))
|
||||
|
||||
@@ -62,19 +62,6 @@
|
||||
(pub fn ledger-total ((l (* const ledger))) int
|
||||
(return (. l total)))
|
||||
|
||||
;;; A closure type crossing the boundary. Both units generate the
|
||||
;;; struct for this signature independently, so they have to agree on
|
||||
;;; its tag and its layout, or the value is passed wrong and nothing
|
||||
;;; says so.
|
||||
(pub fn make-adder ((n int)) (closure ((int)) int)
|
||||
(return (closure ((b int)) int (n)
|
||||
(return (+ n b)))))
|
||||
|
||||
;;; The other direction: a closure built by the importer, whose code
|
||||
;;; pointer is static in *its* object, called from here
|
||||
(pub fn apply-twice ((f (closure ((int)) int)) (x int)) int
|
||||
(return (f (f x))))
|
||||
|
||||
;;; A record and an ops block crossing the boundary. The record has to
|
||||
;;; arrive as the struct *and* its typedef, or the bare name does not
|
||||
;;; work there; the ops block has to arrive as a block rather than as
|
||||
|
||||
Reference in New Issue
Block a user