mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 17:27:33 +02:00
WIP
This commit is contained in:
parent
7d1855d6d4
commit
0ed38ba97e
1 changed files with 43 additions and 76 deletions
|
@ -22,84 +22,49 @@
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
;; TODO: function to actually scan a def to see if that def can be memoized
|
||||||
|
(define (memoizable? var body)
|
||||||
|
(cond
|
||||||
|
((and (ref? var)
|
||||||
|
(ast:lambda? body)
|
||||||
|
(eq? (ast:lambda-formals-type body) 'args:fixed))
|
||||||
|
#t) ;; TODO: no, need to scan further
|
||||||
|
(else #f))
|
||||||
|
)
|
||||||
|
|
||||||
(define (analyze:memoize-pure-fncs sexp)
|
(define (analyze:memoize-pure-fncs sexp)
|
||||||
;; ;; Add new entry for each var as it is found...
|
;; exp - S-expression to scan
|
||||||
;; (define lookup-tbl (make-hash-table))
|
(define (scan exp)
|
||||||
;;
|
;(trace:error `(DEBUG scan ,(ast:ast->pp-sexp exp)))
|
||||||
;; ;; Pass over the sexp
|
(cond
|
||||||
;; ;; exp - S-expression to scan
|
((ast:lambda? exp)
|
||||||
;; ;; vars - alist of current set of variables
|
exp
|
||||||
;; (define (scan exp vars)
|
)
|
||||||
;; ;(trace:error `(DEBUG scan ,(ast:ast->pp-sexp exp)))
|
((quote? exp) exp)
|
||||||
;; (cond
|
((const? exp) exp)
|
||||||
;; ((ast:lambda? exp)
|
((ref? exp) exp)
|
||||||
;; (for-each
|
((define? exp)
|
||||||
;; (lambda (a)
|
;; TODO: support non-top-level defines in the future as well
|
||||||
;; (scan a vars))
|
|
||||||
;; (ast:lambda-formals->list exp))
|
;; TODO: is this a candidate function? if so, scan it using (memoizable?)
|
||||||
;; (for-each
|
(let ((var (define->var exp))
|
||||||
;; (lambda (e)
|
(body (car (define->exp exp))))
|
||||||
;; (scan e vars))
|
(cond
|
||||||
;; (ast:lambda-body exp))
|
((memoizable? var body)
|
||||||
;; )
|
(write `(DEBUG ,var is memoizable))
|
||||||
;; ((quote? exp) #f)
|
(newline)
|
||||||
;; ((const? exp) #f)
|
exp)
|
||||||
;; ((ref? exp)
|
(else exp))))
|
||||||
;; (hash-table-set! lookup-tbl exp vars)
|
;((set!? exp)
|
||||||
;; )
|
; ;; TODO: probably need to keep track of var here
|
||||||
;; ((define? exp)
|
; (scan (set!->var exp) vars)
|
||||||
;; (scan (define->exp exp) '()))
|
; (scan (set!->exp exp) vars))
|
||||||
;; ((set!? exp)
|
((if? exp) exp)
|
||||||
;; ;; TODO: probably need to keep track of var here
|
((app? exp)
|
||||||
;; (scan (set!->var exp) vars)
|
(map scan exp))
|
||||||
;; (scan (set!->exp exp) vars))
|
(else exp)
|
||||||
;; ((if? exp)
|
))
|
||||||
;; (scan (if->condition exp) vars)
|
(scan sexp)
|
||||||
;; (scan (if->then exp) vars)
|
|
||||||
;; (scan (if->else exp) vars))
|
|
||||||
;; ((app? exp)
|
|
||||||
;; (cond
|
|
||||||
;; ((ast:lambda? (car exp))
|
|
||||||
;; ;; Track deps on lambda var(s)
|
|
||||||
;; (for-each
|
|
||||||
;; (lambda (e)
|
|
||||||
;; (scan e vars))
|
|
||||||
;; (ast:lambda-formals->list (car exp)))
|
|
||||||
;; ;; Scan body, with reset vars (??)
|
|
||||||
;; (for-each
|
|
||||||
;; (lambda (e)
|
|
||||||
;; (scan e '()))
|
|
||||||
;; (ast:lambda-body (car exp)))
|
|
||||||
;; ;; Scan lambda arg(s), again also with reset vars
|
|
||||||
;; (for-each
|
|
||||||
;; (lambda (e)
|
|
||||||
;; (scan e '()))
|
|
||||||
;; (cdr exp))
|
|
||||||
;; )
|
|
||||||
;; ((and (ref? (car exp))
|
|
||||||
;; (list? exp)
|
|
||||||
;; (> (length exp) 1))
|
|
||||||
;; (let* ((cont (cadr exp))
|
|
||||||
;; ;; TODO: what if arg is not a ref? Is that possible after cps (probably, with inlining)?
|
|
||||||
;; (args (filter ref? (cddr exp)))
|
|
||||||
;; (vars* (append args vars))
|
|
||||||
;; )
|
|
||||||
;; (scan cont vars*)
|
|
||||||
;; ;(for-each
|
|
||||||
;; ; (lambda (e)
|
|
||||||
;; ; (scan e vars*))
|
|
||||||
;; ; (cdr exp))
|
|
||||||
;; ))
|
|
||||||
;; (else
|
|
||||||
;; (for-each
|
|
||||||
;; (lambda (e)
|
|
||||||
;; (scan e vars))
|
|
||||||
;; exp))))
|
|
||||||
;; (else (error "unknown expression type: " exp))
|
|
||||||
;; ))
|
|
||||||
;; (scan sexp '())
|
|
||||||
;; lookup-tbl
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,6 +132,8 @@
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(analyze:memoize-pure-fncs (ast:sexp->ast sexp))
|
||||||
|
|
||||||
;; (pretty-print
|
;; (pretty-print
|
||||||
;; (ast:ast->pp-sexp
|
;; (ast:ast->pp-sexp
|
||||||
;; (ast:sexp->ast sexp)))
|
;; (ast:sexp->ast sexp)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue