1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Module new -- create new objects of various types */
27 #include "allobjects.h"
30 static char new_im_doc
[] =
31 "Create a instance method object from (FUNCTION, INSTANCE, CLASS).";
34 new_instancemethod(unused
, args
)
42 if (!newgetargs(args
, "O!O!O!",
45 &Classtype
, &classObj
))
47 return newinstancemethodobject(func
, self
, classObj
);
50 static char new_function_doc
[] =
51 "Create a function object from (CODE, GLOBALS, [NAME, ARGCOUNT, ARGDEFS]).";
54 new_function(unused
, args
)
62 object
* argdefs
= None
;
65 if (!newgetargs(args
, "O!O!|SiO!",
67 &Mappingtype
, &globals
,
70 &Tupletype
, &argdefs
))
73 newfunc
= (funcobject
*)newfuncobject(code
, globals
);
79 XDECREF(newfunc
->func_name
);
80 newfunc
->func_name
= name
;
82 newfunc
->func_argcount
= argcount
;
83 if (argdefs
!= NULL
) {
85 XDECREF(newfunc
->func_argdefs
);
86 newfunc
->func_argdefs
= argdefs
;
89 return (object
*)newfunc
;
92 static char new_code_doc
[] =
93 "Create a code object from (CODESTRING, CONSTANTS, NAMES, FILENAME, NAME).";
96 new_code(unused
, args
)
106 if (!newgetargs(args
, "SO!O!SS",
107 &code
, &Tupletype
, &consts
, &Tupletype
, &names
,
110 return (object
*)newcodeobject(code
, consts
, names
, filename
, name
);
113 static char new_module_doc
[] =
114 "Create a module object from (NAME).";
117 new_module(unused
, args
)
123 if (!newgetargs(args
, "s", &name
))
125 return newmoduleobject(name
);
128 static struct methodlist new_methods
[] = {
129 {"instancemethod", new_instancemethod
, 1, new_im_doc
},
130 {"function", new_function
, 1, new_function_doc
},
131 {"code", new_code
, 1, new_code_doc
},
132 {"module", new_module
, 1, new_module_doc
},
133 {NULL
, NULL
} /* sentinel */
137 "Functions to create new objects used by the interpreter.\n\
139 You need to know a great deal about the interpreter to use this!";
144 initmodule4("new", new_methods
, new_doc
, (object
*)NULL
,