better diagnostics on quasiquote errors
authorAndy Wingo <wingo@pobox.com>
Tue, 2 Sep 2008 07:21:10 +0000 (00:21 -0700)
committerAndy Wingo <wingo@pobox.com>
Sun, 7 Sep 2008 20:27:18 +0000 (22:27 +0200)
* module/system/il/compile.scm (constant?, codegen): Add some diagnostics
  so that we can get decent error reporting if we accidentally unquote an
  unreadable value into the compiled output.

module/system/il/compile.scm

index 82c9c42..cb56ed8 100644 (file)
      (make-glil-module op (ghil-var-env var) (ghil-var-name var)))
     (else (error "Unknown kind of variable:" var))))
 
+(define (constant? x)
+  (cond ((or (number? x) (string? x) (symbol? x) (keyword? x) (boolean? x)) #t)
+        ((pair? x) (and (constant? (car x))
+                        (constant? (cdr x))))
+        ((vector? x) (let lp ((i (vector-length x)))
+                       (or (zero? i)
+                           (and (constant? (vector-ref x (1- i)))
+                                (lp (1- i))))))))
+
 (define (codegen ghil)
   (let ((stack '()))
     (define (push-code! loc code)
               ((<ghil-unquote-splicing> env loc exp)
                (comp-push exp)
                (push-call! #f 'list-break '()))))
+            ((constant? x)
+             (push-code! #f (make-glil-const #:obj x)))
             (else
-             (push-code! #f (make-glil-const #:obj x)))))
+             (error "element of quasiquote can't be compiled" x))))
         (maybe-drop)
         (maybe-return))