private void Paking_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { this.CalculateNetAmount(); Dis.Focus(); } }
protected void runProgram(string program, Dictionary <string, object> variablesIn, int expectedIterations, out FrameContext context) { var inputStream = new AntlrInputStream(program); var lexer = new CloacaLexer(inputStream); CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); var errorListener = new ParseErrorListener(); var parser = new CloacaParser(commonTokenStream); parser.AddErrorListener(errorListener); var antlrVisitorContext = parser.file_input(); Assert.That(errorListener.Errors.Count, Is.Zero, "There were parse errors:\n" + errorListener.Report()); var visitor = new CloacaBytecodeVisitor(variablesIn); visitor.Visit(antlrVisitorContext); // We'll do a disassembly here but won't assert against it. We just want to make sure it doesn't crash. CodeObject compiledProgram = visitor.RootProgram.Build(); Dis.dis(compiledProgram); // TODO: This dependency association is kind of gross. It's almost circular and is broken by assigning // the interpreter reference to the schedular after its initial constructor. var scheduler = new Scheduler(); var interpreter = new Interpreter(scheduler); // Create native resource manager which will handle builtins that provide access to 'native' resources such as files. var nativeResourceManager = new NativeResourceManager(); nativeResourceManager.RegisterProvider <INativeFileProvider>(new DefaultFileProvider()); nativeResourceManager.RegisterBuiltins(interpreter); interpreter.DumpState = true; scheduler.SetInterpreter(interpreter); var receipt = scheduler.Schedule(compiledProgram); context = receipt.Frame; foreach (string varName in variablesIn.Keys) { context.SetVariable(varName, variablesIn[varName]); } // Waiting on the task makes sure we get punched in the face by any exceptions it throws. // But they'll come rolling in as AggregateExceptions so we'll have to unpack them. var scheduler_task = scheduler.RunUntilDone(); scheduler_task.Wait(); Assert.That(receipt.Completed); if (receipt.EscapedExceptionInfo != null) { receipt.EscapedExceptionInfo.Throw(); } Assert.That(scheduler.TickCount, Is.EqualTo(expectedIterations)); }
static void DumpState(FrameContext tasklet) { DumpCode(tasklet); var currentLine = Dis.dis(tasklet.Program, tasklet.Cursor, 1); currentLine = ">>>" + currentLine.Substring(3, currentLine.Length - 3); Console.WriteLine(currentLine); DumpDatastack(tasklet); }
private void Disparo() { Disp = (transform.localScale.x >= 0f) ? 0.7f : -0.7f; GameObject clone = (GameObject)Instantiate(DisparoPrefab, new Vector3(Disp + transform.position.x, transform.position.y, transform.position.z), Quaternion.identity); disparos.Add(clone); Dis = clone.GetComponent <Rigidbody2D> (); Vector2 dir = (Disp == 0.7f) ? Vector2.right : Vector2.left; Dis.AddForce(dir * 350f); Dis.velocity = new Vector2(Mathf.Clamp(Dis.velocity.x, -20f, 20f), Dis.velocity.y); Invoke("die", 3f); Animacion.SetBool("Disparar", false); }
void Clear() { txtretId.Clear(); txtorderid.Clear(); txtorderid.Clear(); Barcode.Clear(); Product_name.Clear(); R_price.Clear(); Qte.Clear(); Dis.Clear(); T_Pric.Clear(); Prog_User.Clear(); Notes.Clear(); }
protected void runProgram(string program, Dictionary <string, object> variablesIn, List <ISpecFinder> moduleSpecFinders, int expectedIterations, out FrameContext context) { CodeObject compiledProgram = null; try { compiledProgram = ByteCodeCompiler.Compile(program, variablesIn); } catch (CloacaParseException parseFailed) { Assert.Fail(parseFailed.Message); } Dis.dis(compiledProgram); // TODO: This dependency association is kind of gross. It's almost circular and is broken by assigning // the interpreter reference to the schedular after its initial constructor. var scheduler = new Scheduler(); var interpreter = new Interpreter(scheduler); interpreter.DumpState = true; foreach (var finder in moduleSpecFinders) { interpreter.AddModuleFinder(finder); } scheduler.SetInterpreter(interpreter); var receipt = scheduler.Schedule(compiledProgram); context = receipt.Frame; foreach (string varName in variablesIn.Keys) { context.SetVariable(varName, variablesIn[varName]); } // Waiting on the task makes sure we get punched in the face by any exceptions it throws. // But they'll come rolling in as AggregateExceptions so we'll have to unpack them. var scheduler_task = scheduler.RunUntilDone(); scheduler_task.Wait(); Assert.That(receipt.Completed); if (receipt.EscapedExceptionInfo != null) { receipt.EscapedExceptionInfo.Throw(); } Assert.That(scheduler.TickCount, Is.EqualTo(expectedIterations)); }
private void Walk(int key, int off) { var offq = new Queue <int>(); offq.Enqueue(off); labels[off] = "K" + key; var obs = new CmdObs(); while (offq.Count != 0) { int nextoff = offq.Dequeue(); while (true) { off = nextoff; if (dict.ContainsKey(off)) { break; } si.Position = 0x10 + off * 2; if (si.Position >= si.Length) { errors[off] = null; break; } try { int v0 = br.ReadUInt16(); int cm4 = v0 & 15; int cm8 = v0 & 255; obs.Eat(v0); if (false) { } // -- 16 bits cmd if (v0 == 0xffff) { dict[off] = new Dis(2, String.Format("TERM")); break; } // -- 8 bits cmd if (cm8 == 0x30) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd30 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } else if (cm8 == 0x60) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd60 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } else if (cm8 == 0xa0) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmda0 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } else if (cm8 == 0xc0) { int v2 = br.ReadInt32(); if (obs.Curt == CmdObs.T.Label && v2 != 0) { int newoff = v2; offq.Enqueue(newoff); dict[off] = new Dis(6, String.Format("Cmdc0l {0:x2} {1} ", v0 >> 8, GenLabel(newoff))); } else { dict[off] = new Dis(6, String.Format("Cmdc0i {0:x2} {1:x8} ", v0 >> 8, v2)); } nextoff = off + 3; } else if (cm8 == 0xe0) { int v2 = br.ReadUInt16(); si.Position = 0x10 + v2 * 2; dict[off] = new Dis(4, String.Format("Print {0:x2} '{1}' ", v0 >> 8, Ut.Read0Str(br))); nextoff = off + 2; } else if (cm8 == 0x0B) { int v2 = br.ReadInt32(); int newoff = off + 3 + v2; dict[off] = new Dis(6, String.Format("Call {0:x3} {1} ; {2} ", v0 >> 4, GenLabel(newoff), v2)); offq.Enqueue(newoff); nextoff = off + 3; } #if false else if (cm8 == 0x01) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd01 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } #endif else if (cm8 == 0x00) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd00 {0:x2} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 8, v2, v3, v4, v5)); nextoff = off + 3; } #if false else if (cm8 == 0x0a) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd0a {0:x2} {1:x2} ", v2, v3)); nextoff = off + 2; } #endif else if (cm8 == 0x40) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd40 {0:x2} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 8, v2, v3, v4, v5)); nextoff = off + 3; } else if (cm8 == 0x89) { dict[off] = new Dis(2, String.Format("Ret {0:x2}", v0 >> 8)); //nextoff = off + 1; break; } // -- 4 bits cmd else if (cm4 == 0) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd0 {0:x3} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 4, v2, v3, v4, v5)); nextoff = off + 3; } else if (cm4 == 1) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd1 {0:x3} {1:x2} {2:x2} ", v0 >> 4, v2, v3)); nextoff = off + 2; } else if (cm4 == 2) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd2 {0:x3} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 4, v2, v3, v4, v5)); nextoff = off + 3; } else if (cm4 == 3) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd3 {0:x3} {1:x2} {2:x2} ", v0 >> 4, v2, v3)); nextoff = off + 2; } else if (cm4 == 4) { dict[off] = new Dis(2, String.Format("Cmd4 {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 5) { dict[off] = new Dis(2, String.Format("Cmd5 {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 6) { dict[off] = new Dis(2, String.Format("Cmd6 {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 7) { int v2 = br.ReadInt16(); int newoff = off + 2 + v2; dict[off] = new Dis(4, String.Format("J7 {0:x3} {1} ", v0 >> 4, GenLabel(newoff))); offq.Enqueue(newoff); bool noc = (v0 >> 4) == 0; if (noc) { break; } nextoff = off + 2; } else if (cm4 == 8) { int v2 = br.ReadInt16(); int newoff = off + 2 + v2; dict[off] = new Dis(4, String.Format("J8 {0:x3} {1} ", v0 >> 4, GenLabel(newoff))); offq.Enqueue(newoff); nextoff = off + 2; } else if (cm4 == 9) { dict[off] = new Dis(2, String.Format("Pause {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 10) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmda {0:x3} {1:x2} {2:x2} ", v0 >> 4, v2, v3)); nextoff = off + 2; } else if (cm4 == 11) { dict[off] = new Dis(2, String.Format("Cmdb {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 12) { dict[off] = new Dis(2, String.Format("Cmdc {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 13) { dict[off] = new Dis(2, String.Format("Cmdd {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 14) { dict[off] = new Dis(2, String.Format("Cmde {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 15) { dict[off] = new Dis(2, String.Format("Cmdf {0:x3} ", v0 >> 4)); nextoff = off + 1; } // -- unknown else { dict[off] = new Dis(1, String.Format("? {0:x4} ", v0, si.Position - 2)); break; //nextoff = off + 1; //throw new NotSupportedException(String.Format("{1:X} {0:x4}", v0, si.Position)); } } catch (EndOfStreamException) { errors[off] = null; break; } } } }
private void Walk(int key, int off) { var offq = new Queue<int>(); offq.Enqueue(off); labels[off] = "K" + key; var obs = new CmdObs(); while (offq.Count != 0) { int nextoff = offq.Dequeue(); while (true) { off = nextoff; if (dict.ContainsKey(off)) break; si.Position = 0x10 + off*2; if (si.Position >= si.Length) { errors[off] = null; break; } try { int v0 = br.ReadUInt16(); int cm4 = v0 & 15; int cm8 = v0 & 255; obs.Eat(v0); if (false) { } // -- 16 bits cmd if (v0 == 0xffff) { dict[off] = new Dis(2, String.Format("TERM")); break; } // -- 8 bits cmd if (cm8 == 0x30) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd30 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } else if (cm8 == 0x60) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd60 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } else if (cm8 == 0xa0) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmda0 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } else if (cm8 == 0xc0) { int v2 = br.ReadInt32(); if (obs.Curt == CmdObs.T.Label && v2 != 0) { int newoff = v2; offq.Enqueue(newoff); dict[off] = new Dis(6, String.Format("Cmdc0l {0:x2} {1} ", v0 >> 8, GenLabel(newoff))); } else { dict[off] = new Dis(6, String.Format("Cmdc0i {0:x2} {1:x8} ", v0 >> 8, v2)); } nextoff = off + 3; } else if (cm8 == 0xe0) { int v2 = br.ReadUInt16(); si.Position = 0x10 + v2*2; dict[off] = new Dis(4, String.Format("Print {0:x2} '{1}' ", v0 >> 8, Ut.Read0Str(br))); nextoff = off + 2; } else if (cm8 == 0x0B) { int v2 = br.ReadInt32(); int newoff = off + 3 + v2; dict[off] = new Dis(6, String.Format("Call {0:x3} {1} ; {2} ", v0 >> 4, GenLabel(newoff), v2)); offq.Enqueue(newoff); nextoff = off + 3; } #if false else if (cm8 == 0x01) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd01 {0:x2} {1:x2} {2:x2} ", v0 >> 8, v2, v3)); nextoff = off + 2; } #endif else if (cm8 == 0x00) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd00 {0:x2} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 8, v2, v3, v4, v5)); nextoff = off + 3; } #if false else if (cm8 == 0x0a) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd0a {0:x2} {1:x2} ", v2, v3)); nextoff = off + 2; } #endif else if (cm8 == 0x40) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd40 {0:x2} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 8, v2, v3, v4, v5)); nextoff = off + 3; } else if (cm8 == 0x89) { dict[off] = new Dis(2, String.Format("Ret {0:x2}", v0 >> 8)); //nextoff = off + 1; break; } // -- 4 bits cmd else if (cm4 == 0) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd0 {0:x3} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 4, v2, v3, v4, v5)); nextoff = off + 3; } else if (cm4 == 1) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd1 {0:x3} {1:x2} {2:x2} ", v0 >> 4, v2, v3)); nextoff = off + 2; } else if (cm4 == 2) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); int v4 = br.ReadByte(); int v5 = br.ReadByte(); dict[off] = new Dis(6, String.Format("Cmd2 {0:x3} {1:x2} {2:x2} {3:x2} {4:x2} ", v0 >> 4, v2, v3, v4, v5)); nextoff = off + 3; } else if (cm4 == 3) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmd3 {0:x3} {1:x2} {2:x2} ", v0 >> 4, v2, v3)); nextoff = off + 2; } else if (cm4 == 4) { dict[off] = new Dis(2, String.Format("Cmd4 {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 5) { dict[off] = new Dis(2, String.Format("Cmd5 {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 6) { dict[off] = new Dis(2, String.Format("Cmd6 {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 7) { int v2 = br.ReadInt16(); int newoff = off + 2 + v2; dict[off] = new Dis(4, String.Format("J7 {0:x3} {1} ", v0 >> 4, GenLabel(newoff))); offq.Enqueue(newoff); bool noc = (v0 >> 4) == 0; if (noc) break; nextoff = off + 2; } else if (cm4 == 8) { int v2 = br.ReadInt16(); int newoff = off + 2 + v2; dict[off] = new Dis(4, String.Format("J8 {0:x3} {1} ", v0 >> 4, GenLabel(newoff))); offq.Enqueue(newoff); nextoff = off + 2; } else if (cm4 == 9) { dict[off] = new Dis(2, String.Format("Pause {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 10) { int v2 = br.ReadByte(); int v3 = br.ReadByte(); dict[off] = new Dis(4, String.Format("Cmda {0:x3} {1:x2} {2:x2} ", v0 >> 4, v2, v3)); nextoff = off + 2; } else if (cm4 == 11) { dict[off] = new Dis(2, String.Format("Cmdb {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 12) { dict[off] = new Dis(2, String.Format("Cmdc {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 13) { dict[off] = new Dis(2, String.Format("Cmdd {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 14) { dict[off] = new Dis(2, String.Format("Cmde {0:x3} ", v0 >> 4)); nextoff = off + 1; } else if (cm4 == 15) { dict[off] = new Dis(2, String.Format("Cmdf {0:x3} ", v0 >> 4)); nextoff = off + 1; } // -- unknown else { dict[off] = new Dis(1, String.Format("? {0:x4} ", v0, si.Position - 2)); break; //nextoff = off + 1; //throw new NotSupportedException(String.Format("{1:X} {0:x4}", v0, si.Position)); } } catch (EndOfStreamException) { errors[off] = null; break; } } } }
static void DumpCode(FrameContext tasklet) { Console.WriteLine("Code dump for " + tasklet.Program.Name ?? "<null>"); Console.WriteLine(Dis.dis(tasklet.Program)); }
static void Main(string[] cmdline_args) { if (cmdline_args.Length != 1) { Console.WriteLine("One argument required: path to script to compile and run."); return; } string program = null; using (var inFile = new StreamReader(cmdline_args[0])) { program = inFile.ReadToEnd(); } var inputStream = new AntlrInputStream(program); var lexer = new CloacaLexer(inputStream); CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); var errorListener = new ParseErrorListener(); var parser = new CloacaParser(commonTokenStream); parser.AddErrorListener(errorListener); if (errorListener.Errors.Count > 0) { Console.WriteLine("There were errors trying to compile the script. We cannot run it."); return; } var antlrVisitorContext = parser.file_input(); var variablesIn = new Dictionary <string, object>(); var visitor = new CloacaBytecodeVisitor(variablesIn); visitor.Visit(antlrVisitorContext); CodeObject compiledProgram = visitor.RootProgram.Build(); var scheduler = new Scheduler(); var interpreter = new Interpreter(scheduler); interpreter.DumpState = true; scheduler.SetInterpreter(interpreter); var context = scheduler.Schedule(compiledProgram).Frame; foreach (string varName in variablesIn.Keys) { context.SetVariable(varName, variablesIn[varName]); } interpreter.StepMode = true; bool traceMode = false; var debugRepl = new Piksel.LibREPL.Repl("dbg> ") { HeaderTitle = "Cloaca Interpreter Debugger", HeaderSubTitle = "Debug Cloaca ByteCode Evaluation" }; debugRepl.Commands.Add("g", new Command() { Action = (repl, cmd, args) => { if (scheduler.Done) { repl.Write("Scheduled programs are all done."); } else { interpreter.StepMode = false; while (!scheduler.Done) { try { scheduler.Tick().Wait(); } catch (AggregateException wrappedEscapedException) { // Given the nature of exception handling, we should normally only have one of these! ExceptionDispatchInfo.Capture(wrappedEscapedException.InnerExceptions[0]).Throw(); } } } }, Description = "Runs until finished" }); debugRepl.Commands.Add("s", new Command() { Action = (repl, cmd, args) => { if (scheduler.Done) { repl.Write("Scheduled programs are all done."); } else { interpreter.StepMode = true; try { scheduler.Tick().Wait(); } catch (AggregateException wrappedEscapedException) { // Given the nature of exception handling, we should normally only have one of these! ExceptionDispatchInfo.Capture(wrappedEscapedException.InnerExceptions[0]).Throw(); } if (traceMode) { DumpState(scheduler); } } }, Description = "Steps one line of bytecode" }); debugRepl.Commands.Add("d", new Command() { Action = (repl, cmd, args) => { if (scheduler.Done) { repl.Write("Scheduled programs are all done."); } else { var currentTasklet = scheduler.LastTasklet; if (currentTasklet != null && currentTasklet.Cursor < currentTasklet.CodeBytes.Bytes.Length) { DumpDatastack(currentTasklet); } } }, Description = "Dumps the data stack" }); debugRepl.Commands.Add("t", new Command() { Action = (repl, cmd, args) => { traceMode = !traceMode; if (traceMode) { repl.Write("Trace mode on."); } else { repl.Write("Trace mode off."); } }, Description = "Toggle trace mode." }); debugRepl.Commands.Add("c", new Command() { Action = (repl, cmd, args) => { if (scheduler.Done) { repl.Write("Scheduled programs are all done."); } else { DumpCode(scheduler); } }, Description = "Disassembles the current code object." }); debugRepl.Commands.Add("l", new Command() { Action = (repl, cmd, args) => { if (scheduler.Done) { repl.Write("Scheduled programs are all done."); } else { var currentTasklet = scheduler.LastTasklet; if (currentTasklet != null && currentTasklet.Cursor < currentTasklet.CodeBytes.Bytes.Length) { if (args.Length == 0) { repl.Write(Dis.dis(currentTasklet.Program, currentTasklet.Cursor, 1)); } else if (args.Length == 1) { int count = Int32.Parse(args[0]); repl.Write(Dis.dis(currentTasklet.Program, currentTasklet.Cursor, count)); } } } }, Description = "Disassembles byte code based on the current location (not implemented yet)." }); debugRepl.Start(); }
protected async Task <FrameContext> runProgram(string program, Dictionary <string, object> variablesIn, List <ISpecFinder> moduleSpecFinders, int expectedIterations, bool checkExceptions = true) { // TODO: This dependency association is kind of gross. It's almost circular and is broken by assigning // the interpreter reference to the schedular after its initial constructor. var scheduler = new Scheduler(); var interpreter = new Interpreter(scheduler); interpreter.DumpState = true; foreach (var finder in moduleSpecFinders) { interpreter.AddModuleFinder(finder); } scheduler.SetInterpreter(interpreter); scheduler.OnTaskScheduled += whenTaskScheduled; escapedExceptions = new List <ExceptionDispatchInfo>(); CodeObject compiledProgram = null; Task <CodeObject> compiledTask = null; try { // This is awaitable now but relies on the scheduler. We'll tick the scheduler // awhile until this resolves. compiledTask = ByteCodeCompiler.Compile(program, variablesIn, scheduler); } catch (CloacaParseException parseFailed) { Assert.Fail(parseFailed.Message); } for (int tries = 1; tries < 1000 && !compiledTask.IsCompleted && escapedExceptions.Count == 0; ++tries) { await scheduler.Tick(); } if (!compiledTask.IsCompleted) { Assert.Fail("Compilation did not finish with interpreter after 1,000 scheduler ticks"); } else if (escapedExceptions.Count > 0) { escapedExceptions[0].Throw(); } compiledProgram = await compiledTask; Dis.dis(compiledProgram); receipt = scheduler.Schedule(compiledProgram); FrameContext context = receipt.Frame; foreach (string varName in variablesIn.Keys) { context.SetVariable(varName, variablesIn[varName]); } // Waiting on the task makes sure we get punched in the face by any exceptions it throws. // But they'll come rolling in as AggregateExceptions so we'll have to unpack them. var scheduler_task = scheduler.RunUntilDone(); scheduler_task.Wait(); Assert.That(receipt.Completed); if (checkExceptions) { AssertNoExceptions(); } Assert.That(scheduler.TickCount, Is.EqualTo(expectedIterations)); return(context); }