From ab24e10c2fdd1284e046739eb48190983839322e Mon Sep 17 00:00:00 2001 From: Matt Wette Date: Wed, 2 Oct 2024 15:48:09 +0200 Subject: [PATCH 1/2] Patch for directing information messages (e.g. auto-compile) to /dev/null * libguile/init.c (scm_set_current_info_port): new proc * libguile/load.c (compiled_is_fresh, load_thunk_from_path, do_try_auto_compile, scm_sys_warn_auto_compilation_enabled, scm_primitive_load_path): use info port for compilation messages * libguile/ports.c (cur_infoport_fluid): new variable * libguile/ports.c (scm_current_info_port, scm_set_current_info_port): new proc * libguile/ports.c (scm_init_ice_9_ports): define %current-info-port-fluid * libguile/ports.c (scm_init_ports): init cur_infoport_fluid * libguile/ports.h (scm_current_input_port): declare scm_current_info_port, scm_set_current_info_port * module/ice-9/boot-9.scm (info): define proc * module/ice-9/boot-9.scm (load-in-vicinity): use info port * module/ice-9/command-line.scm (*usage*): document -I * module/ice-9/command-line.scm (compile-shell-switches): parse -I * module/ice-9/ports.scm (replace-bootstrap-bindings): provide current-info-port * module/ice-9/ports.scm (set-current-info-portf, current-info-port): new proc * module/system/repl/common.scm (make-repl): use info port --- libguile/init.c | 1 + libguile/load.c | 42 +++++++++++++++++------------------ libguile/ports.c | 31 ++++++++++++++++++++++++++ libguile/ports.h | 2 ++ module/ice-9/boot-9.scm | 13 ++++++++--- module/ice-9/command-line.scm | 7 +++++- module/ice-9/ports.scm | 18 ++++++++++++--- module/system/repl/common.scm | 8 +++---- 8 files changed, 90 insertions(+), 32 deletions(-) diff --git a/libguile/init.c b/libguile/init.c index 4a3903a2c..3df8c5ae5 100644 --- a/libguile/init.c +++ b/libguile/init.c @@ -200,6 +200,7 @@ scm_init_standard_ports () scm_set_current_error_port (scm_standard_stream_to_port (2, isatty (2) ? "w0" : "w")); scm_set_current_warning_port (scm_current_error_port ()); + scm_set_current_info_port (scm_current_error_port ()); } diff --git a/libguile/load.c b/libguile/load.c index 34e7934b9..35613077b 100644 --- a/libguile/load.c +++ b/libguile/load.c @@ -571,11 +571,11 @@ compiled_is_fresh (SCM full_filename, SCM compiled_filename, else { compiled_is_newer = 0; - scm_puts (";;; note: source file ", scm_current_warning_port ()); - scm_display (full_filename, scm_current_warning_port ()); - scm_puts ("\n;;; newer than compiled ", scm_current_warning_port ()); - scm_display (compiled_filename, scm_current_warning_port ()); - scm_puts ("\n", scm_current_warning_port ()); + scm_puts (";;; note: source file ", scm_current_info_port ()); + scm_display (full_filename, scm_current_info_port ()); + scm_puts ("\n;;; newer than compiled ", scm_current_info_port ()); + scm_display (compiled_filename, scm_current_info_port ()); + scm_puts ("\n", scm_current_info_port ()); } return compiled_is_newer; @@ -770,9 +770,9 @@ load_thunk_from_path (SCM filename, SCM source_file_name, if (found_stale_file && *found_stale_file) { scm_puts (";;; found fresh compiled file at ", - scm_current_warning_port ()); - scm_display (found, scm_current_warning_port ()); - scm_newline (scm_current_warning_port ()); + scm_current_info_port ()); + scm_display (found, scm_current_info_port ()); + scm_newline (scm_current_info_port ()); } goto end; @@ -1017,9 +1017,9 @@ do_try_auto_compile (void *data) SCM source = SCM_PACK_POINTER (data); SCM comp_mod, compile_file; - scm_puts (";;; compiling ", scm_current_warning_port ()); - scm_display (source, scm_current_warning_port ()); - scm_newline (scm_current_warning_port ()); + scm_puts (";;; compiling ", scm_current_info_port ()); + scm_display (source, scm_current_info_port ()); + scm_newline (scm_current_info_port ()); comp_mod = scm_c_resolve_module ("system base compile"); compile_file = scm_module_variable (comp_mod, sym_compile_file); @@ -1046,17 +1046,17 @@ 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 (";;; compiled ", scm_current_warning_port ()); - scm_display (res, scm_current_warning_port ()); - scm_newline (scm_current_warning_port ()); + scm_puts (";;; compiled ", scm_current_info_port ()); + scm_display (res, scm_current_info_port ()); + scm_newline (scm_current_info_port ()); return res; } else { - scm_puts (";;; it seems ", scm_current_warning_port ()); - scm_display (source, scm_current_warning_port ()); + scm_puts (";;; it seems ", scm_current_info_port ()); + scm_display (source, scm_current_info_port ()); scm_puts ("\n;;; is part of the compiler; skipping auto-compilation\n", - scm_current_warning_port ()); + scm_current_info_port ()); return SCM_BOOL_F; } } @@ -1099,7 +1099,7 @@ SCM_DEFINE (scm_sys_warn_auto_compilation_enabled, "%warn-auto-compilation-enabl { scm_puts (";;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0\n" ";;; or pass the --no-auto-compile argument to disable.\n", - scm_current_warning_port ()); + scm_current_info_port ()); message_shown = 1; } @@ -1232,9 +1232,9 @@ SCM_DEFINE (scm_primitive_load_path, "primitive-load-path", 0, 0, 1, if (found_stale_compiled_file) { scm_puts (";;; found fresh local cache at ", - scm_current_warning_port ()); - scm_display (fallback, scm_current_warning_port ()); - scm_newline (scm_current_warning_port ()); + scm_current_info_port ()); + scm_display (fallback, scm_current_info_port ()); + scm_newline (scm_current_info_port ()); } compiled_thunk = try_load_thunk_from_file (fallback); } diff --git a/libguile/ports.c b/libguile/ports.c index d0e4e0c7f..13724edb2 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -432,6 +432,7 @@ static SCM cur_inport_fluid = SCM_BOOL_F; static SCM cur_outport_fluid = SCM_BOOL_F; static SCM cur_errport_fluid = SCM_BOOL_F; static SCM cur_warnport_fluid = SCM_BOOL_F; +static SCM cur_infoport_fluid = SCM_BOOL_F; static SCM cur_loadport_fluid = SCM_BOOL_F; SCM_DEFINE (scm_current_input_port, "current-input-port", 0, 0, 0, @@ -488,6 +489,18 @@ SCM_DEFINE (scm_current_warning_port, "current-warning-port", 0, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_current_info_port, "current-info-port", 0, 0, 0, + (void), + "Return the port to which diagnostic information should be sent.") +#define FUNC_NAME s_scm_current_info_port +{ + if (scm_is_true (cur_infoport_fluid)) + return scm_fluid_ref (cur_infoport_fluid); + else + return SCM_BOOL_F; +} +#undef FUNC_NAME + SCM_DEFINE (scm_current_load_port, "current-load-port", 0, 0, 0, (), "Return the current-load-port.\n" @@ -545,6 +558,18 @@ scm_set_current_warning_port (SCM port) } #undef FUNC_NAME +SCM +scm_set_current_info_port (SCM port) +#define FUNC_NAME "set-current-info-port" +{ + SCM oinfop = scm_fluid_ref (cur_infoport_fluid); + port = SCM_COERCE_OUTPORT (port); + SCM_VALIDATE_OPOUTPORT (1, port); + scm_fluid_set_x (cur_infoport_fluid, port); + return oinfop; +} +#undef FUNC_NAME + void scm_dynwind_current_input_port (SCM port) #define FUNC_NAME NULL @@ -4187,6 +4212,7 @@ scm_init_ice_9_ports (void) scm_c_define ("%current-output-port-fluid", cur_outport_fluid); scm_c_define ("%current-error-port-fluid", cur_errport_fluid); scm_c_define ("%current-warning-port-fluid", cur_warnport_fluid); + scm_c_define ("%current-info-port-fluid", cur_infoport_fluid); } void @@ -4221,6 +4247,7 @@ scm_init_ports (void) cur_outport_fluid = scm_make_fluid (); cur_errport_fluid = scm_make_fluid (); cur_warnport_fluid = scm_make_fluid (); + cur_infoport_fluid = scm_make_fluid (); cur_loadport_fluid = scm_make_fluid (); default_port_encoding_var = @@ -4259,4 +4286,8 @@ scm_init_ports (void) (scm_t_subr) scm_current_error_port); scm_c_define_gsubr (s_scm_current_warning_port, 0, 0, 0, (scm_t_subr) scm_current_warning_port); + + /* Used by welcome and compiler routines. */ + scm_c_define_gsubr (s_scm_current_info_port, 0, 0, 0, + (scm_t_subr) scm_current_info_port); } diff --git a/libguile/ports.h b/libguile/ports.h index 44ef29d87..d481c2967 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -139,11 +139,13 @@ SCM_API SCM scm_current_input_port (void); SCM_API SCM scm_current_output_port (void); SCM_API SCM scm_current_error_port (void); SCM_API SCM scm_current_warning_port (void); +SCM_API SCM scm_current_info_port (void); SCM_API SCM scm_current_load_port (void); SCM_API SCM scm_set_current_input_port (SCM port); SCM_API SCM scm_set_current_output_port (SCM port); SCM_API SCM scm_set_current_error_port (SCM port); SCM_API SCM scm_set_current_warning_port (SCM port); +SCM_API SCM scm_set_current_info_port (SCM port); SCM_API void scm_dynwind_current_input_port (SCM port); SCM_API void scm_dynwind_current_output_port (SCM port); SCM_API void scm_dynwind_current_error_port (SCM port); diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 627910ad9..04f84215c 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -190,6 +190,13 @@ This is handy for tracing function calls, e.g.: (newline (current-warning-port)) (car (last-pair stuff))) +(define (info . stuff) + (newline (current-info-port)) + (display ";;; INFO " (current-info-port)) + (display stuff (current-info-port)) + (newline (current-info-port)) + (car (last-pair stuff))) + ;;; {Features} @@ -4348,15 +4355,15 @@ when none is available, reading FILE-NAME with READER." (load-thunk-from-file go-file-name) (begin (when gostat - (format (current-warning-port) + (format (current-info-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) + (format (current-info-port) ";;; compiling ~a\n" name) (let ((cfn (compile name))) - (format (current-warning-port) ";;; compiled ~a\n" cfn) + (format (current-info-port) ";;; compiled ~a\n" cfn) (load-thunk-from-file cfn))) (else #f))))) #:warning "WARNING: compilation of ~a failed:\n" name)) diff --git a/module/ice-9/command-line.scm b/module/ice-9/command-line.scm index 5133d8d44..c1c197f32 100644 --- a/module/ice-9/command-line.scm +++ b/module/ice-9/command-line.scm @@ -135,6 +135,7 @@ If FILE begins with `-' the -s switch is mandatory. files. --listen[=P] listen on a local port or a path for REPL clients; if P is not given, the default is local port 37146 + -I silence informative diagnostics -q inhibit loading of user init file --use-srfi=LS load SRFI modules for the SRFIs in LS, which is a list of numbers like \"2,13,14\" @@ -385,7 +386,11 @@ If FILE begins with `-' the -s switch is mandatory. ((string=? arg "--listen") ; start a repl server (parse args (cons '((@@ (system repl server) spawn-server)) out))) - + + ((string=? arg "-I") ; silence diagostics + (parse args + (cons `(current-info-port (%make-void-port "w")) out))) + ((string-prefix? "--listen=" arg) ; start a repl server (parse args diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm index 833429eca..e1a6212eb 100644 --- a/module/ice-9/ports.scm +++ b/module/ice-9/ports.scm @@ -30,10 +30,10 @@ %port-property %set-port-property! current-input-port current-output-port - current-error-port current-warning-port + current-error-port current-warning-port current-info-port current-load-port set-current-input-port set-current-output-port - set-current-error-port + set-current-error-port set-current-info-port port-mode port? input-port? @@ -144,7 +144,8 @@ call-with-output-string close-port current-error-port - current-warning-port)) + current-warning-port + current-info-port)) (load-extension (string-append "libguile-" (effective-version)) "scm_init_ice_9_ports") @@ -290,6 +291,13 @@ interpret its input and output." (error "expected an output port" x)) x))) +(define current-info-port + (fluid->parameter %current-info-port-fluid + (lambda (x) + (unless (output-port? x) + (error "expected an output port" x)) + x))) + @@ -396,6 +404,10 @@ interpret its input and output." "Set the current default error port to @var{port}." (current-error-port port)) +(define (set-current-info-port port) + "Set the current default info port to @var{port}." + (current-info-port port)) + ;;;; high level routines diff --git a/module/system/repl/common.scm b/module/system/repl/common.scm index a3f2032ba..b7276f319 100644 --- a/module/system/repl/common.scm +++ b/module/system/repl/common.scm @@ -160,10 +160,10 @@ See , for more details.") #:debug debug)) (define (repl-welcome repl) - (display *version*) - (newline) - (newline) - (display "Enter `,help' for help.\n")) + (display *version* (current-info-port)) + (newline (current-info-port)) + (newline (current-info-port)) + (display "Enter `,help' for help.\n" (current-info-port))) (define (repl-prompt repl) (cond -- 2.46.0