Exemple #1
0
 public override ScriptEngine GetEngine(EngineOptions options)
 {
     if (se == null)
     {
         LanguageContext lc = new IronSchemeLanguageContext();
         se = new IronSchemeScriptEngine(this, options ?? GetOptionsParser().EngineOptions, lc);
     }
     return(se);
 }
Exemple #2
0
        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);
        }
Exemple #3
0
        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));
            }
        }
Exemple #4
0
        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;
            }
        }
        public override ScriptEngine GetEngine(EngineOptions options)
        {
            if (se == null)
              {
            LanguageContext lc = new IronSchemeLanguageContext();
            se = new IronSchemeScriptEngine(this, options ?? new IronSchemeOptionsParser.IronSchemeEngineOptions(), lc);

              }
              return se;
        }
Exemple #6
0
        static object ReadAnnotatedNext(object port)
        {
            Cons c;

            if (readcache.TryGetValue(port, out c))
            {
                if (c.cdr == null)
                {
                    readcache.Remove(port);
                }
                else
                {
                    readcache[port] = c.cdr as Cons;
                }
                return(c.car);
            }
            else
            {
                TextReader r = RequiresNotNull <TextReader>(port);

                try
                {
                    object result = null;

                    if (r is StreamReader)
                    {
                        StreamReader rr = (StreamReader)r;
                        Stream       s  = rr.BaseStream;
                        if (s == null)
                        {
                            return(IOPortViolation("read", "port has already been closed", r));
                        }
                        // check if stream has been read by reader
                        if (s.Position == 0)
                        {
                            result = IronSchemeLanguageContext.ReadExpressions(s, GetContext(s, Context.ModuleContext.CompilerContext));
                        }
                        else
                        {
                            string input = r.ReadToEnd();
                            if (input.Length > 0)
                            {
                                result = IronSchemeLanguageContext.ReadExpressions(input, GetContext(s, Context.ModuleContext.CompilerContext));
                            }
                        }
                    }
                    else
                    {
                        string input = r.ReadToEnd();
                        if (input.Length > 0)
                        {
                            result = IronSchemeLanguageContext.ReadExpressions(input, Context.ModuleContext.CompilerContext);
                        }
                    }

                    if (result is Cons)
                    {
                        c = (Cons)result;
                        if (c.cdr is Cons)
                        {
                            readcache[port] = c.cdr as Cons;
                        }
                        return(c.car);
                    }
                    else if (result != null)
                    {
                        return(result);
                    }

                    return(EOF);
                }
                catch (IOException ex)
                {
                    return(IOPortViolation("read", ex.Message, port));
                }
                catch (SyntaxErrorException ex)
                {
                    return(LexicalError(ex.Message, (ex.SourceUnit ?? (object)"(standard-input-port)").ToString()));
                }
            }
        }