Only lazily compile where profitable
authorAndy Wingo <wingo@pobox.com>
Thu, 12 Mar 2015 13:48:03 +0000 (14:48 +0100)
committerAndy Wingo <wingo@pobox.com>
Thu, 12 Mar 2015 13:48:03 +0000 (14:48 +0100)
* module/ice-9/eval.scm (primitive-eval): Only lazily compile box-ref on
  toplevel variables; otherwise compile eagerly to avoid the
  indirection.

module/ice-9/eval.scm

index f5bcc16..3b68f07 100644 (file)
                            '()
                            (cons ((car args) env) (lp (cdr args)))))))))))))
 
                            '()
                            (cons ((car args) env) (lp (cdr args)))))))))))))
 
-  (define (compile-box-ref cenv box)
+  (define (compile-box-ref box)
     (match box
       ((,(typecode resolve) . loc)
     (match box
       ((,(typecode resolve) . loc)
-       (let ((var (%resolve-variable loc (env-toplevel cenv))))
-         (lambda (env) (variable-ref var))))
+       (lazy (cenv)
+         (let ((var (%resolve-variable loc (env-toplevel cenv))))
+           (lambda (env) (variable-ref var)))))
       ((,(typecode lexical-ref) depth . width)
        (lambda (env)
          (variable-ref (env-ref env depth width))))
       ((,(typecode lexical-ref) depth . width)
        (lambda (env)
          (variable-ref (env-ref env depth width))))
        (compile-call f args))
       
       ((,(typecode box-ref) . box)
        (compile-call f args))
       
       ((,(typecode box-ref) . box)
-       (lazy (env) (compile-box-ref env box)))
+       (compile-box-ref box))
 
       ((,(typecode resolve) . loc)
        (lazy (env) (compile-resolve env loc)))
 
       ((,(typecode resolve) . loc)
        (lazy (env) (compile-resolve env loc)))