changeset 33482:787937817a64 bytecode-interpreter

maint: Merge default to bytecode-interpreter
author Arun Giridhar <arungiridhar@gmail.com>
date Mon, 29 Apr 2024 10:10:44 -0400
parents 31ec057261fb (current diff) 4d037eddd28f (diff)
children 593a2ebbc8da
files
diffstat 6 files changed, 108 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-ed.cc	Sun Apr 28 11:14:38 2024 -0400
+++ b/libgui/src/gui-preferences-ed.cc	Mon Apr 29 10:10:44 2024 -0400
@@ -234,6 +234,9 @@
                                 QVariant (false));
 
 gui_pref
+ed_run_selection_tmp_file ("editor/run_selection_tmp_file", QVariant (QString ()));
+
+gui_pref
 ed_mru_file_list ("editor/mru_file_list", QVariant ());
 
 gui_pref
--- a/libgui/src/gui-preferences-ed.h	Sun Apr 28 11:14:38 2024 -0400
+++ b/libgui/src/gui-preferences-ed.h	Mon Apr 29 10:10:44 2024 -0400
@@ -202,6 +202,8 @@
 
 extern gui_pref ed_always_reload_changed_files;
 
+extern gui_pref ed_run_selection_tmp_file;
+
 extern gui_pref ed_mru_file_list;
 
 extern gui_pref ed_mru_file_encodings;
--- a/libgui/src/m-editor/file-editor.cc	Sun Apr 28 11:14:38 2024 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Mon Apr 29 10:10:44 2024 -0400
@@ -1707,12 +1707,16 @@
         }
       else
         {
-          if (! show_dbg_file && (breakpoint_marker  || debug_pointer))
+          if (! show_dbg_file && (breakpoint_marker || debug_pointer))
             return;   // Do not open a file for showing dbg markers
 
           if (breakpoint_marker && ! insert)
             return;   // Never open a file when removing breakpoints
 
+          if ((breakpoint_marker || debug_pointer)
+              && (openFileName == settings.string_value (ed_run_selection_tmp_file)))
+            return;   // Never open tmp file when debugging while running selection
+
           file_editor_tab *fileEditorTab = nullptr;
           // Reuse <unnamed> tab if it hasn't yet been modified.
           bool reusing = false;
--- a/libgui/src/m-editor/octave-qscintilla.cc	Sun Apr 28 11:14:38 2024 -0400
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Mon Apr 29 10:10:44 2024 -0400
@@ -908,19 +908,8 @@
       line_escaped.replace (QString ("'"), QString ("''"));
       QString line_history = line;
 
-      // Prevent output of breakpoint in temp. file for keyboard
-      QString next_bp_quiet;
-      QString next_bp_quiet_reset;
-      if (line.contains ("keyboard"))
-        {
-          // Define commands for not showing bp location and for resetting
-          // this in case "keyboard" was within a comment
-          next_bp_quiet = "__db_next_breakpoint_quiet__;\n";
-          next_bp_quiet_reset = "\n__db_next_breakpoint_quiet__(false);";
-        }
-
       // Add codeline
-      code += next_bp_quiet + line + next_bp_quiet_reset + "\n";
+      code += line + "\n";
       hist += line_history + "\n";
     }
 
@@ -938,6 +927,10 @@
       return;
     }
 
+  // Store file in settings in order to avoid opening it in editor
+  gui_settings settings;
+  settings.setValue (ed_run_selection_tmp_file.settings_key (), tmp_file->fileName ());
+
   // Create tmp file required for adding command to history
   QPointer<QTemporaryFile> tmp_hist = create_tmp_file ("", hist);
 
@@ -965,12 +958,6 @@
         Fhistory (interp, ovl (opt, path));
       });
 
