public Parser(Runtime runtime) { parser_runtime = new Runtime(); parser_runtime.NativeRegex = true; // find compiled code var parser_assembly = System.Reflection.Assembly.Load("Language.P.Net.Parser"); parser_runtime.ModuleLoaders.Insert(0, new AssemblyModuleLoader(parser_assembly)); // load Language::P frontend Builtins.RequireFile(parser_runtime, Opcode.ContextValues.VOID, new P5Scalar(parser_runtime, "Language/P.pm")); // create generator generator = new DynamicGenerator(runtime, parser_runtime); // instantiate parser P5Array arglist_parser = new P5Array(parser_runtime, new P5Scalar(parser_runtime, "Language::P::Parser"), GetInit(runtime)); parser_template = arglist_parser.CallMethod(parser_runtime, Opcode.ContextValues.SCALAR, "new") as P5Scalar; }
public static void Main(string[] args) { // use the invariant locale as the default System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var runtime = new Runtime(); string[] argv; ParseCommandLine(runtime, args, out argv); try { if (argv[0].EndsWith(".pb")) { var cu = Serializer.ReadCompilationUnit(runtime, argv[0]); P5Code main = new DynamicGenerator(runtime).GenerateAndLoad(cu); if (!runtime.CompileOnly) main.CallMain(runtime); } else { var parser = runtime.parser; parser.Run(runtime, argv); } } catch (System.Reflection.TargetInvocationException te) { var e = te.InnerException as P5Exception; if (e == null) { System.Console.WriteLine(); System.Console.WriteLine(te.InnerException.ToString()); } else System.Console.WriteLine(e.AsString(runtime)); } catch (P5Exception e) { System.Console.WriteLine(e.AsString(runtime)); } }
public IP5Any TryLoad(Runtime runtime, Opcode.ContextValues context, string file) { var path = Builtins.SearchFile(runtime, file); if (path == null) return null; P5Code mod; if (path.EndsWith(".pb")) { var cu = Serializer.ReadCompilationUnit(runtime, path); mod = new DynamicGenerator(runtime).GenerateAndLoad(cu); } else { var parser = runtime.parser; mod = parser.ParseFile(runtime, path, false); } var ret = mod.Call(runtime, context, null); var inc = runtime.SymbolTable.GetHash(runtime, "INC", true); inc.SetItem(runtime, file, new P5Scalar(runtime, path)); return ret; }