コード例 #1
0
ファイル: test-harness.cs プロジェクト: pniederw/flabbergast
        public static int Main(string[] args)
        {
            var uri              = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);
            var directory        = Path.GetDirectoryName(uri.LocalPath);
            var assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"),
                                                                                 AssemblyBuilderAccess.Run);
            var module_builder = assembly_builder.DefineDynamicModule("TestModule");
            var unit           = new CompilationUnit(module_builder, false);
            var id             = 0;
            var success        = true;
            var lib            = new DynamicallyCompiledLibraries(new DirtyCollector());

            lib.Finder = new ResourcePathFinder();
            lib.Finder.AppendPath(Path.Combine(directory, "..", "..", "..", "..", "stdlib"));
            success &= DoTests(Path.Combine(directory, "..", "..", "..", "..", "tests"), "*", unit, lib, ref id);
            success &= DoTests(Path.Combine(directory, "..", "..", "tests"), "I", unit, lib, ref id);
            return(success ? 0 : 1);
        }
コード例 #2
0
ファイル: main-repl.cs プロジェクト: pniederw/flabbergast
        public static int Main(string[] args)
        {
            var show_help       = false;
            var use_precompiled = true;
            var options         = new OptionSet {
                { "p|no-precomp", "do not use precompiled libraries", v => use_precompiled = v == null },
                { "h|help", "show this message and exit", v => show_help = v != null }
            };

            List <string> files;

            try {
                files = options.Parse(args);
            } catch (OptionException e) {
                Console.Error.Write(AppDomain.CurrentDomain.FriendlyName + ": ");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("Try “" + AppDomain.CurrentDomain.FriendlyName + " --help” for more information.");
                return(1);
            }

            if (show_help)
            {
                Console.WriteLine("Usage: " + AppDomain.CurrentDomain.FriendlyName + " input.o_0");
                Console.WriteLine("Run Flabbergast interactively.");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return(1);
            }

            if (files.Count > 1)
            {
                Console.Error.WriteLine("No more than one Flabbergast script may be given.");
                return(1);
            }

            Frame original = null;

            var assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Repl"), AssemblyBuilderAccess.Run);
            var module_builder   = assembly_builder.DefineDynamicModule("ReplModule");
            var unit             = new CompilationUnit(module_builder, false);
            var collector        = new ConsoleCollector();
            var task_master      = new ConsoleTaskMaster();

            task_master.AddUriHandler(new CurrentInformation(true));
            task_master.AddUriHandler(BuiltInLibraries.INSTANCE);
            task_master.AddUriHandler(SettingsHandler.INSTANCE);
            task_master.AddUriHandler(EnvironmentUriHandler.INSTANCE);
            task_master.AddUriHandler(HttpHandler.INSTANCE);
            task_master.AddUriHandler(FtpHandler.INSTANCE);
            task_master.AddUriHandler(FileHandler.INSTANCE);
            var resource_finder = new ResourcePathFinder();

            resource_finder.PrependPath(Path.Combine(files.Count == 1 ? Path.GetDirectoryName(Path.GetFullPath(files[0])) : Environment.CurrentDirectory, "lib"));
            resource_finder.AddDefault();
            var db_handler = new DbUriHandler();

            db_handler.Finder = resource_finder;
            task_master.AddUriHandler(db_handler);
            var resource_handler = new ResourceHandler();

            resource_handler.Finder = resource_finder;
            task_master.AddUriHandler(resource_handler);
            if (use_precompiled)
            {
                var precomp = new LoadPrecompiledLibraries();
                precomp.Finder = resource_finder;
                task_master.AddUriHandler(precomp);
            }
            var dyncomp = new DynamicallyCompiledLibraries(collector);

            dyncomp.Finder = resource_finder;
            task_master.AddUriHandler(dyncomp);

            if (files.Count == 1)
            {
                var parser    = Parser.Open(files[0]);
                var root_type = parser.ParseFile(collector, unit, "REPLRoot");
                if (root_type != null)
                {
                    var computation = (Computation)Activator.CreateInstance(root_type, task_master);
                    computation.Notify(r => original = r as Frame);
                    task_master.Run();
                    task_master.ReportCircularEvaluation();
                }
            }
            if (original == null)
            {
                original = new MutableFrame(task_master, new NativeSourceReference("REPL"), null, null);
            }

            var           id             = 0;
            Frame         current        = original;
            bool          run            = true;
            ConsumeResult update_current = (x) => current = (x as Frame) ?? current;

            var line_editor  = new LineEditor("flabbergast");
            var completables = new Completables();

            line_editor.AutoCompleteEvent = completables.Handler;
            string s;

            while (run && (s = line_editor.Edit(id + "‽ ", "")) != null)
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                var parser   = new Parser("line" + id, s);
                var run_type = parser.ParseRepl(collector, unit, "REPL" + id++);
                if (run_type != null)
                {
                    object result      = null;
                    var    computation = (Computation)Activator.CreateInstance(run_type, new object[] { task_master, original, current, update_current, (ConsumeResult)(output => result = output), (ConsumeResult)Console.WriteLine });
                    computation.Notify(r => run = (r as bool?) ?? true);
                    task_master.Run();
                    if (result != null)
                    {
                        HandleResult(result);
                    }
                    task_master.ReportCircularEvaluation();
                }
            }
            line_editor.SaveHistory();
            return(0);
        }
コード例 #3
0
 public static int Main(string[] args)
 {
     var uri = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);
     var directory = Path.GetDirectoryName(uri.LocalPath);
     var assembly_builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Test"),
         AssemblyBuilderAccess.Run);
     var module_builder = assembly_builder.DefineDynamicModule("TestModule");
     var unit = new CompilationUnit(module_builder, false);
     var id = 0;
     var success = true;
     var lib = new DynamicallyCompiledLibraries(new DirtyCollector());
     lib.ClearPaths();
     lib.AppendPath(Path.Combine(directory, "..", "..", "..", "..", "lib"));
     success &= DoTests(Path.Combine(directory, "..", "..", "..", "..", "tests"), "*", unit, lib, ref id);
     success &= DoTests(Path.Combine(directory, "..", "..", "tests"), "I", unit, lib, ref id);
     return success ? 0 : 1;
 }