Example #1
0
    def test_classof_compare(self):
        int32_a = classof(System.Int32)
        int32_b = classof(System.Int32)

        def fn():
            return int32_a is int32_b

        assert self.interpret(fn, [])
Example #2
0
 def test_mix_classof(self):
     a = classof(System.Int32)
     b = classof(FUNCTYPE)
     def fn(flag):
         if flag:
             x = a
         else:
             x = b
         return clidowncast(box(x), System.Type).get_Name()
     res = self.interpret(fn, [True])
     assert res == 'Int32'
Example #3
0
 def test_class2type(self):
     cInt32 = classof(System.Int32)
     cString = classof(System.String)
     def fn(flag):
         if flag:
             cls = cInt32
         else:
             cls = cString
         clitype = class2type(cls)
         return clitype.get_FullName()
     res = self.interpret(fn, [True])
     assert res == 'System.Int32'
Example #4
0
    def test_mix_classof(self):
        a = classof(System.Int32)
        b = classof(FUNCTYPE)

        def fn(flag):
            if flag:
                x = a
            else:
                x = b
            return clidowncast(box(x), System.Type).get_Name()

        res = self.interpret(fn, [True])
        assert res == 'Int32'
Example #5
0
    def test_class2type(self):
        cInt32 = classof(System.Int32)
        cString = classof(System.String)

        def fn(flag):
            if flag:
                cls = cInt32
            else:
                cls = cString
            clitype = class2type(cls)
            return clitype.get_FullName()

        res = self.interpret(fn, [True])
        assert res == 'System.Int32'
Example #6
0
    def __init__(self, FUNC, ARGS, RESULT, extrainfo=None):
        DescrWithKey.__init__(self, (FUNC, ARGS, RESULT))
        from rpython.jit.backend.llgraph.runner import boxresult, make_getargs
        getargs = make_getargs(FUNC.ARGS)

        def callfunc(funcbox, argboxes):
            funcobj = funcbox.getref(FUNC)
            funcargs = getargs(argboxes)
            res = funcobj(*funcargs)
            if RESULT is not ootype.Void:
                return boxresult(RESULT, res)

        self.callfunc = callfunc
        self.funcclass = dotnet.classof(FUNC)
        self.has_result = (FUNC.RESULT != ootype.Void)
        self.extrainfo = extrainfo
        if RESULT is ootype.Void:

            def get_errbox():
                return None
        elif isinstance(RESULT, ootype.OOType):

            def get_errbox():
                return BoxObj()
        else:

            def get_errbox():
                return BoxInt()

        self.get_errbox = get_errbox
Example #7
0
 def test_classof_external_assembly(self):
     utils_class = classof(Utils)
     def fn():
         utils_obj = box(utils_class)
         utils_type = clidowncast(utils_obj, System.Type)
         return utils_type.get_Name()
     assert self.interpret(fn, []) == 'Utils'
Example #8
0
 def test_classof(self):
     int32_class = classof(System.Int32)
     def fn():
         int32_obj = box(int32_class)
         int32_type = clidowncast(int32_obj, System.Type)
         return int32_type.get_Name()
     assert self.interpret(fn, []) == 'Int32'
Example #9
0
    def test_classof(self):
        int32_class = classof(System.Int32)

        def fn():
            int32_obj = box(int32_class)
            int32_type = clidowncast(int32_obj, System.Type)
            return int32_type.get_Name()

        assert self.interpret(fn, []) == 'Int32'
Example #10
0
    def test_classof_external_assembly(self):
        utils_class = classof(Utils)

        def fn():
            utils_obj = box(utils_class)
            utils_type = clidowncast(utils_obj, System.Type)
            return utils_type.get_Name()

        assert self.interpret(fn, []) == 'Utils'
Example #11
0
 def test_classof_functype(self):
     # this test is overridden in TestPythonnet
     c = classof(FUNCTYPE)
     def fn():
         obj = box(c)
         t = clidowncast(obj, System.Type)
         return t.get_Name()
     res = self.interpret(fn, [])
     assert res == 'DelegateType_int__int_2'
Example #12
0
 def test_classof_functype(self):
     # this test is overridden in TestPythonnet
     c = classof(FUNCTYPE)
     def fn():
         obj = box(c)
         t = clidowncast(obj, System.Type)
         return t.get_Name()
     res = self.interpret(fn, [])
     assert res.startswith('StaticMethod__')
Example #13
0
File: runner.py Project: sota/pypy
def get_class_for_type(T):
    if T is ootype.Void:
        return ootype.nullruntimeclass
    elif T is ootype.Signed:
        return dotnet.classof(System.Int32)
    elif T is ootype.Unsigned:
        return dotnet.classof(System.UInt32)
    elif T is ootype.Bool:
        return dotnet.classof(System.Boolean)
    elif T is ootype.Float:
        return dotnet.classof(System.Double)
##     elif T is ootype.String:
##         return dotnet.classof(System.String)
    elif T in (ootype.Char, ootype.UniChar):
        return dotnet.classof(System.Char)
    elif isinstance(T, ootype.OOType):
        return ootype.runtimeClass(T)
    else:
        assert False
Example #14
0
 def test_type2class(self):
     cInt32 = classof(System.Int32)
     def fn(flag):
         if flag:
             clitype = typeof(System.Int32)
         else:
             clitype = typeof(System.String)
         cls = type2class(clitype)
         return cls is cInt32
     res = self.interpret(fn, [True])
     assert res
