def getNew(self): globals = jast.GetInstanceAttribute(self.def_compiler.frame.frame, "f_globals") pycode = self.makeCode() defaults = [ self.def_compiler.visit(d) for d in self.scope.ac.defaults ] clos = self.def_compiler.frame.makeClosure(self.scope) ctrargs = [globals, PyObjectArray(defaults), pycode] if clos: ctrargs.append(PyObjectArray(clos)) return jast.New("PyFunction", ctrargs)
def visitTryExcept(self, node): if node.orelse is not None: elseBool = self.frame.gettemp("boolean") jbody = jast.Block(self.suite(node.body)) tests = [] ifelse = None tname = jast.Identifier("x$%d" % self.nthrowables) self.nthrowables = self.nthrowables + 1 exctmp = self.frame.gettemp("PyException") setexc = jast.Set(exctmp, jast.InvokeStatic("Py", "setException", [tname, self.frame.frame])) for exchandler in node.handlers: if exchandler.type is None: ifelse = jast.Block(self.suite(exchandler.body)) continue type = self.visit(exchandler.type) t = jast.InvokeStatic("Py", "matchException", [exctmp, type.asAny()]) newbody = [] if exchandler.name is not None: exceptionValue = self.factory.makePyObject( jast.GetInstanceAttribute(exctmp, "value")) newbody.append(self.set(exchandler.name, exceptionValue)) #print self.visit(ebody) newbody.append(self.suite(exchandler.body)) #print newbody #print jast.Block(newbody) tests.append( (t, jast.Block(newbody)) ) if ifelse is None: ifelse = jast.Throw(exctmp) if len(tests) == 0: catchBody = ifelse else: catchBody = jast.MultiIf(tests, ifelse) catchBody = [setexc, catchBody] if node.orelse is not None: catchBody = [jast.Set(elseBool, jast.False), catchBody] catchBody = jast.Block([catchBody]) self.frame.freetemp(exctmp) ret = jast.TryCatch(jbody, "Throwable", tname, catchBody) if node.orelse is not None: ret = jast.Block([jast.Set(elseBool, jast.True), ret, jast.If(elseBool, jast.Block(self.suite(node.orelse)))]) self.frame.freetemp(elseBool) return ret