public void TestParseFunction2() { var byteCodeParser = new ByteCodeParser(new Tokenizer().Tokenize("func std.println(Int) Void\n{\nADDINT\n}").ToList()); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Functions.Count); var function = assembly.Functions[0]; Assert.AreEqual(1, function.Instructions.Count); Assert.AreEqual(OpCodes.AddInt, function.Instructions[0].OpCode); }
public void TestParseFunction3() { var byteCodeParser = new ByteCodeParser(new Tokenizer().Tokenize("func std.println(Int) Void\n{\nNEWARR Int\n}").ToList()); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Functions.Count); var function = assembly.Functions[0]; Assert.AreEqual(1, function.Instructions.Count); Assert.AreEqual(OpCodes.NewArray, function.Instructions[0].OpCode); Assert.AreEqual("Int", function.Instructions[0].StringValue); }
public void TestParseFunction() { var byteCodeParser = new ByteCodeParser(new Tokenizer().Tokenize("func std.println(Int) Void\n{\n}").ToList()); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Functions.Count); var function = assembly.Functions[0]; Assert.AreEqual("std.println", function.Name); Assert.AreEqual(1, function.Parameters.Count); Assert.AreEqual("Int", function.Parameters[0]); Assert.AreEqual("Void", function.ReturnType); }
public void TestLocals() { var byteCodeParser = new ByteCodeParser(this.TokenizeFile("locals.txt")); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Functions.Count); var function = assembly.Functions[0]; Assert.AreEqual(2, function.Locals.Count); Assert.AreEqual("Int", function.Locals[0]); Assert.AreEqual("Float", function.Locals[1]); Assert.AreEqual(1, function.Instructions.Count); Assert.AreEqual(OpCodes.Return, function.Instructions[0].OpCode); }
public void TestClass() { var byteCodeParser = new ByteCodeParser(this.TokenizeFile("class.txt")); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Classes.Count); var currentClass = assembly.Classes[0]; Assert.AreEqual("Point", currentClass.Name); Assert.AreEqual(2, currentClass.Fields.Count); Assert.AreEqual("x", currentClass.Fields[0].Name); Assert.AreEqual("Int", currentClass.Fields[0].Type); Assert.AreEqual("y", currentClass.Fields[1].Name); Assert.AreEqual("Int", currentClass.Fields[1].Type); }
public void TestInt() { var byteCodeParser = new ByteCodeParser(this.TokenizeFile("int.txt")); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Functions.Count); var function = assembly.Functions[0]; Assert.AreEqual(4, function.Instructions.Count); Assert.AreEqual(OpCodes.LoadArgument, function.Instructions[0].OpCode); Assert.AreEqual(0, function.Instructions[0].IntValue); Assert.AreEqual(OpCodes.LoadArgument, function.Instructions[1].OpCode); Assert.AreEqual(1, function.Instructions[1].IntValue); Assert.AreEqual(OpCodes.AddInt, function.Instructions[2].OpCode); Assert.AreEqual(OpCodes.Return, function.Instructions[3].OpCode); }
public void TestCall() { var byteCodeParser = new ByteCodeParser(this.TokenizeFile("call.txt")); var assembly = byteCodeParser.Parse(); Assert.AreEqual(1, assembly.Functions.Count); var function = assembly.Functions[0]; Assert.AreEqual(4, function.Instructions.Count); Assert.AreEqual(OpCodes.LoadArgument, function.Instructions[0].OpCode); Assert.AreEqual(OpCodes.LoadArgument, function.Instructions[1].OpCode); Assert.AreEqual(OpCodes.Call, function.Instructions[2].OpCode); Assert.AreEqual("addInternal", function.Instructions[2].StringValue); Assert.AreEqual(2, function.Instructions[2].Parameters.Count); Assert.AreEqual("Int", function.Instructions[2].Parameters[0]); Assert.AreEqual("Float", function.Instructions[2].Parameters[1]); Assert.AreEqual(OpCodes.Return, function.Instructions[3].OpCode); }