Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a module.
        /// <c>dictionary</c> can be <c>null</c>
        /// </summary>
        /// <returns></returns>
        public IScriptModule CreateModule(string name, ScriptModuleKind kind, IAttributesCollection dictionary, params ICompiledCode[] compiledCodes)
        {
            Contract.RequiresNotNullItems(compiledCodes, "compiledCodes");

            ScriptCode[] script_codes = new ScriptCode[compiledCodes.Length];
            for (int i = 0; i < compiledCodes.Length; i++)
            {
                script_codes[i] = ScriptCode.FromCompiledCode(compiledCodes[i] as CompiledCode);
                if (script_codes[i] == null)
                {
                    throw new ArgumentException(Resources.RemoteCodeModuleComposition, String.Format("{0}[{1}]", "compiledCodes", i));
                }
            }

            return(_manager.CreateModule(name, kind, new Scope(dictionary), script_codes));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a module.
        /// <c>dictionary</c> can be <c>null</c>
        /// </summary>
        /// <returns></returns>
        public IScriptModule CreateModule(string name, ScriptModuleKind kind, IAttributesCollection dictionary, params ICompiledCode[] compiledCodes)
        {
            Contract.RequiresNotNullItems(compiledCodes, "compiledCodes");

            ScriptCode[] script_codes = new ScriptCode[compiledCodes.Length];
            for (int i = 0; i < compiledCodes.Length; i++) {
                script_codes[i] = ScriptCode.FromCompiledCode(compiledCodes[i] as CompiledCode);
                if (script_codes[i] == null) {
                    throw new ArgumentException(Resources.RemoteCodeModuleComposition, String.Format("{0}[{1}]", "compiledCodes", i));
                }
            }

            return _manager.CreateModule(name, kind, new Scope(dictionary), script_codes);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Compiles a list of source units into a single module.
 /// <c>options</c> can be <c>null</c>
 /// <c>errroSink</c> can be <c>null</c>
 /// <c>dictionary</c> can be <c>null</c>
 /// </summary>
 public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink, 
     IAttributesCollection dictionary, params SourceUnit[] sourceUnits)
 {
     return _manager.CompileModule(name, kind, new Scope(dictionary), options, errorSink, sourceUnits);
 }
 public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink, IAttributesCollection dictionary, params SourceUnit[] sourceUnits)
 {
     return(RemoteWrapper.WrapRemotable <IScriptModule>(_manager.Environment.CompileModule(name, kind, options, errorSink, dictionary, sourceUnits)));
 }
 public IScriptModule CreateModule(string name, ScriptModuleKind kind, IAttributesCollection dictionary, params ICompiledCode[] compiledCodes)
 {
     return(RemoteWrapper.WrapRemotable <IScriptModule>(_manager.Environment.CreateModule(name, kind, dictionary, compiledCodes)));
 }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Compiles a list of source units into a single module.
 /// <c>options</c> can be <c>null</c>
 /// <c>errroSink</c> can be <c>null</c>
 /// <c>dictionary</c> can be <c>null</c>
 /// </summary>
 public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink,
                                    IAttributesCollection dictionary, params SourceUnit[] sourceUnits)
 {
     return(_manager.CompileModule(name, kind, new Scope(dictionary), options, errorSink, sourceUnits));
 }
 public IScriptModule CompileModule(string name, ScriptModuleKind kind, CompilerOptions options, ErrorSink errorSink, IAttributesCollection dictionary, params SourceUnit[] sourceUnits) {
     return RemoteWrapper.WrapRemotable<IScriptModule>(_manager.Environment.CompileModule(name, kind, options, errorSink, dictionary, sourceUnits));
 }
 public IScriptModule CreateModule(string name, ScriptModuleKind kind, IAttributesCollection dictionary, params ICompiledCode[] compiledCodes) {
     return RemoteWrapper.WrapRemotable<IScriptModule>(_manager.Environment.CreateModule(name, kind, dictionary, compiledCodes));
 }