Mercurial > octave
annotate libinterp/octave-value/ov-mex-fcn.cc @ 22094:9203833cab7d
move new interpreter class to separate file
* libinterp/corefcn/interpreter.cc, libinterp/corefcn/interpreter.h:
New files. Move interpreter class and some supporting functions here
from octave.h, octave.cc, toplev.h, and toplev.cc. Move main_loop
into the interpreter class. Handle exiting with a separate exception
object from interrupts, passing the exit status with the object.
Update other files as needed to remove toplev.h or include
interpreter.h instead of toplev.h.
* libinterp/corefcn/module.mk: Update.
* toplev.h: Deprecate.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Jul 2016 18:05:53 -0400 |
parents | 0f6fc2ec3b1a |
children | bac0d6f07a3e |
rev | line source |
---|---|
5864 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
5864 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
5864 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
5864 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
5864 | 25 #endif |
26 | |
27 #include "oct-shlib.h" | |
28 | |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
21750
diff
changeset
|
29 #include "call-stack.h" |
5864 | 30 #include <defaults.h> |
31 #include "dynamic-ld.h" | |
32 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
33 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20555
diff
changeset
|
34 #include "ovl.h" |
5864 | 35 #include "ov-mex-fcn.h" |
36 #include "ov.h" | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11523
diff
changeset
|
37 #include "profiler.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22091
diff
changeset
|
38 #include "interpreter.h" |
5864 | 39 #include "unwind-prot.h" |
40 | |
41 | |
42 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_mex_function, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
43 "mex function", "mex function"); |
5864 | 44 |
45 octave_mex_function::octave_mex_function | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
46 (void *fptr, bool fmex, const octave::dynamic_library& shl, |
5864 | 47 const std::string& nm) |
6068 | 48 : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0), |
49 have_fmex (fmex), sh_lib (shl) | |
5864 | 50 { |
51 mark_fcn_file_up_to_date (time_parsed ()); | |
52 | |
53 std::string file_name = fcn_file_name (); | |
54 | |
55 system_fcn_file | |
56 = (! file_name.empty () | |
57 && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ())); | |
58 } | |
59 | |
60 octave_mex_function::~octave_mex_function (void) | |
61 { | |
6068 | 62 if (exit_fcn_ptr) |
63 (*exit_fcn_ptr) (); | |
64 | |
7872 | 65 octave_dynamic_loader::remove_mex (my_name, sh_lib); |
5864 | 66 } |
67 | |
68 std::string | |
69 octave_mex_function::fcn_file_name (void) const | |
70 { | |
71 return sh_lib.file_name (); | |
72 } | |
73 | |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
74 octave::sys::time |
5864 | 75 octave_mex_function::time_parsed (void) const |
76 { | |
77 return sh_lib.time_loaded (); | |
78 } | |
79 | |
80 octave_value_list | |
81 octave_mex_function::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
82 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
83 int nargout) |
5864 | 84 { |
85 octave_value_list retval; | |
86 | |
87 switch (type[0]) | |
88 { | |
89 case '(': | |
90 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5864 | 92 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
5864 | 94 } |
95 break; | |
96 | |
97 case '{': | |
98 case '.': | |
99 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
5864 | 102 } |
103 break; | |
104 | |
105 default: | |
106 panic_impossible (); | |
107 } | |
108 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 // FIXME: perhaps there should be an |
5864 | 110 // octave_value_list::next_subsref member function? See also |
111 // octave_user_function::subsref. | |
112 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 // FIXME: Note that if a function call returns multiple |
5864 | 114 // values, and there is further indexing to perform, then we are |
115 // ignoring all but the first value. Is this really what we want to | |
116 // do? If it is not, then what should happen for stat("file").size, | |
117 // for exmaple? | |
118 | |
119 if (idx.size () > 1) | |
120 retval = retval(0).next_subsref (nargout, type, idx); | |
121 | |
122 return retval; | |
123 } | |
124 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 // FIXME: shouldn't this declaration be a header file somewhere? |
5864 | 126 extern octave_value_list |
6068 | 127 call_mex (bool have_fmex, void *f, const octave_value_list& args, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
128 int nargout, octave_mex_function *curr_mex_fcn); |
5864 | 129 |
130 octave_value_list | |
131 octave_mex_function::do_multi_index_op (int nargout, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 const octave_value_list& args) |
5864 | 133 { |
134 octave_value_list retval; | |
135 | |
136 if (args.has_magic_colon ()) | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
137 error ("invalid use of colon in function argument list"); |
5864 | 138 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21730
diff
changeset
|
139 octave::unwind_protect frame; |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
140 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
141 octave_call_stack::push (this); |
5864 | 142 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
143 frame.add_fcn (octave_call_stack::pop); |
5864 | 144 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
145 BEGIN_PROFILER_BLOCK (octave_mex_function) |
19327
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17787
diff
changeset
|
146 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
147 retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20428
diff
changeset
|
148 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
149 END_PROFILER_BLOCK |
5864 | 150 |
151 return retval; | |
152 } |