# HG changeset patch # User jwe # Date 862260637 0 # Node ID 8303749672bea08be968aca78fb1cbfc977cc551 # Parent 64ff56723e751b339a0c2ac435ee8e350fc7ace6 [project @ 1997-04-28 20:50:36 by jwe] diff -r 64ff56723e75 -r 8303749672be src/ChangeLog --- a/src/ChangeLog Mon Apr 28 20:41:15 1997 +0000 +++ b/src/ChangeLog Mon Apr 28 20:50:37 1997 +0000 @@ -1,3 +1,20 @@ +Mon Apr 28 00:38:19 1997 John W. Eaton + + * pt-misc.cc (Vsilent_functions, silent_functions): + Move here from oct-usr-fcn.cc. + (symbols_of_pt_misc): New function. DEFVAR silent_functions. + (tree_statement_list::eval): Handle Vsilent_functions here instead + of in octave_user_function::eval. + (tree_statement::eval): New functions. + (tree_statement_list::eval): Use them. + Change print flag arg to silent flag. Change all callers. + * variables.cc (install_builtin_variables): Call symbols_of_pt_misc. + * toplev.cc (parse_and_execute): Delete print arg. Change all callers. + (eval_string): Change print flag arg to silent flag. Change callers. + + * dynamic-ld.h, dynamic-ld.cc: Rewrite to use singleton class. + * variables.cc (load_fcn_from_file): Use new dynamic linking class. + Sun Apr 27 20:17:49 1997 John W. Eaton * dynamic-ld.h (Octave_builtin_fcn): Delete typedef. diff -r 64ff56723e75 -r 8303749672be src/oct-usr-fcn.cc --- a/src/oct-usr-fcn.cc Mon Apr 28 20:41:15 1997 +0000 +++ b/src/oct-usr-fcn.cc Mon Apr 28 20:50:37 1997 +0000 @@ -54,10 +54,6 @@ // don't actually define any return variables. static bool Vreturn_last_computed_value; -// If TRUE, turn off printing of results in functions (as if a -// semicolon has been appended to each statement). -static bool Vsilent_functions; - // Nonzero means we're breaking out of a loop or function body. extern int breaking; @@ -341,8 +337,7 @@ // Evaluate the commands that make up the function. - bool pf = ! Vsilent_functions; - octave_value last_computed_value = cmd_list->eval (pf); + octave_value last_computed_value = cmd_list->eval (); if (echo_commands) print_code_function_trailer (); @@ -536,14 +531,6 @@ return 0; } -static int -silent_functions (void) -{ - Vsilent_functions = check_preference ("silent_functions"); - - return 0; -} - void symbols_of_oct_usr_fcn (void) { @@ -560,9 +547,6 @@ DEFVAR (return_last_computed_value, 0.0, 0, return_last_computed_value, "if a function does not return any values explicitly, return the\n\ last computed value"); - - DEFVAR (silent_functions, 0.0, 0, silent_functions, - "suppress printing results in called functions"); } /* diff -r 64ff56723e75 -r 8303749672be src/pt-misc.cc --- a/src/pt-misc.cc Mon Apr 28 20:41:15 1997 +0000 +++ b/src/pt-misc.cc Mon Apr 28 20:50:37 1997 +0000 @@ -37,6 +37,7 @@ #include #endif +#include "defun.h" #include "error.h" #include "input.h" #include "oct-obj.h" @@ -53,6 +54,7 @@ #include "pt-pr-code.h" #include "pt-walk.h" #include "toplev.h" +#include "utils.h" #include "variables.h" // Nonzero means we're breaking out of a loop or function body. @@ -64,6 +66,10 @@ // Nonzero means we're returning from a function. extern int returning; +// If TRUE, turn off printing of results in functions (as if a +// semicolon has been appended to each statement). +static bool Vsilent_functions; + // A list of commands to be executed. tree_statement::~tree_statement (void) @@ -96,6 +102,57 @@ } } +octave_value +tree_statement::eval (bool silent, bool in_function_body) +{ + octave_value retval; + + bool pf = silent ? false : print_flag; + + if (cmd || expr) + { + maybe_echo_code (in_function_body); + + if (cmd) + cmd->eval (); + else + retval = expr->eval (pf); + } + + return retval; +} + +octave_value_list +tree_statement::eval (bool silent, int nargout, bool in_function_body) +{ + bool pf = silent ? false : print_flag; + + octave_value_list retval; + + if (cmd || expr) + { + maybe_echo_code (in_function_body); + + if (cmd) + cmd->eval (); + else + { + if (expr->is_multi_val_ret_expression ()) + { + octave_value_list args; + + tree_multi_val_ret *t = static_cast (expr); + + retval = t->eval (pf, nargout, args); + } + else + retval = expr->eval (pf); + } + } + + return retval; +} + void tree_statement::accept (tree_walker& tw) { @@ -103,9 +160,8 @@ } octave_value -tree_statement_list::eval (bool print) +tree_statement_list::eval (bool silent) { - bool pf; octave_value retval; if (error_state) @@ -115,25 +171,42 @@ { tree_statement *elt = this->operator () (p); - if (! print) - pf = false; - else - pf = elt->print_flag; + bool silent_flag = + silent ? true : (function_body ? Vsilent_functions : false); + + retval = elt->eval (silent_flag, function_body); - tree_command *cmd = elt->command (); - tree_expression *expr = elt->expression (); + if (error_state) + break; + + if (breaking || continuing) + break; + + if (returning) + break; + } - if (cmd || expr) - { - elt->maybe_echo_code (function_body); + return retval; +} + +octave_value_list +tree_statement_list::eval (bool no_print, int nargout) +{ + octave_value_list retval; - if (cmd) - cmd->eval (); - else - retval = expr->eval (pf); + if (error_state) + return retval; + + if (nargout > 1) + { + for (Pix p = first (); p != 0; next (p)) + { + tree_statement *elt = this->operator () (p); + + retval = elt->eval (no_print, nargout, function_body); if (error_state) - return octave_value (); + break; if (breaking || continuing) break; @@ -141,71 +214,9 @@ if (returning) break; } - else - retval = octave_value (); - } - return retval; -} - -octave_value_list -tree_statement_list::eval (bool print, int nargout) -{ - octave_value_list retval; - - if (nargout > 1) - { - bool pf; - - if (error_state) - return retval; - - for (Pix p = first (); p != 0; next (p)) - { - tree_statement *elt = this->operator () (p); - - if (! print) - pf = false; - else - pf = elt->print_flag; - - tree_command *cmd = elt->command (); - tree_expression *expr = elt->expression (); - - if (cmd || expr) - { - elt->maybe_echo_code (function_body); - - if (cmd) - cmd->eval (); - else - { - if (expr->is_multi_val_ret_expression ()) - { - octave_value_list args; - tree_multi_val_ret *t; - t = static_cast (expr); - retval = t->eval (pf, nargout, args); - } - else - retval = expr->eval (pf); - } - - if (error_state) - return octave_value (); - - if (breaking || continuing) - break; - - if (returning) - break; - } - else - retval = octave_value_list (); - } - return retval; } else - retval = eval (print); + retval = eval (no_print); return retval; } @@ -486,7 +497,7 @@ if (is_else_clause () || expr->is_logically_true ("if")) { if (list) - list->eval (true); + list->eval (); return 1; } @@ -569,7 +580,7 @@ if (is_default_case () || label_matches (val)) { if (list) - list->eval (true); + list->eval (); retval = 1; } @@ -609,6 +620,21 @@ tw.visit_switch_case_list (*this); } +static int +silent_functions (void) +{ + Vsilent_functions = check_preference ("silent_functions"); + + return 0; +} + +void +symbols_of_pt_misc (void) +{ + DEFVAR (silent_functions, 0.0, 0, silent_functions, + "suppress printing results in called functions"); +} + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r 64ff56723e75 -r 8303749672be src/pt-misc.h --- a/src/pt-misc.h Mon Apr 28 20:41:15 1997 +0000 +++ b/src/pt-misc.h Mon Apr 28 20:50:37 1997 +0000 @@ -62,8 +62,6 @@ class tree_statement { -friend class tree_statement_list; - public: tree_statement (void) @@ -89,12 +87,16 @@ int line (void); int column (void); - void maybe_echo_code (bool); + void maybe_echo_code (bool in_function_body); bool print_result (void) { return print_flag; } tree_command *command (void) { return cmd; } + octave_value eval (bool silent, bool in_function_body); + + octave_value_list eval (bool silent, int nargout, bool in_function_body); + tree_expression *expression (void) { return expr; } void accept (tree_walker& tw); @@ -137,9 +139,9 @@ void mark_as_function_body (void) { function_body = true; } - octave_value eval (bool print = false); + octave_value eval (bool silent = false); - octave_value_list eval (bool print, int nargout); + octave_value_list eval (bool silent, int nargout); void accept (tree_walker& tw); @@ -434,6 +436,8 @@ void accept (tree_walker& tw); }; +extern void symbols_of_pt_misc (void); + #endif /* diff -r 64ff56723e75 -r 8303749672be src/toplev.cc --- a/src/toplev.cc Mon Apr 28 20:41:15 1997 +0000 +++ b/src/toplev.cc Mon Apr 28 20:50:37 1997 +0000 @@ -141,7 +141,7 @@ jmp_buf toplevel; void -parse_and_execute (FILE *f, bool print) +parse_and_execute (FILE *f) { begin_unwind_frame ("parse_and_execute"); @@ -170,7 +170,7 @@ if (retval == 0 && global_command) { - global_command->eval (print); + global_command->eval (); delete global_command; @@ -209,8 +209,7 @@ } void -parse_and_execute (const string& s, bool print, bool verbose, - const char *warn_for) +parse_and_execute (const string& s, bool verbose, const char *warn_for) { begin_unwind_frame ("parse_and_execute_2"); @@ -239,7 +238,7 @@ cout.flush (); } - parse_and_execute (f, print); + parse_and_execute (f); if (verbose) cout << "done." << endl; @@ -283,7 +282,7 @@ if (retval == 0 && global_command) { - global_command->eval (true); + global_command->eval (); delete global_command; @@ -340,7 +339,7 @@ { file = oct_tilde_expand (file); - parse_and_execute (file, 1, 0, "source"); + parse_and_execute (file, false, "source"); if (error_state) error ("source: error sourcing file `%s'", file.c_str ()); @@ -530,7 +529,7 @@ } static octave_value_list -eval_string (const string& s, bool print, int& parse_status, int nargout) +eval_string (const string& s, bool silent, int& parse_status, int nargout) { begin_unwind_frame ("eval_string"); @@ -569,7 +568,7 @@ if (parse_status == 0 && command) { - retval = command->eval (print, nargout); + retval = command->eval (silent, nargout); delete command; } @@ -577,11 +576,11 @@ } octave_value -eval_string (const string& s, bool print, int& parse_status) +eval_string (const string& s, bool silent, int& parse_status) { octave_value retval; - octave_value_list tmp = eval_string (s, print, parse_status, 1); + octave_value_list tmp = eval_string (s, silent, parse_status, 1); retval = tmp(0); @@ -589,7 +588,7 @@ } static octave_value_list -eval_string (const octave_value& arg, bool print, int& parse_status, +eval_string (const octave_value& arg, bool silent, int& parse_status, int nargout) { string s = arg.string_value (); @@ -600,7 +599,7 @@ return -1.0; } - return eval_string (s, print, parse_status, nargout); + return eval_string (s, silent, parse_status, nargout); } DEFUN (eval, args, nargout, @@ -625,7 +624,7 @@ int parse_status = 0; - retval = eval_string (args(0), Vdefault_eval_print_flag, + retval = eval_string (args(0), ! Vdefault_eval_print_flag, parse_status, nargout); if (nargin > 1 && (parse_status != 0 || error_state)) diff -r 64ff56723e75 -r 8303749672be src/variables.cc --- a/src/variables.cc Mon Apr 28 20:41:15 1997 +0000 +++ b/src/variables.cc Mon Apr 28 20:50:37 1997 +0000 @@ -80,6 +80,7 @@ #include "pt-id.h" #include "pt-indir.h" #include "pt-mat.h" +#include "pt-misc.h" #include "pt-plot.h" #include "pr-output.h" #include "syscalls.h" @@ -300,7 +301,7 @@ { int parse_status; - eval_string (cmd, 0, parse_status); + eval_string (cmd, true, parse_status); if (parse_status == 0) { @@ -749,7 +750,7 @@ Vsaving_history = 0; reading_script_file = 1; - parse_and_execute (ffile, 1); + parse_and_execute (ffile); script_file_executed = 1; } @@ -1716,6 +1717,7 @@ symbols_of_parse (); symbols_of_pr_output (); symbols_of_pt_mat (); + symbols_of_pt_misc (); symbols_of_pt_plot (); symbols_of_syscalls (); symbols_of_toplev ();