diff Python/compile.c @ 1354:fccd415e2eb8 legacy-trunk

* bltinmodule.c: removed exec() built-in function. * Grammar: add exec statement; allow testlist in expr statement. * ceval.c, compile.c, opcode.h: support exec statement; avoid optimizing locals when it is used * fileobject.{c,h}: add getfilename() internal function.
author Guido van Rossum <guido@python.org>
date Mon, 18 Oct 1993 17:06:59 +0000
parents cd397266dc1c
children 132602d854d8
line wrap: on
line diff
--- a/Python/compile.c	Mon Oct 18 11:44:47 1993 +0000
+++ b/Python/compile.c	Mon Oct 18 17:06:59 1993 +0000
@@ -1305,7 +1305,7 @@
 	struct compiling *c;
 	node *n;
 {
-	REQ(n, expr_stmt); /* exprlist ('=' exprlist)* */
+	REQ(n, expr_stmt); /* testlist ('=' testlist)* */
 	com_node(c, CHILD(n, NCH(n)-1));
 	if (NCH(n) == 1) {
 		com_addbyte(c, PRINT_EXPR);
@@ -1467,6 +1467,25 @@
 }
 
 static void
+com_exec_stmt(c, n)
+	struct compiling *c;
+	node *n;
+{
+	REQ(n, exec_stmt);
+	/* exec_stmt: 'exec' expr ['in' expr [',' expr]] */
+	com_node(c, CHILD(n, 1));
+	if (NCH(n) >= 4)
+		com_node(c, CHILD(n, 3));
+	else
+		com_addoparg(c, LOAD_CONST, com_addconst(c, None));
+	if (NCH(n) >= 6)
+		com_node(c, CHILD(n, 5));
+	else
+		com_addbyte(c, DUP_TOP);
+	com_addbyte(c, EXEC_STMT);
+}
+
+static void
 com_if_stmt(c, n)
 	struct compiling *c;
 	node *n;
@@ -1909,6 +1928,9 @@
 	case access_stmt:
 		com_access_stmt(c, n);
 		break;
+	case exec_stmt:
+		com_exec_stmt(c, n);
+		break;
 	case if_stmt:
 		com_if_stmt(c, n);
 		break;
@@ -2183,6 +2205,8 @@
 		opcode = NEXTOP();
 		if (opcode == STOP_CODE)
 			break;
+		if (opcode == EXEC_STMT)
+			goto end; /* Don't optimize if exec present */
 		if (HAS_ARG(opcode))
 			oparg = NEXTARG();
 		if (opcode == STORE_NAME || opcode == DELETE_NAME ||