本文整理汇总了C#中clojure.lang.CljCompiler.Ast.GenContext.WithNewDynInitHelper方法的典型用法代码示例。如果您正苦于以下问题:C# GenContext.WithNewDynInitHelper方法的具体用法?C# GenContext.WithNewDynInitHelper怎么用?C# GenContext.WithNewDynInitHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clojure.lang.CljCompiler.Ast.GenContext
的用法示例。
在下文中一共展示了GenContext.WithNewDynInitHelper方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public Type Compile(Type superType, Type stubType, IPersistentVector interfaces, bool onetimeUse, GenContext context)
{
if (_compiledType != null)
return _compiledType;
string publicTypeName = IsDefType || (_isStatic && Compiler.IsCompiling) ? InternalName : InternalName + "__" + RT.nextID();
//Console.WriteLine("DefFn {0}, {1}", publicTypeName, context.AssemblyBuilder.GetName().Name);
_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.COMPILE_STUB_CLASS, _baseType));
}
EmitConstantFieldDefs(_typeBuilder);
EmitKeywordCallsiteDefs(_typeBuilder);
DefineStaticConstructor(_typeBuilder);
if (SupportsMeta)
_metaField = _typeBuilder.DefineField("__meta", typeof(IPersistentMap), FieldAttributes.Public | FieldAttributes.InitOnly);
EmitClosedOverFields(_typeBuilder);
EmitProtocolCallsites(_typeBuilder);
_ctorInfo = EmitConstructor(_typeBuilder, superType);
if (_altCtorDrops > 0)
EmitFieldOnlyConstructor(_typeBuilder, superType);
if (SupportsMeta)
{
EmitNonMetaConstructor(_typeBuilder, superType);
EmitMetaFunctions(_typeBuilder);
}
EmitStatics(_typeBuilder);
EmitMethods(_typeBuilder);
//if (KeywordCallsites.count() > 0)
// EmitSwapThunk(_typeBuilder);
_compiledType = _typeBuilder.CreateType();
if (context.DynInitHelper != null)
context.DynInitHelper.FinalizeType();
// If we don't pick up the ctor after we finalize the type,
// we sometimes get a ctor which is not a RuntimeConstructorInfo
// This causes System.DynamicILGenerator.Emit(opcode,ContructorInfo) to blow up.
// The error says the ConstructorInfo is null, but there is a second case in the code.
// Thank heavens one can run Reflector on mscorlib.
ConstructorInfo[] cis = _compiledType.GetConstructors();
foreach (ConstructorInfo ci in cis)
{
if (ci.GetParameters().Length == CtorTypes().Length)
{
_ctorInfo = ci;
break;
}
}
return _compiledType;
}
finally
{
if (IsDefType)
Var.popThreadBindings();
}
}
finally
{
Var.popThreadBindings();
}
}
示例2: Compile
public Type Compile(Type superType, Type stubType, IPersistentVector interfaces, bool onetimeUse, GenContext context)
{
if (_compiledType != null)
return _compiledType;
string publicTypeName = IsDefType || (_isStatic && 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.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)
EmitFieldOnlyConstructor(_typeBuilder, superType);
if (SupportsMeta)
{
EmitNonMetaConstructor(_typeBuilder, superType);
EmitMetaFunctions(_typeBuilder);
}
EmitStatics(_typeBuilder);
EmitMethods(_typeBuilder);
//if (KeywordCallsites.count() > 0)
// EmitSwapThunk(_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();
}
}