time-expand.ss
;; Utilities for timing macro expansion.

;; Copyright (c) 2007 David Van Horn
;; Licensed under the Academic Free License version 3.0

;; <[email protected]>

(module time-expand mzscheme 
  (provide time-expand time-expand-invoke)
  
  (define-syntax (time-expand stx)
    (with-syntax (((_ exp) stx))
      (time
       (local-expand (syntax exp) (syntax-local-context) '()))))
  
  (define-syntax (time-expand-invoke stx)
    (with-syntax (((_ exp) stx))
      (let-values (((res cpu real gc)
                    (time-apply local-expand 
                                (list (syntax exp) 
                                      (syntax-local-context) '()))))
        (with-syntax (((res) res)
                      (cpu cpu)
                      (real real)
                      (gc gc))
          (syntax
           (values res cpu real gc))))))
  
  ) ; end of module time-expand.