Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 846e431

Browse files
committed
Function objects no longer contain a parse tree node, but intermediate
code.
1 parent 5b3138b commit 846e431

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

Objects/funcobject.c

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,39 @@
44

55
#include "PROTO.h"
66
#include "object.h"
7-
#include "node.h"
8-
#include "stringobject.h"
97
#include "funcobject.h"
108
#include "objimpl.h"
11-
#include "token.h"
129

1310
typedef struct {
1411
OB_HEAD
15-
node *func_node;
12+
object *func_code;
1613
object *func_globals;
1714
} funcobject;
1815

1916
object *
20-
newfuncobject(n, globals)
21-
node *n;
17+
newfuncobject(code, globals)
18+
object *code;
2219
object *globals;
2320
{
2421
funcobject *op = NEWOBJ(funcobject, &Functype);
2522
if (op != NULL) {
26-
op->func_node = n;
27-
if (globals != NULL)
28-
INCREF(globals);
23+
INCREF(code);
24+
op->func_code = code;
25+
INCREF(globals);
2926
op->func_globals = globals;
3027
}
3128
return (object *)op;
3229
}
3330

34-
node *
35-
getfuncnode(op)
31+
object *
32+
getfunccode(op)
3633
object *op;
3734
{
3835
if (!is_funcobject(op)) {
3936
err_badcall();
4037
return NULL;
4138
}
42-
return ((funcobject *) op) -> func_node;
39+
return ((funcobject *) op) -> func_code;
4340
}
4441

4542
object *
@@ -59,31 +56,9 @@ static void
5956
funcdealloc(op)
6057
funcobject *op;
6158
{
62-
/* XXX free node? */
59+
DECREF(op->func_code);
6360
DECREF(op->func_globals);
64-
free((char *)op);
65-
}
66-
67-
static void
68-
funcprint(op, fp, flags)
69-
funcobject *op;
70-
FILE *fp;
71-
int flags;
72-
{
73-
node *n = op->func_node;
74-
n = CHILD(n, 1);
75-
fprintf(fp, "<user function %s>", STR(n));
76-
}
77-
78-
static object *
79-
funcrepr(op)
80-
funcobject *op;
81-
{
82-
char buf[100];
83-
node *n = op->func_node;
84-
n = CHILD(n, 1);
85-
sprintf(buf, "<user function %.80s>", STR(n));
86-
return newstringobject(buf);
61+
DEL(op);
8762
}
8863

8964
typeobject Functype = {
@@ -93,9 +68,9 @@ typeobject Functype = {
9368
sizeof(funcobject),
9469
0,
9570
funcdealloc, /*tp_dealloc*/
96-
funcprint, /*tp_print*/
71+
0, /*tp_print*/
9772
0, /*tp_getattr*/
9873
0, /*tp_setattr*/
9974
0, /*tp_compare*/
100-
funcrepr, /*tp_repr*/
75+
0, /*tp_repr*/
10176
};

0 commit comments

Comments
 (0)