Пример #1
0
    def getMethod(self, name, paramList, returnType):
        if isinstance(returnType, vartypes.Type):
            returnType = returnType.builder

        if returnType is None:
            # Only user types will not have builders at this point.
            # External classes never return user types.
            # If they could, it would be some sort of circular inter-program dependancy.
            # Thus, if the returnType has no builder, there cannot possibly be a match.
            return None

        if not isinstance(returnType, System.Type):
            returnType = ExternalType.getNineType(returnType).builder

        args = util.toTypedArray(System.Type, [util.getNetType(t) for t in paramList])

        assert None not in args, paramList

        methodInfo = self.builder.GetMethod(name, args)
        if methodInfo is None: return None

        if System.Object.ReferenceEquals(methodInfo.ReturnType, returnType):
            return ExternalMethod(self, methodInfo)
        else:
            return None
Пример #2
0
    def getMethod(self, name, paramList, returnType):
        if isinstance(returnType, vartypes.Type):
            returnType = returnType.builder

        if returnType is None:
            # Only user types will not have builders at this point.
            # External classes never return user types.
            # If they could, it would be some sort of circular inter-program dependancy.
            return None

        if not isinstance(returnType, System.Type):
            returnType = ExternalType.getNineType(returnType).builder

        args = util.toTypedArray(System.Type, [util.getNetType(t) for t in paramList])

        assert None not in args, paramList

        # IronPython hack: Querying MulticastDelegate for its Invoke method segfaults Mono for some reason.
        # -- andy 2 Feb 2014
        if self.builder == System.MulticastDelegate and name == 'Invoke':
            return None

        methodInfo = self.builder.GetMethod(name, args)
        if methodInfo is None:
            return None

        if System.Object.ReferenceEquals(methodInfo.ReturnType, returnType):
            return ExternalMethod(self, methodInfo)
        else:
            return None
    def emitLoad(self, gen):

        self.base.emitLoad(gen)
        gen.ilGen.Emit(gen.opCodes.Conv_R8)

        self.exp.emitLoad(gen)
        gen.ilGen.Emit(gen.opCodes.Conv_R8)

        powerMethod = util.getNetType(System.Math).GetMethod('Pow')
        gen.ilGen.Emit(gen.opCodes.Call, powerMethod)
Пример #4
0
    def emitCode(self, gen):
        consoleArgs = System.Array.CreateInstance(System.Type, 1)

        argType = self.arg.getType()
        assert argType is not None, self.arg

        if not isinstance(argType.builder, System.Reflection.Emit.TypeBuilder):
            consoleArgs[0] = argType.builder
        else:
            consoleArgs[0] = System.Object

        # This is silly.  Need to get a System.Type reference for the Console class.
        consoleType = util.getNetType(System.Console)

        mi = consoleType.GetMethod('WriteLine', consoleArgs)

        self.arg.emitLoad(gen)
        gen.ilGen.Emit(gen.opCodes.Call, mi)
Пример #5
0
    def getCtor(self, params):
        '''Returns a constructor that recieves the given set of parameters.

        params is a list that contains the types that the returned constructor
        recieves.

        (types, not Parameter instances!)
        '''
        paramTypes = util.toTypedArray(System.Type,
            [util.getNetType(param.getType()) for param in params]
        )

        ctorInfo = self.builder.GetConstructor(paramTypes)

        if ctorInfo is None:
            return None

        else:
            return ExternalConstructor(ctorInfo, self)
Пример #6
0
 def __init__(self, type):
     from nine import util
     self.type = util.getNetType(type)