Mercurial > octave
comparison libinterp/parse-tree/oct-parse.in.yy @ 23553:14723784b9f2
don't use singleton for call_stack
* call-stack.h, call-stack.cc (class call_stack):
Don't use singleton pattern. Store reference to parent intepreter
object in call stack.
* pt-eval.h, pt-eval.cc (tree_evaluator::m_call_stack): New data
member.
(tree_evaluator::get_call_stack): New function.
* interpreter-private.h, interpreter-private.cc (__get_call_stack__):
New function.
* interpreter.h, interpreter.cc (interpreter::get_call_stack):
New function.
Change all uses of call_stack to access call_stack object from the
interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 Jun 2017 02:13:05 -0400 |
parents | 8edbc923a7dc |
children | 00e518162fda |
comparison
equal
deleted
inserted
replaced
23552:654661539e20 | 23553:14723784b9f2 |
---|---|
4566 | 4566 |
4567 return retval; | 4567 return retval; |
4568 } | 4568 } |
4569 } | 4569 } |
4570 | 4570 |
4571 DEFUN (autoload, args, , | 4571 DEFMETHOD (autoload, interp, args, , |
4572 doc: /* -*- texinfo -*- | 4572 doc: /* -*- texinfo -*- |
4573 @deftypefn {} {@var{autoload_map} =} autoload () | 4573 @deftypefn {} {@var{autoload_map} =} autoload () |
4574 @deftypefnx {} {} autoload (@var{function}, @var{file}) | 4574 @deftypefnx {} {} autoload (@var{function}, @var{file}) |
4575 @deftypefnx {} {} autoload (@dots{}, "remove") | 4575 @deftypefnx {} {} autoload (@dots{}, "remove") |
4576 Define @var{function} to autoload from @var{file}. | 4576 Define @var{function} to autoload from @var{file}. |
4577 | 4577 |
4642 | 4642 |
4643 std::string nm = argv[2]; | 4643 std::string nm = argv[2]; |
4644 | 4644 |
4645 if (! octave::sys::env::absolute_pathname (nm)) | 4645 if (! octave::sys::env::absolute_pathname (nm)) |
4646 { | 4646 { |
4647 octave_user_code *fcn = octave::call_stack::caller_user_code (); | 4647 octave::call_stack& cs = interp.get_call_stack (); |
4648 | |
4649 octave_user_code *fcn = cs.caller_user_code (); | |
4648 | 4650 |
4649 bool found = false; | 4651 bool found = false; |
4650 | 4652 |
4651 if (fcn) | 4653 if (fcn) |
4652 { | 4654 { |
4745 if (source_call_depth[file_full_name] >= Vmax_recursion_depth) | 4747 if (source_call_depth[file_full_name] >= Vmax_recursion_depth) |
4746 error ("max_recursion_depth exceeded"); | 4748 error ("max_recursion_depth exceeded"); |
4747 | 4749 |
4748 if (! context.empty ()) | 4750 if (! context.empty ()) |
4749 { | 4751 { |
4752 octave::call_stack& cs = octave::__get_call_stack__ ("source_file"); | |
4753 | |
4750 if (context == "caller") | 4754 if (context == "caller") |
4751 octave::call_stack::goto_caller_frame (); | 4755 cs.goto_caller_frame (); |
4752 else if (context == "base") | 4756 else if (context == "base") |
4753 octave::call_stack::goto_base_frame (); | 4757 cs.goto_base_frame (); |
4754 else | 4758 else |
4755 error ("source: context must be \"caller\" or \"base\""); | 4759 error ("source: context must be \"caller\" or \"base\""); |
4756 | 4760 |
4757 frame.add_fcn (octave::call_stack::pop); | 4761 frame.add_method (cs, &octave::call_stack::pop); |
4758 } | 4762 } |
4759 | 4763 |
4760 octave_function *fcn = 0; | 4764 octave_function *fcn = 0; |
4761 // Don't delete a function already in symbol_table | 4765 // Don't delete a function already in symbol_table |
4762 bool delete_fcn = false; | 4766 bool delete_fcn = false; |
4831 if (delete_fcn) | 4835 if (delete_fcn) |
4832 delete fcn; | 4836 delete fcn; |
4833 } | 4837 } |
4834 } | 4838 } |
4835 | 4839 |
4836 DEFUN (mfilename, args, , | 4840 DEFMETHOD (mfilename, interp, args, , |
4837 doc: /* -*- texinfo -*- | 4841 doc: /* -*- texinfo -*- |
4838 @deftypefn {} {} mfilename () | 4842 @deftypefn {} {} mfilename () |
4839 @deftypefnx {} {} mfilename ("fullpath") | 4843 @deftypefnx {} {} mfilename ("fullpath") |
4840 @deftypefnx {} {} mfilename ("fullpathext") | 4844 @deftypefnx {} {} mfilename ("fullpathext") |
4841 Return the name of the currently executing file. | 4845 Return the name of the currently executing file. |
4842 | 4846 |
4861 if (nargin == 1) | 4865 if (nargin == 1) |
4862 arg = args(0).xstring_value ("mfilename: argument must be a string"); | 4866 arg = args(0).xstring_value ("mfilename: argument must be a string"); |
4863 | 4867 |
4864 std::string fname; | 4868 std::string fname; |
4865 | 4869 |
4866 octave_user_code *fcn = octave::call_stack::caller_user_code (); | 4870 octave::call_stack& cs = interp.get_call_stack (); |
4871 | |
4872 octave_user_code *fcn = cs.caller_user_code (); | |
4867 | 4873 |
4868 if (fcn) | 4874 if (fcn) |
4869 { | 4875 { |
4870 fname = fcn->fcn_file_name (); | 4876 fname = fcn->fcn_file_name (); |
4871 | 4877 |
5374 | 5380 |
5375 %!error eval ("switch = 13;") | 5381 %!error eval ("switch = 13;") |
5376 | 5382 |
5377 */ | 5383 */ |
5378 | 5384 |
5379 DEFUN (assignin, args, , | 5385 DEFMETHOD (assignin, interp, args, , |
5380 doc: /* -*- texinfo -*- | 5386 doc: /* -*- texinfo -*- |
5381 @deftypefn {} {} assignin (@var{context}, @var{varname}, @var{value}) | 5387 @deftypefn {} {} assignin (@var{context}, @var{varname}, @var{value}) |
5382 Assign @var{value} to @var{varname} in context @var{context}, which | 5388 Assign @var{value} to @var{varname} in context @var{context}, which |
5383 may be either @qcode{"base"} or @qcode{"caller"}. | 5389 may be either @qcode{"base"} or @qcode{"caller"}. |
5384 @seealso{evalin} | 5390 @seealso{evalin} |
5385 @end deftypefn */) | 5391 @end deftypefn */) |
5391 | 5397 |
5392 std::string context = args(0).xstring_value ("assignin: CONTEXT must be a string"); | 5398 std::string context = args(0).xstring_value ("assignin: CONTEXT must be a string"); |
5393 | 5399 |
5394 octave::unwind_protect frame; | 5400 octave::unwind_protect frame; |
5395 | 5401 |
5402 octave::call_stack& cs = interp.get_call_stack (); | |
5403 | |
5396 if (context == "caller") | 5404 if (context == "caller") |
5397 octave::call_stack::goto_caller_frame (); | 5405 cs.goto_caller_frame (); |
5398 else if (context == "base") | 5406 else if (context == "base") |
5399 octave::call_stack::goto_base_frame (); | 5407 cs.goto_base_frame (); |
5400 else | 5408 else |
5401 error ("assignin: CONTEXT must be \"caller\" or \"base\""); | 5409 error ("assignin: CONTEXT must be \"caller\" or \"base\""); |
5402 | 5410 |
5403 frame.add_fcn (octave::call_stack::pop); | 5411 frame.add_method (cs, &octave::call_stack::pop); |
5404 | 5412 |
5405 std::string nm = args(1).xstring_value ("assignin: VARNAME must be a string"); | 5413 std::string nm = args(1).xstring_value ("assignin: VARNAME must be a string"); |
5406 | 5414 |
5407 if (valid_identifier (nm)) | 5415 if (valid_identifier (nm)) |
5408 { | 5416 { |
5425 | 5433 |
5426 %!error assignin ("base", "switch", "13") | 5434 %!error assignin ("base", "switch", "13") |
5427 | 5435 |
5428 */ | 5436 */ |
5429 | 5437 |
5430 DEFUN (evalin, args, nargout, | 5438 DEFMETHOD (evalin, interp, args, nargout, |
5431 doc: /* -*- texinfo -*- | 5439 doc: /* -*- texinfo -*- |
5432 @deftypefn {} {} evalin (@var{context}, @var{try}) | 5440 @deftypefn {} {} evalin (@var{context}, @var{try}) |
5433 @deftypefnx {} {} evalin (@var{context}, @var{try}, @var{catch}) | 5441 @deftypefnx {} {} evalin (@var{context}, @var{try}, @var{catch}) |
5434 Like @code{eval}, except that the expressions are evaluated in the context | 5442 Like @code{eval}, except that the expressions are evaluated in the context |
5435 @var{context}, which may be either @qcode{"caller"} or @qcode{"base"}. | 5443 @var{context}, which may be either @qcode{"caller"} or @qcode{"base"}. |
5436 @seealso{eval, assignin} | 5444 @seealso{eval, assignin} |
5445 | 5453 |
5446 std::string context = args(0).xstring_value ("evalin: CONTEXT must be a string"); | 5454 std::string context = args(0).xstring_value ("evalin: CONTEXT must be a string"); |
5447 | 5455 |
5448 octave::unwind_protect frame; | 5456 octave::unwind_protect frame; |
5449 | 5457 |
5458 octave::call_stack& cs = interp.get_call_stack (); | |
5459 | |
5450 if (context == "caller") | 5460 if (context == "caller") |
5451 octave::call_stack::goto_caller_frame (); | 5461 cs.goto_caller_frame (); |
5452 else if (context == "base") | 5462 else if (context == "base") |
5453 octave::call_stack::goto_base_frame (); | 5463 cs.goto_base_frame (); |
5454 else | 5464 else |
5455 error ("evalin: CONTEXT must be \"caller\" or \"base\""); | 5465 error ("evalin: CONTEXT must be \"caller\" or \"base\""); |
5456 | 5466 |
5457 frame.add_fcn (octave::call_stack::pop); | 5467 frame.add_method (cs, &octave::call_stack::pop); |
5458 | 5468 |
5459 if (nargin > 2) | 5469 if (nargin > 2) |
5460 { | 5470 { |
5461 frame.protect_var (buffer_error_messages); | 5471 frame.protect_var (buffer_error_messages); |
5462 buffer_error_messages++; | 5472 buffer_error_messages++; |