1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

Fixed error handling; detect and report macro expansion errors.

* module/language/scheme/translate.scm (trans): Catch exceptions thrown
  by `macroexpand' and throw a syntax error.
  (trans-pair): Catch calls to `procedure->memoizing-macro' and raise a
  syntax error.

* module/system/base/compile.scm (call-with-compile-error-catch): Made a
  macro (a procedure doesn't do the job).
  (compile-file): Uncommented call to `call-with-compile-error-catch'.

git-archimport-id: lcourtes@laas.fr--2005-mobile/guile-vm--mobile--0.6--patch-7
This commit is contained in:
Ludovic Courtes 2005-12-13 21:33:50 +00:00 committed by Ludovic Courtès
parent 884d46de23
commit 48302624d9
2 changed files with 29 additions and 15 deletions

View file

@ -24,6 +24,7 @@
:use-module (system il ghil) :use-module (system il ghil)
:use-module (ice-9 match) :use-module (ice-9 match)
:use-module (ice-9 receive) :use-module (ice-9 receive)
:use-module ((system base compile) :select (syntax-error))
:export (translate)) :export (translate))
(define (translate x e) (define (translate x e)
@ -41,10 +42,12 @@
(define (trans e l x) (define (trans e l x)
(cond ((pair? x) (cond ((pair? x)
(let ((y (macroexpand x))) (let ((y (false-if-exception (macroexpand x))))
(if (not y)
(syntax-error l "failed to expand macro" x)
(if (eq? x y) (if (eq? x y)
(trans-pair e (or (location x) l) (car x) (cdr x)) (trans-pair e (or (location x) l) (car x) (cdr x))
(trans e l y)))) (trans e l y)))))
((symbol? x) ((symbol? x)
(let ((y (symbol-expand x))) (let ((y (symbol-expand x)))
(if (symbol? y) (if (symbol? y)
@ -241,7 +244,14 @@
(else (else
(if (memq head scheme-primitives) (if (memq head scheme-primitives)
(<ghil-inline> e l head (map trans:x tail)) (<ghil-inline> e l head (map trans:x tail))
(<ghil-call> e l (trans:x head) (map trans:x tail)))))) (if (eq? head 'procedure->memoizing-macro)
;;; XXX: `procedure->memoizing-macro' is evil because it crosses
;;; the compilation boundary. One solution might be to evaluate
;;; calls to `procedure->memoizing-macro' at compilation time,
;;; but it may be more compicated than that.
(syntax-error l "`procedure->memoizing-macro' is forbidden"
(cons head tail))
(<ghil-call> e l (trans:x head) (map trans:x tail)))))))
(define (trans-quasiquote e l x) (define (trans-quasiquote e l x)
(cond ((not (pair? x)) x) (cond ((not (pair? x)) x)

View file

@ -25,7 +25,7 @@
:use-module (system il compile) :use-module (system il compile)
:use-module (system il glil) :use-module (system il glil)
:use-module ((system vm core) :use-module ((system vm core)
#:select (the-vm vm-load objcode->u8vector)) :select (the-vm vm-load objcode->u8vector))
:use-module (system vm assemble) :use-module (system vm assemble)
:use-module (ice-9 regex)) :use-module (ice-9 regex))
@ -41,11 +41,14 @@
(define-public (syntax-error loc msg exp) (define-public (syntax-error loc msg exp)
(throw 'syntax-error loc msg exp)) (throw 'syntax-error loc msg exp))
(define-public (call-with-compile-error-catch thunk) (define-macro (call-with-compile-error-catch thunk)
(catch 'syntax-error `(catch 'syntax-error
(thunk) ,thunk
(lambda (key loc msg exp) (lambda (key loc msg exp)
(format #t "~A:~A: ~A: ~A" (car loc) (cdr loc) msg exp)))) (format #t "~A:~A: ~A: ~A~%" (car loc) (cdr loc) msg exp))))
(export-syntax call-with-compile-error-catch)
;;; ;;;
@ -56,10 +59,10 @@
(define-public (compile-file file . opts) (define-public (compile-file file . opts)
(let ((comp (compiled-file-name file))) (let ((comp (compiled-file-name file)))
(catch #t (catch 'nothing-at-all
(lambda ()
(call-with-compile-error-catch
(lambda () (lambda ()
; (call-with-compile-error-catch
; (lambda ()
(call-with-output-file comp (call-with-output-file comp
(lambda (port) (lambda (port)
(let* ((source (read-file-in file scheme)) (let* ((source (read-file-in file scheme))
@ -68,7 +71,7 @@
(if (memq :c opts) (if (memq :c opts)
(pprint-glil objcode port) (pprint-glil objcode port)
(uniform-vector-write (objcode->u8vector objcode) port))))) (uniform-vector-write (objcode->u8vector objcode) port)))))
(format #t "wrote `~A'\n" comp)) (format #t "wrote `~A'\n" comp))))
(lambda (key . args) (lambda (key . args)
(format #t "ERROR: during compilation of ~A:\n" file) (format #t "ERROR: during compilation of ~A:\n" file)
(display "ERROR: ") (display "ERROR: ")
@ -120,6 +123,7 @@
;; translate ;; translate
(set! x (lang.translator x e)) (set! x (lang.translator x e))
(if (memq :t opts) (throw 'result x)) (if (memq :t opts) (throw 'result x))
(format #t "transed~%")
;; compile ;; compile
(set! x (apply compile x e opts)) (set! x (apply compile x e opts))
(if (memq :c opts) (throw 'result x)) (if (memq :c opts) (throw 'result x))