mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 12:35:05 +02:00
Finished (inline-ok?)
This commit is contained in:
parent
d415ccee31
commit
741e71415e
1 changed files with 30 additions and 6 deletions
|
@ -17,8 +17,8 @@
|
||||||
; can write initial analyze, but can't get too far without being able
|
; can write initial analyze, but can't get too far without being able
|
||||||
; to uniquely ID each lambda
|
; to uniquely ID each lambda
|
||||||
|
|
||||||
(define-library (cps-optimizations)
|
;(define-library (cps-optimizations)
|
||||||
;(define-library (scheme cyclone cps-optimizations)
|
(define-library (scheme cyclone cps-optimizations)
|
||||||
(import (scheme base)
|
(import (scheme base)
|
||||||
(scheme cyclone util)
|
(scheme cyclone util)
|
||||||
(scheme cyclone ast)
|
(scheme cyclone ast)
|
||||||
|
@ -482,7 +482,12 @@
|
||||||
(lambda (arg)
|
(lambda (arg)
|
||||||
(and (prim-call? arg)
|
(and (prim-call? arg)
|
||||||
(not (prim:cont? (car arg)))))
|
(not (prim:cont? (car arg)))))
|
||||||
(cdr exp)))
|
(cdr exp))
|
||||||
|
(inline-prim-call?
|
||||||
|
(ast:lambda-body (car exp))
|
||||||
|
(prim-calls->arg-variables (cdr exp))
|
||||||
|
(ast:lambda-formals->list (car exp)))
|
||||||
|
)
|
||||||
(let ((args (cdr exp)))
|
(let ((args (cdr exp)))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (param)
|
(lambda (param)
|
||||||
|
@ -504,6 +509,18 @@
|
||||||
(all-prim-calls? (cdr exps)))
|
(all-prim-calls? (cdr exps)))
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
|
||||||
|
;; Find all variables passed to all prim calls
|
||||||
|
(define (prim-calls->arg-variables exps)
|
||||||
|
(apply
|
||||||
|
append
|
||||||
|
(map
|
||||||
|
(lambda (exp)
|
||||||
|
(cond
|
||||||
|
((pair? exp)
|
||||||
|
(filter symbol? (cdr exp)))
|
||||||
|
(else '())))
|
||||||
|
exps)))
|
||||||
|
|
||||||
;; Find variables passed to a primitive
|
;; Find variables passed to a primitive
|
||||||
(define (prim-call->arg-variables exp)
|
(define (prim-call->arg-variables exp)
|
||||||
(filter symbol? (cdr exp)))
|
(filter symbol? (cdr exp)))
|
||||||
|
@ -524,9 +541,16 @@
|
||||||
;; This is a cons "box" so it can be mutated.
|
;; This is a cons "box" so it can be mutated.
|
||||||
;; return - call into this continuation to return early
|
;; return - call into this continuation to return early
|
||||||
(define (inline-ok? exp ivars args arg-used return)
|
(define (inline-ok? exp ivars args arg-used return)
|
||||||
|
(trace:error `(inline-ok? ,exp ,ivars ,args ,arg-used))
|
||||||
(cond
|
(cond
|
||||||
((ref? exp)
|
((ref? exp)
|
||||||
'TODO)
|
(cond
|
||||||
|
((member exp args)
|
||||||
|
(set-car! arg-used #t))
|
||||||
|
((member exp ivars)
|
||||||
|
(return #f))
|
||||||
|
(else
|
||||||
|
#t)))
|
||||||
((ast:lambda? exp)
|
((ast:lambda? exp)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (e)
|
(lambda (e)
|
||||||
|
@ -611,8 +635,8 @@
|
||||||
(define (optimize-cps ast)
|
(define (optimize-cps ast)
|
||||||
(adb:clear!)
|
(adb:clear!)
|
||||||
(analyze-cps ast)
|
(analyze-cps ast)
|
||||||
(trace:info "---------------- cps analysis db:")
|
;(trace:info "---------------- cps analysis db:")
|
||||||
(trace:info (adb:get-db))
|
;(trace:info (adb:get-db))
|
||||||
;ast ;; DEBUGGING!!!
|
;ast ;; DEBUGGING!!!
|
||||||
(contract-prims
|
(contract-prims
|
||||||
(opt:contract ast))
|
(opt:contract ast))
|
||||||
|
|
Loading…
Add table
Reference in a new issue