From 4300a759e39c853b1c1ff4c44abe234a911a9022 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 11 Apr 2019 13:53:26 -0400 Subject: [PATCH] Emit sexp along with arg error --- scheme/cyclone/cps-optimizations.sld | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index 6c6ff4d5..71517274 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -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))) + ))