Example #15
0
    def test_classof_functype(self):
        # this test is overridden in TestPythonnet
        c = classof(FUNCTYPE)

        def fn():
            obj = box(c)
            t = clidowncast(obj, System.Type)
            return t.get_Name()

        res = self.interpret(fn, [])
        assert res == 'DelegateType_int__int_2'
Example #16
0
    def test_classof_functype(self):
        # this test is overridden in TestPythonnet
        c = classof(FUNCTYPE)

        def fn():
            obj = box(c)
            t = clidowncast(obj, System.Type)
            return t.get_Name()

        res = self.interpret(fn, [])
        assert res.startswith('StaticMethod__')
Example #17
0
def get_class_for_type(T):
    if T is ootype.Void:
        return ootype.nullruntimeclass
    elif T is ootype.Signed:
        return dotnet.classof(System.Int32)
    elif T is ootype.Unsigned:
        return dotnet.classof(System.UInt32)
    elif T is ootype.Bool:
        return dotnet.classof(System.Boolean)
    elif T is ootype.Float:
        return dotnet.classof(System.Double)


##     elif T is ootype.String:
##         return dotnet.classof(System.String)
    elif T in (ootype.Char, ootype.UniChar):
        return dotnet.classof(System.Char)
    elif isinstance(T, ootype.OOType):
        return ootype.runtimeClass(T)
    else:
        assert False
Example #18
0
    def test_type2class(self):
        cInt32 = classof(System.Int32)

        def fn(flag):
            if flag:
                clitype = typeof(System.Int32)
            else:
                clitype = typeof(System.String)
            cls = type2class(clitype)
            return cls is cInt32

        res = self.interpret(fn, [True])
        assert res
Example #19
0
File: runner.py Project: sota/pypy
 def __init__(self, FUNC, ARGS, RESULT, extrainfo=None):
     DescrWithKey.__init__(self, (FUNC, ARGS, RESULT))
     from rpython.jit.backend.llgraph.runner import boxresult, make_getargs
     getargs = make_getargs(FUNC.ARGS)
     def callfunc(funcbox, argboxes):
         funcobj = funcbox.getref(FUNC)
         funcargs = getargs(argboxes)
         res = funcobj(*funcargs)
         if RESULT is not ootype.Void:
             return boxresult(RESULT, res)
     self.callfunc = callfunc
     self.funcclass = dotnet.classof(FUNC)
     self.has_result = (FUNC.RESULT != ootype.Void)
     self.extrainfo = extrainfo
     if RESULT is ootype.Void:
         def get_errbox():
             return None
     elif isinstance(RESULT, ootype.OOType):
         def get_errbox():
             return BoxObj()
     else:
         def get_errbox():
             return BoxInt()
     self.get_errbox = get_errbox
Example #20
0
from rpython.jit.metainterp import history
from rpython.jit.metainterp.history import AbstractDescr, AbstractMethDescr
from rpython.jit.metainterp.history import AbstractFailDescr, LoopToken
from rpython.jit.metainterp.history import Box, BoxInt, BoxObj, ConstObj, Const
from rpython.jit.metainterp import executor
from rpython.jit.metainterp.resoperation import rop, opname
from rpython.jit.backend import model
from rpython.jit.backend.llgraph.runner import KeyManager
from rpython.translator.cli import dotnet
from rpython.translator.cli.dotnet import CLR
from rpython.jit.metainterp.typesystem import oohelper

System = CLR.System
OpCodes = System.Reflection.Emit.OpCodes
InputArgs = CLR.pypy.runtime.InputArgs
cpypyString = dotnet.classof(CLR.pypy.runtime.String)

LoopToken.cliloop = None
AbstractFailDescr._loop_token = None
AbstractFailDescr._guard_op = None


class CliLoop(object):
    def __init__(self, name, inputargs, operations):
        self.name = name
        self.inputargs = inputargs
        self.operations = operations
        self.guard2ops = {}  # guard_op --> (inputargs, operations)
        self.funcbox = None
        self.methcount = 0
Example #21
0
 def test_classof_compare(self):
     int32_a = classof(System.Int32)
     int32_b = classof(System.Int32)
     def fn():
         return int32_a is int32_b
     assert self.interpret(fn, [])
Example #22
0
File: runner.py Project: sota/pypy
from rpython.jit.metainterp import history
from rpython.jit.metainterp.history import AbstractDescr, AbstractMethDescr
from rpython.jit.metainterp.history import AbstractFailDescr, LoopToken
from rpython.jit.metainterp.history import Box, BoxInt, BoxObj, ConstObj, Const
from rpython.jit.metainterp import executor
from rpython.jit.metainterp.resoperation import rop, opname
from rpython.jit.backend import model
from rpython.jit.backend.llgraph.runner import KeyManager
from rpython.translator.cli import dotnet
from rpython.translator.cli.dotnet import CLR
from rpython.jit.metainterp.typesystem import oohelper

System = CLR.System
OpCodes = System.Reflection.Emit.OpCodes
InputArgs = CLR.pypy.runtime.InputArgs
cpypyString = dotnet.classof(CLR.pypy.runtime.String)

LoopToken.cliloop = None
AbstractFailDescr._loop_token = None
AbstractFailDescr._guard_op = None

class CliLoop(object):
    
    def __init__(self, name, inputargs, operations):
        self.name = name
        self.inputargs = inputargs
        self.operations = operations
        self.guard2ops = {}  # guard_op --> (inputargs, operations)
        self.funcbox = None
        self.methcount = 0