Exemplo n.º 1
0
        /// <summary>
        /// Called only from OptimizedModuleGenerator. ModuleContext will be set later.
        /// </summary>
        internal CodeContext(Scope scope, LanguageContext languageContext)
        {
            Assert.NotNull(scope, languageContext);

            _languageContext = languageContext;
            _moduleContext = null;
            _scope = scope;
        }
Exemplo n.º 2
0
        public CodeContext(Scope scope, LanguageContext languageContext, ModuleContext moduleContext)
        {
            Assert.NotNull(scope, languageContext, moduleContext);

            _languageContext = languageContext;
            _moduleContext = moduleContext;
            _scope = scope;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a ScriptModule consisting of multiple ScriptCode blocks (possibly with each
        /// ScriptCode block belonging to a different language). 
        /// Can ONLY be called from ScriptDomainManager.CreateModule factory (due to host notification).
        /// </summary>
        internal ScriptModule(string name, ScriptModuleKind kind, Scope scope, ScriptCode[] codeBlocks) {
            Assert.NotNull(name, scope, codeBlocks);
            Assert.NotNull(codeBlocks);

            _codeBlocks = ArrayUtils.Copy(codeBlocks);
            _name = name;
            _scope = scope;
            _kind = kind;
            _moduleContexts = ModuleContext.EmptyArray;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new Scope with the provided parent, dictionary and visibility.
 /// </summary>
 public Scope(Scope parent, IAttributesCollection dictionary, bool isVisible) {
     _parent = parent;
     _dict = dictionary ?? new SymbolDictionary();
     //_isVisible = isVisible;
     //_temps = null;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new Scope with the provided parent and dictionary.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="dictionary"></param>
 public Scope(Scope parent, IAttributesCollection dictionary)
     : this(parent, dictionary, true) {
 }
Exemplo n.º 6
0
 private Scope CloneForTemporaries() {
     Scope s = new Scope();
     s._parent = _parent;
     s._dict = _dict;
     s._attrs = _attrs;
     s._contextScopes = _contextScopes;
     s._isVisible = _isVisible;
     return s;
 }
        private List<Scope> GenerateScriptScopes()
        {
            List<Scope> scopes = new List<Scope>(_scriptCodes.Length);
            ScriptModule sm = ScriptDomainManager.CurrentManager.Host.DefaultModule as ScriptModule;
            for (int i = 0; i < _scriptCodes.Length; i++) {
                ScriptCode scriptCode = _scriptCodes[i];

                // Force creation of names used in other script codes into all optimized dictionaries
                ScopeAllocator allocator = _allocators[scriptCode.LanguageContext];
                IAttributesCollection iac = CreateLanguageDictionary(scriptCode.LanguageContext, allocator);
                Scope scope = new Scope(sm.Scope, iac);

                // module context is filled later:
                CodeContext codeContext = new CodeContext(scope, scriptCode.LanguageContext);

                IModuleDictionaryInitialization ici = iac as IModuleDictionaryInitialization;
                if (ici != null) {
                    ici.InitializeModuleDictionary(codeContext);
                }

                scopes.Add(scope);
                _codeContexts.Add(codeContext);
            }
            return scopes;
        }
Exemplo n.º 8
0
        public object Run(Scope scope, ModuleContext moduleContext, bool tryEvaluate) {
            Contract.RequiresNotNull(scope, "scope");
            Contract.RequiresNotNull(moduleContext, "moduleContext");

            return Run(new CodeContext(scope, _languageContext, moduleContext), tryEvaluate);
        }
Exemplo n.º 9
0
 public object Run(Scope scope, ModuleContext moduleContext) {
     return Run(scope, moduleContext, false);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Module creation factory. The only way how to create a module.
        /// Modules compiled from a single source file unit get <see cref="ScriptModule.FileName"/> property set to a host 
        /// normalized full path of that source unit. The property is set to a <c>null</c> reference for other modules.
        /// <c>scope</c> can be <c>null</c>.
        /// 
        /// Ensures creation of module contexts for all languages whose code is assembled into the module.
        /// </summary>
        public ScriptModule CreateModule(string name, ScriptModuleKind kind, Scope scope, params ScriptCode[] scriptCodes)
        {
            Contract.RequiresNotNull(name, "name");
            Contract.RequiresNotNullItems(scriptCodes, "scriptCodes");

            CodeGen.SymbolWriters.Clear();

            OptimizedModuleGenerator generator = null;

            if (scope == null) {
                if (scriptCodes.Length > 0) {
                    if (scriptCodes[0].LanguageContext.Engine.Options.InterpretedMode) {
                        scope = new Scope();
                    } else {
                        generator = OptimizedModuleGenerator.Create(name, scriptCodes);
                        scope = generator.GenerateScope();
                    }
                } else {
                    scope = new Scope();
                }
            }

            ScriptModule result = new ScriptModule(name, kind, scope, scriptCodes);

            CodeGen.SymbolWriters.Clear();

            {
              if (name == "ironscheme.boot.new")
              {
                return result;
              }
            }

            // single source file unit modules have unique full path:
            if (scriptCodes.Length == 1) {
                result.FileName = scriptCodes[0].SourceUnit.Id;
            } else {
                result.FileName = null;
            }

            // Initializes module contexts for all contained optimized script codes;
            // Module contexts stored in optimized module's code contexts cannot be changed from now on.
            // Such change would require the CodeContexts to be overwritten.
            if (generator != null) {
                generator.BindGeneratedCodeToModule(result);
            } else {
                foreach (ScriptCode code in scriptCodes) {
                    code.LanguageContext.EnsureModuleContext(result);
                }
            }

            _host.ModuleCreated(result);
            return result;
        }
Exemplo n.º 11
0
 public ScriptModule CreateModule(string name, Scope scope, params ScriptCode[] scriptCodes)
 {
     return CreateModule(name, ScriptModuleKind.Default, scope, scriptCodes);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Module creation factory. The only way how to create a module.
 /// <c>scope</c> can be <c>null</c>.
 /// </summary>
 public ScriptModule CreateModule(string name, Scope scope)
 {
     return CreateModule(name, scope, ScriptCode.EmptyArray);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Compiles a list of source units into a single module.
        /// <c>scope</c> can be <c>null</c>.
        /// <c>options</c> can be <c>null</c>.
        /// <c>errorSink</c> can be <c>null</c>.
        /// </summary>
        public ScriptModule CompileModule(string name, ScriptModuleKind kind, Scope scope, CompilerOptions options, ErrorSink errorSink, 
            params SourceUnit[] sourceUnits)
        {
            Contract.RequiresNotNull(name, "name");
            Contract.RequiresNotNullItems(sourceUnits, "sourceUnits");

            // TODO: Two phases: parse/compile?

            // compiles all source units:
            ScriptCode[] scriptCodes = new ScriptCode[sourceUnits.Length];
            for (int i = 0; i < sourceUnits.Length; i++) {
                scriptCodes[i] = LanguageContext.FromEngine(sourceUnits[i].Engine).CompileSourceCode(sourceUnits[i], options, errorSink);
            }

            return CreateModule(name, kind, scope, scriptCodes);
        }