help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] reorganize some command-line options


From: Paolo Bonzini
Subject: [Help-smalltalk] [PATCH] reorganize some command-line options
Date: Fri, 30 Mar 2007 10:46:09 +0200
User-agent: Thunderbird 1.5.0.10 (Macintosh/20070221)

This deletes -d, -e, -p, -Q.  -Q is now a synonym of -q
actually (it was used in the documentation, so it's better
to keep it for a release or two).  -p is used for Emacs
mode so the long version is enough.

For execution tracing we have this mapping:

   old -d    => -D
   old -D    => -D -D
   old -e    => -E
   old -E    => -E -E

which is also more than enough for these rarely used
options.

Of course, the aim of this is to enable (half tongue-in-cheek)

   gst -pe 'self asUppercase'

:-)

Paolo
2007-03-30  Paolo Bonzini  <address@hidden>

        * libgst/comp.c: Change _gst_declare_tracing to int, use value of 2
        for tracing variables intead _gst_trace_kernel_*.
        * libgst/comp.h: Likewise.
        * libgst/interp.c: Likewise.  Adapt bool_addr_index to return int *.
        * libgst/interp.h: Likewise.
        * libgst/prims.def: Support passing/returning an int in trace flag
        get/set primitives.
        * libgst/lib.c: Remove -d, -e options, and map old -[de] to new
        -[DE], allowing the user to specify them multiple times.  Keep only
        long version of -p, make option -Q synonym of -q (it was in the
        documentation).  Kill _gst_trace_kernel_*.  Only valid verbosity
        values are now 1/2/3.
        * libgst/oop.h: Change _gst_gc_message to int.
        * libgst/oop.c: Likewise, adapting to changes to the verbosity values.
        

--- orig/doc/gst.texi
+++ mod/doc/gst.texi
@@ -337,31 +337,22 @@ When this flag is set and a fatal signal
 after an error message is printed.  Normally, the backtrace is produced
 and the system terminates without dumping core.
 
address@hidden -d --user-declaration-trace
address@hidden -d --declaration-trace
 Declaration tracing prints the class name, the method name, and the byte
-codes that the compiler is generating as it compiles methods.  Only for
-files that are named explicitly on the command line; kernel files that
-are loaded automatically as part of rebuilding the image file do not
-have their declarations traced.
-
address@hidden -D --kernel-declaration-trace
-Like the -d flag, but also includes declarations processed for the
-kernel files.
+codes that the compiler is generating as it compiles methods.  Only applies
+to files that are named explicitly on the command line, unless the flag is
+given multiple times on the command line.
 
 @item -e --user-execution-trace
 Prints the byte codes being executed as the interpreter operates.  Only
-works for those executions that occur after the kernel files have been
-loaded and the image file dumped.
+works for statements explicitly issued by the user (either interactively
+or from files given on the command line), unless the flag is given
+multiple times on the command line.
 @ignore
-This option and the following one is disabled when the dynamic
+This option is disabled when the dynamic
 translator (@pxref{Dynamic translator}) is enabled.
 @end ignore
 
address@hidden -E --kernel-execution-trace
-Like the -e flag, but includes all byte codes executed, whether they
-occur during the loading of the kernel method definition files, or
-during the loading and execution of user files.
-
 @item --image-directory
 @itemx --kernel-directory
 Specify, respectively, the directory in which the image file @file{gst.im}
@@ -392,7 +383,7 @@ equivalent:
 
 @example
 gst -f @var{file} @file{args...}
-gst -Q @var{file} -a @file{args...}
+gst -q @var{file} -a @file{args...}
 @end example
 
 This is meant to be used in the so called ``sharp-bang'' sequence at the
@@ -449,10 +440,6 @@ Produce a log of the compiled Smalltalk 
 @item -q --quiet --silent
 Suppress the printing of returned values while @gst{} runs.
 
address@hidden -Q --no-messages
-Suppress the printing of execution information and any other informative
-message while @gst{} runs.
-
 @item -r --regression-test
 Controls printing of certain informative I/O; this is used by the
 regression testing system and is probably not of interest to the general


--- orig/libgst/comp.c
+++ mod/libgst/comp.c
@@ -107,7 +107,7 @@ OOP _gst_latest_compiled_method = NULL;
 
 /* This flag controls whether byte codes are printed after
    compilation.  */
