clojure.lang.CljCompiler.Ast.ObjExpr.Compile C# (CSharp) Method

Compile() private method

private Compile ( Type superType, Type stubType, IPersistentVector interfaces, bool onetimeUse, GenContext context ) : Type
superType System.Type
stubType System.Type
interfaces IPersistentVector
onetimeUse bool
context GenContext
return System.Type
        public Type Compile(Type superType, Type stubType, IPersistentVector interfaces, bool onetimeUse, GenContext context)
        {
            if (CompiledType != null)
                return CompiledType;

            string publicTypeName = IsDefType /* || (CanBeDirect && Compiler.IsCompiling) */ ? InternalName : InternalName + "__" + RT.nextID();

            TypeBuilder = context.AssemblyGen.DefinePublicType(publicTypeName, superType, true);
            context = context.WithNewDynInitHelper().WithTypeBuilder(TypeBuilder);

            Var.pushThreadBindings(RT.map(Compiler.CompilerContextVar, context));

            try
            {
                if (interfaces != null)
                {
                    for (int i = 0; i < interfaces.count(); i++)
                        TypeBuilder.AddInterfaceImplementation((Type)interfaces.nth(i));
                }

                ObjExpr.MarkAsSerializable(TypeBuilder);
                GenInterface.SetCustomAttributes(TypeBuilder, ClassMeta);

                try
                {
                    if (IsDefType)
                    {
                        Compiler.RegisterDuplicateType(TypeBuilder);

                        Var.pushThreadBindings(RT.map(
                            Compiler.CompileStubOrigClassVar, stubType,
                            Compiler.CompilingDefTypeVar, true
                            ));
                        //,
                        //Compiler.COMPILE_STUB_CLASS, _baseType));
                    }
                    EmitConstantFieldDefs(TypeBuilder);
                    EmitKeywordCallsiteDefs(TypeBuilder);

                    DefineStaticConstructor(TypeBuilder);

                    if (SupportsMeta)
                        MetaField = TypeBuilder.DefineField("__meta", typeof(IPersistentMap), FieldAttributes.Public | FieldAttributes.InitOnly);

                    // If this IsDefType, then it has already emitted the closed-over fields on the base class.
                    if ( ! IsDefType )
                        EmitClosedOverFields(TypeBuilder);
                    EmitProtocolCallsites(TypeBuilder);

                    CtorInfo = EmitConstructor(TypeBuilder, superType);

                    if (AltCtorDrops > 0)
                        EmitFieldOnlyConstructors(TypeBuilder, superType);

                    if (SupportsMeta)
                    {
                        EmitNonMetaConstructor(TypeBuilder, superType);
                        EmitMetaFunctions(TypeBuilder);
                    }

                    EmitStatics(TypeBuilder);
                    EmitMethods(TypeBuilder);

                    CompiledType = TypeBuilder.CreateType();

                    if (context.DynInitHelper != null)
                        context.DynInitHelper.FinalizeType();

                    CtorInfo = GetConstructorWithArgCount(CompiledType, CtorTypes().Length);

                    return CompiledType;
                }
                finally
                {
                    if (IsDefType)
                        Var.popThreadBindings();
                }
            }
            finally
            {
                Var.popThreadBindings();
            }
        }