예제 #1
0
    def emitType(self, gen):
        # Redundant calls to emitType have no effect.
        if self.builder is not None: return

        log.write('emit', 'emitType class ', self, self.name)

        from CLR import System

        flags = gen.TypeAttributes.Public

        if self.flags.abstract:
            flags |= gen.TypeAttributes.Abstract
        if self.flags.sealed:
            flags |= gen.TypeAttributes.Sealed

        # Be sure everybody gets their builders built.
        self.baseClass.emitType(gen)
        for iface in self.baseInterfaces:
            iface.emitType(gen)

        ifaces = util.toTypedArray(System.Type, [iface.builder for iface in self.baseInterfaces])

        assert self.baseClass is not None, self
        assert self.baseClass.builder is not None, self.baseClass
        assert None not in ifaces, self.baseInterfaces

        self.builder = gen.module.DefineType(self.name, flags, self.baseClass.builder, ifaces)
예제 #2
0
    def emitType(self, gen):
        if self.builder is not None: return

        log.write('emit', 'emitType iface ', self, self.name)

        flags = gen.TypeAttributes.Interface | gen.TypeAttributes.Abstract | gen.TypeAttributes.Public

        ifaces = util.toTypedArray(System.Type, [iface.builder for iface in self.bases])

        self.builder = gen.module.DefineType(self.name, flags, None, ifaces)
예제 #3
0
    def emitCode(self, gen):
        log.write('emit', 'emitCode class ', self, self.name)

        subGen = CodeGenerator(gen)
        subGen.typeBuilder = self.builder

        for decl in self.body.decls:
            decl.emitCode(subGen)

        self.builder.CreateType()
예제 #4
0
    def semantic(self, scope):
        localScope = Scope(parent=scope)

        newBody = []

        for child in self.children:
            newBody.append(child.semantic(localScope))
            log.write('semantic', 'BlockStatement.semantic:\n\t%r\n\t%r' % (child, newBody[-1]))

        return BlockStatement(newBody)
예제 #5
0
    def emitDeclaration(self, gen):
        from nine.codegenerator import CodeGenerator

        if self.__emitDecls: return
        self.__emitDecls = True

        log.write('emit', 'emitDeclaration iface ', self, self.name)

        subGen = CodeGenerator(gen)
        subGen.typeBuilder = self.builder

        for decl in self.body.decls:
            decl.emitDeclaration(subGen)
예제 #6
0
    def emitCode(self, gen):
        from nine.codegenerator import CodeGenerator

        log.write('emit', 'emitCode func', self, self.name)

        assert self.builder is not None, (self, self.name, self.klass)

        subGen = CodeGenerator(gen)
        subGen.ilGen = self.builder.GetILGenerator()
        subGen.methodBuilder = self.builder

        if not self.flags.abstract:
            self.body.emitCode(subGen)
            subGen.ilGen.Emit(subGen.opCodes.Ret)
예제 #7
0
    def emitDeclaration(self, gen):
        from CLR import System

        if self.builder is not None: return

        log.write('emit', 'emitDeclaration func ', self, self.name, self.flags)

        params = System.Array.CreateInstance(System.Type, len(self.params))

        for index, param in enumerate(self.params):
            type = param.type
            assert type is not None, "Internal error: type deduction isn't quite there yet."
            assert type.builder is not None
            params[index] = type.builder

        flagMap = {
            'static' : gen.MethodAttributes.Static,
            'virtual' : gen.MethodAttributes.Virtual,
            'override' : gen.MethodAttributes.Virtual,
            'abstract' : gen.MethodAttributes.Abstract | gen.MethodAttributes.Virtual,
            'sealed' : gen.MethodAttributes.Final,

            'newslot' : gen.MethodAttributes.NewSlot, # TODO: eradicate
        }

        flags = gen.MethodAttributes.Public

        for flag in self.flags:
            flags |= flagMap[flag]

        if self.klass is None:
            flags |= gen.MethodAttributes.Static

        self.builder = gen.typeBuilder.DefineMethod(
            self.name,
            flags,
            self.returnType.builder,
            params
        )
예제 #8
0
    def emitDeclaration(self, gen):
        from CLR.System.Reflection.Emit import CustomAttributeBuilder

        if self.__declsBuilt: return
        self.__declsBuilt = True

        log.write('emit', 'emitDeclaration class ', self, self.name)

        for attr in self.attributes:
            ctorInfo = attr.className.builder.GetConstructor([])
            attrBuilder = CustomAttributeBuilder(ctorInfo, [])
            self.builder.SetCustomAttribute(attrBuilder)

        # Be sure base classes get their stuff done before us.
        self.baseClass.emitDeclaration(gen)
        for iface in self.baseInterfaces:
            iface.emitDeclaration(gen)

        subGen = CodeGenerator(gen)
        subGen.typeBuilder = self.builder

        for decl in self.body.decls:
            decl.emitDeclaration(subGen)
예제 #9
0
 def emitCode(self, gen):
     log.write('emit', 'emitType iface ', self, self.name)
     # Interfaces have no method implementations, so just bake it.
     self.builder.CreateType()