Mercurial > hg > octave-nkf
annotate src/ov-builtin.cc @ 10828:322f43e0e170
Grammarcheck .txi documentation files.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 28 Jul 2010 12:45:04 -0700 |
parents | 57a59eae83cc |
children | f10d0bc8f9cc |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008, 2009 John W. Eaton |
2974 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2974 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2974 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "error.h" | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7487
diff
changeset
|
29 #include "gripes.h" |
2974 | 30 #include "oct-obj.h" |
31 #include "ov-builtin.h" | |
32 #include "ov.h" | |
4748 | 33 #include "toplev.h" |
34 #include "unwind-prot.h" | |
2974 | 35 |
3219 | 36 DEFINE_OCTAVE_ALLOCATOR (octave_builtin); |
2974 | 37 |
4612 | 38 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
39 "built-in function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
40 "built-in function"); |
2974 | 41 |
42 octave_value_list | |
4247 | 43 octave_builtin::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
44 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
45 int nargout) |
3933 | 46 { |
47 octave_value_list retval; | |
48 | |
49 switch (type[0]) | |
50 { | |
51 case '(': | |
5154 | 52 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
53 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 54 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
55 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
5154 | 56 } |
3933 | 57 break; |
58 | |
59 case '{': | |
60 case '.': | |
61 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
62 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
63 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 64 } |
65 break; | |
66 | |
67 default: | |
68 panic_impossible (); | |
69 } | |
70 | |
5775 | 71 // FIXME -- perhaps there should be an |
4059 | 72 // octave_value_list::next_subsref member function? See also |
73 // octave_user_function::subsref. | |
74 // | |
5775 | 75 // FIXME -- Note that if a function call returns multiple |
4059 | 76 // values, and there is further indexing to perform, then we are |
77 // ignoring all but the first value. Is this really what we want to | |
78 // do? If it is not, then what should happen for stat("file").size, | |
79 // for exmaple? | |
3933 | 80 |
4219 | 81 if (idx.size () > 1) |
4994 | 82 retval = retval(0).next_subsref (nargout, type, idx); |
4059 | 83 |
84 return retval; | |
3933 | 85 } |
86 | |
87 octave_value_list | |
3544 | 88 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974 | 89 { |
90 octave_value_list retval; | |
91 | |
92 if (error_state) | |
93 return retval; | |
94 | |
5864 | 95 if (args.has_magic_colon ()) |
2974 | 96 ::error ("invalid use of colon in function argument list"); |
97 else | |
4748 | 98 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
99 unwind_protect frame; |
4987 | 100 |
5743 | 101 octave_call_stack::push (this); |
4975 | 102 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
103 frame.add_fcn (octave_call_stack::pop); |
4748 | 104 |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
105 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
106 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
107 retval = (*f) (args, nargout); |
10184
b39bd23019eb
partially revert a668fbd32e34
Jaroslav Hajek <highegg@gmail.com>
parents:
10181
diff
changeset
|
108 // Do not allow null values to be returned from functions. |
b39bd23019eb
partially revert a668fbd32e34
Jaroslav Hajek <highegg@gmail.com>
parents:
10181
diff
changeset
|
109 // FIXME -- perhaps true builtins should be allowed? |
b39bd23019eb
partially revert a668fbd32e34
Jaroslav Hajek <highegg@gmail.com>
parents:
10181
diff
changeset
|
110 retval.make_storable_values (); |
10181
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
111 // Fix the case of a single undefined value. |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
112 // This happens when a compiled function uses |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
113 // octave_value retval; |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
114 // instead of |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
115 // octave_value_list retval; |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
116 // the idiom is very common, so we solve that here. |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
117 if (retval.length () == 1 && retval.xelem (0).is_undefined ()) |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
118 retval.clear (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
119 } |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
120 catch (octave_execution_exception) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
121 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
122 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
123 } |
4748 | 124 } |
2974 | 125 |
126 return retval; | |
127 } |