From fae58130188f4182189ad6773e1c786eef73700e Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 17 Apr 2017 21:34:21 +0000 Subject: [PATCH] WIP: (inlinable-top-level-function? expr) --- scheme/cyclone/transforms.sld | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scheme/cyclone/transforms.sld b/scheme/cyclone/transforms.sld index fd5ab5db..9326bcc4 100644 --- a/scheme/cyclone/transforms.sld +++ b/scheme/cyclone/transforms.sld @@ -105,6 +105,7 @@ pos-in-list closure-convert prim-convert + inlinable-top-level-function? ) (begin @@ -1230,6 +1231,30 @@ ast))) (conv expr)) +;; Determine if the given top-level function can be freed from CPS, due +;; to it only containing calls to code that itself can be inlined. +(define (inlinable-top-level-function? expr) +;; TODO: (define (scan expr) +;; TODO: (cond +;; TODO: ((string? expr) #f) +;; TODO: ((bytevectors? expr) #f) +;; TODO: ((const? expr) #t) ;; Good enough? what about large vectors or anything requiring alloca (strings, bytevectors, what else?) +;; TODO: ((ref? expr) #t) +;; TODO: ;; if - ok by itself, check clauses +;; TODO: ;; prim-app - OK only if prim does not require CPS. +;; TODO: ;; still need to check all its args +;; TODO: ;; app - same as prim, only OK if function does not require CPS. +;; TODO: ;; probably safe to return #t if calling self, since if no +;; TODO: ;; CPS it will be rejected anyway +;; TODO: ;; define, set - reject +;; TODO: ;; lambda of all forms - reject +;; TODO: (else #f))) + (cond + ((and (define? expr) + (lambda? (car (define->exp expr))) + (equal? 'args:fixed (lambda-formals-type (car (define->exp expr))))) + #t) ;; TODO: no, scan lambda body + (else #f))) ;; ;; Helpers to syntax check primitive calls ;;