pypy / pypy / translator / jvm /

from pypy.rpython.ootypesystem import ootype
from pypy.rpython.lltypesystem import rffi
from pypy.translator.oosupport.metavm import MicroInstruction
from pypy.translator.jvm.typesystem import JvmScalarType, JvmClassType
import pypy.translator.jvm.typesystem as jvm
from pypy.translator.jvm.builtin import JvmBuiltInType
from pypy.translator.jvm import cmpopcodes

class _IndirectCall(MicroInstruction):
    def render(self, gen, op):
        interface = gen.db.lltype_to_cts(op.args[0].concretetype)
        method = interface.lookup_method('invoke')
IndirectCall = _IndirectCall()

class _JvmCallMethod(MicroInstruction):

    def _invoke_method(self, gen, db, jmethod, jactargs, args, jactres, res):
        assert len(args) == len(jactargs)
        for arg, jmthdty in zip(args, jactargs):
            # Load the argument on the stack:
            # Perform any boxing required:
            jargty = db.lltype_to_cts(arg.concretetype)
            if jargty != jmthdty:

        # Perform any unboxing required:
        jresty = db.lltype_to_cts(res.concretetype)
        if jresty != jactres:
    def render(self, gen, op):

        method = op.args[0] # a FlowConstant string...
        this = op.args[1]

        # Locate the java method we will be invoking:
        thisjtype = gen.db.lltype_to_cts(this.concretetype)
        jmethod = thisjtype.lookup_method(method.value)

        # if this is a builtin-type, the signature is exact and we
        # need to keep Void values; else, the signature does not
        # include Void values, so we need to drop them.
        if isinstance(thisjtype, JvmBuiltInType):
            args = op.args[2:]
            args = [arg for arg in op.args[2:] if arg.concretetype is not ootype.Void]

        # Ugly: if jmethod ends up being a static method, then
        # peel off the first argument
        jactargs = jmethod.argument_types
        if jmethod.is_static():
            jactargs = jactargs[1:]

        # Iterate through the arguments, inserting casts etc as required
        self._invoke_method(gen, gen.db, jmethod,
                            jactargs, args,
                            jmethod.return_type, op.result)
JvmCallMethod = _JvmCallMethod()

class _NewCustomDict(MicroInstruction):
    def _load_func(self, gen, fn, obj, method_name):
        db = gen.db
        if fn.value:
            # Standalone function: find the delegate class and
            # instantiate it.
            assert method_name.value is None
            smimpl = fn.value                      # ootype._static_meth
            db.record_delegate(smimpl._TYPE)       # _TYPE is a StaticMethod
            ty = db.record_delegate_standalone_func_impl(smimpl.graph)
            # Bound method: create a wrapper bound to the given
            # object, using the "bind()" static method that bound
            # method wrapper classes have.
            INSTANCE = obj.concretetype
            method_name = method_name.value._str
            ty = db.record_delegate_bound_method_impl(INSTANCE, method_name)
    def render(self, generator, op):
        self._load_func(generator, *op.args[1:4])
        self._load_func(generator, *op.args[4:7])
NewCustomDict = _NewCustomDict()

#   FROM                      TO
    (ootype.Signed,           ootype.UnsignedLongLong): jvm.I2L,
    (ootype.Unsigned,         ootype.UnsignedLongLong): jvm.I2L,
    (ootype.SignedLongLong,   ootype.Signed):           jvm.L2I,
    (ootype.UnsignedLongLong, ootype.Unsigned):         jvm.L2I,
    (ootype.UnsignedLongLong, ootype.Signed):           jvm.L2I,
    (ootype.Signed,           rffi.SHORT):              jvm.I2S,
    (ootype.Unsigned,         ootype.SignedLongLong):   jvm.PYPYUINTTOLONG,
    (ootype.UnsignedLongLong, ootype.SignedLongLong):   None,
    (ootype.SignedLongLong,   ootype.UnsignedLongLong): None,
    (ootype.Signed,           ootype.Unsigned):         None,
    (ootype.Unsigned,         ootype.Signed):           None,

class _CastPrimitive(MicroInstruction):
    def render(self, generator, op):
        FROM = op.args[0].concretetype
        TO = op.result.concretetype
        if TO == FROM:
        opcode = CASTS[(FROM, TO)]
        if opcode:
CastPrimitive = _CastPrimitive()

class _PushPyPy(MicroInstruction):
    """ Pushes the PyPy instance where our helper functions are found
    from the static field on the generated PyPyMain class """
    def render(self, generator, op):
PushPyPy = _PushPyPy()

class _PushComparisonResult(MicroInstruction):
    def render(self, generator, op):
        assert cmpopcodes.can_branch_directly(op.opname)
        truelbl = generator.unique_label('load_comparision_result_true')
        endlbl = generator.unique_label('load_comparision_result_end')
        cmpopcodes.branch_if(generator, op.opname, truelbl)
        generator.emit(jvm.ICONST, 0)
        generator.emit(jvm.ICONST, 1)
PushComparisonResult = _PushComparisonResult()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.