public override void Execute() { var inst = (ArithmeticInstruction)PlottyMachine.CurrentLine.Instruction; var origin = inst.Left.Id; var destination = inst.Destination.Id; int value = inst.Right.GetValue(PlottyMachine); if (inst.ArithmeticOperator == ArithmeticOperator.Add) { PlottyMachine.Registers[destination] = PlottyMachine.Registers[origin] + value; } if (inst.ArithmeticOperator == ArithmeticOperator.Substract) { PlottyMachine.Registers[destination] = PlottyMachine.Registers[origin] - value; } if (inst.ArithmeticOperator == ArithmeticOperator.Multiply) { PlottyMachine.Registers[destination] = PlottyMachine.Registers[origin] * value; } PlottyMachine.GoToNext(); }
private static void AssertRun(GenerationResult result, IEnumerable <Expectation> expectations) { var machine = new PlottyMachine(); machine.Load(result.Lines); while (machine.CanExecute) { machine.Execute(); } //foreach (var expectation in expectations) //{ // var address = result.AddressMap[new Reference(expectation.Reference)]; // if (expectation.Operator == Operator.Equal) // { // machine.Memory[address].Should().Be(expectation.Value); // } // else // { // machine.Memory[address].Should().NotBe(expectation.Value); // } //} }
private void AssertRun(string source, Expectation[] expectations) { var result = new PlottyCompiler() .Compile(source) .GenerationResult; var machine = new PlottyMachine(); machine.Load(result.Lines); while (machine.CanExecute) { machine.Execute(); } //foreach (var expectation in expectations) //{ // var address = result.AddressMap[new Reference(expectation.Reference)]; // if (expectation.Operator == Operator.Equal) // { // machine.Memory[address].Should().Be(expectation.Value); // } // else // { // machine.Memory[address].Should().NotBe(expectation.Value); // } //} }
public override void Execute() { var inst = (LoadInstruction)PlottyMachine.CurrentLine.Instruction; var value = inst.MemoryAddress.GetValue(PlottyMachine); PlottyMachine.Registers[inst.Destination.Id] = value; PlottyMachine.GoToNext(); }
public override void Execute() { var inst = (StoreInstruction)PlottyMachine.CurrentLine.Instruction; int value = inst.Source.GetValue(PlottyMachine); var address = inst.MemoryAddress.GetAddress(PlottyMachine); PlottyMachine.Memory[address] = value; PlottyMachine.GoToNext(); }
private static void ShowMachineState(PlottyMachine machine, CompilationResult result) { System.Console.WriteLine("Memory References:"); var state = machine.GetMemoryState(null); var taggedReferences = state.Select(x => $"[{x.Index}]\t{x.Reference}={x.Value}"); System.Console.WriteLine(string.Join("\n", taggedReferences)); System.Console.WriteLine(); }
private static void Run(CompilationResult result) { var machine = new PlottyMachine(); machine.Load(result.GenerationResult.Lines.ToList()); while (machine.CanExecute) { machine.Execute(); } System.Console.WriteLine(); //ShowMachineState(machine, result); }
public override void Execute() { var inst = (MoveInstruction)PlottyMachine.CurrentLine.Instruction; switch (inst.Source) { case ImmediateSource im: PlottyMachine.Registers[inst.Destination.Id] = im.Immediate; break; case RegisterSource reg: PlottyMachine.Registers[inst.Destination.Id] = PlottyMachine.Registers[reg.Register.Id]; break; } PlottyMachine.GoToNext(); }
public async Task Execute(List <ILine> lines, CancellationToken ct) { History.Clear(); PlottyMachine.Load(lines); while (PlottyMachine.CanExecute) { CurrentLine = new LineViewModel(PlottyMachine.LineNumber, PlottyMachine.CurrentLine); PlottyMachine.Execute(); RefreshRegisters(); //RefreshMemory(); if (CurrentLine?.Line?.Instruction is StoreInstruction) { RefreshConsole(); } ct.ThrowIfCancellationRequested(); await Task.Delay(Delay, ct); } }
public override void Execute() { var instruction = (BranchInstruction)PlottyMachine.CurrentLine.Instruction; var r1 = PlottyMachine.Registers[instruction.One.Id]; var r2 = PlottyMachine.Registers[instruction.Another.Id]; if (ShouldBranch(r1, r2, instruction.Operator)) { switch (instruction.Target) { case LabelTarget jt: PlottyMachine.GoTo(jt.Label.Name); break; case SourceTarget rt: PlottyMachine.GoTo(rt.Target.GetValue(PlottyMachine)); break; } } else { PlottyMachine.GoToNext(); } }
public PlottyMachineViewModel(PlottyMachine plottyMachine) { PlottyMachine = plottyMachine; Registers = PlottyMachine.Registers.Select((value, index) => new RegisterViewModel(index, value)).ToList(); Console = new ConsoleHandler(PlottyMachine.Memory, 20, 20); }
public MachineFixture() { Machine = new PlottyMachine(); }
public MachineContext(string source) { machine = new PlottyMachine(); machine.Load(new PlottyCompiler().Compile(source).GenerationResult.Lines); }
public override void Execute() { PlottyMachine.GoToNext(); }