Mercurial > octave
diff libinterp/corefcn/load-save.cc @ 26661:cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
Apologies for the massive commit. I see no way to untangle these
changes into a set of smaller incremental changes in a way that would
be more useful.
Previously, handling data for recursive function calls was managed by
a stack of values in the symbol_record class and an auxiliary integer
variable was used for managing the recursion depth (context_id). Now,
values for local variables are in the stack_frame class and recursion
is handled naturally by the call_stack as a new stack frame is added
to the call_stack object for any call to a function or a script.
Values for internal function call information (nargin, nargout, etc.)
are now stored specially in the stack_frame object. Values for global
variables are now stored in a map in the call_stack object. Values
for persistent variables are stored in the corresponding
octave_user_function object. Access to non-local variables inside
nested functions is managed through pointers to stack_frame objects
for the parent function scopes. The new implementation more closely
resembles the techniques described in standard compiler literature.
These changes should make it easier to create proper closures and
finally solve bug #39257 (handles to nested functions are not yet
supported). They may also make it easier to implement JIT compiler,
though that is probably still a long way off.
The new stack-frame.h file has some details about the new
implementation of stack frames that should help in understanding how
things work now.
Describing each change to each file and function will probably not
provide much greater understanding of the changes and would be quite
tedious to write so I am omitting them.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 28 Jan 2019 18:01:46 +0000 |
parents | 00f796120a6d |
children | f02695656257 |
line wrap: on
line diff
--- a/libinterp/corefcn/load-save.cc Sat Jan 26 15:53:29 2019 +0000 +++ b/libinterp/corefcn/load-save.cc Mon Jan 28 18:01:46 2019 +0000 @@ -66,7 +66,6 @@ #include "ov-cell.h" #include "pager.h" #include "syminfo.h" -#include "symtab.h" #include "sysdep.h" #include "unwind-prot.h" #include "utils.h" @@ -685,17 +684,10 @@ std::string struct_name = argv[argv_idx]; - symbol_scope scope = m_interpreter.get_current_scope (); - - octave_value struct_var; + if (! m_interpreter.is_variable (struct_name)) + error ("save: no such variable: '%s'", struct_name.c_str ()); - if (scope) - { - if (! scope.is_variable (struct_name)) - error ("save: no such variable: '%s'", struct_name.c_str ()); - - struct_var = scope.varval (struct_name); - } + octave_value struct_var = m_interpreter.varval (struct_name); if (! struct_var.isstruct () || struct_var.numel () != 1) error ("save: '%s' is not a scalar structure", struct_name.c_str ()); @@ -1070,24 +1062,7 @@ bool global, const std::string& /*doc*/) { - symbol_table& symtab = m_interpreter.get_symbol_table (); - - symbol_scope scope = symtab.require_current_scope ("load_save_system::install_loaded_variable"); - - if (global) - { - symbol_record sym = scope.find_symbol (name); - - if (! sym.is_global ()) - { - symbol_scope global_scope = symtab.global_scope (); - symbol_record global_sym = global_scope.find_symbol (name); - - sym.bind_fwd_rep (global_scope.get_rep (), global_sym); - } - } - - scope.assign (name, val); + m_interpreter.install_variable (name, val, global); } std::string load_save_system::init_save_header_format (void)