public static object CompileBootfile(object libs) { AssemblyGenAttributes aga = ScriptDomainManager.Options.AssemblyGenAttributes; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.EmitDebugInfo; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.GenerateDebugAssemblies; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.DisableOptimizations; if (ScriptDomainManager.Options.DebugMode) { ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.EmitDebugInfo; ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.GenerateDebugAssemblies; //ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.DisableOptimizations; ScriptDomainManager.Options.DebugCodeGeneration = false; } else { ScriptDomainManager.Options.DebugCodeGeneration = false; } ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.SaveAndReloadAssemblies; ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly = Compiler.Generator.CurrentAssemblyGen = AssemblyGen.CreateModuleAssembly("ironscheme.boot.new.dll"); //Console.WriteLine(new Cons(libs).PrettyPrint); CodeBlock cb = IronSchemeLanguageContext.CompileExpr(libs as Cons); cb.ExplicitCodeContextExpression = null; cb.Name = "ironscheme.boot.new"; ScriptCode sc = cc.LanguageContext.CompileSourceCode(cb); sc.LibraryGlobals = Compiler.SimpleGenerator.libraryglobals; sc.LibraryGlobalsN = Compiler.SimpleGenerator.libraryglobalsN; sc.LibraryGlobalsX = Compiler.SimpleGenerator.libraryglobalsX; sc.SourceUnit.IsVisibleToDebugger = true; ScriptModule sm = ScriptDomainManager.CurrentManager.CreateModule("ironscheme.boot.new", sc); ScriptDomainManager.Options.AssemblyGenAttributes = aga; sc.ClearCache(); Compiler.SimpleGenerator.ClearGlobals(); return(TRUE); }
public static object CompileCore(object expr) { // fast path for really simple stuff if (expr is SymbolId) { CallTarget0 n = delegate { return(SymbolValue(expr)); }; return(Closure.Create(n)); } AssemblyGenAttributes aga = ScriptDomainManager.Options.AssemblyGenAttributes; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.EmitDebugInfo; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.GenerateDebugAssemblies; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.DisableOptimizations; if (ScriptDomainManager.Options.DebugMode) { ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.EmitDebugInfo; ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.GenerateDebugAssemblies; ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.DisableOptimizations; ScriptDomainManager.Options.DebugCodeGeneration = true; } else { ScriptDomainManager.Options.DebugCodeGeneration = false; } ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.SaveAndReloadAssemblies; // if you ever want to inspect the emitted dll's comment the following out (or skip in the debugger), use with care ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.SaveAndReloadAssemblies; var prevt = IronScheme.Compiler.Generator.AllowTransientBinding; var prevag = Compiler.Generator.CurrentAssemblyGen; if ((ScriptDomainManager.Options.AssemblyGenAttributes & AssemblyGenAttributes.SaveAndReloadAssemblies) != 0) { IronScheme.Compiler.Generator.AllowTransientBinding = false; ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly = Compiler.Generator.CurrentAssemblyGen = AssemblyGen.CreateModuleAssembly(null); } else { Compiler.Generator.CurrentAssemblyGen = ScriptDomainManager.Options.DebugMode ? ScriptDomainManager.CurrentManager.Snippets.DebugAssembly : ScriptDomainManager.CurrentManager.Snippets.Assembly; } int c = Interlocked.Increment(ref evalcounter); #if DEBUG Stopwatch sw = Stopwatch.StartNew(); #endif //Console.WriteLine(new Cons(expr).PrettyPrint); try { CodeBlock cb = IronSchemeLanguageContext.CompileExpr(new Cons(expr)); cb.ExplicitCodeContextExpression = null; ScriptCode sc = Context.LanguageContext.CompileSourceCode(cb); //wrap #if DEBUG sw.Stop(); Trace.WriteLine(sw.Elapsed.TotalMilliseconds, string.Format("compile - eval-core({0:D3})", c)); sw = Stopwatch.StartNew(); #endif try { sc.LibraryGlobals = Compiler.SimpleGenerator.libraryglobals; sc.LibraryGlobalsN = Compiler.SimpleGenerator.libraryglobalsN; sc.LibraryGlobalsX = Compiler.SimpleGenerator.libraryglobalsX; ScriptModule sm = ScriptDomainManager.CurrentManager.CreateModule(string.Format("eval-core({0:D3})", c), sc); sc = sm.GetScripts()[0]; #if DEBUG sw.Stop(); Trace.WriteLine(sw.Elapsed.TotalMilliseconds, string.Format("compile*- eval-core({0:D3})", c)); #endif CallTarget0 compiled = delegate { #if DEBUG try { sw = Stopwatch.StartNew(); #endif return(sc.Run(Context.ModuleContext.Module)); #if DEBUG } finally { sw.Stop(); Trace.WriteLine(sw.Elapsed.TotalMilliseconds, string.Format("run - eval-core({0:D3})", c)); } #endif }; return(Closure.Create(compiled)); } catch (Variable.UnInitializedUsageException ex) { CallTarget0 err = delegate { return(AssertionViolation(ex.Variable.Block.Name, ex.Message, UnGenSym(ex.Variable.Name))); }; return(Closure.Create(err)); } finally { BoundExpression.Fixups.Clear(); BoundExpression.FixupTypes.Clear(); Compiler.Generator.CurrentAssemblyGen = prevag; ScriptDomainManager.Options.AssemblyGenAttributes = aga; IronScheme.Compiler.Generator.AllowTransientBinding = prevt; sc.ClearCache(); Compiler.SimpleGenerator.ClearGlobals(); Compiler.ClrGenerator.compiletimetypes.Clear(); } } catch (Continuation) { throw; } catch (Exception ex) { var who = ex.Data["Who"]; return(SyntaxError(who ?? FALSE, ex.Message, FALSE, FALSE)); } }
public static object CompileLibrary(object filename, object content) { IronScheme.Compiler.Generator.LocationHint = null; AssemblyGenAttributes aga = ScriptDomainManager.Options.AssemblyGenAttributes; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.EmitDebugInfo; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.GenerateDebugAssemblies; ScriptDomainManager.Options.AssemblyGenAttributes &= ~AssemblyGenAttributes.DisableOptimizations; if (ScriptDomainManager.Options.DebugMode) { ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.EmitDebugInfo; ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.GenerateDebugAssemblies; ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.DisableOptimizations; ScriptDomainManager.Options.DebugCodeGeneration = true; } else { ScriptDomainManager.Options.DebugCodeGeneration = false; } ScriptDomainManager.Options.AssemblyGenAttributes |= AssemblyGenAttributes.SaveAndReloadAssemblies; //object[] arr = ListToVector(content as Cons); //0: id //1: name //2: version //3: imp* //4: vis* //5: inv* //6: subst //7: env //8: visit code //9: invoke code //10: guard code //11: guard req? //12: visible? Compiler.Generator.AllowTransientBinding = false; ScriptDomainManager.CurrentManager.Snippets.CurrentAssembly = Compiler.Generator.CurrentAssemblyGen = AssemblyGen.CreateModuleAssembly(filename as string); try { CodeBlock cb = IronSchemeLanguageContext.CompileExpr(new Cons(content)); cb.ExplicitCodeContextExpression = null; cb.Name = ""; ScriptCode sc = cc.LanguageContext.CompileSourceCode(cb, filename as string); sc.LibraryGlobals = Compiler.SimpleGenerator.libraryglobals; sc.LibraryGlobalsN = Compiler.SimpleGenerator.libraryglobalsN; sc.LibraryGlobalsX = Compiler.SimpleGenerator.libraryglobalsX; sc.SourceUnit.IsVisibleToDebugger = true; ScriptModule sm = ScriptDomainManager.CurrentManager.CreateModule(Path.GetFileNameWithoutExtension(filename as string), sc); // clean up transient non-generative types, could maybe also have used AllowTransientBinding to check? IronScheme.Runtime.R6RS.Records.ClearTypesFrom(Compiler.Generator.CurrentAssemblyGen); ScriptDomainManager.Options.AssemblyGenAttributes = aga; Compiler.SimpleGenerator.ClearGlobals(); return(TRUE); } finally { Compiler.Generator.AllowTransientBinding = true; } }