Function objects no longer contain a parse tree node, but intermediate

code.
This commit is contained in:
Guido van Rossum 1990-11-18 17:44:06 +00:00
parent 5b3138bec0
commit 846e431372
1 changed files with 13 additions and 38 deletions

View File

@ -4,42 +4,39 @@
#include "PROTO.h" #include "PROTO.h"
#include "object.h" #include "object.h"
#include "node.h"
#include "stringobject.h"
#include "funcobject.h" #include "funcobject.h"
#include "objimpl.h" #include "objimpl.h"
#include "token.h"
typedef struct { typedef struct {
OB_HEAD OB_HEAD
node *func_node; object *func_code;
object *func_globals; object *func_globals;
} funcobject; } funcobject;
object * object *
newfuncobject(n, globals) newfuncobject(code, globals)
node *n; object *code;
object *globals; object *globals;
{ {
funcobject *op = NEWOBJ(funcobject, &Functype); funcobject *op = NEWOBJ(funcobject, &Functype);
if (op != NULL) { if (op != NULL) {
op->func_node = n; INCREF(code);
if (globals != NULL) op->func_code = code;
INCREF(globals); INCREF(globals);
op->func_globals = globals; op->func_globals = globals;
} }
return (object *)op; return (object *)op;
} }
node * object *
getfuncnode(op) getfunccode(op)
object *op; object *op;
{ {
if (!is_funcobject(op)) { if (!is_funcobject(op)) {
err_badcall(); err_badcall();
return NULL; return NULL;
} }
return ((funcobject *) op) -> func_node; return ((funcobject *) op) -> func_code;
} }
object * object *
@ -59,31 +56,9 @@ static void
funcdealloc(op) funcdealloc(op)
funcobject *op; funcobject *op;
{ {
/* XXX free node? */ DECREF(op->func_code);
DECREF(op->func_globals); DECREF(op->func_globals);
free((char *)op); DEL(op);
}
static void
funcprint(op, fp, flags)
funcobject *op;
FILE *fp;
int flags;
{
node *n = op->func_node;
n = CHILD(n, 1);
fprintf(fp, "<user function %s>", STR(n));
}
static object *
funcrepr(op)
funcobject *op;
{
char buf[100];
node *n = op->func_node;
n = CHILD(n, 1);
sprintf(buf, "<user function %.80s>", STR(n));
return newstringobject(buf);
} }
typeobject Functype = { typeobject Functype = {
@ -93,9 +68,9 @@ typeobject Functype = {
sizeof(funcobject), sizeof(funcobject),
0, 0,
funcdealloc, /*tp_dealloc*/ funcdealloc, /*tp_dealloc*/
funcprint, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
0, /*tp_compare*/ 0, /*tp_compare*/
funcrepr, /*tp_repr*/ 0, /*tp_repr*/
}; };