-mst_Boolean _gst_declare_tracing = false;
+int _gst_declare_tracing = 0;
 
 /* If true, the compilation of a set of methods will be skipped
    completely; only syntax will be checked.  Set by primitive, cleared
@@ -538,7 +538,8 @@ _gst_invoke_hook (const char *hook)
 {
   int save_execution;
   save_execution = _gst_execution_tracing;
-  _gst_execution_tracing = _gst_trace_kernel_execution;
+  if (_gst_execution_tracing == 1)
+    _gst_execution_tracing = 0;
   _gst_msg_sendf (NULL, "%v %o changed: %S", 
                  _gst_object_memory_class, hook);
   _gst_execution_tracing = save_execution;


--- orig/libgst/comp.h
+++ mod/libgst/comp.h
@@ -241,8 +241,9 @@ extern OOP _gst_last_returned_value 
   ATTRIBUTE_HIDDEN;
 
 /* This flag controls whether byte codes are printed after
-   compilation.  */
-extern mst_Boolean _gst_declare_tracing 
+   compilation.  If > 1, it applies also to code not invoked by
+   the user.  */
+extern int _gst_declare_tracing 
   ATTRIBUTE_HIDDEN;
 
 /* If true, the compilation of a set of methods will be skipped


--- orig/libgst/interp.c
+++ mod/libgst/interp.c
@@ -140,7 +140,7 @@ interp_jmp_buf;
 /* If this is true, for each byte code that is executed, we print on
    stdout the byte index within the current gst_compiled_method and a
    decoded interpretation of the byte code.  */
-mst_Boolean _gst_execution_tracing = false;
+int _gst_execution_tracing = 0;
 
 /* When this is true, and an interrupt occurs (such as SIGABRT),
    Smalltalk will terminate itself by making a core dump (normally it
@@ -277,7 +277,7 @@ static interp_jmp_buf *reentrancy_jmp_bu
 
 /* when this flag is on and execution tracing is in effect, the top of
    the stack is printed as well as the byte code */
-static mst_Boolean verbose_exec_tracing = false;
+static int verbose_exec_tracing = false;
 
 /* This is the bridge to the primitive operations in the GNU Smalltalk
    system.  This function invokes the proper primitive_func with the
@@ -474,7 +474,7 @@ static void unwind_context (void);
 /* Used to help minimize the number of primitives used to control the
    various debugging flags, this routine maps the variable's INDEX to the
    address of a boolean debug flag, which it returns.  */
-static inline mst_Boolean *bool_addr_index (int index) ATTRIBUTE_PURE;
+static inline int *bool_addr_index (int index) ATTRIBUTE_PURE;
 
 /* Check whether it is true that sending SENDSELECTOR to RECEIVER
    accepts NUMARGS arguments.  Note that the RECEIVER is only used to
@@ -2027,7 +2027,7 @@ create_callin_process (OOP contextOOP)
   return (initialProcessOOP);
 }
 
-mst_Boolean *
+int *
 bool_addr_index (int index)
 {
   switch (index)
@@ -2444,7 +2444,7 @@ interrupt_handler (int sig)
 #ifdef HAVE_EXECINFO_H
       /* Don't print a backtrace, for example, if exiting during a
         compilation.  */
-      if ((_gst_verbosity > 2 && (ip || _gst_gc_running))
+      if ((_gst_verbosity == 3 && (ip || _gst_gc_running))
          || is_serious_error || sig == SIGUSR1)
        {
           PTR array[11];


--- orig/libgst/interp.h
+++ mod/libgst/interp.h
@@ -253,8 +253,9 @@ extern unsigned long _gst_sample_counter
 
 /* If this is true, for each byte code that is executed, we print on
    stdout the byte index within the current gst_compiled_method and a
-   decoded interpretation of the byte code.  */
-extern mst_Boolean _gst_execution_tracing 
+   decoded interpretation of the byte code.  If > 1, it applies also
+   to code not invoked by the user.  */
+extern int _gst_execution_tracing 
   ATTRIBUTE_HIDDEN;
 
 /* When this is true, and an interrupt occurs (such as SIGSEGV),


--- orig/libgst/lib.c
+++ mod/libgst/lib.c
@@ -86,27 +86,27 @@ static const char help_text[] =
   "\nShort flags can appear either as -xyz or as -x -y -z.  If an option is"
   "\nmandatory for a long option, it is also mandatory for a short one. The"
   "\ncurrently defined set of flags is:"
-  "\n   -a --smalltalk\t\t Pass the remaining arguments to Smalltalk"
-  "\n   -c --core-dump\t\t Dump core on fatal signal"
-  "\n   -d --declaration-trace-user\t Trace compilation of files on the 
command line"
-  "\n   -D --declaration-trace-all\t Trace compilation of all loaded files"
+  "\n   -a --smalltalk-args\t\t Pass the remaining arguments to Smalltalk."
+  "\n   -c --core-dump\t\t Dump core on fatal signal."
+  "\n   -D --declaration-trace\t Trace compilation of all loaded files."
 #ifndef ENABLE_JIT_TRANSLATION
-  "\n   -e --execution-trace-user\t Trace execution of files on the command 
line"
-  "\n   -E --execution-trace-all\t Trace execution of all loaded files"
+  "\n   -E --execution-trace\t\t Trace execution of all loaded files."
 #endif
-  "\n   -g --no-gc-message\t\t Do not print garbage collection messages"
-  "\n   -H --help\t\t\t Print this message and exit"
-  "\n   -i --rebuild-image\t\t Ignore the image file; rebuild it from scratch"
-  "\n   -I --image-file file\t\t Instead of `gst.im', use `file' as the 
image\n\t\t\t\t file, and ignore the kernel files' timestamps\n"
-  "\n   -K --kernel-file file\t Make file's path relative to the image path."
-  "\n   -p --emacs-mode\t\t Execute as a `process' (from within Emacs)"
-  "\n   -q --quiet --silent\t\t Do not print execution information"
-  "\n   -Q --no-messages\t\t Run Smalltalk with -q -g and no startup banner"
-  "\n   -r --regression-test\t\t Run in regression test mode, i.e. 
make\n\t\t\t\t printed messages constant\n"
-  "\n   -S --snapshot\t\t Save a snapshot just before exiting"
-  "\n   -v --version\t\t\t Print the Smalltalk version number and exit"
-  "\n   -V --verbose\t\t\t Print names of loaded files and execution stats"
-  "\n   -\t\t\t\t Read input from standard input explicitly"
+  "\n   -g --no-gc-message\t\t Do not print garbage collection messages."
+  "\n   -H --help\t\t\t Print this message and exit."
+  "\n   -i --rebuild-image\t\t Ignore the image file; rebuild it from scratch."
+  "\n   -I --image-file FILE\t\t Instead of `gst.im', use FILE as the 
image\n\t\t\t\t file, and ignore the kernel files' timestamps.\n"
+  "\n   -K --kernel-file FILE\t Make FILE's path relative to the image path."
+  "\n   -q --quiet --silent\t\t Do not print execution information."
+  "\n   -r --regression-test\t\t Run in regression test mode, i.e. 
make\n\t\t\t\t printed messages constant.\n"
+  "\n   -S --snapshot\t\t Save a snapshot just before exiting."
+  "\n   -v --version\t\t\t Print the Smalltalk version number and exit."
+  "\n   -V --verbose\t\t\t Print names of loaded files and execution stats."
+  "\n      --emacs-mode\t\t Execute as a `process' (from within Emacs)"
+  "\n      --image-dir DIR\t\t Look for the image in directory DIR."
+  "\n      --kernel-dir DIR\t\t Look for kernel files in directory DIR."
+  "\n      --no-user-files\t\t Don't read user customization files.\n"
+  "\n   -\t\t\t\t Read input from standard input explicitly."
   "\n"
   "\nFiles are loaded one after the other.  After the last one is loaded,"
   "\nSmalltalk will exit.  If no files are specified, Smalltalk reads from"
@@ -132,15 +132,14 @@ static const char copyright_and_legal_st
 #define OPT_KERNEL_DIR 2
 #define OPT_IMAGE_DIR 3
 #define OPT_NO_USER 4
+#define OPT_EMACS_MODE 5
 
 static const struct option long_options[] = {
   {"smalltalk-args", 0, 0, 'a'},
   {"core-dump", 0, 0, 'c'},
-  {"declaration-trace-user", 0, 0, 'd'},
-  {"declaration-trace-all", 0, 0, 'D'},
+  {"declaration-trace", 0, 0, 'D'},
 #ifndef ENABLE_JIT_TRANSLATION
-  {"execution-trace-user", 0, 0, 'e'},
-  {"execution-trace-all", 0, 0, 'E'},
+  {"execution-trace", 0, 0, 'E'},
 #endif
   {"file", 0, 0, 'f'},
   {"kernel-directory", 1, 0, OPT_KERNEL_DIR},
@@ -151,9 +150,9 @@ static const struct option long_options[
   {"rebuild-image", 0, 0, 'i'},
   {"image-file", 1, 0, 'I'},
   {"kernel-file", 1, 0, 'K'},
-  {"emacs-mode", 0, 0, 'p'},
+  {"emacs-mode", 0, 0, OPT_EMACS_MODE},
   {"quiet", 0, 0, 'q'},
-  {"no-messages", 0, 0, 'Q'},
+  {"no-messages", 0, 0, 'q'},
   {"silent", 0, 0, 'q'},
   {"regression-test", 0, 0, 'r'},
   {"snapshot", 0, 0, 'S'},
@@ -211,14 +210,6 @@ mst_Boolean _gst_smalltalk_initialized =
    the system is ready to do them.  */
 mst_Boolean _gst_kernel_initialized = false;
 
-/* If true, even both kernel and user method definitions are shown as
-   they are compiled.  */
-mst_Boolean _gst_trace_kernel_declarations = false;
-
-/* If true, execution tracing is performed when loading kernel method
-   definitions.  */
-mst_Boolean _gst_trace_kernel_execution = false;
-
 /* This is TRUE if we are doing regression testing, and causes
    whatever sources of variance to be suppressed (such as printing out
    execution statistics).  */
@@ -477,16 +468,18 @@ gst_init_smalltalk (void)
 
   if (_gst_regression_testing)
     {
-      _gst_trace_kernel_declarations = _gst_declare_tracing = false;
-      _gst_trace_kernel_execution = _gst_execution_tracing = false;
+      _gst_declare_tracing = 0;
+      _gst_execution_tracing = 0;
       _gst_verbosity = 2;
       setvbuf (stdout, NULL, _IOLBF, 1024);
     }
 
   traceUserDeclarations = _gst_declare_tracing;
   traceUserExecution = _gst_execution_tracing;
-  _gst_declare_tracing = _gst_trace_kernel_declarations;
-  _gst_execution_tracing = _gst_trace_kernel_execution;
+  if (_gst_declare_tracing == 1)
+    _gst_declare_tracing--;
+  if (_gst_execution_tracing == 1)
+    _gst_execution_tracing--;
 
   if (_gst_binary_image_name)
     loadBinary = abortOnFailure = true;
@@ -822,7 +815,7 @@ find_user_file (const char *fileName)
 void
 process_stdin ()
 {
-  if (_gst_verbosity > 0)
+  if (_gst_verbosity == 3 || isatty (0))
     {
       printf ("GNU Smalltalk ready\n\n");
       fflush (stdout);
@@ -844,7 +837,7 @@ process_file (const char *fileName)
   if (fd == -1)
     return (false);
 
-  if (_gst_verbosity > 2)
+  if (_gst_verbosity == 3)
     printf ("Processing %s\n", fileName);
 
   _gst_use_undeclared++;
@@ -863,9 +856,9 @@ parse_args (int argc,
   int ch, prev_optind = 1, minus_a_optind = -1;
 
 #ifndef ENABLE_DYNAMIC_TRANSLATION
-# define OPTIONS "-acdDeEf:ghiI:K:lL:pQqrSvV"
+# define OPTIONS "-acDEf:ghiI:K:lL:QqrSvV"
 #else
-# define OPTIONS "-acdDf:ghiI:K:lL:pQqrSvV"
+# define OPTIONS "-acDf:ghiI:K:lL:QqrSvV"
 #endif
 
   loaded_files =
@@ -890,15 +883,11 @@ parse_args (int argc,
          _gst_make_core_file = true;
          break;
        case 'D':
-         _gst_trace_kernel_declarations = true;        /* fall thru */
-       case 'd':
-         _gst_declare_tracing = true;
+         _gst_declare_tracing++;
          break;
 #ifndef ENABLE_JIT_TRANSLATION
        case 'E':
-         _gst_trace_kernel_execution = true;           /* fall thru */
-       case 'e':
-         _gst_execution_tracing = true;
+         _gst_execution_tracing++;
          break;
 #endif
        case 'g':
@@ -907,14 +896,12 @@ parse_args (int argc,
        case 'i':
          ignore_image = true;
          break;
-       case 'p':
+       case OPT_EMACS_MODE:
          _gst_emacs_process = true;
          break;
-       case 'Q':
-         _gst_verbosity = 0;
-         break;
        case 'q':
-         _gst_verbosity = (_gst_verbosity > 1) ? 1 : _gst_verbosity;
+       case 'Q':
+         _gst_verbosity = 1;
          break;
        case 'r':
          _gst_regression_testing = true;
@@ -927,8 +914,8 @@ parse_args (int argc,
          break;
 
        case 'f':
-         /* Same as -Q, passing a file, and -a.  */
-         _gst_verbosity = 0;
+         /* Same as -q, passing a file, and -a.  */
+         _gst_verbosity = 1;
          loaded_files[n_loaded_files].kernel_path = false;
          loaded_files[n_loaded_files++].file_name = optarg;
 


--- orig/libgst/lib.h
+++ mod/libgst/lib.h
@@ -110,16 +110,6 @@ extern const char **_gst_smalltalk_passe
 extern mst_Boolean _gst_kernel_initialized 
   ATTRIBUTE_HIDDEN;
 
-/* If true, even both kernel and user method definitions are shown as
-   they are compiled.  */
-extern mst_Boolean _gst_trace_kernel_declarations 
-  ATTRIBUTE_HIDDEN;
-
-/* If true, execution tracing is performed when loading kernel method
-   definitions.  */
-extern mst_Boolean _gst_trace_kernel_execution 
-  ATTRIBUTE_HIDDEN;
-
 /* Set by cmd line flag.  If true, Smalltalk is more verbose about
    what it's doing.  */
 extern mst_Boolean _gst_verbose 


--- orig/libgst/oop.c
+++ mod/libgst/oop.c
@@ -103,7 +103,7 @@ OOP _gst_true_oop = NULL;
 OOP _gst_false_oop = NULL;
 
 /* This is true to show a message whenever a GC happens.  */
-mst_Boolean _gst_gc_message = true;
+int _gst_gc_message = true;
 
 /* This is != 0 in the middle of a GC.  */
 int _gst_gc_running = 0;
@@ -1075,7 +1075,7 @@ _gst_global_gc (int next_allocation)
     
   if (!_gst_gc_running++
       && _gst_gc_message
-      && _gst_verbosity > 0
+      && _gst_verbosity >= 2
       && !_gst_regression_testing)
     {
       /* print the first part of this message before we finish
@@ -1145,7 +1145,7 @@ _gst_global_gc (int next_allocation)
 
   if (!--_gst_gc_running
       && _gst_gc_message
-      && _gst_verbosity > 0
+      && _gst_verbosity >= 2
       && !_gst_regression_testing)
     {
       fprintf (stderr, "%s\"\n", s);


--- orig/libgst/oop.h
+++ mod/libgst/oop.h
@@ -257,7 +257,7 @@ struct memory_space
 };
 
 /* This is true to show a message whenever a GC happens.  */
-extern mst_Boolean _gst_gc_message 
+extern int _gst_gc_message 
   ATTRIBUTE_HIDDEN;
 
 /* This is true in the middle of a GC.  */


--- orig/libgst/prims.def
+++ mod/libgst/prims.def
@@ -3363,12 +3363,13 @@ primitive VMpr_SystemDictionary_getTrace
   if (IS_INT (oop2))
     {
       intptr_t arg2;
-      mst_Boolean *boolAddr;
+      int *varAddr;
       arg2 = TO_INT (oop2);
-      boolAddr = bool_addr_index (arg2);
-      if (boolAddr != NULL)
+      varAddr = bool_addr_index (arg2);
+      if (varAddr != NULL)
        {
-         oop1 = *boolAddr ? _gst_true_oop : _gst_false_oop;
+         oop1 = (*varAddr > 1 ? FROM_INT (oop2 ) :
+                 (*varAddr ? _gst_true_oop : _gst_false_oop));
          PUSH_OOP (oop1);
          PRIM_SUCCEEDED;
        }
@@ -3389,12 +3390,12 @@ primitive VMpr_SystemDictionary_setTrace
   oop1 = POP_OOP ();
   if (IS_INT (oop1))
     {
-      mst_Boolean *boolAddr;
+      mst_Boolean *varAddr;
       intptr_t arg1 = TO_INT (oop1);
-      boolAddr = bool_addr_index (arg1);
-      if (boolAddr != NULL)
+      varAddr = bool_addr_index (arg1);
+      if (varAddr != NULL)
        {
-         *boolAddr = (oop2 == _gst_true_oop);
+         *varAddr = IS_INT (oop2) ? TO_INT (oop2) : (oop2 == _gst_true_oop);
          SET_EXCEPT_FLAG (true);
          PRIM_SUCCEEDED;
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]