1741
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
1741
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <iostream.h> |
|
32 #include <strstream.h> |
|
33 |
|
34 #include <SLList.h> |
|
35 |
|
36 #include "dynamic-ld.h" |
|
37 #include "error.h" |
|
38 #include "gripes.h" |
|
39 #include "oct-obj.h" |
|
40 #include "pager.h" |
|
41 #include "symtab.h" |
|
42 #include "pt-const.h" |
|
43 #include "pt-fvc.h" |
2124
|
44 #include "pt-walk.h" |
1741
|
45 #include "utils.h" |
|
46 |
|
47 // But first, some extra functions used by the tree classes. |
|
48 |
1827
|
49 static bool |
1741
|
50 any_element_less_than (const Matrix& a, double val) |
|
51 { |
|
52 int nr = a.rows (); |
|
53 int nc = a.columns (); |
1827
|
54 |
1741
|
55 for (int j = 0; j < nc; j++) |
|
56 for (int i = 0; i < nr; i++) |
|
57 if (a.elem (i, j) < val) |
1827
|
58 return true; |
|
59 |
|
60 return false; |
1741
|
61 } |
|
62 |
1827
|
63 static bool |
1741
|
64 any_element_greater_than (const Matrix& a, double val) |
|
65 { |
|
66 int nr = a.rows (); |
|
67 int nc = a.columns (); |
1827
|
68 |
1741
|
69 for (int j = 0; j < nc; j++) |
|
70 for (int i = 0; i < nr; i++) |
|
71 if (a.elem (i, j) > val) |
1827
|
72 return true; |
|
73 |
|
74 return false; |
1741
|
75 } |
|
76 |
|
77 // Make sure that all arguments have values. |
|
78 |
|
79 // Are any of the arguments `:'? |
|
80 |
1827
|
81 static bool |
2086
|
82 any_arg_is_magic_colon (const octave_value_list& args) |
1741
|
83 { |
|
84 int nargin = args.length (); |
|
85 |
|
86 for (int i = 0; i < nargin; i++) |
|
87 if (args(i).is_magic_colon ()) |
1827
|
88 return true; |
1741
|
89 |
1827
|
90 return false; |
1741
|
91 } |
|
92 |
|
93 // Symbols from the symbol table. |
|
94 |
1755
|
95 string |
1741
|
96 tree_identifier::name (void) const |
|
97 { |
1755
|
98 string retval; |
|
99 if (sym) |
|
100 retval = sym->name (); |
|
101 return retval; |
1741
|
102 } |
|
103 |
|
104 tree_identifier * |
2086
|
105 tree_identifier::define (octave_value *t) |
1741
|
106 { |
|
107 int status = sym->define (t); |
|
108 return status ? this : 0; |
|
109 } |
|
110 |
|
111 tree_identifier * |
|
112 tree_identifier::define (tree_function *t) |
|
113 { |
|
114 int status = sym->define (t); |
|
115 return status ? this : 0; |
|
116 } |
|
117 |
|
118 void |
1755
|
119 tree_identifier::document (const string& s) |
1741
|
120 { |
1755
|
121 if (sym) |
|
122 sym->document (s); |
1741
|
123 } |
|
124 |
2086
|
125 octave_value |
|
126 tree_identifier::assign (octave_value& rhs) |
1741
|
127 { |
2086
|
128 octave_value retval; |
1741
|
129 |
|
130 if (rhs.is_defined ()) |
|
131 { |
|
132 if (! sym->is_defined ()) |
|
133 { |
|
134 if (! (sym->is_formal_parameter () |
|
135 || sym->is_linked_to_global ())) |
|
136 { |
|
137 link_to_builtin_variable (sym); |
|
138 } |
|
139 } |
|
140 else if (sym->is_function ()) |
|
141 { |
|
142 sym->clear (); |
|
143 } |
|
144 |
2086
|
145 octave_value *tmp = new octave_value (rhs); |
1741
|
146 |
|
147 if (sym->define (tmp)) |
|
148 retval = rhs; |
|
149 else |
|
150 delete tmp; |
|
151 } |
|
152 |
|
153 return retval; |
|
154 } |
|
155 |
2086
|
156 octave_value |
|
157 tree_identifier::assign (octave_value& rhs, const octave_value_list& args) |
1741
|
158 { |
2086
|
159 octave_value retval; |
1741
|
160 |
|
161 if (rhs.is_defined ()) |
|
162 { |
|
163 if (! sym->is_defined ()) |
|
164 { |
|
165 if (! (sym->is_formal_parameter () |
|
166 || sym->is_linked_to_global ())) |
|
167 { |
|
168 link_to_builtin_variable (sym); |
|
169 } |
|
170 } |
|
171 else if (sym->is_function ()) |
|
172 { |
|
173 sym->clear (); |
|
174 } |
|
175 |
|
176 if (sym->is_variable () && sym->is_defined ()) |
|
177 { |
|
178 tree_fvc *tmp = sym->def (); |
|
179 retval = tmp->assign (rhs, args); |
|
180 } |
|
181 else |
|
182 { |
|
183 assert (! sym->is_defined ()); |
|
184 |
2179
|
185 if (! Vresize_on_range_error) |
1741
|
186 { |
|
187 ::error ("indexed assignment to previously undefined variables"); |
|
188 ::error ("is only possible when resize_on_range_error is true"); |
|
189 } |
|
190 else |
|
191 { |
2086
|
192 octave_value *tmp = new octave_value (); |
1741
|
193 retval = tmp->assign (rhs, args); |
|
194 if (retval.is_defined ()) |
|
195 sym->define (tmp); |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 return retval; |
|
201 } |
|
202 |
2086
|
203 octave_value |
|
204 tree_identifier::assign (SLList<string> list, octave_value& rhs) |
1741
|
205 { |
2086
|
206 octave_value retval; |
1741
|
207 |
|
208 if (rhs.is_defined ()) |
|
209 { |
|
210 if (sym->is_function ()) |
|
211 sym->clear (); |
|
212 |
|
213 tree_fvc *curr_val = sym->def (); |
|
214 |
2086
|
215 octave_value *tmp = 0; |
1741
|
216 if (curr_val && curr_val->is_constant ()) |
2086
|
217 tmp = (octave_value *) curr_val; |
1741
|
218 else |
|
219 { |
2086
|
220 tmp = new octave_value (); |
1741
|
221 if (! sym->define (tmp)) |
|
222 { |
|
223 delete tmp; |
|
224 tmp = 0; |
|
225 } |
|
226 } |
|
227 |
|
228 if (tmp) |
|
229 retval = tmp->assign_map_element (list, rhs); |
|
230 } |
|
231 |
|
232 return retval; |
|
233 } |
|
234 |
2086
|
235 octave_value |
|
236 tree_identifier::assign (SLList<string> list, octave_value& rhs, |
|
237 const octave_value_list& args) |
1741
|
238 { |
2086
|
239 octave_value retval; |
1741
|
240 |
|
241 if (rhs.is_defined ()) |
|
242 { |
|
243 if (sym->is_function ()) |
|
244 sym->clear (); |
|
245 |
|
246 if (sym->is_variable () && sym->is_defined ()) |
|
247 { |
|
248 tree_fvc *curr_val = sym->def (); |
|
249 |
2086
|
250 octave_value *tmp; |
1741
|
251 if (curr_val && curr_val->is_constant ()) |
2086
|
252 tmp = (octave_value *) curr_val; |
1741
|
253 else |
|
254 panic_impossible (); |
|
255 |
|
256 retval = tmp->assign_map_element (list, rhs, args); |
|
257 } |
|
258 else |
|
259 { |
|
260 assert (! sym->is_defined ()); |
|
261 |
2179
|
262 if (! Vresize_on_range_error) |
1741
|
263 { |
|
264 ::error ("indexed assignment to previously undefined variables"); |
|
265 ::error ("is only possible when resize_on_range_error is true"); |
|
266 } |
|
267 else |
|
268 { |
2086
|
269 octave_value *tmp = new octave_value (); |
1741
|
270 |
|
271 retval = tmp->assign_map_element (list, rhs, args); |
|
272 |
|
273 if (retval.is_defined ()) |
|
274 sym->define (tmp); |
|
275 } |
|
276 } |
|
277 } |
|
278 |
|
279 return retval; |
|
280 } |
|
281 |
1827
|
282 bool |
1741
|
283 tree_identifier::is_defined (void) |
|
284 { |
|
285 return (sym && sym->is_defined ()); |
|
286 } |
|
287 |
|
288 void |
|
289 tree_identifier::bump_value (tree_expression::type etype) |
|
290 { |
|
291 if (sym) |
|
292 { |
|
293 if (sym->is_read_only ()) |
|
294 { |
1755
|
295 ::error ("can't redefined read-only variable `%s'", |
|
296 name ().c_str ()); |
1741
|
297 } |
|
298 else |
|
299 { |
|
300 tree_fvc *tmp = sym->def (); |
|
301 if (tmp) |
|
302 tmp->bump_value (etype); |
|
303 } |
|
304 } |
|
305 } |
|
306 |
|
307 void |
|
308 tree_identifier::eval_undefined_error (void) |
|
309 { |
|
310 int l = line (); |
|
311 int c = column (); |
1827
|
312 |
1741
|
313 if (l == -1 && c == -1) |
1755
|
314 ::error ("`%s' undefined", name ().c_str ()); |
1741
|
315 else |
1755
|
316 ::error ("`%s' undefined near line %d column %d", |
|
317 name ().c_str (), l, c); |
1741
|
318 } |
|
319 |
|
320 // Try to find a definition for an identifier. Here's how: |
|
321 // |
|
322 // * If the identifier is already defined and is a function defined |
|
323 // in an function file that has been modified since the last time |
|
324 // we parsed it, parse it again. |
|
325 // |
|
326 // * If the identifier is not defined, try to find a builtin |
|
327 // variable or an already compiled function with the same name. |
|
328 // |
|
329 // * If the identifier is still undefined, try looking for an |
|
330 // function file to parse. |
|
331 // |
|
332 // * On systems that support dynamic linking, we prefer .oct files |
|
333 // over .m files. |
|
334 |
|
335 tree_fvc * |
1827
|
336 tree_identifier::do_lookup (bool& script_file_executed, bool exec_script) |
1741
|
337 { |
|
338 script_file_executed = lookup (sym, exec_script); |
|
339 |
|
340 tree_fvc *retval = 0; |
|
341 |
|
342 if (! script_file_executed) |
|
343 retval = sym->def (); |
|
344 |
|
345 return retval; |
|
346 } |
|
347 |
|
348 void |
|
349 tree_identifier::link_to_global (void) |
|
350 { |
|
351 if (sym) |
|
352 link_to_global_variable (sym); |
|
353 } |
|
354 |
|
355 void |
|
356 tree_identifier::mark_as_formal_parameter (void) |
|
357 { |
|
358 if (sym) |
|
359 sym->mark_as_formal_parameter (); |
|
360 } |
|
361 |
2086
|
362 octave_value |
1827
|
363 tree_identifier::eval (bool print) |
1741
|
364 { |
2086
|
365 octave_value retval; |
1741
|
366 |
|
367 if (error_state) |
|
368 return retval; |
|
369 |
1827
|
370 bool script_file_executed = false; |
1741
|
371 |
|
372 tree_fvc *object_to_eval = do_lookup (script_file_executed); |
|
373 |
|
374 if (! script_file_executed) |
|
375 { |
|
376 if (object_to_eval) |
|
377 { |
|
378 int nargout = maybe_do_ans_assign ? 0 : 1; |
|
379 |
|
380 if (nargout) |
|
381 { |
2086
|
382 octave_value_list tmp_args; |
|
383 octave_value_list tmp = object_to_eval->eval (0, nargout, tmp_args); |
1741
|
384 |
|
385 if (tmp.length () > 0) |
|
386 retval = tmp(0); |
|
387 } |
|
388 else |
1827
|
389 retval = object_to_eval->eval (false); |
1741
|
390 } |
|
391 else |
|
392 eval_undefined_error (); |
|
393 } |
|
394 |
|
395 if (! error_state && retval.is_defined ()) |
|
396 { |
|
397 if (maybe_do_ans_assign && ! object_to_eval->is_constant ()) |
|
398 bind_ans (retval, print); |
|
399 else if (print) |
1755
|
400 retval.print_with_name (name ()); |
1741
|
401 } |
|
402 |
|
403 return retval; |
|
404 } |
|
405 |
2086
|
406 octave_value_list |
|
407 tree_identifier::eval (bool print, int nargout, const octave_value_list& args) |
1741
|
408 { |
2086
|
409 octave_value_list retval; |
1741
|
410 |
|
411 if (error_state) |
|
412 return retval; |
|
413 |
1827
|
414 bool script_file_executed = false; |
1741
|
415 |
|
416 tree_fvc *object_to_eval = do_lookup (script_file_executed); |
|
417 |
|
418 if (! script_file_executed) |
|
419 { |
|
420 if (object_to_eval) |
|
421 { |
|
422 if (maybe_do_ans_assign && nargout == 1) |
|
423 { |
|
424 |
|
425 // Don't count the output arguments that we create |
|
426 // automatically. |
|
427 |
|
428 nargout = 0; |
|
429 |
|
430 retval = object_to_eval->eval (0, nargout, args); |
|
431 |
|
432 if (retval.length () > 0 && retval(0).is_defined ()) |
|
433 bind_ans (retval(0), print); |
|
434 } |
|
435 else |
|
436 retval = object_to_eval->eval (print, nargout, args); |
|
437 } |
|
438 else |
|
439 eval_undefined_error (); |
|
440 } |
|
441 |
|
442 return retval; |
|
443 } |
|
444 |
|
445 void |
2124
|
446 tree_identifier::accept (tree_walker& tw) |
1741
|
447 { |
2124
|
448 tw.visit_identifier (*this); |
1741
|
449 } |
|
450 |
|
451 // Indirect references to values (structure elements). |
|
452 |
|
453 tree_indirect_ref::~tree_indirect_ref (void) |
|
454 { |
|
455 if (! preserve_ident) |
|
456 delete id; |
|
457 } |
|
458 |
|
459 tree_indirect_ref * |
1755
|
460 tree_indirect_ref::chain (const string& elt) |
1741
|
461 { |
1755
|
462 refs.append (elt); |
1741
|
463 return this; |
|
464 } |
|
465 |
1755
|
466 string |
|
467 tree_indirect_ref::name (void) const |
1741
|
468 { |
1755
|
469 string id_nm = id->name (); |
|
470 |
1741
|
471 if (refs.empty ()) |
|
472 return id_nm; |
|
473 else |
|
474 { |
|
475 for (Pix p = refs.first (); p != 0; refs.next (p)) |
|
476 { |
1755
|
477 id_nm.append ("."); |
|
478 id_nm.append (refs (p)); |
1741
|
479 } |
|
480 |
1755
|
481 return id_nm; |
1741
|
482 } |
|
483 } |
|
484 |
2086
|
485 octave_value |
|
486 tree_indirect_ref::assign (octave_value& t) |
1741
|
487 { |
2086
|
488 octave_value retval; |
1741
|
489 |
|
490 if (refs.empty ()) |
|
491 retval = id->assign (t); |
|
492 else |
|
493 retval = id->assign (refs, t); |
|
494 |
|
495 return retval; |
|
496 } |
|
497 |
2086
|
498 octave_value |
|
499 tree_indirect_ref::assign (octave_value& t, const octave_value_list& args) |
1741
|
500 { |
2086
|
501 octave_value retval; |
1741
|
502 |
|
503 if (refs.empty ()) |
|
504 retval = id->assign (t, args); |
|
505 else |
|
506 retval = id->assign (refs, t, args); |
|
507 |
|
508 return retval; |
|
509 } |
|
510 |
2086
|
511 octave_value |
1827
|
512 tree_indirect_ref::eval (bool print) |
1741
|
513 { |
2086
|
514 octave_value retval; |
1741
|
515 |
|
516 if (error_state) |
|
517 return retval; |
|
518 |
|
519 if (refs.empty ()) |
|
520 { |
|
521 retval = id->eval (print); |
|
522 } |
|
523 else |
|
524 { |
1827
|
525 bool script_file_executed; |
1741
|
526 |
|
527 tree_fvc *object_to_eval = id->do_lookup (script_file_executed, 0); |
|
528 |
|
529 if (object_to_eval) |
|
530 { |
|
531 retval = object_to_eval->lookup_map_element (refs); |
|
532 |
|
533 if (! error_state && print) |
1755
|
534 retval.print_with_name (name ()); |
1741
|
535 } |
|
536 else |
|
537 id->eval_undefined_error (); |
|
538 } |
|
539 |
|
540 return retval; |
|
541 } |
|
542 |
2086
|
543 octave_value_list |
|
544 tree_indirect_ref::eval (bool print, int nargout, const octave_value_list& args) |
1741
|
545 { |
2086
|
546 octave_value_list retval; |
1741
|
547 |
|
548 if (error_state) |
|
549 return retval; |
|
550 |
|
551 if (refs.empty ()) |
|
552 { |
|
553 retval = id->eval (print, nargout, args); |
|
554 } |
|
555 else |
|
556 { |
1827
|
557 bool script_file_executed; |
1741
|
558 |
|
559 tree_fvc *object_to_eval = id->do_lookup (script_file_executed, 0); |
|
560 |
|
561 if (object_to_eval) |
|
562 { |
2086
|
563 octave_value tmp = object_to_eval->lookup_map_element (refs); |
1741
|
564 |
|
565 if (! error_state) |
|
566 { |
|
567 retval = tmp.eval (0, nargout, args); |
|
568 |
|
569 if (! error_state && print) |
|
570 { |
|
571 tmp = retval (0); |
|
572 if (tmp.is_defined ()) |
1755
|
573 tmp.print_with_name (name ()); |
1741
|
574 } |
|
575 } |
|
576 } |
|
577 else |
|
578 id->eval_undefined_error (); |
|
579 } |
|
580 |
|
581 return retval; |
|
582 } |
|
583 |
|
584 void |
2124
|
585 tree_indirect_ref::accept (tree_walker& tw) |
1741
|
586 { |
2124
|
587 tw.visit_indirect_ref (*this); |
1741
|
588 } |
|
589 |
|
590 // Builtin functions. |
|
591 |
1755
|
592 tree_builtin::tree_builtin (const string& nm) |
1741
|
593 { |
|
594 is_mapper = 0; |
|
595 fcn = 0; |
1755
|
596 my_name = nm; |
1741
|
597 } |
|
598 |
2089
|
599 tree_builtin::tree_builtin (const builtin_mapper_function& m_fcn, |
|
600 const string &nm) |
1741
|
601 { |
|
602 mapper_fcn = m_fcn; |
|
603 is_mapper = 1; |
|
604 fcn = 0; |
1755
|
605 my_name = nm; |
1741
|
606 } |
|
607 |
1755
|
608 tree_builtin::tree_builtin (Octave_builtin_fcn g_fcn, const string& nm) |
1741
|
609 { |
|
610 is_mapper = 0; |
|
611 fcn = g_fcn; |
1755
|
612 my_name = nm; |
1741
|
613 } |
|
614 |
2086
|
615 octave_value |
1827
|
616 tree_builtin::eval (bool /* print */) |
1741
|
617 { |
2086
|
618 octave_value retval; |
1741
|
619 |
|
620 if (error_state) |
|
621 return retval; |
|
622 |
|
623 if (fcn) |
|
624 { |
2086
|
625 octave_value_list args; |
|
626 octave_value_list tmp = (*fcn) (args, 0); |
1741
|
627 if (tmp.length () > 0) |
|
628 retval = tmp(0); |
|
629 } |
|
630 else if (is_mapper) |
|
631 { |
1755
|
632 ::error ("%s: too few arguments", my_name.c_str ()); |
1741
|
633 } |
|
634 else |
1907
|
635 panic_impossible (); |
1741
|
636 |
|
637 return retval; |
|
638 } |
|
639 |
2086
|
640 static octave_value |
2088
|
641 apply_mapper_fcn (const octave_value& arg, builtin_mapper_function& m_fcn, |
1827
|
642 bool /* print */) |
1741
|
643 { |
2086
|
644 octave_value retval; |
1741
|
645 |
2089
|
646 if (m_fcn.ch_mapper) |
1741
|
647 { |
2089
|
648 // XXX FIXME XXX -- this could be done in a better way... |
|
649 |
|
650 octave_value tmp = arg.convert_to_str (); |
|
651 |
|
652 if (! error_state) |
1741
|
653 { |
2089
|
654 charMatrix chm = tmp.char_matrix_value (); |
1741
|
655 |
2089
|
656 if (! error_state) |
1741
|
657 { |
2089
|
658 int nr = chm.rows (); |
|
659 int nc = chm.cols (); |
|
660 |
|
661 Matrix result (nr, nc); |
|
662 |
|
663 // islapha and friends can return any nonzero value to |
|
664 // mean true. |
|
665 |
|
666 for (int j = 0; j < nc; j++) |
|
667 for (int i = 0; i < nr; i++) |
|
668 result.elem (i, j) |
|
669 = (*m_fcn.ch_mapper) (chm.elem (i, j)) ? 1 : 0; |
|
670 |
|
671 retval = result; |
1741
|
672 } |
|
673 } |
2089
|
674 } |
|
675 else |
|
676 { |
|
677 if (arg.is_real_type ()) |
1741
|
678 { |
2089
|
679 if (arg.is_scalar_type ()) |
|
680 { |
|
681 double d = arg.double_value (); |
1741
|
682 |
2089
|
683 if (m_fcn.can_return_complex_for_real_arg |
|
684 && (d < m_fcn.lower_limit || d > m_fcn.upper_limit)) |
|
685 { |
|
686 if (m_fcn.c_c_mapper) |
|
687 retval = m_fcn.c_c_mapper (Complex (d)); |
|
688 else |
|
689 error ("%s: unable to handle real arguments", |
|
690 m_fcn.name.c_str ()); |
|
691 } |
|
692 else if (m_fcn.d_d_mapper) |
|
693 retval = m_fcn.d_d_mapper (d); |
1741
|
694 else |
1755
|
695 error ("%s: unable to handle real arguments", |
|
696 m_fcn.name.c_str ()); |
1741
|
697 } |
|
698 else |
2089
|
699 { |
|
700 Matrix m = arg.matrix_value (); |
|
701 |
|
702 if (error_state) |
|
703 return retval; |
|
704 |
|
705 if (m_fcn.can_return_complex_for_real_arg |
|
706 && (any_element_less_than (m, m_fcn.lower_limit) |
|
707 || any_element_greater_than (m, m_fcn.upper_limit))) |
|
708 { |
|
709 if (m_fcn.c_c_mapper) |
|
710 retval = map (m_fcn.c_c_mapper, ComplexMatrix (m)); |
|
711 else |
|
712 error ("%s: unable to handle real arguments", |
|
713 m_fcn.name.c_str ()); |
|
714 } |
|
715 else if (m_fcn.d_d_mapper) |
|
716 retval = map (m_fcn.d_d_mapper, m); |
|
717 else |
|
718 error ("%s: unable to handle real arguments", |
|
719 m_fcn.name.c_str ()); |
|
720 } |
1741
|
721 } |
2089
|
722 else if (arg.is_complex_type ()) |
1741
|
723 { |
2089
|
724 if (arg.is_scalar_type ()) |
|
725 { |
|
726 Complex c = arg.complex_value (); |
1741
|
727 |
2089
|
728 if (m_fcn.d_c_mapper) |
|
729 retval = m_fcn.d_c_mapper (c); |
|
730 else if (m_fcn.c_c_mapper) |
|
731 retval = m_fcn.c_c_mapper (c); |
|
732 else |
|
733 error ("%s: unable to handle complex arguments", |
|
734 m_fcn.name.c_str ()); |
|
735 } |
1741
|
736 else |
2089
|
737 { |
|
738 ComplexMatrix cm = arg.complex_matrix_value (); |
|
739 |
|
740 if (error_state) |
|
741 return retval; |
|
742 |
|
743 if (m_fcn.d_c_mapper) |
|
744 retval = map (m_fcn.d_c_mapper, cm); |
|
745 else if (m_fcn.c_c_mapper) |
|
746 retval = map (m_fcn.c_c_mapper, cm); |
|
747 else |
|
748 error ("%s: unable to handle complex arguments", |
|
749 m_fcn.name.c_str ()); |
|
750 } |
1741
|
751 } |
|
752 else |
2089
|
753 gripe_wrong_type_arg ("mapper", arg); |
1741
|
754 } |
|
755 |
|
756 return retval; |
|
757 } |
|
758 |
2086
|
759 octave_value_list |
|
760 tree_builtin::eval (bool /* print */, int nargout, const octave_value_list& args) |
1741
|
761 { |
2086
|
762 octave_value_list retval; |
1741
|
763 |
|
764 if (error_state) |
|
765 return retval; |
|
766 |
|
767 int nargin = args.length (); |
|
768 |
|
769 if (fcn) |
|
770 { |
|
771 if (any_arg_is_magic_colon (args)) |
|
772 ::error ("invalid use of colon in function argument list"); |
|
773 else |
|
774 retval = (*fcn) (args, nargout); |
|
775 } |
|
776 else if (is_mapper) |
|
777 { |
|
778 // XXX FIXME XXX -- should we just assume nargin_max == 1? |
|
779 // |
|
780 // if (nargin > nargin_max) |
1755
|
781 // ::error ("%s: too many arguments", my_name.c_str ()); |
1741
|
782 // else |
|
783 if (nargin > 0 && args(0).is_defined ()) |
|
784 { |
2086
|
785 octave_value tmp = apply_mapper_fcn (args(0), mapper_fcn, 0); |
1741
|
786 retval(0) = tmp; |
|
787 } |
|
788 else |
|
789 { |
1755
|
790 ::error ("%s: too few arguments", my_name.c_str ()); |
1741
|
791 } |
|
792 } |
|
793 else |
1907
|
794 panic_impossible (); |
1741
|
795 |
|
796 return retval; |
|
797 } |
|
798 |
|
799 void |
2124
|
800 tree_builtin::accept (tree_walker& tw) |
1741
|
801 { |
2124
|
802 tw.visit_builtin (*this); |
1741
|
803 } |
|
804 |
|
805 /* |
|
806 ;;; Local Variables: *** |
|
807 ;;; mode: C++ *** |
|
808 ;;; End: *** |
|
809 */ |