Mercurial > hg > octave-lyh
annotate src/ov-builtin.cc @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | ad3afaaa19c1 |
children | 610bf90fce2a |
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, |
39 "built-in function", | |
40 "built-in function"); | |
2974 | 41 |
42 octave_value_list | |
4247 | 43 octave_builtin::subsref (const std::string& type, |
4219 | 44 const std::list<octave_value_list>& idx, |
3933 | 45 int nargout) |
46 { | |
47 octave_value_list retval; | |
48 | |
49 switch (type[0]) | |
50 { | |
51 case '(': | |
5154 | 52 { |
5155 | 53 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 54 |
55 retval = do_multi_index_op (tmp_nargout, idx.front ()); | |
56 } | |
3933 | 57 break; |
58 | |
59 case '{': | |
60 case '.': | |
61 { | |
62 std::string nm = type_name (); | |
63 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); | |
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 { |
4987 | 99 unwind_protect::begin_frame ("builtin_func_eval"); |
100 | |
5743 | 101 octave_call_stack::push (this); |
4975 | 102 |
5743 | 103 unwind_protect::add (octave_call_stack::unwind_pop, 0); |
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 |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
107 retval = (*f) (args, nargout); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8011
diff
changeset
|
108 // Do not allow null values to be returned from functions. |
8333 | 109 // FIXME -- perhaps true builtins should be allowed? |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
110 retval.make_storable_values (); |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
111 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
112 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
113 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7487
diff
changeset
|
114 gripe_library_execution_error (); |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
115 } |
4748 | 116 |
4987 | 117 unwind_protect::run_frame ("builtin_func_eval"); |
4748 | 118 } |
2974 | 119 |
120 return retval; | |
121 } | |
122 | |
123 /* | |
124 ;;; Local Variables: *** | |
125 ;;; mode: C++ *** | |
126 ;;; End: *** | |
127 */ |