Anonymous avatar Anonymous committed a79cbb2

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

Comments (0)

Files changed (1)

Objects/funcobject.c

 
 #include "PROTO.h"
 #include "object.h"
-#include "node.h"
-#include "stringobject.h"
 #include "funcobject.h"
 #include "objimpl.h"
-#include "token.h"
 
 typedef struct {
 	OB_HEAD
-	node *func_node;
+	object *func_code;
 	object *func_globals;
 } funcobject;
 
 object *
-newfuncobject(n, globals)
-	node *n;
+newfuncobject(code, globals)
+	object *code;
 	object *globals;
 {
 	funcobject *op = NEWOBJ(funcobject, &Functype);
 	if (op != NULL) {
-		op->func_node = n;
-		if (globals != NULL)
-			INCREF(globals);
+		INCREF(code);
+		op->func_code = code;
+		INCREF(globals);
 		op->func_globals = globals;
 	}
 	return (object *)op;
 }
 
-node *
-getfuncnode(op)
+object *
+getfunccode(op)
 	object *op;
 {
 	if (!is_funcobject(op)) {
 		err_badcall();
 		return NULL;
 	}
-	return ((funcobject *) op) -> func_node;
+	return ((funcobject *) op) -> func_code;
 }
 
 object *
 funcdealloc(op)
 	funcobject *op;
 {
-	/* XXX free node? */
+	DECREF(op->func_code);
 	DECREF(op->func_globals);
-	free((char *)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);
+	DEL(op);
 }
 
 typeobject Functype = {
 	sizeof(funcobject),
 	0,
 	funcdealloc,	/*tp_dealloc*/
-	funcprint,	/*tp_print*/
+	0,		/*tp_print*/
 	0,		/*tp_getattr*/
 	0,		/*tp_setattr*/
 	0,		/*tp_compare*/
-	funcrepr,	/*tp_repr*/
+	0,		/*tp_repr*/
 };
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.