public void CodeGenerator_ShouldFillInAddressOfLabelsCorrectly() { // Arrange var tacs = new Tacs() { Tac.Init(0), Tac.Goto("label0"), Tac.PrintValue(1), Tac.Label("label0", null), Tac.PrintValue(2), Tac.Halt() }; var output = new CodeGenerator().Generate(tacs); // Act var tinyOut = new TinyMachine(ExePath, TestFilePath).Execute(output); // Assert Assert.That(tinyOut, Is.EqualTo(new[] { "2" }), tinyOut.ToString()); }
public void TestStackFrameReturnAddress_WhenFunctionIsCalled_ExecutionShouldJumpToTheFunction_WhenFunctionFinishes_ExectionShouldReturn() { // Arrange var tacs = new Tacs { Tac.Init(0), Tac.PrintValue(1), Tac.BeginCall("main", 0, "t0"), Tac.Call("main", "t0"), Tac.PrintValue(2), Tac.Halt(), Tac.BeginFunc("main", 0), Tac.PrintValue(3), Tac.EndFunc("main") }; var output = new CodeGenerator().Generate(tacs); // Act var tinyOut = new TinyMachine(ExePath, TestFilePath).Execute(output); // Assert Assert.That(tinyOut, Is.EqualTo(new[] { "1", "3", "2" })); }