コード例 #1
0
ファイル: LanguageContext.cs プロジェクト: gavz/IronKit
        protected LanguageContext(ScriptDomainManager domainManager)
        {
            ContractUtils.RequiresNotNull(domainManager, nameof(domainManager));

            DomainManager = domainManager;
            ContextId     = domainManager.GenerateContextId();
        }
コード例 #2
0
 public TopNamespaceTracker(ScriptDomainManager manager)
     : base(null) {
     ContractUtils.RequiresNotNull(manager, "manager");
     SetTopPackage(this);
     _manager = manager;
     HierarchyLock = new object();
 }
コード例 #3
0
ファイル: LanguageContext.cs プロジェクト: rudimk/dlr-dotnet
        protected LanguageContext(ScriptDomainManager domainManager)
        {
            ContractUtils.RequiresNotNull(domainManager, "domainManager");

            _domainManager = domainManager;
            _id            = domainManager.GenerateContextId();
        }
コード例 #4
0
ファイル: DlrConfiguration.cs プロジェクト: jcteague/ironruby
        /// <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;
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        /// <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;
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: ScriptRuntime.cs プロジェクト: joshholmes/ironruby
        /// <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);
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
ファイル: ScriptRuntime.cs プロジェクト: jxnmaomao/ironruby
        /// <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);
            }
        }
コード例 #13
0
        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;
        }
コード例 #14
0
        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;
        }
コード例 #15
0
        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;
        }
コード例 #16
0
 // friend: ScriptDomainManager
 internal InvariantContext(ScriptDomainManager manager)
     : base(manager)
 {
     // TODO: use InvariantBinder
     Binder = new DefaultActionBinder(manager, Type.EmptyTypes);
 }
コード例 #17
0
ファイル: ActionBinder.cs プロジェクト: Jaykul/IronLangs
 protected ActionBinder(ScriptDomainManager manager) {
     _manager = manager;
 }
コード例 #18
0
ファイル: DefaultBinder.cs プロジェクト: jcteague/ironruby
 protected DefaultBinder(ScriptDomainManager manager)
     : base(manager) {
 }
コード例 #19
0
 public DefaultActionBinder(ScriptDomainManager manager, Type[] extensionTypes)
     : base(manager) {
     this._extensionTypes = extensionTypes;
 }
コード例 #20
0
 public ScopeAttributesWrapper(ScriptDomainManager manager) {
     _tracker = new TopNamespaceTracker(manager);
 }
コード例 #21
0
 public DefaultActionBinder(ScriptDomainManager manager, Type[] extensionTypes)
     : base(manager)
 {
     this._extensionTypes = extensionTypes;
 }
コード例 #22
0
 // friend: ScriptDomainManager
 internal InvariantContext(ScriptDomainManager manager)
     : base(manager) {
 }
コード例 #23
0
ファイル: DlrConfiguration.cs プロジェクト: gavz/IronKit
 internal bool TryLoadLanguage(ScriptDomainManager manager, in AssemblyQualifiedTypeName providerName, out LanguageContext language)
コード例 #24
0
 // friend: ScriptDomainManager
 internal InvariantContext(ScriptDomainManager manager)
     : base(manager)
 {
 }
コード例 #25
0
 public ScopeAttributesWrapper(ScriptDomainManager manager)
 {
     _tracker = new TopNamespaceTracker(manager);
 }