Esempio n. 1
0
        protected IshtarTestBase()
        {
            if (VM.watcher is DefaultWatchDog)
            {
                VM.watcher = new TestWatchDog();
            }
            AppVault.CurrentVault ??= new AppVault("<test-app>");
            lock (guarder)
            {
                if (!isInited)
                {
                    VeinCore.Init();

                    IshtarGC.INIT();
                    FFI.INIT();
                    _corlib = LoadCorLib();
                    IshtarCore.INIT_ADDITIONAL_MAPPING();
                    foreach (var @class in VeinCore.All.OfType <RuntimeIshtarClass>())
                    {
                        @class.init_vtable();
                    }
                    // ReSharper disable once VirtualMemberCallInConstructor
                    StartUp();
                    isInited = true;
                }
            }
        }
Esempio n. 2
0
        public static unsafe int Main(string[] args)
        {
            ishtar.Trace.init();
            //while (!Debugger.IsAttached)
            //    Thread.Sleep(200);
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Console.OutputEncoding = Encoding.Unicode;
            }
            IshtarCore.INIT();
            INIT_VTABLES();
            IshtarGC.INIT();
            FFI.INIT();

            AppVault.CurrentVault = new AppVault("app");

            var masterModule = default(IshtarAssembly);
            var resolver     = default(AssemblyResolver);

            if (AssemblyBundle.IsBundle(out var bundle))
            {
                resolver     = AppVault.CurrentVault.GetResolver();
                masterModule = bundle.Assemblies.First();
                resolver.AddInMemory(bundle);
            }
            else
            {
                if (args.Length < 1)
                {
                    return(-1);
                }
                var entry = new FileInfo(args.First());
                if (!entry.Exists)
                {
                    return(-2);
                }
                AppVault.CurrentVault.WorkDirecotry = entry.Directory;
                resolver     = AppVault.CurrentVault.GetResolver();
                masterModule = IshtarAssembly.LoadFromFile(entry);
                resolver.AddSearchPath(entry.Directory);
            }


            var module = resolver.Resolve(masterModule);

            foreach (var @class in module.class_table.OfType <RuntimeIshtarClass>())
            {
                @class.init_vtable();
                VM.ValidateLastError();
            }

            var entry_point = module.GetEntryPoint();

            if (entry_point is null)
            {
                VM.FastFail(WNE.MISSING_METHOD, $"Entry point in '{module.Name}' module is not defined.", IshtarFrames.EntryPoint);
                VM.ValidateLastError();
                return(-280);
            }

            var args_ = stackalloc stackval[1];

            var frame = new CallFrame
            {
                args   = args_,
                method = entry_point,
                level  = 0
            };

            {// i don't know why
                IshtarCore.INIT_ADDITIONAL_MAPPING();
                INIT_VTABLES();
            }



            var watcher = Stopwatch.StartNew();

            VM.exec_method(frame);

            if (frame.exception is not null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"unhandled exception '{frame.exception.value->decodeClass().Name}' was thrown. \n" +
                                  $"{frame.exception.stack_trace}");
                Console.ForegroundColor = ConsoleColor.White;
            }

            watcher.Stop();
            Console.WriteLine($"Elapsed: {watcher.Elapsed}");

            return(0);
        }