mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
Built-out (simple-lambda?)
This commit is contained in:
parent
5f6feb378f
commit
d989040cf8
1 changed files with 36 additions and 18 deletions
|
@ -180,22 +180,40 @@
|
||||||
;
|
;
|
||||||
; Need to check analysis DB against CPS generated and make sure
|
; Need to check analysis DB against CPS generated and make sure
|
||||||
; things like ref-by make sense (ref by seems like its only -1 right now??)
|
; things like ref-by make sense (ref by seems like its only -1 right now??)
|
||||||
; (define (simple-lambda? ast)
|
;; Does ref-by list contains references to lambdas other than owner?
|
||||||
; (let ((body (ast:lambda-body ast)))
|
;; int -> ast-variable -> boolean
|
||||||
; (and (pair? body)
|
(define (nonlocal-ref? owner-id adb-var)
|
||||||
; (app? body)
|
(define (loop ref-by-ids)
|
||||||
; (ast:lambda? (car body))
|
(cond
|
||||||
; (> (length (ast:lambda-formals->list ast)) 0)
|
((null? ref-by-ids) #f)
|
||||||
;;; TODO: rewrite these last 2 using the analysis DB
|
(else
|
||||||
;; ;; TODO: not sure this is good enough for all cases
|
(let ((ref (car ref-by-ids)))
|
||||||
;; (equal? (app->args body)
|
(if (and (number? ref) (not (= owner-id ref)))
|
||||||
;; ;(lambda->formals (car body))
|
#t ;; Another lambda uses this variable
|
||||||
;; (lambda->formals exp)
|
(loop (cdr ref-by-ids)))))))
|
||||||
;; )
|
(loop (adbv:ref-by adb-var)))
|
||||||
;; ;; TODO: don't do it if args are used in the body
|
|
||||||
;; ;; this won't work if we have any num other than 1 arg
|
;; int -> [symbol] -> boolean
|
||||||
;; (not (member
|
(define (any-nonlocal-refs? owner-id vars)
|
||||||
;; (car (lambda->formals exp))
|
(call/cc
|
||||||
;; (free-vars (car body))))
|
(lambda (return)
|
||||||
; #f)
|
(for-each
|
||||||
|
(lambda (var)
|
||||||
|
(if (nonlocal-ref? owner-id (adb:get var))
|
||||||
|
(return #t)))
|
||||||
|
vars)
|
||||||
|
(return #f))))
|
||||||
|
|
||||||
|
;; ast-function -> boolean
|
||||||
|
(define (simple-lambda? ast)
|
||||||
|
(let ((body (ast:lambda-body ast))
|
||||||
|
(formals (ast:lambda-formals->list ast))
|
||||||
|
(id (ast:lambda-id ast)))
|
||||||
|
(and (pair? body)
|
||||||
|
(app? body)
|
||||||
|
(ast:lambda? (car body))
|
||||||
|
(> (length formals) 0)
|
||||||
|
(equal? (app->args body)
|
||||||
|
formals)
|
||||||
|
(not (any-nonlocal-refs? id formals)))))
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue