示例#1
0
文件: Program.cs 项目: DatZach/Xi
        private static void RunScript(string filename)
        {
            // Compile script
            Compiler compiler = new Compiler();

            List<Token> tokenStream = Tokenizer.ParseFile(filename);
            if (tokenStream == null)
                return;

            if (!compiler.Compile(new TokenStream(tokenStream)))
                return;

            //Disassembler.Dump(compiler.Modules);

            // Create state and add modules
            State state = new State();
            state.Modules.AddRange(compiler.Modules);

            // Run script
            try
            {
                state.SetEntryPoint(Module.GetNameFromFilename(filename));
                VirtualMachine.Execute(state);
            }
            catch (StackOverflowException e)
            {
                Console.WriteLine("VM Error: {0}", e.Message);
            }
        }
示例#2
0
文件: Script.cs 项目: DatZach/Xi
        private bool CompileStream(TokenStream tokenStream)
        {
            Compiler compiler = new Compiler();
            if (!compiler.Compile(tokenStream))
                return false;

            state.Modules.AddRange(compiler.Modules);

            return true;
        }
示例#3
0
文件: Program.cs 项目: DatZach/Xi
        private static void RunRepl()
        {
            string value;

            do
            {
                Console.Write(">> ");
                value = Console.ReadLine();

                // Compile line
                Compiler compiler = new Compiler();

                List<Token> tokenStream = Tokenizer.ParseString(value);
                if (tokenStream == null)
                    continue;

                if (!compiler.Compile(new TokenStream(tokenStream)))
                    continue;

                Disassembler.Dump(compiler.Modules);

                // Add line
                State state = new State();
                state.Modules.AddRange(compiler.Modules);

                // Run line
                try
                {
                    state.SetEntryPoint(Module.ModuleDefaultName);
                    VirtualMachine.Execute(state);
                }
                catch (Exception e)
                {
                    Console.WriteLine("VM Error: {0}", e.Message);
                }
            } while (value != "exit");
        }
示例#4
0
文件: Label.cs 项目: DatZach/Xi
 public Label(Compiler compiler)
 {
     patches = new List<int>();
     labelOffset = 0;
     this.compiler = compiler;
 }
示例#5
0
 public BytecodeObject(Compiler compiler)
 {
     Modules = compiler.Modules;
 }