Emit sexp along with arg error

This commit is contained in:
Justin Ethier 2019-04-11 13:53:26 -04:00
parent 64c96545c1
commit 4300a759e3

View file

@ -2403,6 +2403,8 @@
(expected-argc (length (ast:lambda-args lam)))
(argc (- (length ast) 1)) )
(when (not (= argc expected-argc))
(compiler-msg "Compiler Error: ")
(compiler-msg ast)
(compiler-error
"Expected "
(number->string expected-argc)
@ -2419,4 +2421,21 @@
(newline (current-error-port))
(exit 1))
;; Display a compilation message to the user
(define (compiler-msg . sexp)
(display (apply sexp->string sexp) (current-error-port))
(newline (current-error-port)))
;; Convert given scheme expressions to a string, via (display)
;; TODO: move to util module
(define (sexp->string . sexps)
(let ((p (open-output-string)))
(for-each
(lambda (sexp)
(apply display (cons sexp (list p))))
sexps)
(let ((result (get-output-string p)))
(close-port p)
result)))
))