public void Repeat01() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("i", IrisType.Integer); globals.Add("a", IrisType.Integer); string input = @" repeat a := 0; i := i + 1; until i = 10;"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"L0: ldc.i4.0 stsfld 1 ldsfld 0 ldc.i4.1 add stsfld 0 ldsfld 0 ldc.i4.s 10 bne.un L0 "; Assert.AreEqual(expected, output); }
public void For01() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("i", IrisType.Integer); globals.Add("a", IrisType.Integer); string input = @"for i := 0 to 10 do a := 0;"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"ldc.i4.0 stsfld 0 L0: ldsfld 0 ldc.i4.s 10 bgt L1 ldc.i4.0 stsfld 1 ldsfld 0 ldc.i4.1 add stsfld 0 br L0 L1: "; Assert.AreEqual(expected, output); }
public void If02() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("a", IrisType.Integer); string input = @"if 1 > 0 or 1 < 0 then a := 0 else a := 1"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"ldc.i4.1 ldc.i4.0 cgt ldc.i4.1 ldc.i4.0 clt or brfalse L0 ldc.i4.0 stsfld 0 br L1 L0: ldc.i4.1 stsfld 0 L1: "; Assert.AreEqual(expected, output); }
public void CallProcedure02() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("p", Procedure.Create(new Variable[0])); string input = @"p();"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"call _Unknown "; Assert.AreEqual(expected, output); }
public void CallFunction02() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("f", Function.Create(IrisType.Integer, new Variable[0])); string input = @"f();"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"call _Unknown pop "; Assert.AreEqual(expected, output); }
public void Assign02() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("a", IrisType.Integer.MakeByRefType()); string input = @"a := 1;"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"ldsfld 0 ldc.i4.1 stind.i4 "; Assert.AreEqual(expected, output); }
public void If03() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("a", IrisType.Integer); string input = @"if 0 > 1 then a := 0 else if 1 < 1 then a := 1 else if 2 < 1 then a := 2 else a := 3"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"ldc.i4.0 ldc.i4.1 ble L0 ldc.i4.0 stsfld 0 br L1 L0: ldc.i4.1 ldc.i4.1 bge L2 ldc.i4.1 stsfld 0 br L3 L2: ldc.i4.2 ldc.i4.1 bge L4 ldc.i4.2 stsfld 0 br L5 L4: ldc.i4.3 stsfld 0 L5: L3: L1: "; Assert.AreEqual(expected, output); }
public void Assign01() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("a", IrisType.Integer.MakeArrayType()); string input = @"a[0] := a[1];"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"ldsfld 0 ldc.i4.0 ldsfld 0 ldc.i4.1 ldelem.i4 stelem.i4 "; Assert.AreEqual(expected, output); }
public void If01() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("a", IrisType.Integer); string input = @"if 1 > 0 then a := 0;"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"ldc.i4.1 ldc.i4.0 ble L0 ldc.i4.0 stsfld 0 L0: "; Assert.AreEqual(expected, output); }
public void While01() { GlobalSymbolList globals = new GlobalSymbolList(); globals.Add("a", IrisType.Integer); string input = @"while 1 > 0 do a := 0;"; string output = TestHelpers.TestStatementParser(input, globals); string expected = @"L0: ldc.i4.1 ldc.i4.0 ble L1 ldc.i4.0 stsfld 0 br L0 L1: "; Assert.AreEqual(expected, output); }