public static void Start() { if (flag.EngineType == flag.engineType.eval) { _evalRepl(); return; // unreachable } List <Object> constants = new List <Object>(); List <Object> globals = new List <Object>(new Object[VM.GlobalSize]); symbol_table.SymbolTable symbolTable = symbol_table.NewSymbolTable(); for (int i = 0; i < builtins.Builtins.Length; i++) { _BuiltinDefinition v = builtins.Builtins[i]; symbol_table.DefineBuiltin(ref symbolTable, i, v.Name); } for (;;) { System.Console.Write(PROMPT); string line = System.Console.ReadLine(); Lexer l = Lexer.New(line); Parser p = Parser.New(l); ast.Program program = p.ParseProgram(); if (Parser.Errors().Count != 0) { printParserErrors(Parser.Errors()); continue; } Compiler_t comp = Compiler.NewWithState(ref symbolTable, constants); Compiler._SetCompiler(ref comp); // work around error err = Compiler.Compile(program); if (err != null) { System.Console.WriteLine("Woops! Compilation failed:\n {0}", err); continue; } Bytecode code = Compiler.Bytecode(); constants = code.Constants; VM_t machine = VM.NewWithGlobalStore(code, ref globals); VM._SetVM(ref machine); // work around err = VM.Run(); if (err != null) { System.Console.WriteLine("Woops! Executing bytecode failed:\n {0}", err); continue; } Object lastPopped = VM.LastPoppedStackElem(); System.Console.Write(lastPopped.Inspect()); System.Console.WriteLine(); } }
public static void Start() { List <Object> constants = new List <Object>(); List <Object> globals = new List <Object>(new Object[VM.GlobalSize]); symbol_table.SymbolTable symbolTable = symbol_table.NewSymbolTable(); for (int i = 0; i < builtins.Builtins.Length; i++) { _BuiltinDefinition v = builtins.Builtins[i]; symbol_table.DefineBuiltin(ref symbolTable, i, v.Name); } for (;;) { System.Console.Write(PROMPT); string line = System.Console.ReadLine(); Lexer l = Lexer.New(line); Compiler.InitParser(l); Compiler.NewWithState(ref symbolTable, constants); error err = Compiler.CompileProgram(); if (Compiler.ParseErrors().Count != 0) // parse errors { printParserErrors(Compiler.ParseErrors()); continue; } if (err != null) { System.Console.WriteLine("Woops! Compilation failed:\n {0}", err); continue; } Bytecode code = Compiler.Bytecode(); constants = code.Constants; if (code.Instructions.Count == 0) // nothing compiled { continue; } VM.NewWithGlobalStore(code, ref globals); err = VM.Run(); if (err != null) { System.Console.WriteLine("Woops! Executing bytecode failed:\n {0}", err); continue; } if (VM.ExitVM) { return; } Object lastPopped = VM.LastPoppedStackElem(); System.Console.Write(lastPopped.Inspect()); System.Console.WriteLine(); } }