def dumpCodes(self): self.constants.append([ "PyFunctionTable", self.getFunctionTable(), jast.New(self.name, []) ]) for label, name, code, frame in self.codes: code = frame.toCellPrepend(code) funcid = self.addFunctionCode(name, code) arglist = keyworddict = jast. False if frame.args_arglist(): arglist = jast. True if frame.args_keyworddict(): keyworddict = jast. True names = jast.StringArray(frame.getnames()) cellnames = StringArrayOrNull(frame.getcellnames()) freenames = StringArrayOrNull(frame.getfreenames()) npurecell = frame.get_npurecell() cargs = [ jast.IntegerConstant(frame.args_count()), names, jast.StringConstant(self.filename), jast.StringConstant(name), arglist, keyworddict, self.getFunctionTable(), jast.IntegerConstant(funcid), cellnames, freenames, jast.IntegerConstant(npurecell), jast.IntegerConstant((frame.opt_globals and CO_OPTIMIZED) | ( frame.scope.nested_scopes and CO_NESTED)) ] newcode = jast.InvokeStatic("Py", "newCode", cargs) self.constants.append(("PyCode", jast.Identifier(label), newcode))
def makeDictionary(self, items): lst = [] for key, value in items: lst.append(key) lst.append(value) code = jast.New("PyDictionary", [PyObjectArray(lst)]) return Object(code, Generic)
def mkcall(self, callee, args): if self.isConstructor: op = jast.New(self.name, args) elif self.isStatic: op = jast.InvokeStatic(callee, self.name, args) else: #print callee, self.name, args op = jast.Invoke(callee, self.name, args) return op, self.retType
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 dumpInitModule(self): meths = [] dict = jast.Identifier("dict") sargs = [ jast.StringConstant("__name__"), jast.New("PyString", [jast.StringConstant(self.name)]) ] rargs = [ jast.Invoke(jast.New("_PyInner", []), "getMain", []), dict, dict ] code = jast.Block([ jast.Invoke(dict, "__setitem__", sargs), jast.InvokeStatic("Py", "runCode", rargs) ]) meths.append( jast.Method("moduleDictInit", "public static", ["void", ("PyObject", "dict")], code)) return meths
def makeTuple(self, items): code = jast.New("PyTuple", [PyObjectArray(items)]) return Object(code, Generic)
def makeList(self, items): code = jast.New("PyList", [PyObjectArray(items)]) return Object(code, Generic)
def makeSlice(self, items): code = jast.New("PySlice", [items[0].asAny(), items[1].asAny(), items[2].asAny()]) return Object(code, Generic)