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