From 10f01e82bbb29e88b9e86026ef1ff4e165d7f47b Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 31 May 2018 13:34:51 -0400 Subject: [PATCH] WIP --- find-direct-rec-calls.scm | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/find-direct-rec-calls.scm b/find-direct-rec-calls.scm index 9b843add..eaff6e62 100644 --- a/find-direct-rec-calls.scm +++ b/find-direct-rec-calls.scm @@ -1,3 +1,7 @@ +;; Instead of just porting this to cps-optmizations should consider +;; creating a new subdirectory under scheme/cyclone/cps-optimizations and starting to place +;; things like this there as new libraries, to isolate them, improve testability, and help +;; make optimizations easiser to maintain (import (scheme base) (scheme cyclone ast) @@ -8,10 +12,25 @@ ) (define (find-direct-recursive-calls exp) + (define (check-args args) + (define (check exp) + (cond + ((quote? exp) #t) + ((const? exp) #t) + ((ref? exp) #t) + ((app? exp) + (and + ;; Very conservative right now + (member (car exp) '(car cdr)) + (check-args (cdr exp)))) + (else #f))) + (every check args)) + (define (scan exp def-sym) (write `(scan ,def-sym ,exp)) (newline) (cond ((ast:lambda? exp) + ;; Reject if there are nested functions #f) ((quote? exp) exp) ((const? exp) exp) @@ -20,12 +39,16 @@ ((define? exp) #f) ((set!? exp) #f) ((if? exp) - (scan (if->condition exp) def-sym) + (scan (if->condition exp) def-sym) ;; OK to check?? (scan (if->then exp) def-sym) (scan (if->else exp) def-sym)) ((app? exp) (when (equal? (car exp) def-sym) - (write `(possible direct recursive call ,exp))) + (if (check-args (cddr exp)) ;; Skip func and continuation + (write `(direct recursive call ,exp)) + (write `(not a direct recursive call ,exp)) + ) + ) ) (else #f))) (for-each