public static DynamicContext Create()
{
if (dc != null)
{
return(dc);
}
lock (compiler_initializer) {
if (dc != null)
{
return(dc);
}
var settings = new Compiler.CompilerSettings()
{
WarningLevel = 0
};
var cc = new Compiler.CompilerContext(settings, ErrorPrinter.Instance)
{
IsRuntimeBinder = true
};
//
// Any later loaded assemblies are handled internally by GetAssemblyDefinition
// domain.AssemblyLoad cannot be used as that would be too destructive as we
// would hold all loaded assemblies even if they can be never visited
//
// TODO: Remove this code and rely on GetAssemblyDefinition only
//
var module = new Compiler.ModuleContainer(cc);
module.HasTypesFullyDefined = true;
// Setup fake assembly, it's used mostly to simplify checks like friend-access
var temp = new Compiler.AssemblyDefinitionDynamic(module, "dynamic");
module.SetDeclaringAssembly(temp);
var importer = new Compiler.ReflectionImporter(module, cc.BuiltinTypes)
{
IgnorePrivateMembers = false,
IgnoreCompilerGeneratedField = false
};
// Import all currently loaded assemblies
// TODO: Rewrite this to populate type cache on-demand, that should greatly
// reduce our start-up cost
var domain = AppDomain.CurrentDomain;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
importer.ImportAssembly(a, module.GlobalRootNamespace);
}
cc.BuiltinTypes.CheckDefinitions(module);
module.InitializePredefinedTypes();
dc = new DynamicContext(module, importer);
}
return(dc);
}