Example #1
0
 internal WorkerThread(CodeAssembly asm)
 {
     Assembly  = asm;
     Module    = asm.GetRootModule();
     CallStack = new CallStack();
     Context   = new ExecutionContext();
 }
Example #2
0
        internal CompiledAssembly(Document rootDoc, CodeAssembly asm)
        {
            Assembly = asm;
            Units    = Assembly.EnumerateModules()
                       .Select(n => Assembly.GetModule(Assembly.GetModuleHandle(n)))
                       .Select(m => new CompiledUnit(new VirtualDocument(m.File.ToFileInfo()), m))
                       .ToList();
            var root = Assembly.GetRootModule();

            MainUnit = new CompiledUnit(rootDoc, root);
        }
Example #3
0
        private void ExecuteInput(CodeAssembly asm)
        {
            if (vm == null)
            {
                vm = new ElaMachine(asm);
            }
            else
            {
                vm.RefreshState();
                vm.Recover();
            }

            var mod = asm.GetRootModule();
            var os  = lastOffset;

            lastOffset = mod.Ops.Count;

            try
            {
                Con.Invoke(() => { Con.ReadOnly = true; });
                var exer = vm.Run(os);

                if (exer.ReturnValue.TypeCode != Ela.ElaTypeCode.Unit)
                {
                    Con.Invoke(() => Con.PrintLine(exer.ReturnValue.ToString()));
                }
            }
            catch (ElaCodeException ex)
            {
                Con.Invoke(() => Con.PrintLine("``!!!ELA" + ex.Error.Code + ": " + ex.Error.Message));
            }
            catch (Exception) { }
            finally
            {
                Con.Invoke(() => { Con.ReadOnly = false; });
                Con.PrintLine();
                Con.PrintLine();
                Con.Print(Con.Prompt + ">");
                Con.ScrollToCaret();
                App.GetService <IStatusBarService>().ClearStatusString();
            }
        }
Example #4
0
        private static int Execute(CodeAssembly asm, bool interactive)
        {
            var mod = asm.GetRootModule();

            if (opt.ShowEil)
            {
                var gen = new EilGenerator(mod);
                Console.WriteLine("EIL ({0}-{1}):", lastOffset, mod.Ops.Count - 1);
                Console.Write(gen.Generate(lastOffset));
                lastOffset = mod.Ops.Count;
            }
            else if (opt.ShowSymbols != SymTables.None)
            {
                var gen = new DebugReader(mod.Symbols);
                helper.PrintSymTables(gen);
                lastOffset = mod.Ops.Count;
            }
            else
            {
                try
                {
                    if (vm == null)
                    {
                        vm = new ElaMachine(asm);
                        vm.AddTracePointListener(new TracePointListener());
                    }
                    else
                    {
                        vm.RefreshState();
                        vm.Recover();
                    }

                    if (opt.ShowTime != 0 && !interactive)
                    {
                        Warmup(asm); //GIT
                    }
                    var os = lastOffset;
                    lastOffset = mod.Ops.Count;
                    var sw = new Stopwatch();
                    sw.Start();
                    var exer = default(ExecutionResult);

                    if (opt.ShowTime != 0)
                    {
                        for (var i = 0; i < opt.ShowTime; i++)
                        {
                            exer = vm.Run(os);
                        }

                        sw.Stop();
                    }
                    else
                    {
                        exer = vm.Run(os);
                    }

                    if (opt.ShowTime != 0 && !interactive)
                    {
                        Console.WriteLine("Executed: {0} time(s). Execution time: {1}", opt.ShowTime, sw.Elapsed);
                    }

                    if (exer.ReturnValue.TypeCode != ElaTypeCode.None && exer.ReturnValue.TypeCode != ElaTypeCode.Unit)
                    {
                        Console.WriteLine(vm.PrintValue(exer.ReturnValue));
                    }
                }
                catch (ElaException ex)
                {
                    helper.PrintError(ex.ToString());
                    return(R_ERR);
                }
            }

            return(R_OK);
        }