mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-04 19:56:34 +02:00
WIP, emit AST lambda's from closure convert
This commit is contained in:
parent
b383ea6d01
commit
8e75b435d7
1 changed files with 24 additions and 11 deletions
|
@ -1583,11 +1583,13 @@
|
||||||
(difference (free-vars body) (ast:lambda-formals->list exp))
|
(difference (free-vars body) (ast:lambda-formals->list exp))
|
||||||
globals)))
|
globals)))
|
||||||
`(%closure
|
`(%closure
|
||||||
(lambda
|
,(ast:%make-lambda
|
||||||
,(list->lambda-formals
|
(ast:lambda-id exp)
|
||||||
|
(list->lambda-formals
|
||||||
(cons new-self-var (ast:lambda-formals->list exp))
|
(cons new-self-var (ast:lambda-formals->list exp))
|
||||||
(ast:lambda-formals-type 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 (car body) new-self-var new-free-vars)
|
||||||
|
(ast:lambda-has-cont exp))
|
||||||
,@(map (lambda (v) ;; TODO: splice here?
|
,@(map (lambda (v) ;; TODO: splice here?
|
||||||
(cc v))
|
(cc v))
|
||||||
new-free-vars))))
|
new-free-vars))))
|
||||||
|
@ -1652,18 +1654,27 @@
|
||||||
; Free vars, create a closure for them
|
; Free vars, create a closure for them
|
||||||
(let* ((new-self-var (gensym 'self)))
|
(let* ((new-self-var (gensym 'self)))
|
||||||
`((%closure
|
`((%closure
|
||||||
(lambda
|
,(ast:%make-lambda
|
||||||
,(list->lambda-formals
|
(ast:lambda-id fn)
|
||||||
|
(list->lambda-formals
|
||||||
(cons new-self-var (ast:lambda-formals->list fn))
|
(cons new-self-var (ast:lambda-formals->list fn))
|
||||||
(ast:lambda-formals-type fn))
|
(ast:lambda-formals-type fn))
|
||||||
,(convert (car body) new-self-var new-free-vars))
|
(convert (car body) new-self-var new-free-vars)
|
||||||
|
(ast:lambda-has-cont fn)
|
||||||
|
)
|
||||||
,@(map (lambda (v) (cc v))
|
,@(map (lambda (v) (cc v))
|
||||||
new-free-vars))
|
new-free-vars))
|
||||||
,@args))
|
,@args))
|
||||||
; No free vars, just create simple lambda
|
; No free vars, just create simple lambda
|
||||||
`((lambda ,(ast:lambda-args fn)
|
`(,(ast:%make-lambda
|
||||||
,@(map cc body))
|
(ast:lambda-id fn)
|
||||||
,@args))))))
|
(ast:lambda-args fn)
|
||||||
|
(map cc body)
|
||||||
|
(ast:lambda-has-cont fn)
|
||||||
|
)
|
||||||
|
,@args)
|
||||||
|
|
||||||
|
)))))
|
||||||
((lambda? fn) (error `(Unexpected lambda in closure-convert ,exp)))
|
((lambda? fn) (error `(Unexpected lambda in closure-convert ,exp)))
|
||||||
(else
|
(else
|
||||||
(let ((f (cc fn)))
|
(let ((f (cc fn)))
|
||||||
|
@ -1674,8 +1685,10 @@
|
||||||
(error "unhandled exp: " exp))))
|
(error "unhandled exp: " exp))))
|
||||||
(cc exp))
|
(cc exp))
|
||||||
|
|
||||||
`(lambda ()
|
(ast:make-lambda
|
||||||
,(convert exp #f '())))
|
(list)
|
||||||
|
(convert exp #f '())
|
||||||
|
#f))
|
||||||
|
|
||||||
(define (analyze:find-named-lets exp)
|
(define (analyze:find-named-lets exp)
|
||||||
(define (scan exp lp)
|
(define (scan exp lp)
|
||||||
|
|
Loading…
Add table
Reference in a new issue