Mercurial > octave
diff libinterp/corefcn/interpreter.cc @ 23599:5cb3a2bb5e1e
don't use singleton for symbol_table
This is the first of a series of changes to make the symbol table a
part of the interpreter instead of a global object. These changes
also aim to simplify the implementation of symbol table so that it is
easier to understand and modify.
* Functions now own their scope (workspace) data.
* The list of subfunctions is contained in the scope rather than a
global list.
* symtab.h, symtab.cc (class symbol_table): Don't use singleton
pattern.
* interpreter.h, interpreter.cc (interpreter::m_symbol_table): New
data member.
(interpreter::~interpreter): Don't set instance to 0.
* interpreter-private.h, interpreter-private.cc
(__get_symbol_table__): New function.
Change all uses of call_stack to access call_stack object from the
interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Jun 2017 02:21:28 -0400 |
parents | 14723784b9f2 |
children | 99989ab8f142 |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc Fri Jun 09 11:36:34 2017 -0400 +++ b/libinterp/corefcn/interpreter.cc Fri Jun 09 02:21:28 2017 -0400 @@ -372,8 +372,8 @@ // path. interpreter::interpreter (application *app_context) - : m_app_context (app_context), m_evaluator (new tree_evaluator (*this)), - m_load_path (), m_interactive (false), + : m_app_context (app_context), m_load_path (), m_symbol_table (), + m_evaluator (new tree_evaluator (*this)), m_interactive (false), m_read_site_files (true), m_read_init_files (m_app_context != 0), m_verbose (false), m_inhibit_startup_message (false), m_load_path_initialized (false), m_history_initialized (false), @@ -439,13 +439,16 @@ if (m_app_context) { - // Embedded interpeters don't execute command line options or + // Embedded interpeters don't execute command line options. const cmdline_options& options = m_app_context->options (); // Make all command-line arguments available to startup files, // including PKG_ADD files. - m_app_context->intern_argv (options.all_args ()); + string_vector args = options.all_args (); + + m_app_context->intern_argv (args); + intern_nargin (args.numel () - 1); bool is_octave_program = m_app_context->is_octave_program (); @@ -512,8 +515,12 @@ interpreter::~interpreter (void) { cleanup (); + } - instance = 0; + void interpreter::intern_nargin (octave_idx_type nargs) + { + m_symbol_table.assign (".nargin.", nargs); + m_symbol_table.mark_hidden (".nargin."); } // Read the history file unless a command-line option inhibits that. @@ -868,9 +875,11 @@ frame.add_method (this, &interpreter::interactive, m_interactive); - frame.add_method (m_app_context, - &application::intern_argv, - options.all_args ()); + string_vector args = options.all_args (); + + frame.add_method (m_app_context, &application::intern_argv, args); + + frame.add_method (this, &interpreter::intern_nargin, args.numel () - 1); frame.add_method (m_app_context, &application::program_invocation_name, @@ -888,6 +897,7 @@ string_vector script_args = options.remaining_args (); m_app_context->intern_argv (script_args); + intern_nargin (script_args.numel () - 1); std::string fname = script_args[0]; @@ -934,7 +944,7 @@ parser.reset (); - if (symbol_table::at_top_level ()) + if (m_symbol_table.at_top_level ()) octave::tree_evaluator::reset_debug_state (); retval = parser.run (); @@ -1112,7 +1122,10 @@ OCTAVE_SAFE_CALL (cleanup_tmp_files, ()); - OCTAVE_SAFE_CALL (symbol_table::cleanup, ()); + // FIXME: May still need something like this to ensure that + // destructors for class objects will run properly. Should that be + // done earlier? Before or after atexit functions are executed? + m_symbol_table.cleanup (); OCTAVE_SAFE_CALL (sysdep_cleanup, ());