diff options
author | Guido van Rossum <guido@python.org> | 1994-05-23 12:37:57 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-05-23 12:37:57 (GMT) |
commit | 34162a123a28f9092d6d9f361dd11bbfe23139a4 (patch) | |
tree | 14f69ad21f4d8a7eca17fd9d722d1bbf9d2ed655 /Modules/newmodule.c | |
parent | b3107c3beef67b75458ba68bf3482a263f7ec7fd (diff) | |
download | cpython-34162a123a28f9092d6d9f361dd11bbfe23139a4.zip cpython-34162a123a28f9092d6d9f361dd11bbfe23139a4.tar.gz cpython-34162a123a28f9092d6d9f361dd11bbfe23139a4.tar.bz2 |
Added some new modules
Diffstat (limited to 'Modules/newmodule.c')
-rw-r--r-- | Modules/newmodule.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/Modules/newmodule.c b/Modules/newmodule.c new file mode 100644 index 0000000..aa5f77e --- /dev/null +++ b/Modules/newmodule.c @@ -0,0 +1,111 @@ +/* newmodule.c */ +#include "allobjects.h" +#include "compile.h" +#include "modsupport.h" + + +object* +new_instancemethod(unused, args) + object* unused; + object* args; +{ + object* func; + object* self; + object* classObj; + + if (!getargs(args, "(OOO)", &func, &self, &classObj)) { + return NULL; + } else if (!is_funcobject(func) || !is_instanceobject(self) || !is_classobject(classObj)) { + err_setstr(TypeError, "expected a function, instance and classobject as args"); + return NULL; + } + return newinstancemethodobject(func, self, classObj); +} + + +object* +new_function(unused, args) + object* unused; + object* args; +{ + object* code; + object* globals; + object* name; + object* newfunc; + object* argcount; + object* argdefs; + + if (!getargs(args, "(OOOOO)", &code, &globals, &name, &argcount, &argdefs)) { + return NULL; + } else if (!is_codeobject(code) || !is_mappingobject(globals) || !is_stringobject(name) || !is_intobject(argcount) || !is_tupleobject(argdefs)) { + err_setstr(TypeError, "expected a code object, a dict for globals, a string name, an integer default argument count and a tuple of default argument definitions."); + return NULL; + } + + newfunc = newfuncobject(code, globals); + + ((funcobject *)newfunc)->func_name = name; + XINCREF( name ); + XDECREF( ((codeobject*)(((funcobject *)(newfunc))->func_code))->co_name ); + + ((funcobject *)newfunc)->func_argcount = getintvalue(argcount); + ((funcobject *)newfunc)->func_argdefs = argdefs; + XINCREF( argdefs ); + + return newfunc; +} + + +object* +new_code(unused, args) + object* unused; + object* args; +{ + object* code; + object* consts; + object* names; + object* filename; + object* name; + + if (!getargs(args, "(OOOOO)", &code, &consts, &names, &filename, &name)) { + return NULL; + } else if (!is_stringobject(code) || !is_listobject(consts) || \ + !is_listobject(names) || !is_stringobject(filename) || \ + !is_stringobject(name)) { + err_setstr(TypeError, "expected a string of compiled code, a list of constants, \ + a list of names used, a string filename, and a string name \ + as args"); + return NULL; + } + return (object *)newcodeobject(code, consts, names, filename, name); +} + + +object* +new_module(unused, args) + object* unused; + object* args; +{ + object* name; + + if (!getargs(args, "S", &name)) { + err_setstr(TypeError, "expected a string name as args"); + return NULL; + } + return newmoduleobject(getstringvalue(name)); +} + + +static struct methodlist new_methods[] = { + { "instancemethod", new_instancemethod }, + { "function", new_function }, + { "code", new_code }, + { "module", new_module }, + {NULL, NULL} /* sentinel */ +}; + +void +initnew() +{ + initmodule("new", new_methods); +} |