Index: BaseEvaluator.py =================================================================== RCS file: /cvsroot/jython/jython/Tools/jythonc/BaseEvaluator.py,v retrieving revision 2.10 diff -u -5 -r2.10 BaseEvaluator.py --- BaseEvaluator.py 2001/05/27 18:50:56 2.10 +++ BaseEvaluator.py 2001/07/27 16:23:05 @@ -10,10 +10,11 @@ def __init__(self): self.globalnames = {} self.augtemps = {} self.lineno = -1 self.visitor = PythonVisitor(self) + self.imp_accu = None def parse(self, node): try: return self.visit(node) except: @@ -162,10 +163,12 @@ def makeTemp(self, value): return value def freeTemp(self, tmp): pass + def makeFreeDecl(self,type,value): pass + def expr_stmt(self, lhss, rhs): if len(lhss) == 0: return self.visit(rhs).makeStatement() if len(lhss) == 1: return self.set(lhss[0], self.visit(rhs)) @@ -269,24 +272,38 @@ modnames = [] asnames = [] for modname, asname in names: if asname is None: asname = modname - self.set_name(asname, module.getattr(modname)) asnames.append(asname) modnames.append(modname) topmodname = jast.StringConstant(".".join(top)) - modnames = jast.FilledArray( + modnamesArray = jast.FilledArray( "String", map(lambda x: jast.StringConstant(x), modnames)) - asnames = jast.FilledArray( - "String", - map(lambda x: jast.StringConstant(x), asnames)) - return jast.InvokeStatic( - "org.python.core.imp", "importFromAs", - [topmodname, modnames, asnames, self.frame.frame]) + + do_import = jast.InvokeStatic("org.python.core.imp", "importFrom", + [topmodname, modnamesArray, + self.frame.frame]) + + if not self.imp_accu: + imp_accu = self.imp_accu = jast.Identifier("imp_accu") + self.makeFreeDecl("PyObject[]",imp_accu) + else: + imp_accu = self.imp_accu + + stmts = [jast.Set(imp_accu,do_import)] + + for i in range(len(asnames)): + asname = asnames[i] + modname = modnames[i] + code = jast.Subscript(imp_accu,i) + stmts.append(self.set_name(asname, + module.getattr(modname).makeReference(code))) + + return stmts #external interfaces def execstring(self, data): self.data = data from org.python.core import parser Index: SimpleCompiler.py =================================================================== RCS file: /cvsroot/jython/jython/Tools/jythonc/SimpleCompiler.py,v retrieving revision 2.14 diff -u -5 -r2.14 SimpleCompiler.py --- SimpleCompiler.py 2001/05/27 18:50:56 2.14 +++ SimpleCompiler.py 2001/07/27 16:23:06 @@ -251,10 +251,12 @@ self.nthrowables = 0 self.factory = factory self.options = options self.listComprehensionStack = [] + self.free_decls = [] + def isAlwaysFalse(self, name): if self.options is None: return 0 return name in self.options.falsenames @@ -279,11 +281,11 @@ futures.preprocessFutures(node,None) ScopesCompiler(self).parse(node) self.frame.setScope(node.scope) ret = BaseEvaluator.parse(self, node) #print 'parse', ret - decs = self.frame.getDeclarations() + decs = self.free_decls + self.frame.getDeclarations() if len(decs) != 0: return [decs, jast.SimpleComment('Code'), ret] else: return ret @@ -293,10 +295,13 @@ return self.factory.makePyObject(tmp), setit def freeTemp(self, tmp): self.frame.freetemp(tmp.asAny()) + def makeFreeDecl(self,type,value): + self.free_decls.append(jast.Declare(type,value)) + #primitive values def int_const(self, value): return self.factory.makeInteger(value) def long_const(self, value): @@ -433,22 +438,21 @@ self.set_name(name, module.getattr(name)) def import_stmt(self, names): ret = [] for dotted, asname in names: - modname = jast.StringConstant(".".join(dotted)) + modnameConst = jast.StringConstant(".".join(dotted)) if asname: - self.set_name(asname, self.get_module(dotted,0)) - asname = jast.StringConstant(asname) - ret.append(jast.InvokeStatic("org.python.core.imp", - "importOneAs", - [modname, asname, self.frame.frame])) + code = jast.InvokeStatic("org.python.core.imp","importOneAs", + [modnameConst, self.frame.frame]) + code = self.get_module(dotted,0).makeReference(code) + ret.append(self.set_name(asname,code)) else: - self.set_name(dotted[0], self.get_module(dotted,1)) - ret.append(jast.InvokeStatic("org.python.core.imp", - "importOne", - [modname, self.frame.frame])) + code = jast.InvokeStatic("org.python.core.imp","importOne", + [modnameConst, self.frame.frame]) + code = self.get_module(dotted,1).makeReference(code) + ret.append(self.set_name(dotted[0],code)) return ret def getSlice(self, index): indices = self.visitor.getSlice(index) Index: jast/Statement.py =================================================================== RCS file: /cvsroot/jython/jython/Tools/jythonc/jast/Statement.py,v retrieving revision 2.4 diff -u -5 -r2.4 Statement.py --- jast/Statement.py 2000/11/08 08:20:16 2.4 +++ jast/Statement.py 2001/07/27 16:23:06 @@ -561,10 +561,19 @@ def sourceString(self): return "%s%s" % (self.x.safeSourceString(), self.op) +class Subscript(UnsafeExpression): + def __init__(self, x, ind): + self.ind = ind + self.x = x + + def sourceString(self): + return "%s[%s]" % (self.x.safeSourceString(), self.ind) + + class InvokeLocal(Expression): def __init__(self, name, args): self.name = name self.args = args