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, [])
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'
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'
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'
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'
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.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
def sigToken(FUNCTYPE): """Return a token describing the signature of FUNCTYPE.""" # XXX: the right thing to do would be to have a way to # represent typeof(t) as a pbc args = [RCliGenOp.kindToken(T) for T in FUNCTYPE.ARGS] res = RCliGenOp.kindToken(FUNCTYPE.RESULT) funcclass = classof(FUNCTYPE) return SigToken(args, res, funcclass)
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'
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__')
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
def __init__(self, FUNC, ARGS, RESULT): DescrWithKey.__init__(self, (FUNC, ARGS, RESULT)) from pypy.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) 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
from pypy.jit.metainterp import history from pypy.jit.metainterp.history import AbstractDescr, AbstractMethDescr from pypy.jit.metainterp.history import AbstractFailDescr, LoopToken from pypy.jit.metainterp.history import Box, BoxInt, BoxObj, ConstObj, Const from pypy.jit.metainterp import executor from pypy.jit.metainterp.resoperation import rop, opname from pypy.jit.backend import model from pypy.jit.backend.llgraph.runner import KeyManager from pypy.translator.cli import dotnet from pypy.translator.cli.dotnet import CLR from pypy.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
from pypy.rpython.ootypesystem import ootype from pypy.rlib.objectmodel import specialize from pypy.jit.codegen.model import AbstractRGenOp, GenBuilder, GenLabel from pypy.jit.codegen.model import GenVarOrConst, GenVar, GenConst, CodeGenSwitch from pypy.jit.codegen.cli import operation as ops from pypy.jit.codegen.cli.dumpgenerator import DumpGenerator from pypy.translator.cli.dotnet import CLR, typeof, new_array, box, unbox, clidowncast, classof System = CLR.System Utils = CLR.pypy.runtime.Utils DelegateHolder = CLR.pypy.runtime.DelegateHolder OpCodes = System.Reflection.Emit.OpCodes DUMP_IL = False DEBUG = False cInt32 = classof(System.Int32) cBoolean = classof(System.Boolean) cObject = classof(System.Object) class SigToken: def __init__(self, args, res, funcclass): self.args = args self.res = res self.funcclass = funcclass def class2type(cls): 'Cast a PBC of type ootype.Class into a System.Type instance' return clidowncast(box(cls), System.Type) class __extend__(GenVarOrConst): __metaclass__ = extendabletype