Added prim-convert

This commit is contained in:
Justin Ethier 2017-03-21 11:15:53 +00:00
parent e8c5a3415a
commit bf2643ce3d
2 changed files with 48 additions and 15 deletions

View file

@ -207,6 +207,15 @@
(trace:info "---------------- after alpha conversion:") (trace:info "---------------- after alpha conversion:")
(trace:info input-program) ;pretty-print (trace:info input-program) ;pretty-print
;; Convert some function calls to primitives, if possible
(set! input-program
(map
(lambda (expr)
(prim-convert expr))
input-program))
(trace:info "---------------- after func->primitive conversion:")
(trace:info input-program) ;pretty-print
(let ((cps (map (let ((cps (map
(lambda (expr) (lambda (expr)
(cps-convert expr)) (cps-convert expr))

View file

@ -104,6 +104,7 @@
cps-convert cps-convert
pos-in-list pos-in-list
closure-convert closure-convert
prim-convert
) )
(begin (begin
@ -1185,22 +1186,45 @@
(difference fv (built-in-syms))) (difference fv (built-in-syms)))
(list)))))) (list))))))
;TODO: upgrade applicable function calls to inlinable primitives ;; Upgrade applicable function calls to inlinable primitives
;;
;; Assumptions:
;; - This executes after alpha conversion, so there are no define
;; expressions or if's without an else clause
;;
;first case is char=? => Cyc-fast-char-eq (and rest of the family) ;first case is char=? => Cyc-fast-char-eq (and rest of the family)
;(define (inline-applicable-funcs expr) (define (prim-convert expr)
; (define (conv ast) (define (conv ast)
; (cond (cond
; ((define? ast) ((const? ast) ast)
; `(define ,@(map (lambda (a) (conv a)) (cdr ast)))) ((quote? ast) ast)
; ((set!? ast) ((ref? ast) ast)
; `(set! ,@(map (lambda (a) (conv a)) (cdr ast)))) ((set!? ast)
; ((if? ast) `(set! ,@(map (lambda (a) (conv a)) (cdr ast))))
; TODO ((if? ast)
; ((lambda? ast) `(if ,(conv (if->condition ast))
; ((app? ast) ,(conv (if->then ast))
; (else ,(conv (if->else ast))))
; ast))) ((lambda? ast)
; (conv expr)) (let* ((args (lambda-formals->list ast))
(ltype (lambda-formals-type ast))
(body (lambda->exp ast))
)
`(lambda
,(list->lambda-formals args ltype) ;; Overkill??
,@(map conv body))))
((app? ast)
(cond
((and
(eq? (car ast) 'char=?)
(= (length ast) 3)
)
`(Cyc-fast-char-eq ,@(cdr ast)))
(else
(map conv ast))))
(else
ast)))
(conv expr))
;; ;;
;; Helpers to syntax check primitive calls ;; Helpers to syntax check primitive calls