Hi,

I have been having a bit of a go at understanding boot-9.scm. While investigating it, i found out an interesting bit where SCM code is compiled to new .GO code when performing fresh-compilation. I found similar code in the C sources in load.c.

Now I wanted to add an option to disable the display of the compilation messages so went ahead with creating such an option. However, before I continue, I want a discussion about two things:

- Shouldn't it be that either the C code or the SCM is responsible for displaying the messages? If so, I would assume the C code should be changed to have formal procedures to handle these things.

- Also, is this option in general wanted? If this is the case, I would also like to clean up the above mess of having two procedures printing exactly the same kind of information, leading to maintenance issues.

I attached a simple diff file, so everyone could have their opinions shared.
diff --git a/libguile/load.c b/libguile/load.c
index 5019201..48f7443 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -228,6 +228,9 @@ static SCM *scm_loc_fresh_auto_compile;
 /* The fallback path for auto-compilation */
 static SCM *scm_loc_compile_fallback_path;
 
+/* Whether or not to display messages for auto-compilation */
+static SCM *scm_loc_display_auto_compilation_messages;
+
 /* Ellipsis: "..." */
 static SCM scm_ellipsis;
 
@@ -763,9 +766,12 @@ do_try_auto_compile (void *data)
   SCM source = SCM_PACK_POINTER (data);
   SCM comp_mod, compile_file;
 
-  scm_puts_unlocked (";;; compiling ", scm_current_error_port ());
-  scm_display (source, scm_current_error_port ());
-  scm_newline (scm_current_error_port ());
+  if (scm_is_true (*scm_loc_display_auto_compilation_messages))
+    {
+      scm_puts_unlocked (";;; compiling ", scm_current_error_port ());
+      scm_display (source, scm_current_error_port ());
+      scm_newline (scm_current_error_port ());
+    }
 
   comp_mod = scm_c_resolve_module ("system base compile");
   compile_file = scm_module_variable (comp_mod, sym_compile_file);
@@ -792,9 +798,12 @@ do_try_auto_compile (void *data)
       /* Assume `*current-warning-prefix*' has an appropriate value.  */
       res = scm_call_n (scm_variable_ref (compile_file), args, 5);
 
-      scm_puts_unlocked (";;; compiled ", scm_current_error_port ());
-      scm_display (res, scm_current_error_port ());
-      scm_newline (scm_current_error_port ());
+      if (scm_is_true (*scm_loc_display_auto_compilation_messages))
+	{       
+	  scm_puts_unlocked (";;; compiled ", scm_current_error_port ());
+	  scm_display (res, scm_current_error_port ());
+	  scm_newline (scm_current_error_port ());
+	}
       return res;
     }
   else
@@ -840,6 +849,13 @@ SCM_DEFINE (scm_sys_warn_auto_compilation_enabled, "%warn-auto-compilation-enabl
 #define FUNC_NAME s_scm_sys_warn_auto_compilation_enabled
 {
   static int message_shown = 0;
+  
+  if (scm_is_false (*scm_loc_display_auto_compilation_messages))
+    {
+      /* If auto-compilation messages are not to be shown, this should be set
+         to disable further display of this message */
+      message_shown = 1;
+    }
 
   if (!message_shown)
     {
@@ -1136,6 +1152,8 @@ scm_init_load ()
     = SCM_VARIABLE_LOC (scm_c_define ("%load-should-auto-compile", SCM_BOOL_F));
   scm_loc_fresh_auto_compile
     = SCM_VARIABLE_LOC (scm_c_define ("%fresh-auto-compile", SCM_BOOL_F));
+  scm_loc_display_auto_compilation_messages
+    = SCM_VARIABLE_LOC (scm_c_define ("%display-auto-compilation-messages", SCM_BOOL_T));
 
   scm_ellipsis = scm_from_latin1_string ("...");
 
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index cac058c..5789db0 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -4091,18 +4091,27 @@ when none is available, reading FILE-NAME with READER."
        (if (and gostat (more-recent? gostat scmstat))
            go-file-name
            (begin
-             (if gostat
-                 (format (current-warning-port)
-                         ";;; note: source file ~a\n;;;       newer than compiled ~a\n"
-                         name go-file-name))
-             (cond
-              (%load-should-auto-compile
-               (%warn-auto-compilation-enabled)
-               (format (current-warning-port) ";;; compiling ~a\n" name)
-               (let ((cfn (compile name)))
-                 (format (current-warning-port) ";;; compiled ~a\n" cfn)
-                 cfn))
-              (else #f)))))
+	     (let ((newer-message-note "note: source file")
+		   (newer-than-compiled-message "newer than compiled"))
+	       (if gostat
+		   (if %display-auto-compilation-messages
+		       (format (current-warning-port)
+			     ";;;~a ~a\n;;;       ~a ~a\n" 
+			     newer-message-note
+			     name
+			     newer-than-compiled-message
+			     go-file-name)))
+	       (cond
+		(%load-should-auto-compile
+		 (%warn-auto-compilation-enabled)
+		 (if %display-auto-compilation-messages
+		     (begin
+		       (format (current-warning-port) ";;; compiling ~a\n" name)))
+		 (let ((cfn (compile name)))
+		   (if %display-auto-compilation-messages
+		       (format (current-warning-port) ";;; compiled ~a\n" cfn))
+		   cfn))
+		(else #f))))))
      #:warning "WARNING: compilation of ~a failed:\n" name))
 
   (define (sans-extension file)
diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm
index b387eb3..5171ee5 100644
--- a/module/ice-9/command-line.scm
+++ b/module/ice-9/command-line.scm
@@ -133,6 +133,8 @@ If FILE begins with `-' the -s switch is mandatory.
   --no-auto-compile  disable automatic source file compilation;
                  default is to enable auto-compilation of source
                  files.
+  --no-auto-compilation-messages disable display of auto-compilation 
+                 messages.
   --listen[=P]   listen on a local port or a path for REPL clients;
                  if P is not given, the default is local port 37146
   -q             inhibit loading of user init file
@@ -343,6 +345,10 @@ If FILE begins with `-' the -s switch is mandatory.
             (set! %load-should-auto-compile #t)
             (parse args out))
 
+           ((string=? arg "--no-auto-compilation-messages")
+	    (set! %display-auto-compilation-messages #f)
+	    (parse args out))
+
            ((string=? arg "--fresh-auto-compile")
             (set! %load-should-auto-compile #t)
             (set! %fresh-auto-compile #t)

Reply via email to