-  // Disable opening a file at a breakpoint in case keyboard () is used
-  gui_settings settings;
-
-  bool show_dbg_file = settings.bool_value (ed_show_dbg_file);
-  settings.setValue (ed_show_dbg_file.settings_key (), false);
-
   // The interpreter_event callback function below emits a signal.
   // Because we don't control when that happens, use a guarded pointer
   // so that the callback can abort if this object is no longer valid.
@@ -979,7 +966,7 @@
 
   // Let the interpreter execute the tmp file
   emit interpreter_event
-    ([this, this_oq, tmp_file, tmp_hist, show_dbg_file] (interpreter& interp)
+    ([this, this_oq, tmp_file, tmp_hist] (interpreter& interp)
      {
        // INTERPRETER THREAD
 
@@ -1066,7 +1053,7 @@
              stack.pop_back ();
 
            // Clean up before throwing the modified error.
-           emit ctx_menu_run_finished_signal (show_dbg_file, err_line,
+           emit ctx_menu_run_finished_signal (err_line,
                                               tmp_file, tmp_hist,
                                               dbg, auto_repeat);
 
@@ -1080,7 +1067,7 @@
 
        // Clean up
 
-       emit ctx_menu_run_finished_signal (show_dbg_file, err_line,
+       emit ctx_menu_run_finished_signal (err_line,
                                           tmp_file, tmp_hist,
                                           dbg, auto_repeat);
 
@@ -1096,7 +1083,7 @@
 }
 
 void octave_qscintilla::ctx_menu_run_finished
-  (bool show_dbg_file, int, QPointer<QTemporaryFile> tmp_file,
+  (int, QPointer<QTemporaryFile> tmp_file,
    QPointer<QTemporaryFile> tmp_hist, bool dbg, bool auto_repeat)
 {
   emit focus_console_after_command_signal ();
@@ -1106,12 +1093,12 @@
   //       possible lines from commands at a debug prompt must be
   //       taken into consideration.
 
-  gui_settings settings;
-
-  settings.setValue (ed_show_dbg_file.settings_key (), show_dbg_file);
-
   if (tmp_file && tmp_file->exists ())
-    tmp_file->remove ();
+    {
+      tmp_file->remove ();
+      gui_settings settings;
+      settings.setValue (ed_run_selection_tmp_file.settings_key (), QString ());
+    }
 
   if (tmp_hist && tmp_hist->exists ())
     tmp_hist->remove ();
--- a/libgui/src/m-editor/octave-qscintilla.h	Sun Apr 28 11:14:38 2024 -0400
+++ b/libgui/src/m-editor/octave-qscintilla.h	Mon Apr 29 10:10:44 2024 -0400
@@ -96,7 +96,7 @@
   void show_symbol_tooltip_signal (const QPoint&, const QString&);
   void context_menu_break_condition_signal (int);
   void context_menu_break_once (int);
-  void ctx_menu_run_finished_signal (bool, int, QPointer<QTemporaryFile>,
+  void ctx_menu_run_finished_signal (int, QPointer<QTemporaryFile>,
                                      QPointer<QTemporaryFile>, bool, bool);
   void focus_console_after_command_signal ();
 
@@ -110,7 +110,7 @@
 
 private slots:
 
-  void ctx_menu_run_finished (bool, int, QPointer<QTemporaryFile>,
+  void ctx_menu_run_finished (int, QPointer<QTemporaryFile>,
                               QPointer<QTemporaryFile>, bool, bool);
 
   void contextmenu_help (bool);
--- a/scripts/general/rat.m	Sun Apr 28 11:14:38 2024 -0400
+++ b/scripts/general/rat.m	Mon Apr 29 10:10:44 2024 -0400
@@ -61,7 +61,7 @@
 ## @example
 ## @group
 ## s = rat (0.5 + i * pi)
-## @result{} s = (1 + 1/(-2)) + (3 + 1/(7 + 1/16)) * i
+## @result{} s = complex (1 + 1/(-2), 3 + 1/(7 + 1/16))
 ##
 ## [n, d] = rat (0.5 + i * pi)
 ## @result{} n =  113 + 710i
@@ -72,9 +72,14 @@
 ## @end group
 ## @end example
 ##
-## Programming Note: With one output @code{rat} produces a string which is a
-## continued fraction expansion.  To produce a string which is a simple
-## fraction (one numerator, one denominator) use @code{rats}.
+## Programming Notes:
+##
+## 1. With one output @code{rat} produces a string which is a continued
+## fraction expansion.  To produce a string which is a simple fraction
+## (one numerator, one denominator) use @code{rats}.
+##
+## 2. The string output produced by @code{rat} can be passed to @code{eval}
+## to get back the original input up to the tolerance used.
 ##
 ## @seealso{rats, format}
 ## @end deftypefn
@@ -89,6 +94,43 @@
     error ("rat: X must be a single or double array");
   endif
 
+  if (iscomplex (x))
+    if (nargout == 2)  # return numerator and denominator
+      if (nargin == 2)
+        [nr, dr] = rat (real (x), tol);
+        [ni, di] = rat (imag (x), tol);
+      else
+        [nr, dr] = rat (real (x));
+        [ni, di] = rat (imag (x));
+      endif
+
+      ## For inputs with inf, the output is set to 1/0 or -1/0.
+      ## Override that to +inf/1 or -inf/1.
+      ii = (dr == 0 & nr > 0); dr(ii) = 1; nr(ii) = +inf;
+      ii = (dr == 0 & nr < 0); dr(ii) = 1; nr(ii) = -inf;
+      ii = (di == 0 & ni > 0); di(ii) = 1; ni(ii) = +inf;
+      ii = (di == 0 & ni < 0); di(ii) = 1; ni(ii) = -inf;
+
+      d = lcm (dr, di);  # now this should always be nonzero
+      n = complex (nr .* (d ./ dr), ni .* (d ./ di));
+    elseif (nargout <= 1)  # string output
+      if (nargin == 2)
+        realstr = rat (real (x), tol);
+        imagstr = rat (imag (x), tol);
+      else
+        realstr = rat (real (x));
+        imagstr = rat (imag (x));
+      endif
+
+      nn = rows (realstr);
+      start  = repmat ("complex (", nn, 1);
+      mid    = repmat (", ",        nn, 1);
+      finish = repmat (")",         nn, 1);
+      n = [start, realstr, mid, imagstr, finish];
+    endif
+    return
+  endif
+
   y = x(:);
 
   ## Replace Inf with 0 while calculating ratios.
@@ -104,20 +146,6 @@
     endif
   endif
 
-  if (iscomplex (x))
-    if (nargout == 2)  # return numerator and denominator
-      [nr, dr] = rat (real (x), tol);
-      [ni, di] = rat (imag (x), tol);
-      d = lcm (dr, di);
-      n = nr .* (d ./ dr) + ni .* (d ./ di) * i;
-    elseif (nargout <= 1)  # string output
-      realstr = rat (real (x), tol);
-      imagstr = rat (imag (x), tol);
-      n = [repmat("(", rows (realstr), 1), realstr, repmat(") + (", rows (realstr), 1), imagstr, repmat(") * i", rows (imagstr), 1)];
-    endif
-    return
-  endif
-
   ## First step in the approximation is the integer portion
 
   ## First element in the continued fraction.
@@ -246,7 +274,7 @@
 
 ## Test complex scalar input
 %!test <*55198>
-%! assert (rat (complex (0.5, pi)), "(1 + 1/(-2)) + (3 + 1/(7 + 1/16)) * i");
+%! assert (rat (complex (0.5, pi)), "complex (1 + 1/(-2), 3 + 1/(7 + 1/16))");
 %! [n, d] = rat (complex (0.5, pi));
 %! assert (n, 113 + 710*i);
 %! assert (d, 226);
@@ -260,21 +288,50 @@
 %! assert (d, [887313, 49387, 49387, 887313]);
 %! assert (all (abs (n ./ d - x) <= 2e-6));
 %! str = rat (x);
-%! assert (str(1, :), "(0 + 1/(3 + 1/(4 + 1/(4 + 1/(4 + 1/4))))) + (1 + 1/(-20 + 1/(-2 + 1/(-3 + 1/(-6))))) * i");
-%! assert (str(2, :), "(-1 + 1/(5 + 1/(4 + 1/(4 + 1/4)))       ) + (1 + 1/(-2 + 1/(-2 + 1/(-3 + 1/8)))    ) * i");
-%! assert (str(3, :), "(-1 + 1/(5 + 1/(4 + 1/(4 + 1/4)))       ) + (-1 + 1/(2 + 1/(2 + 1/(3 + 1/(-8))))   ) * i");
-%! assert (str(4, :), "(0 + 1/(3 + 1/(4 + 1/(4 + 1/(4 + 1/4))))) + (-1 + 1/(20 + 1/(2 + 1/(3 + 1/6)))     ) * i");
+%! assert (str(1, :), "complex (0 + 1/(3 + 1/(4 + 1/(4 + 1/(4 + 1/4)))), 1 + 1/(-20 + 1/(-2 + 1/(-3 + 1/(-6)))))");
+%! assert (str(2, :), "complex (-1 + 1/(5 + 1/(4 + 1/(4 + 1/4)))       , 1 + 1/(-2 + 1/(-2 + 1/(-3 + 1/8)))    )");
+%! assert (str(3, :), "complex (-1 + 1/(5 + 1/(4 + 1/(4 + 1/4)))       , -1 + 1/(2 + 1/(2 + 1/(3 + 1/(-8))))   )");
+%! assert (str(4, :), "complex (0 + 1/(3 + 1/(4 + 1/(4 + 1/(4 + 1/4)))), -1 + 1/(20 + 1/(2 + 1/(3 + 1/6)))     )");
 
 ## Test complex exceptional inputs
 %!test <*55198>
-%! assert (rat (complex (inf, 0)), "(Inf) + (0) * i");
-%! assert (rat (complex (0, inf)), "(0) + (Inf) * i");
+%! assert (rat (complex (inf, 0)), "complex (Inf, 0)");
+%! assert (rat (complex (0, inf)), "complex (0, Inf)");
+%! assert (rat (complex (-inf, 0)), "complex (-Inf, 0)");
+%! assert (rat (complex (0, -inf)), "complex (0, -Inf)");
+%! assert (rat (complex (nan, 0)), "complex (NaN , 0)");
+%! assert (rat (complex (0, nan)), "complex (0, NaN )");
+
+%!test <*55198>
+%! [n, d] = rat (complex (inf, 0));
+%! assert (n, complex (inf, 0));
+%! assert (d, 1);
+%! [n, d] = rat (complex (0, inf));
+%! assert (n, complex (0, inf));
+%! assert (d, 1);
+%! [n, d] = rat (complex (-inf, 0));
+%! assert (n, complex (-inf, 0));
+%! assert (d, 1);
+%! [n, d] = rat (complex (0, -inf));
+%! assert (n, complex (0, -inf));
+%! assert (d, 1);
+%! [n, d] = rat (complex (nan, 0));
+%! assert (n, complex (nan, 0));
+%! assert (d, 1);
+%! [n, d] = rat (complex (0, nan));
+%! assert (n, complex (0, nan));
+%! assert (d, 1);
 
 ## Test eval with complex inputs
 %!test <*55198>
 %! x = complex (0.5, pi);
 %! assert (eval (rat (x)), x, 1e-6 * norm (x, 1))
 
+## Test eval with inf*i
+%!test <*55198>
+%! x = complex (0, inf);
+%! assert (eval (rat (x)), x, 1e-6 * norm (x, 1))
+
 %!assert <*43374> (eval (rat (0.75)), [0.75])
 
 ## Test input validation