mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 17:27:33 +02:00
Added analyze:cc-ast->vars
This commit is contained in:
parent
9993956709
commit
80ad85883b
1 changed files with 45 additions and 0 deletions
|
@ -20,6 +20,7 @@
|
||||||
(srfi 69))
|
(srfi 69))
|
||||||
(export
|
(export
|
||||||
closure-convert
|
closure-convert
|
||||||
|
analyze:cc-ast->vars
|
||||||
pos-in-list
|
pos-in-list
|
||||||
inlinable-top-level-lambda?
|
inlinable-top-level-lambda?
|
||||||
optimize-cps
|
optimize-cps
|
||||||
|
@ -2080,6 +2081,50 @@
|
||||||
(else exp)))
|
(else exp)))
|
||||||
(scan exp #f))
|
(scan exp #f))
|
||||||
|
|
||||||
|
;;; This function walks over a Closure-converted expression and
|
||||||
|
;;; builds a table of all variable references. This can be used
|
||||||
|
;;; to determine with certainty what variables are actually used.
|
||||||
|
;;;
|
||||||
|
;;; Returns a hash table where each key/var is a referenced var.
|
||||||
|
(define (analyze:cc-ast->vars sexp)
|
||||||
|
(define %ht (make-hash-table))
|
||||||
|
|
||||||
|
(define (add! ref)
|
||||||
|
(hash-table-set! %ht ref ref))
|
||||||
|
|
||||||
|
(define (scan exp)
|
||||||
|
(cond
|
||||||
|
((ast:lambda? exp)
|
||||||
|
(scan
|
||||||
|
`(%closure ,exp)
|
||||||
|
))
|
||||||
|
((const? exp) #f)
|
||||||
|
((prim? exp) #f)
|
||||||
|
((ref? exp) (add! exp))
|
||||||
|
((quote? exp) #f)
|
||||||
|
((if? exp)
|
||||||
|
(scan (if->condition exp))
|
||||||
|
(scan (if->then exp))
|
||||||
|
(scan (if->else exp)))
|
||||||
|
((tagged-list? '%closure exp)
|
||||||
|
(let* ((lam (closure->lam exp))
|
||||||
|
(body (car (ast:lambda-body lam))))
|
||||||
|
(scan body)))
|
||||||
|
;; Global definition
|
||||||
|
((define? exp)
|
||||||
|
(scan (car (define->exp exp))))
|
||||||
|
((define-c? exp)
|
||||||
|
#f)
|
||||||
|
|
||||||
|
;; Application:
|
||||||
|
((app? exp)
|
||||||
|
(for-each scan exp))
|
||||||
|
(else
|
||||||
|
(error "unknown exp in analyze-cc-vars " exp))))
|
||||||
|
|
||||||
|
(for-each scan sexp)
|
||||||
|
%ht)
|
||||||
|
|
||||||
;; Find any top-level functions that call themselves directly
|
;; Find any top-level functions that call themselves directly
|
||||||
(define (analyze:find-direct-recursive-calls exp)
|
(define (analyze:find-direct-recursive-calls exp)
|
||||||
;; Verify the continuation is simple and there is no closure allocation
|
;; Verify the continuation is simple and there is no closure allocation
|
||||||
|
|
Loading…
Add table
Reference in a new issue