Exemplo n.º 1
0
        private ScopeAllocator CreateStorageAllocator(ScriptCode scriptCode)
        {
            ScopeAllocator allocator;

            if (!_allocators.TryGetValue(scriptCode.LanguageContext, out allocator))
            {
                var sf  = CreateSlotFactory(scriptCode) as StaticFieldSlotFactory;
                var mgf = new ModuleGlobalFactory(sf);
                var sf2 = new StaticFieldSlotFactory(sf.TypeGen);
                GlobalFieldAllocator gfa = new GlobalFieldAllocator(mgf);
                var gfa2 = new GlobalFieldAllocator(sf2);

                // Locals and globals are allocated from the same namespace for optimized modules
                ScopeAllocator global = new ScopeAllocator(null, gfa);
                allocator = new ScopeAllocator(global, gfa2);

                _allocators[scriptCode.LanguageContext] = allocator;
            }

            return(allocator);
        }
Exemplo n.º 2
0
        protected override SlotFactory CreateSlotFactory(ScriptCode scriptCode)
        {
            AssemblyGen ag = null;

            if (scriptCode.SourceUnit.Kind == SourceCodeKind.Default && scriptCode.CodeBlock.Name != "ironscheme.boot.new")
            {
                if (ScriptDomainManager.Options.DebugMode)
                {
                    if ((ScriptDomainManager.Options.AssemblyGenAttributes & AssemblyGenAttributes.SaveAndReloadAssemblies) != 0)
                    {
                        ag = ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly;
                        //CreateModuleAssembly(scriptCode);
                    }
                    else
                    {
                        ag = ScriptDomainManager.CurrentManager.Snippets.DebugAssembly;
                    }
                }
                else
                {
                    if ((ScriptDomainManager.Options.AssemblyGenAttributes & AssemblyGenAttributes.SaveAndReloadAssemblies) != 0)
                    {
                        ag = ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly;
                        //CreateModuleAssembly(scriptCode);
                    }
                    else
                    {
                        ag = ScriptDomainManager.CurrentManager.Snippets.Assembly;
                    }
                }
            }
            else
            {
                ag = ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly; //CreateModuleAssembly(scriptCode);
            }

            ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly = ag;

            TypeGen tg = GenerateModuleGlobalsType(ag, scriptCode);

            if (scriptCode.LibraryGlobals != null)
            {
                foreach (var kvp in scriptCode.LibraryGlobals)
                {
                    var k = kvp.Key;
                    var v = kvp.Value;

                    var cg = v.Block.CreateGlobalMethodStub(tg);

                    if (cg != null)
                    {
                        CodeGen._codeBlockStubs[v.Block] = cg;
                        CodeGen._codeBlockLookup[k]      = cg;
                    }
                }
            }

            if (scriptCode.LibraryGlobalsX != null)
            {
                foreach (var kvp in scriptCode.LibraryGlobalsX)
                {
                    var k = kvp.Key;
                    var v = kvp.Value;

                    var cg = v.Block.CreateGlobalMethodStub(tg);

                    if (cg != null)
                    {
                        CodeGen._codeBlockStubsX[v.Block] = cg;
                        CodeGen._codeBlockLookupX[k]      = cg;
                    }
                }
            }

            if (scriptCode.LibraryGlobalsN != null)
            {
                foreach (var kvp in scriptCode.LibraryGlobalsN)
                {
                    var k = kvp.Key;
                    var v = kvp.Value;

                    var cgd = new List <CodeGenDescriptor>();

                    foreach (var i in v)
                    {
                        var cg = i.codeblock.Block.CreateGlobalMethodStub(tg);

                        if (cg != null)
                        {
                            CodeGen._codeBlockStubsN[i.codeblock.Block] = cg;

                            cgd.Add(new CodeGenDescriptor
                            {
                                arity   = i.arity,
                                varargs = i.varargs,
                                cg      = cg,
                            });
                        }
                    }

                    CodeGen._codeBlockLookupN[k] = cgd.ToArray();
                }
            }

            StaticFieldSlotFactory factory = new StaticFieldSlotFactory(tg);

            _languages[scriptCode.LanguageContext] = new LanguageInfo(factory, tg);

            return(factory);
        }
