Kaydet (Commit) 681d79aa authored tarafından Guido van Rossum's avatar Guido van Rossum

keyword arguments and faster calls

üst 11a3f0c2
...@@ -80,15 +80,20 @@ builtin_apply(self, args) ...@@ -80,15 +80,20 @@ builtin_apply(self, args)
object *self; object *self;
object *args; object *args;
{ {
object *func, *alist; object *func, *alist, *kwdict = NULL;
if (!newgetargs(args, "OO:apply", &func, &alist)) if (!newgetargs(args, "O|OO:apply", &func, &alist, &kwdict))
return NULL; return NULL;
if (!is_tupleobject(alist)) { if (alist != NULL && !is_tupleobject(alist)) {
err_setstr(TypeError, "apply() 2nd argument must be tuple"); err_setstr(TypeError, "apply() 2nd argument must be tuple");
return NULL; return NULL;
} }
return call_object(func, alist); if (kwdict != NULL && !is_dictobject(kwdict)) {
err_setstr(TypeError,
"apply() 3rd argument must be dictionary");
return NULL;
}
return PyEval_CallObjectWithKeywords(func, alist, kwdict);
} }
static object * static object *
...@@ -373,8 +378,7 @@ builtin_eval(self, args) ...@@ -373,8 +378,7 @@ builtin_eval(self, args)
return NULL; return NULL;
} }
if (is_codeobject(cmd)) if (is_codeobject(cmd))
return eval_code((codeobject *) cmd, globals, locals, return eval_code((codeobject *) cmd, globals, locals);
(object *)NULL, (object *)NULL);
if (!is_stringobject(cmd)) { if (!is_stringobject(cmd)) {
err_setstr(TypeError, err_setstr(TypeError,
"eval() argument 1 must be string or code object"); "eval() argument 1 must be string or code object");
......
This diff is collapsed.
This diff is collapsed.
...@@ -54,7 +54,7 @@ extern long getmtime(); /* In getmtime.c */ ...@@ -54,7 +54,7 @@ extern long getmtime(); /* In getmtime.c */
Apple MPW compiler swaps their values, botching string constants */ Apple MPW compiler swaps their values, botching string constants */
/* XXX Perhaps the magic number should be frozen and a version field /* XXX Perhaps the magic number should be frozen and a version field
added to the .pyc file header? */ added to the .pyc file header? */
#define MAGIC (0x4127L | ((long)'\r'<<16) | ((long)'\n'<<24)) #define MAGIC (11913 | ((long)'\r'<<16) | ((long)'\n'<<24))
object *import_modules; /* This becomes sys.modules */ object *import_modules; /* This becomes sys.modules */
...@@ -159,7 +159,7 @@ exec_code_module(name, co) ...@@ -159,7 +159,7 @@ exec_code_module(name, co)
if (dictinsert(d, "__builtins__", getbuiltins()) != 0) if (dictinsert(d, "__builtins__", getbuiltins()) != 0)
return NULL; return NULL;
} }
v = eval_code((codeobject *)co, d, d, d, (object *)NULL); v = eval_code((codeobject *)co, d, d); /* XXX owner? */
if (v == NULL) if (v == NULL)
return NULL; return NULL;
DECREF(v); DECREF(v);
......
...@@ -44,7 +44,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -44,7 +44,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TYPE_TUPLE '(' #define TYPE_TUPLE '('
#define TYPE_LIST '[' #define TYPE_LIST '['
#define TYPE_DICT '{' #define TYPE_DICT '{'
#define TYPE_CODE 'C' #define TYPE_CODE 'c'
#define TYPE_UNKNOWN '?' #define TYPE_UNKNOWN '?'
typedef struct { typedef struct {
...@@ -187,9 +187,13 @@ w_object(v, p) ...@@ -187,9 +187,13 @@ w_object(v, p)
else if (is_codeobject(v)) { else if (is_codeobject(v)) {
codeobject *co = (codeobject *)v; codeobject *co = (codeobject *)v;
w_byte(TYPE_CODE, p); w_byte(TYPE_CODE, p);
w_short(co->co_argcount, p);
w_short(co->co_nlocals, p);
w_short(co->co_flags, p);
w_object((object *)co->co_code, p); w_object((object *)co->co_code, p);
w_object(co->co_consts, p); w_object(co->co_consts, p);
w_object(co->co_names, p); w_object(co->co_names, p);
w_object(co->co_varnames, p);
w_object(co->co_filename, p); w_object(co->co_filename, p);
w_object(co->co_name, p); w_object(co->co_name, p);
} }
...@@ -374,14 +378,20 @@ r_object(p) ...@@ -374,14 +378,20 @@ r_object(p)
case TYPE_CODE: case TYPE_CODE:
{ {
int argcount = r_short(p);
int nlocals = r_short(p);
int flags = r_short(p);
object *code = r_object(p); object *code = r_object(p);
object *consts = r_object(p); object *consts = r_object(p);
object *names = r_object(p); object *names = r_object(p);
object *varnames = r_object(p);
object *filename = r_object(p); object *filename = r_object(p);
object *name = r_object(p); object *name = r_object(p);
if (!err_occurred()) { if (!err_occurred()) {
v = (object *) newcodeobject(code, v = (object *) newcodeobject(
consts, names, filename, name); argcount, nlocals, flags,
code, consts, names, varnames,
filename, name);
} }
else else
v = NULL; v = NULL;
......
...@@ -430,7 +430,7 @@ run_node(n, filename, globals, locals) ...@@ -430,7 +430,7 @@ run_node(n, filename, globals, locals)
freetree(n); freetree(n);
if (co == NULL) if (co == NULL)
return NULL; return NULL;
v = eval_code(co, globals, locals, (object *)NULL, (object *)NULL); v = eval_code(co, globals, locals);
DECREF(co); DECREF(co);
return v; return v;
} }
...@@ -462,7 +462,7 @@ run_pyc_file(fp, filename, globals, locals) ...@@ -462,7 +462,7 @@ run_pyc_file(fp, filename, globals, locals)
return NULL; return NULL;
} }
co = (codeobject *)v; co = (codeobject *)v;
v = eval_code(co, globals, locals, (object *)NULL, (object *)NULL); v = eval_code(co, globals, locals);
DECREF(co); DECREF(co);
return v; return v;
} }
...@@ -603,16 +603,9 @@ cleanup() ...@@ -603,16 +603,9 @@ cleanup()
object *exitfunc = sysget("exitfunc"); object *exitfunc = sysget("exitfunc");
if (exitfunc) { if (exitfunc) {
object *arg;
object *res; object *res;
sysset("exitfunc", (object *)NULL); sysset("exitfunc", (object *)NULL);
arg = newtupleobject(0); res = call_object(exitfunc, (object *)NULL);
if (arg == NULL)
res = NULL;
else {
res = call_object(exitfunc, arg);
DECREF(arg);
}
if (res == NULL) { if (res == NULL) {
fprintf(stderr, "Error in sys.exitfunc:\n"); fprintf(stderr, "Error in sys.exitfunc:\n");
print_error(); print_error();
......
...@@ -68,7 +68,10 @@ tb_dealloc(tb) ...@@ -68,7 +68,10 @@ tb_dealloc(tb)
DEL(tb); DEL(tb);
} }
static typeobject Tracebacktype = { #define Tracebacktype PyTraceback_Type
#define is_tracebackobject PyTraceback_Check
typeobject Tracebacktype = {
OB_HEAD_INIT(&Typetype) OB_HEAD_INIT(&Typetype)
0, 0,
"traceback", "traceback",
...@@ -85,8 +88,6 @@ static typeobject Tracebacktype = { ...@@ -85,8 +88,6 @@ static typeobject Tracebacktype = {
0, /*tp_as_mapping*/ 0, /*tp_as_mapping*/
}; };
#define is_tracebackobject(v) ((v)->ob_type == &Tracebacktype)
static tracebackobject * static tracebackobject *
newtracebackobject(next, frame, lasti, lineno) newtracebackobject(next, frame, lasti, lineno)
tracebackobject *next; tracebackobject *next;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment