def callConstructor(self, access, sig, throws=[], dosuper=1): args = [] argids = [] objects = [] throws = filterThrows(throws) for c in sig: if isinstance(c, TupleType): argname = c[1] c = c[0] else: argname = "arg" + str(len(argids)) args.append((typeName(c), argname)) argid = jast.Identifier(argname) argids.append(argid) objects.append(makeObject(argid, c)) objects = jast.FilledArray("Object", objects) stmts = [] this = jast.Identifier("this") if dosuper: supercall = jast.InvokeLocal("super", argids) else: supercall = jast.InvokeLocal("super", []) ## for saccess, ssig in self.jconstructors: ## if len(ssig) == len(sig): ## supercall = jast.InvokeLocal("super", argids) ## break ## else: ## supercall = jast.InvokeLocal("super", []) frozen = self.module.getFrozen() initargs = [objects] initproxy = jast.InvokeLocal("__initProxy__", initargs) code = jast.Block([supercall, initproxy]) self.statements.append( jast.Constructor(self.name, jast.Modifier.ModifierString(access), args, code, throws))
def visitListComp(self, node): # Since this code generated here is placed in its own # java method, we need a new set of temp vrbls. oldtmps = self.frame.temporaries self.frame.temporaries = {} lst = self.factory.makeList([]) lsttmp, lstcode = self.makeTemp(lst) append = self.factory.makePyObject(jast.Invoke(lsttmp.asAny(), "__getattr__", [jast.StringConstant("append")])) appendtmp, appendcode = self.makeTemp(append) self.list_comprehension_count += 1 tmp_append = "_[%d]" % self.list_comprehension_count #tmp_append = "_[1]" n = ast.Expr(ast.Call(ast.Name(tmp_append, ast.Name.Load, node), [ node.elt ], [], None, None, node), node); for lc in node.generators[::-1]: for ifs in lc.ifs[::-1]: n = ast.If(ifs, [ n ], None, ifs); n = ast.For(lc.target, lc.iter, [ n ], None, lc); #visit(new Delete(new exprType[] { new Name(tmp_append, Name.Del) })); stmts = [ lstcode ] stmts.append(self.set_name(tmp_append, append)) #stmts.append(appendcode) stmts.append(self.visit(n)) stmts.append(jast.Return(lsttmp.asAny())) decs = self.frame.getDeclarations() if len(decs) != 0: stmts.insert(0, decs) idx = self.module.addFunctionCode("__listcomprehension", jast.Block(stmts)) self.freeTemp(lsttmp) self.freeTemp(appendtmp) self.frame.temporaries = oldtmps return self.factory.makePyObject( jast.InvokeLocal("__listcomprehension$%d" % (idx+1), [jast.Identifier("frame")]))
def list_comprehension(self, node): # Since this code generated here is placed in its own # java method, we need a new set of temp vrbls. oldtmps = self.frame.temporaries self.frame.temporaries = {} expr = node.getChild(0) suite = node.getChild(1) lst = self.factory.makeList([]) lsttmp, lstcode = self.makeTemp(lst) append = self.factory.makePyObject( jast.Invoke(lsttmp.asAny(), "__getattr__", [jast.StringConstant("append")])) appendtmp, appendcode = self.makeTemp(append) self.listComprehensionStack.append((appendtmp, expr)) stmts = [lstcode, appendcode] stmts.append(self.visit(suite)) stmts.append(jast.Return(lsttmp.asAny())) decs = self.frame.getDeclarations() if len(decs) != 0: stmts.insert(0, decs) self.listComprehensionStack.pop(-1) idx = self.module.addFunctionCode("__listcomprehension", jast.Block(stmts)) self.freeTemp(lsttmp) self.freeTemp(appendtmp) self.frame.temporaries = oldtmps return self.factory.makePyObject( jast.InvokeLocal("__listcomprehension$%d" % (idx + 1), [jast.Identifier("frame")]))