protected LanguageContext(ScriptDomainManager domainManager) { ContractUtils.RequiresNotNull(domainManager, nameof(domainManager)); DomainManager = domainManager; ContextId = domainManager.GenerateContextId(); }
public TopNamespaceTracker(ScriptDomainManager manager) : base(null) { ContractUtils.RequiresNotNull(manager, "manager"); SetTopPackage(this); _manager = manager; HierarchyLock = new object(); }
protected LanguageContext(ScriptDomainManager domainManager) { ContractUtils.RequiresNotNull(domainManager, "domainManager"); _domainManager = domainManager; _id = domainManager.GenerateContextId(); }
/// <summary> /// Must not be called under a lock as it can potentially call a user code. /// </summary> /// <exception cref="MissingTypeException"></exception> /// <exception cref="Microsoft.Scripting.InvalidImplementationException">The language context's implementation failed to instantiate.</exception> internal LanguageContext LoadLanguageContext(ScriptDomainManager domainManager, out bool alreadyLoaded) { if (_context == null) { // Let assembly load errors bubble out var assembly = domainManager.Platform.LoadAssembly(_providerName.AssemblyName.FullName); Type type = assembly.GetType(_providerName.TypeName); if (type == null) { throw new InvalidOperationException( string.Format( "Failed to load language '{0}': assembly '{1}' does not contain type '{2}'", _displayName, assembly.Location, _providerName.TypeName )); } if (!type.IsSubclassOf(typeof(LanguageContext))) { throw new InvalidOperationException( string.Format( "Failed to load language '{0}': type '{1}' is not a valid language provider because it does not inherit from LanguageContext", _displayName, type )); } var context = ReflectionUtils.CreateInstance<LanguageContext>(type, domainManager, _options); alreadyLoaded = Interlocked.CompareExchange(ref _context, context, null) != null; } else { alreadyLoaded = true; } return _context; }
/// <summary> /// Must not be called under a lock as it can potentially call a user code. /// </summary> /// <exception cref="InvalidImplementationException">The language context's implementation failed to instantiate.</exception> internal LanguageContext LoadLanguageContext(ScriptDomainManager domainManager, out bool alreadyLoaded) { if (_context == null) { // Let assembly load errors bubble out var assembly = domainManager.Platform.LoadAssembly(_providerName.AssemblyName.FullName); Type type = assembly.GetType(_providerName.TypeName); if (type == null) { throw new InvalidOperationException( String.Format( "Failed to load language '{0}': assembly '{1}' does not contain type '{2}'", _displayName, #if FEATURE_FILESYSTEM assembly.Location, #else assembly.FullName, #endif _providerName.TypeName )); } if (!type.GetTypeInfo().IsSubclassOf(typeof(LanguageContext))) { throw new InvalidOperationException( String.Format( "Failed to load language '{0}': type '{1}' is not a valid language provider because it does not inherit from LanguageContext", _displayName, type )); } LanguageContext context; try { context = (LanguageContext)Activator.CreateInstance(type, new object[] { domainManager, _options }); } catch (TargetInvocationException e) { throw new TargetInvocationException( String.Format("Failed to load language '{0}': {1}", _displayName, e.InnerException.Message), e.InnerException ); } catch (Exception e) { throw new InvalidImplementationException(Strings.InvalidCtorImplementation(type, e.Message), e); } alreadyLoaded = Interlocked.CompareExchange(ref _context, context, null) != null; } else { alreadyLoaded = true; } return(_context); }
internal bool TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName providerName, out LanguageContext language) { Assert.NotNull(manager); if (_languageConfigurations.TryGetValue(providerName, out LanguageConfiguration config)) { language = LoadLanguageContext(manager, config); return(true); } language = null; return(false); }
internal bool TryLoadLanguage(ScriptDomainManager manager, string str, bool isExtension, out LanguageContext language) { Assert.NotNull(manager, str); var dict = isExtension ? _languageExtensions : _languageNames; if (dict.TryGetValue(str, out LanguageConfiguration config)) { language = LoadLanguageContext(manager, config); return(true); } language = null; return(false); }
/// <summary> /// Must not be called under a lock as it can potentially call a user code. /// </summary> /// <exception cref="InvalidImplementationException">The language context's implementation failed to instantiate.</exception> internal LanguageContext LoadLanguageContext(ScriptDomainManager domainManager, out bool alreadyLoaded) { if (_context == null) { // Let assembly load errors bubble out var assembly = domainManager.Platform.LoadAssembly(_providerName.AssemblyName.FullName); Type type = assembly.GetType(_providerName.TypeName); if (type == null) { throw new InvalidOperationException( String.Format( "Failed to load language '{0}': assembly '{1}' does not contain type '{2}'", _displayName, #if FEATURE_FILESYSTEM && !WP75 && !WIN8 assembly.Location, #else assembly.FullName, #endif _providerName.TypeName )); } if (!type.GetTypeInfo().IsSubclassOf(typeof(LanguageContext))) { throw new InvalidOperationException( String.Format( "Failed to load language '{0}': type '{1}' is not a valid language provider because it does not inherit from LanguageContext", _displayName, type )); } LanguageContext context; try { context = (LanguageContext)Activator.CreateInstance(type, new object[] { domainManager, _options }); } catch (TargetInvocationException e) { throw new TargetInvocationException( String.Format("Failed to load language '{0}': {1}", _displayName, e.InnerException.Message), e.InnerException ); } catch (Exception e) { throw new InvalidImplementationException(Strings.InvalidCtorImplementation(type, e.Message), e); } alreadyLoaded = Interlocked.CompareExchange(ref _context, context, null) != null; } else { alreadyLoaded = true; } return _context; }
private LanguageContext LoadLanguageContext(ScriptDomainManager manager, LanguageConfiguration config) { var language = config.LoadLanguageContext(manager, out bool alreadyLoaded); if (!alreadyLoaded) { // Checks whether a single language is not registered under two different AQTNs. // We can only do it now because there is no way how to ensure that two AQTNs don't refer to the same type w/o loading the type. // The check takes place after config.LoadLanguageContext is called to avoid calling user code while holding a lock. lock (_loadedProviderTypes) { Type type = language.GetType(); if (_loadedProviderTypes.TryGetValue(type, out LanguageConfiguration existingConfig)) { throw new InvalidOperationException( $"Language implemented by type '{config.ProviderName}' has already been loaded using name '{existingConfig.ProviderName}'"); } _loadedProviderTypes.Add(type, config); } } return(language); }
/// <summary> /// Creates ScriptRuntime in the current app-domain and initialized according to the the specified settings. /// Creates an instance of host class specified in the setup and associates it with the created runtime. /// Both Runtime and ScriptHost are collocated in the current app-domain. /// </summary> public ScriptRuntime(ScriptRuntimeSetup setup) { ContractUtils.RequiresNotNull(setup, "setup"); // Do this first, so we detect configuration errors immediately DlrConfiguration config = setup.ToConfiguration(); _setup = setup; _host = ReflectionUtils.CreateInstance<ScriptHost>(setup.HostType, setup.HostArguments.ToArray<object>()); ScriptHostProxy hostProxy = new ScriptHostProxy(_host); _manager = new ScriptDomainManager(hostProxy, config); _invariantContext = new InvariantContext(_manager); _io = new ScriptIO(_manager.SharedIO); _engines = new Dictionary<LanguageContext, ScriptEngine>(); bool freshEngineCreated; _globals = new ScriptScope(GetEngineNoLockNoNotification(_invariantContext, out freshEngineCreated), _manager.Globals); // runtime needs to be all set at this point, host code is called _host.SetRuntime(this); }
/// <summary> /// Must not be called under a lock as it can potentially call a user code. /// </summary> /// <exception cref="MissingTypeException"></exception> /// <exception cref="Microsoft.Scripting.InvalidImplementationException">The language context's implementation failed to instantiate.</exception> internal LanguageContext LoadLanguageContext(ScriptDomainManager domainManager, out bool alreadyLoaded) { if (_context == null) { // Let assembly load errors bubble out var assembly = domainManager.Platform.LoadAssembly(_providerName.AssemblyName.FullName); Type type = assembly.GetType(_providerName.TypeName); if (type == null) { throw new InvalidOperationException( string.Format( "Failed to load language '{0}': assembly '{1}' does not contain type '{2}'", _displayName, assembly.Location, _providerName.TypeName )); } if (!type.IsSubclassOf(typeof(LanguageContext))) { throw new InvalidOperationException( string.Format( "Failed to load language '{0}': type '{1}' is not a valid language provider because it does not inherit from LanguageContext", _displayName, type )); } var context = ReflectionUtils.CreateInstance <LanguageContext>(type, domainManager, _options); alreadyLoaded = Interlocked.CompareExchange(ref _context, context, null) != null; } else { alreadyLoaded = true; } return(_context); }
/// <summary> /// Creates ScriptRuntime in the current app-domain and initialized according to the the specified settings. /// Creates an instance of host class specified in the setup and associates it with the created runtime. /// Both Runtime and ScriptHost are collocated in the current app-domain. /// </summary> public ScriptRuntime(ScriptRuntimeSetup setup) { ContractUtils.RequiresNotNull(setup, "setup"); // Do this first, so we detect configuration errors immediately DlrConfiguration config = setup.ToConfiguration(); _setup = setup; try { _host = (ScriptHost)Activator.CreateInstance(setup.HostType, setup.HostArguments.ToArray<object>()); } catch (TargetInvocationException e) { throw new InvalidImplementationException(Strings.InvalidCtorImplementation(setup.HostType, e.InnerException.Message), e.InnerException); } catch (Exception e) { throw new InvalidImplementationException(Strings.InvalidCtorImplementation(setup.HostType, e.Message), e); } ScriptHostProxy hostProxy = new ScriptHostProxy(_host); _manager = new ScriptDomainManager(hostProxy, config); _invariantContext = new InvariantContext(_manager); _io = new ScriptIO(_manager.SharedIO); _engines = new Dictionary<LanguageContext, ScriptEngine>(); bool freshEngineCreated; _globals = new ScriptScope(GetEngineNoLockNoNotification(_invariantContext, out freshEngineCreated), _manager.Globals); // runtime needs to be all set at this point, host code is called _host.SetRuntime(this); object noDefaultRefs; if (!setup.Options.TryGetValue("NoDefaultReferences", out noDefaultRefs) || Convert.ToBoolean(noDefaultRefs) == false) { LoadAssembly(typeof(string).Assembly); LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); } }
private LanguageContext LoadLanguageContext(ScriptDomainManager manager, LanguageConfiguration config) { bool alreadyLoaded; var language = config.LoadLanguageContext(manager, out alreadyLoaded); if (!alreadyLoaded) { // Checks whether a single language is not registered under two different AQTNs. // We can only do it now because there is no way how to ensure that two AQTNs don't refer to the same type w/o loading the type. // The check takes place after config.LoadLanguageContext is called to avoid calling user code while holding a lock. lock (_loadedProviderTypes) { LanguageConfiguration existingConfig; Type type = language.GetType(); if (_loadedProviderTypes.TryGetValue(type, out existingConfig)) { throw new InvalidOperationException(String.Format("Language implemented by type '{0}' has already been loaded using name '{1}'", config.ProviderName, existingConfig.ProviderName)); } _loadedProviderTypes.Add(type, config); } } return language; }
internal bool TryLoadLanguage(ScriptDomainManager manager, string str, bool isExtension, out LanguageContext language) { Assert.NotNull(manager, str); var dict = (isExtension) ? _languageExtensions : _languageNames; LanguageConfiguration config; if (dict.TryGetValue(str, out config)) { language = LoadLanguageContext(manager, config); return true; } language = null; return false; }
internal bool TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName providerName, out LanguageContext language) { Assert.NotNull(manager); LanguageConfiguration config; if (_languageConfigurations.TryGetValue(providerName, out config)) { language = LoadLanguageContext(manager, config); return true; } language = null; return false; }
// friend: ScriptDomainManager internal InvariantContext(ScriptDomainManager manager) : base(manager) { // TODO: use InvariantBinder Binder = new DefaultActionBinder(manager, Type.EmptyTypes); }
protected ActionBinder(ScriptDomainManager manager) { _manager = manager; }
protected DefaultBinder(ScriptDomainManager manager) : base(manager) { }
public DefaultActionBinder(ScriptDomainManager manager, Type[] extensionTypes) : base(manager) { this._extensionTypes = extensionTypes; }
public ScopeAttributesWrapper(ScriptDomainManager manager) { _tracker = new TopNamespaceTracker(manager); }
// friend: ScriptDomainManager internal InvariantContext(ScriptDomainManager manager) : base(manager) { }
internal bool TryLoadLanguage(ScriptDomainManager manager, in AssemblyQualifiedTypeName providerName, out LanguageContext language)