Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    def addClassDictInit(self):
        self.interfaces.append(org.python.core.ClassDictInit)

        namelist = jast.InvokeStatic(
            "Py", "java2py", [jast.StringArray(self.supermethods.keys())])

        code = jast.Invoke(jast.Identifier("dict"), "__setitem__",
                           [jast.StringConstant("__supernames__"), namelist])

        code = jast.Block([code])
        self.statements.append(
            jast.Method("classDictInit", "static public",
                        ["void", ("PyObject", "dict")], code))
Exemplo n.º 3
0
    def addPyProxyInterface(self):
        self.statements.append(
            jast.Declare('private PyInstance', jast.Identifier('__proxy')))
        code = jast.Set(jast.Identifier("__proxy"), jast.Identifier("inst"))
        code = jast.Block([code])
        self.statements.append(
            jast.Method("_setPyInstance", "public",
                        ["void", ("PyInstance", "inst")], code))
        code = jast.Block([jast.Return(jast.Identifier("__proxy"))])
        self.statements.append(
            jast.Method("_getPyInstance", "public", ["PyInstance"], code))

        self.statements.append(
            jast.Declare('private PySystemState',
                         jast.Identifier('__sysstate')))
        code = jast.Set(jast.Identifier("__sysstate"), jast.Identifier("inst"))
        code = jast.Block([code])
        self.statements.append(
            jast.Method("_setPySystemState", "public",
                        ["void", ("PySystemState", "inst")], code))
        code = jast.Block([jast.Return(jast.Identifier("__sysstate"))])
        self.statements.append(
            jast.Method("_getPySystemState", "public", ["PySystemState"],
                        code))

        frozen = self.module.getFrozen()
        this = jast.Identifier("this")
        initargs = [
            this,
            jast.StringConstant(self.modname),
            jast.StringConstant(self.name),
            jast.Identifier("args"), self.packages, self.properties, frozen,
            jast.StringArray(self.modules)
        ]

        initproxy = jast.InvokeStatic("Py", "initProxy", initargs)

        code = jast.Block([initproxy])
        self.statements.append(
            jast.Method("__initProxy__", "public",
                        ["void", ("Object[]", "args")], code))

        self.interfaces.append(org.python.core.PyProxy)
Exemplo n.º 4
0
    def dumpMain(self):
        meths = []
        if self.javamain:
            code = []
            newargs = jast.Identifier("newargs")
            code.append(
                jast.Declare("String[]", newargs,
                             jast.NewArray("String", ["args.length+1"])))
            code.append(
                jast.Set(jast.Identifier("newargs[0]"),
                         jast.StringConstant(self.name)))

            args = [
                jast.Identifier('args'),
                jast.IntegerConstant(0),
                jast.Identifier('newargs'),
                jast.IntegerConstant(1),
                jast.Identifier('args.length')
            ]
            code.append(
                jast.InvokeStatic("java.lang.System", "arraycopy", args))

            args = [
                jast.GetStaticAttribute(
                    self.getclassname(self.name + '.' + self.pyinner.name),
                    "class"),
                jast.Identifier('newargs'),
                self.getPackages(qual=1),
                self.getMainProperties(qual=1),
                self.getFrozen(),
                jast.StringArray(self.modules.keys())
            ]

            code.append([jast.InvokeStatic("Py", "runMain", args)])
            maincode = jast.Block(code)
            meths.append(
                jast.Method("main", "public static",
                            ["void", ("String[]", "args")], maincode,
                            ["java.lang.Exception"]))

        return meths
Exemplo n.º 5
0
def StringArrayOrNull(strs):
    if strs:
        return jast.StringArray(strs)
    else:
        return jast.Null
Exemplo n.º 6
0
 def dumpDictionary(self, dict, field):
     props = []
     for name, value in dict.items():
         props.append(name)
         props.append(value)
     return jast.Declare("static String[]", field, jast.StringArray(props))
Exemplo n.º 7
0
def makeStringArray(args):
    return Object(jast.StringArray(args),
                  findType(java.lang.Class.forName("[Ljava.lang.String;")))