Exemple #1
0
        static void Main(string[] args)
        {
            {
                //Type[] types = new Type[] {
                //    typeof(bool),
                //    typeof(char),
                //    typeof(byte), typeof(sbyte),
                //    typeof(ushort), typeof(short),
                //    typeof(uint), typeof(int),
                //    typeof(ulong), typeof(long),
                //    typeof(float), typeof(double),
                //};

                //foreach(var t in types)
                //{
                //    Console.WriteLine("{0}, {1}", t.IsPrimitive, t.IsValueType);
                //    var obj = Activator.CreateInstance(t, true);
                //    Console.WriteLine("{0}", obj);
                //}

                //return;
            }

            {
                SimpleScript.Test.TestManager.RunTest();
                //return;
            }

            {
                //ImportCodeGenerate.GenDelegateFactorySource("generate/DelegateFactory.cs", new Type[]{
                //    typeof(Func<int,int>),
                //    typeof(Action),
                //});

                //Console.WriteLine(typeof(Int64).IsPrimitive);
                VM vm = new VM();
                LibBase.Register(vm);
                LibCoroutine.Register(vm);

                vm.ComileFile("test.oms", "test.omsc");

                var pipe = new IOPipe();
                vm.m_hooker.SetPipeServer(pipe);
                vm.m_hooker.SetBreakMode(SimpleScript.DebugProtocol.BreakMode.StopForOnce);

                vm.DoFile("test.omsc");

                // 测试协程,当成是事件循环也行
                Console.Write("Start update coroutine!");
                if (Console.IsInputRedirected == false)
                {
                    Console.WriteLine(" Press Esc to end.");
                }
                else
                {
                    Console.WriteLine();
                }

                while (true)
                {
                    if (Console.IsInputRedirected == false && Console.KeyAvailable)
                    {
                        var key = Console.ReadKey(true);
                        if (key.Key == ConsoleKey.Escape)
                        {
                            break;
                        }
                    }
                    CoroutineMgr.Update();
                    System.Threading.Thread.Sleep(10);
                }

                return;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            VM vm = new VM();

            LibBase.Register(vm);
            LibCoroutine.Register(vm);

            if (args.Length == 0)
            {
                ExecuteConsole(vm);
            }

            if (args[0] == "-c" || args[0] == "-b")
            {
                bool   is_compile = args[0] == "-c";
                string src_file   = null;
                string bin_file   = null;
                if (args.Length == 2)
                {
                    src_file = args[1];
                    bin_file = src_file + "c";
                    if (is_compile == false)
                    {
                        bin_file = src_file + "b";
                    }
                }
                else if (args.Length == 4 && args[2] == "-o")
                {
                    src_file = args[1];
                    bin_file = args[3];
                }
                if (src_file != null && File.Exists(src_file) &&
                    Directory.Exists(Path.GetDirectoryName(Path.GetFullPath(bin_file))))
                {
                    if (is_compile)
                    {
                        Compile(src_file, bin_file, vm);
                    }
                    else
                    {
                        ShowBinCode(src_file, bin_file, vm);
                    }
                }
                else
                {
                    ShowHelpThenExit();
                }
            }
            else if (args.Length == 1)
            {
                if (File.Exists(args[0]))
                {
                    ExecuteFile(args[0], vm);
                }
                else
                {
                    ShowHelpThenExit();
                }
            }
            else if (args[0] == "-d" && args.Length >= 2)
            {
                if (File.Exists(args[1]))
                {
                    if (args.Length == 2)
                    {
                        DebugFile(args[1], vm, 0);
                    }
                    else if (args.Length == 4 && args[2] == "-p")
                    {
                        int port = 0;
                        int.TryParse(args[3], out port);
                        if (port > 0)
                        {
                            DebugFile(args[1], vm, port);
                        }
                        else
                        {
                            ShowHelpThenExit();
                        }
                    }
                    else
                    {
                        ShowHelpThenExit();
                    }
                }
                else
                {
                    ShowHelpThenExit();
                }
            }
            else
            {
                ShowHelpThenExit();
            }
        }