525
|
1 // defun-int.h -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
525
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_defun_int_h) |
|
25 #define octave_defun_int_h 1 |
|
26 |
550
|
27 // MAKE_BUILTINS is defined to extract function names and related |
|
28 // information and create the *.def files that are eventually used to |
|
29 // create the buitlins.cc file. |
|
30 |
525
|
31 #ifdef MAKE_BUILTINS |
|
32 |
550
|
33 // Generate code to install name in the symbol table. The script |
|
34 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
|
35 // DEFUN_TEXT, or DEFUN_DLD. |
|
36 |
525
|
37 #define DEFUN_INTERNAL(name, fname, sname, nargin_max, nargout_max, \ |
|
38 is_text_fcn, doc) \ |
|
39 BEGIN_INSTALL_BUILTIN \ |
703
|
40 extern DECLARE_FUN (fname); \ |
|
41 DEFINE_FUN_STRUCT (name, fname, sname, nargin_max, nargout_max, \ |
|
42 is_text_fcn, doc); \ |
525
|
43 install_builtin_function (&sname); \ |
|
44 END_INSTALL_BUILTIN |
|
45 |
550
|
46 // Generate code for making another name for an existing function. |
|
47 |
|
48 #define DEFALIAS_INTERNAL(alias, name) \ |
|
49 BEGIN_INSTALL_BUILTIN \ |
|
50 alias_builtin (#alias, #name); \ |
|
51 END_INSTALL_BUILTIN |
525
|
52 |
|
53 #else /* ! MAKE_BUILTINS */ |
|
54 |
550
|
55 // Generate the first line of the function definition. This ensures |
|
56 // that the internal functions all have the same signature. |
|
57 |
525
|
58 #define DEFUN_INTERNAL(name, fname, sname, nargin_max, nargout_max, \ |
|
59 is_text_fcn, doc) \ |
703
|
60 DECLARE_FUN (fname) |
525
|
61 |
550
|
62 // No definition is required for an alias. |
|
63 |
|
64 #define DEFALIAS_INTERNAL(name, alias) |
525
|
65 |
|
66 #endif /* ! MAKE_BUILTINS */ |
|
67 |
703
|
68 // Define the structure that will be used to insert this function into |
|
69 // the symbol table. |
|
70 |
|
71 #define DEFINE_FUN_STRUCT(name, fname, sname, nargin_max, \ |
|
72 nargout_max, is_text_fcn, doc) \ |
|
73 static builtin_function sname = \ |
|
74 { name, nargin_max, nargout_max, is_text_fcn, fname, doc } |
|
75 |
|
76 #define DEFINE_FUN_STRUCT_FUN(sname, fsname) \ |
|
77 builtin_function * \ |
|
78 fsname (void) \ |
|
79 { \ |
|
80 return &sname; \ |
|
81 } |
|
82 |
550
|
83 // Declare an internal function named fname. This is the interface |
|
84 // used by all internal functions in Octave that are also callable |
|
85 // from the Octave language. |
|
86 |
525
|
87 #define DECLARE_FUN(fname) \ |
|
88 Octave_object \ |
|
89 fname (const Octave_object& args, int nargout) |
|
90 |
540
|
91 // XXX FIXME XXX -- eliminate the need for these in the functions that |
|
92 // use them? |
|
93 |
578
|
94 #define DEFINE_ARGV(fcn_name) \ |
712
|
95 int argc = args.length () + 1; \ |
540
|
96 int save_argc = argc; \ |
578
|
97 char **argv = make_argv (args, fcn_name); \ |
540
|
98 char **save_argv = argv; \ |
525
|
99 if (error_state) \ |
|
100 return retval |
|
101 |
|
102 #define DELETE_ARGV \ |
|
103 do \ |
|
104 { \ |
540
|
105 while (--save_argc >= 0) \ |
|
106 delete [] save_argv[save_argc]; \ |
|
107 delete [] save_argv; \ |
525
|
108 } \ |
|
109 while (0) |
|
110 |
|
111 #endif |
|
112 |
|
113 /* |
|
114 ;;; Local Variables: *** |
|
115 ;;; mode: C++ *** |
|
116 ;;; page-delimiter: "^/\\*" *** |
|
117 ;;; End: *** |
|
118 */ |