public InterpretResult(int programCounter, TimeSpan execute, DeviceNetwork network, MachineState state) { _network = network; _state = state; ProgramCounter = programCounter; Execute = execute; }
private static InterpretResult RunInterpreted(Yolol.Grammar.AST.Program ast, int max, int iters) { int CheckPc(int pc) { if (pc >= max) { return(0); } if (pc < 0) { return(0); } return(pc); } var pc = 0; var nt = new DeviceNetwork(); var st = new MachineState(nt, (ushort)max, 1024); var timer = new Stopwatch(); timer.Start(); for (var i = 0; i < iters; i++) { if (pc >= ast.Lines.Count) { pc++; } else { try { pc = ast.Lines[pc].Evaluate(pc, st); } catch (ExecutionException) { pc++; } } pc = CheckPc(pc); } return(new InterpretResult(pc + 1, timer.Elapsed, nt, st)); }
public static IMachineState Interpret(Program ast, int ticks) { var maxLines = Math.Max(20, ast.Lines.Count); int CheckPc(int pc) { if (pc >= maxLines) { return(0); } if (pc < 0) { return(0); } return(pc); } var pc = 0; var nt = new DeviceNetwork(); var st = new MachineState(nt, (ushort)maxLines); for (var i = 0; i < ticks; i++) { if (pc >= ast.Lines.Count) { pc++; } else { try { pc = ast.Lines[pc].Evaluate(pc, st); } catch (ExecutionException) { pc++; } } pc = CheckPc(pc); } return(new InterpretMachineState(pc + 1, st)); }
public static void Compare(Program ast, int ticks) { // Compile setup var ext = new ExternalsMap(); var lines = Math.Max(20, ast.Lines.Count); var compiled = ast.Compile(ext, lines); var internals = new Value[compiled.InternalsMap.Count]; Array.Fill(internals, new Value((Number)0)); var externals = new Value[ext.Count]; Array.Fill(externals, new Value((Number)0)); // Interpret setup var maxLines = Math.Max(20, ast.Lines.Count); int CheckPc(int pc) { if (pc >= maxLines) { return(0); } if (pc < 0) { return(0); } return(pc); } var pc = 0; var nt = new DeviceNetwork(); var st = new MachineState(nt, (ushort)maxLines); for (var i = 0; i < ticks; i++) { if (pc >= ast.Lines.Count) { pc++; } else { try { pc = ast.Lines[pc].Evaluate(pc, st); } catch (ExecutionException) { pc++; } } pc = CheckPc(pc); compiled.Tick(internals, externals); foreach (var item in compiled.InternalsMap) { var interpretedVal = st.GetVariable(item.Key.Name).Value; var compiledVal = internals[item.Value]; Assert.AreEqual(interpretedVal, compiledVal, $"varname:{item.Key} ticks:{i}"); } foreach (var item in ext) { var interpretedVal = st.GetVariable(item.Key.Name).Value; var compiledVal = externals[item.Value]; Assert.AreEqual(interpretedVal, compiledVal, $"varname:{item.Key} ticks:{i}"); } } }
public DeviceNetworkTest() { iOSNetwork = new DeviceNetwork(); }