summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2000-08-27 20:31:27 (GMT)
committerThomas Wouters <thomas@python.org>2000-08-27 20:31:27 (GMT)
commitdd13e4f91ff2d8824e852afaec59d95d7dd409b3 (patch)
tree89497ccf5d8b6307d7b32bb71a8142c00b494bfa /Python/compile.c
parente868211e106d4da348925e1c1bd1ea62b3560721 (diff)
downloadcpython-dd13e4f91ff2d8824e852afaec59d95d7dd409b3.zip
cpython-dd13e4f91ff2d8824e852afaec59d95d7dd409b3.tar.gz
cpython-dd13e4f91ff2d8824e852afaec59d95d7dd409b3.tar.bz2
Replace the run-time 'future-bytecode-stream-inspection' hack to find out
how 'import' was called with a compiletime mechanism: create either a tuple of the import arguments, or None (in the case of a normal import), add it to the code-block constants, and load it onto the stack before calling IMPORT_NAME.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c
index dc6e2fb..ba910c4 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -2329,14 +2329,27 @@ static void
com_import_stmt(struct compiling *c, node *n)
{
int i;
+ PyObject *tup;
REQ(n, import_stmt);
/* 'import' dotted_name (',' dotted_name)* |
'from' dotted_name 'import' ('*' | NAME (',' NAME)*) */
if (STR(CHILD(n, 0))[0] == 'f') {
/* 'from' dotted_name 'import' ... */
REQ(CHILD(n, 1), dotted_name);
- com_addopname(c, IMPORT_NAME, CHILD(n, 1));
+
+ if (TYPE(CHILD(n, 3)) == STAR) {
+ tup = Py_BuildValue("(s)", "*");
+ } else {
+ tup = PyTuple_New((NCH(n) - 2)/2);
+ for (i = 3; i < NCH(n); i += 2) {
+ PyTuple_SET_ITEM(tup, (i-3)/2,
+ PyString_FromString(STR(
+ CHILD(CHILD(n, i), 0))));
+ }
+ }
+ com_addoparg(c, LOAD_CONST, com_addconst(c, tup));
com_push(c, 1);
+ com_addopname(c, IMPORT_NAME, CHILD(n, 1));
if (TYPE(CHILD(n, 3)) == STAR)
com_addbyte(c, IMPORT_STAR);
else {
@@ -2351,8 +2364,9 @@ com_import_stmt(struct compiling *c, node *n)
for (i = 1; i < NCH(n); i += 2) {
node *subn = CHILD(n, i);
REQ(subn, dotted_as_name);
- com_addopname(c, IMPORT_NAME, CHILD(subn, 0));
+ com_addoparg(c, LOAD_CONST, com_addconst(c, Py_None));
com_push(c, 1);
+ com_addopname(c, IMPORT_NAME, CHILD(subn, 0));
if (NCH(subn) > 1) {
int j;
if (strcmp(STR(CHILD(subn, 1)), "as") != 0) {