[Python-checkins] python/dist/src/Python newcompile.c,1.1.2.34,1.1.2.35

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Tue, 25 Mar 2003 12:53:31 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv19161/Python

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
Implement from/import stmt
Fix import x as y to lookup in the proper location (names, not varnames)


Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.34
retrieving revision 1.1.2.35
diff -C2 -d -r1.1.2.34 -r1.1.2.35
*** newcompile.c	25 Mar 2003 20:17:57 -0000	1.1.2.34
--- newcompile.c	25 Mar 2003 20:53:22 -0000	1.1.2.35
***************
*** 825,829 ****
  		identifier store_name;
  		ADDOP_O(c, LOAD_CONST, Py_None, consts);
! 		ADDOP_O(c, IMPORT_NAME, alias->name, varnames);
  
  		store_name = alias->name;
--- 825,829 ----
  		identifier store_name;
  		ADDOP_O(c, LOAD_CONST, Py_None, consts);
! 		ADDOP_O(c, IMPORT_NAME, alias->name, names);
  
  		store_name = alias->name;
***************
*** 838,841 ****
--- 838,874 ----
  
  static int
+ compiler_from_import(struct compiler *c, stmt_ty s)
+ {
+ 	int i, n = asdl_seq_LEN(s->v.ImportFrom.names);
+ 	PyObject *names = PyTuple_New(n);
+ 	if (!names)
+ 		return 0;
+ 
+ 	/* build up the names */
+ 	for (i = 0; i < n; i++) {
+ 		alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
+ 		PyTuple_SET_ITEM(names, i, alias->name);
+ 	}
+ 
+ 	ADDOP_O(c, LOAD_CONST, names, consts);
+ 	ADDOP_O(c, IMPORT_NAME, s->v.ImportFrom.module, names);
+ 	for (i = 0; i < n; i++) {
+ 		alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);
+ 		identifier store_name;
+ 
+ 		ADDOP_O(c, IMPORT_FROM, alias->name, names);
+ 		store_name = alias->name;
+ 		if (alias->asname)
+ 			store_name = alias->asname;
+ 
+ 		if (!compiler_nameop(c, store_name, Store))
+ 			return 0;
+ 	}
+ 	/* remove imported module */
+ 	ADDOP(c, POP_TOP);
+ 	return 1;
+ }
+ 
+ static int
  compiler_assert(struct compiler *c, stmt_ty s)
  {
***************
*** 945,949 ****
  		return compiler_import(c, s);
          case ImportFrom_kind:
! 		break;
          case Exec_kind:
  		VISIT(c, expr, s->v.Exec.body);
--- 978,982 ----
  		return compiler_import(c, s);
          case ImportFrom_kind:
! 		return compiler_from_import(c, s);
          case Exec_kind:
  		VISIT(c, expr, s->v.Exec.body);