(py-indent-right, py-outdent-left): new commands, bound to C-c C-r and
[python/dscho.git] / Modules / newmodule.c
blob5a6e32c8037267de73cfc52f47b31087b42b8b6f
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
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"
28 #include "compile.h"
30 static char new_im_doc[] =
31 "Create a instance method object from (FUNCTION, INSTANCE, CLASS).";
33 static object *
34 new_instancemethod(unused, args)
35 object* unused;
36 object* args;
38 object* func;
39 object* self;
40 object* classObj;
42 if (!newgetargs(args, "O!O!O!",
43 &Functype, &func,
44 &Instancetype, &self,
45 &Classtype, &classObj))
46 return NULL;
47 return newinstancemethodobject(func, self, classObj);
50 static char new_function_doc[] =
51 "Create a function object from (CODE, GLOBALS, [NAME, ARGCOUNT, ARGDEFS]).";
53 static object *
54 new_function(unused, args)
55 object* unused;
56 object* args;
58 object* code;
59 object* globals;
60 object* name = None;
61 int argcount = -1;
62 object* argdefs = None;
63 funcobject* newfunc;
65 if (!newgetargs(args, "O!O!|SiO!",
66 &Codetype, &code,
67 &Mappingtype, &globals,
68 &name,
69 &argcount,
70 &Tupletype, &argdefs))
71 return NULL;
73 newfunc = (funcobject *)newfuncobject(code, globals);
74 if (newfunc == NULL)
75 return NULL;
77 if (name != None) {
78 XINCREF(name);
79 XDECREF(newfunc->func_name);
80 newfunc->func_name = name;
82 newfunc->func_argcount = argcount;
83 if (argdefs != NULL) {
84 XINCREF(argdefs);
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).";
95 static object *
96 new_code(unused, args)
97 object* unused;
98 object* args;
100 object* code;
101 object* consts;
102 object* names;
103 object* filename;
104 object* name;
106 if (!newgetargs(args, "SO!O!SS",
107 &code, &Tupletype, &consts, &Tupletype, &names,
108 &filename, &name))
109 return NULL;
110 return (object *)newcodeobject(code, consts, names, filename, name);
113 static char new_module_doc[] =
114 "Create a module object from (NAME).";
116 static object *
117 new_module(unused, args)
118 object* unused;
119 object* args;
121 char *name;
123 if (!newgetargs(args, "s", &name))
124 return NULL;
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 */
136 char new_doc[] =
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!";
141 void
142 initnew()
144 initmodule4("new", new_methods, new_doc, (object *)NULL,
145 PYTHON_API_VERSION);