mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 16:27:35 +02:00
Closure convert, convert ast:lambda's before vectors
This commit is contained in:
parent
a86a8262fa
commit
9b72e8dcd7
1 changed files with 20 additions and 19 deletions
|
@ -1164,6 +1164,9 @@
|
||||||
(define (analyze-mutable-variables exp)
|
(define (analyze-mutable-variables exp)
|
||||||
(cond
|
(cond
|
||||||
; Core forms:
|
; Core forms:
|
||||||
|
((ast:lambda? exp)
|
||||||
|
(map analyze-mutable-variables (ast:lambda-body exp))
|
||||||
|
(void))
|
||||||
((const? exp) (void))
|
((const? exp) (void))
|
||||||
((prim? exp) (void))
|
((prim? exp) (void))
|
||||||
((ref? exp) (void))
|
((ref? exp) (void))
|
||||||
|
@ -1171,9 +1174,6 @@
|
||||||
((lambda? exp)
|
((lambda? exp)
|
||||||
(map analyze-mutable-variables (lambda->exp exp))
|
(map analyze-mutable-variables (lambda->exp exp))
|
||||||
(void))
|
(void))
|
||||||
((ast:lambda? exp)
|
|
||||||
(map analyze-mutable-variables (ast:lambda-body exp))
|
|
||||||
(void))
|
|
||||||
((set!? exp)
|
((set!? exp)
|
||||||
(mark-mutable (set!->var exp))
|
(mark-mutable (set!->var exp))
|
||||||
(analyze-mutable-variables (set!->exp exp)))
|
(analyze-mutable-variables (set!->exp exp)))
|
||||||
|
@ -1617,6 +1617,23 @@
|
||||||
(define (convert exp self-var free-var-lst)
|
(define (convert exp self-var free-var-lst)
|
||||||
(define (cc exp)
|
(define (cc exp)
|
||||||
(cond
|
(cond
|
||||||
|
((ast:lambda? exp)
|
||||||
|
(let* ((new-self-var (gensym 'self))
|
||||||
|
(body (ast:lambda-body exp))
|
||||||
|
(new-free-vars
|
||||||
|
(difference
|
||||||
|
(difference (free-vars body) (ast:lambda-formals->list exp))
|
||||||
|
globals)))
|
||||||
|
`(%closure
|
||||||
|
(lambda
|
||||||
|
,(list->lambda-formals
|
||||||
|
(cons new-self-var (ast:lambda-formals->list exp))
|
||||||
|
(ast:lambda-formals-type exp))
|
||||||
|
,(convert (car body) new-self-var new-free-vars)) ;; TODO: should this be a map??? was a list in 90-min-scc.
|
||||||
|
;,(convert body new-self-var new-free-vars)) ;; TODO: should this be a map??? was a list in 90-min-scc.
|
||||||
|
,@(map (lambda (v) ;; TODO: splice here?
|
||||||
|
(cc v))
|
||||||
|
new-free-vars))))
|
||||||
((const? exp) exp)
|
((const? exp) exp)
|
||||||
((quote? exp) exp)
|
((quote? exp) exp)
|
||||||
((ref? exp)
|
((ref? exp)
|
||||||
|
@ -1634,22 +1651,6 @@
|
||||||
,@(map cc (cdr exp)))) ;; TODO: need to splice?
|
,@(map cc (cdr exp)))) ;; TODO: need to splice?
|
||||||
((set!? exp) `(set! ,(set!->var exp)
|
((set!? exp) `(set! ,(set!->var exp)
|
||||||
,(cc (set!->exp exp))))
|
,(cc (set!->exp exp))))
|
||||||
((ast:lambda? exp)
|
|
||||||
(let* ((new-self-var (gensym 'self))
|
|
||||||
(body (ast:lambda-body exp))
|
|
||||||
(new-free-vars
|
|
||||||
(difference
|
|
||||||
(difference (free-vars body) (ast:lambda-formals->list exp))
|
|
||||||
globals)))
|
|
||||||
`(%closure
|
|
||||||
(lambda
|
|
||||||
,(list->lambda-formals
|
|
||||||
(cons new-self-var (ast:lambda-formals->list exp))
|
|
||||||
(ast:lambda-formals-type exp))
|
|
||||||
,(convert (car body) new-self-var new-free-vars)) ;; TODO: should this be a map??? was a list in 90-min-scc.
|
|
||||||
,@(map (lambda (v) ;; TODO: splice here?
|
|
||||||
(cc v))
|
|
||||||
new-free-vars))))
|
|
||||||
((if? exp) `(if ,@(map cc (cdr exp))))
|
((if? exp) `(if ,@(map cc (cdr exp))))
|
||||||
((cell? exp) `(cell ,(cc (cell->value exp))))
|
((cell? exp) `(cell ,(cc (cell->value exp))))
|
||||||
((cell-get? exp) `(cell-get ,(cc (cell-get->cell exp))))
|
((cell-get? exp) `(cell-get ,(cc (cell-get->cell exp))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue