public Interpreter(CompiledScript script, ISyscallShim syscallShim) { _script = script; _state = new RuntimeState(script.NumGlobals); _state.MemInfo.UseMemory(script.CalcBaseMemorySize()); _syscallShim = syscallShim; }
public void Compile(ICharStream input) { try { AssemblerLexer lex = new AssemblerLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); AssemblerParser p = new AssemblerParser(tokens); BytecodeGenerator gen = new BytecodeGenerator(Defaults.SystemMethods.Values); p.SetGenerator(gen); p.TraceDestination = _traceDestination; p.program(); if (p.NumberOfSyntaxErrors > 0 && _listener != null) { _listener.Error(Convert.ToString(p.NumberOfSyntaxErrors) + " syntax error(s)"); return; } _result = gen.Result; } catch (GenerationException ex) { _listener.Error(ex.Message); } }
public static Interpreter Run(CompiledScript script) { if (script != null) { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); Interpreter i = new Interpreter(script, null); i.TraceDestination = Console.Out; while (i.ScriptState.RunState == RuntimeState.Status.Running) { i.Tick(); } watch.Stop(); System.Console.WriteLine("Execution: {0} seconds", watch.ElapsedMilliseconds / 1000.0); System.Console.WriteLine("Free Memory: {0} bytes", i.ScriptState.MemInfo.MemoryFree); return i; } return null; }
private static void SaveScript(CompiledScript script) { SerializedScript serScript = SerializedScript.FromCompiledScript(script); using (var file = File.Create("script.plx")) { ProtoBuf.Serializer.Serialize(file, serScript); } using (var file = File.OpenRead("script.plx")) { SerializedScript readscript = ProtoBuf.Serializer.Deserialize<SerializedScript>(file); CompiledScript compiled = readscript.ToCompiledScript(); } }
public Interpreter(CompiledScript script, RuntimeState state, ISyscallShim syscallShim) { _script = script; _state = state; _syscallShim = syscallShim; }
public Interpreter(CompiledScript script, RuntimeState state, ISyscallShim syscallShim) { _script = script; _state = state; _syscallShim = syscallShim; }
/// <summary> /// Reserializes a compiled script into a form again usable to pass over the wire or write to disk /// </summary> /// <param name="compiledScript"></param> /// <returns></returns> private byte[] ReserializeScript(CompiledScript compiledScript) { SerializedScript script = SerializedScript.FromCompiledScript(compiledScript); using (MemoryStream memStream = new MemoryStream()) { ProtoBuf.Serializer.Serialize(memStream, script); return memStream.ToArray(); } }
private void BeginScriptRun(LoadUnloadRequest lrq, CompiledScript script) { RuntimeState state = this.TryLoadState(lrq); //if this is a reload, we unload first if (lrq.RequestType == LoadUnloadRequest.LUType.Reload) { this.PerformUnloadRequest(lrq); } try { _exeScheduler.FinishedLoading(lrq, script, state); } catch (Exception e) { _log.ErrorFormat("[Phlox]: Error when informing scheduler of script load. Script: {0} Item: {1} Group: {2} Part: {3}. {4}", script.AssetId, lrq.ItemId, lrq.Prim.ParentGroup.LocalId, lrq.Prim.LocalId, e); throw; } }
private void CacheCompiledScript(CompiledScript comp) { string scriptCacheDir = this.LookupDirectoryFromId(PhloxConstants.COMPILE_CACHE_DIR, comp.AssetId); Directory.CreateDirectory(scriptCacheDir); string scriptPath = Path.Combine(scriptCacheDir, comp.AssetId.ToString() + PhloxConstants.COMPILED_SCRIPT_EXTENSION); SerializedScript script = SerializedScript.FromCompiledScript(comp); using (FileStream f = File.Open(scriptPath, FileMode.Create)) { ProtoBuf.Serializer.Serialize(f, script); f.Close(); } }