Exemplo n.º 3
0
 public LanguageInfo(StaticFieldSlotFactory slotFactory, TypeGen tg)
 {
     TypeGen     = tg;
     SlotFactory = slotFactory;
 }
 public LanguageInfo(StaticFieldSlotFactory slotFactory, TypeGen tg)
 {
     TypeGen = tg;
     SlotFactory = slotFactory;
 }
        protected override SlotFactory CreateSlotFactory(ScriptCode scriptCode)
        {
            AssemblyGen ag = null;

            if (scriptCode.SourceUnit.Kind == SourceCodeKind.Default && scriptCode.CodeBlock.Name != "ironscheme.boot.new")
            {
              if (ScriptDomainManager.Options.DebugMode)
              {
                if ((ScriptDomainManager.Options.AssemblyGenAttributes & AssemblyGenAttributes.SaveAndReloadAssemblies) != 0)
                {
                  ag = ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly;
                    //CreateModuleAssembly(scriptCode);
                }
                else
                {
                  ag = ScriptDomainManager.CurrentManager.Snippets.DebugAssembly;
                }
              }
              else
              {
                if ((ScriptDomainManager.Options.AssemblyGenAttributes & AssemblyGenAttributes.SaveAndReloadAssemblies) != 0)
                {
                  ag = ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly;
                    //CreateModuleAssembly(scriptCode);
                }
                else
                {
                  ag = ScriptDomainManager.CurrentManager.Snippets.Assembly;
                }
              }
            }
            else
            {
              ag = ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly; //CreateModuleAssembly(scriptCode);
            }

            ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly = ag;

            TypeGen tg = GenerateModuleGlobalsType(ag, scriptCode);

            if (scriptCode.LibraryGlobals != null)
            {
              foreach (var kvp in scriptCode.LibraryGlobals)
              {
                var k = kvp.Key;
                var v = kvp.Value;

                var cg = v.Block.CreateGlobalMethodStub(tg);

                if (cg != null)
                {
                  CodeGen._codeBlockStubs[v.Block] = cg;
                  CodeGen._codeBlockLookup[k] = cg;
                }
              }
            }

            if (scriptCode.LibraryGlobalsX != null)
            {
              foreach (var kvp in scriptCode.LibraryGlobalsX)
              {
                var k = kvp.Key;
                var v = kvp.Value;

                var cg = v.Block.CreateGlobalMethodStub(tg);

                if (cg != null)
                {
                  CodeGen._codeBlockStubsX[v.Block] = cg;
                  CodeGen._codeBlockLookupX[k] = cg;
                }
              }
            }

            if (scriptCode.LibraryGlobalsN != null)
            {
              foreach (var kvp in scriptCode.LibraryGlobalsN)
              {
                var k = kvp.Key;
                var v = kvp.Value;

                var cgd = new List<CodeGenDescriptor>();

                foreach (var i in v)
                {
                  var cg = i.codeblock.Block.CreateGlobalMethodStub(tg);

                  if (cg != null)
                  {
                    CodeGen._codeBlockStubsN[i.codeblock.Block] = cg;

                    cgd.Add(new CodeGenDescriptor
                    {
                      arity = i.arity,
                      varargs = i.varargs,
                      cg = cg,
                    });
                  }
                }

                CodeGen._codeBlockLookupN[k] = cgd.ToArray();

              }
            }

            StaticFieldSlotFactory factory = new StaticFieldSlotFactory(tg);

            _languages[scriptCode.LanguageContext] = new LanguageInfo(factory, tg);

            return factory;
        }
        private ScopeAllocator CreateStorageAllocator(ScriptCode scriptCode)
        {
            ScopeAllocator allocator;
            if (!_allocators.TryGetValue(scriptCode.LanguageContext, out allocator)) {
                var sf = CreateSlotFactory(scriptCode) as StaticFieldSlotFactory;
                var mgf = new ModuleGlobalFactory(sf);
                var sf2 = new StaticFieldSlotFactory(sf.TypeGen);
                GlobalFieldAllocator gfa = new GlobalFieldAllocator(mgf);
                var gfa2 = new GlobalFieldAllocator(sf2);

                // Locals and globals are allocated from the same namespace for optimized modules
                ScopeAllocator global = new ScopeAllocator(null, gfa);
                allocator = new ScopeAllocator(global, gfa2);

                _allocators[scriptCode.LanguageContext] = allocator;
            }

            return allocator;
        }