public void ConstructorTest() { string outputPath = "../../../TestFiles/PrintNumber/UnitTest.vm"; VmWriter vmWriter = new VmWriter(outputPath); Assert.IsTrue(File.Exists(outputPath), "file not found."); }
public CompilationEngineVm(IList <Pair <string, string> > classTokensList, VmWriter vmWriter, string className) { // reverse tokens before push onto stack (so we Pop them in the correct order!) classTokensList = classTokensList.Reverse().ToList(); this.classTokens = new Stack <Pair <string, string> >(); this.vmWriter = vmWriter; this.className = className; foreach (Pair <string, string> token in classTokensList) { this.classTokens.Push(token); } }
public CompilationEngineVm(IList<Pair<string, string>> classTokensList, VmWriter vmWriter, string className) { // reverse tokens before push onto stack (so we Pop them in the correct order!) classTokensList = classTokensList.Reverse().ToList(); this.classTokens = new Stack<Pair<string, string>>(); this.vmWriter = vmWriter; this.className = className; foreach (Pair<string, string> token in classTokensList) { this.classTokens.Push(token); } }
public void WriteGotoTest() { string outputPath = "../../../TestFiles/PrintNumber/UnitTest.vm"; using (VmWriter vmWriter = new VmWriter(outputPath)) { vmWriter.WriteGoto("SomeLabel"); } using (StreamReader streamReader = new StreamReader(File.OpenRead("../../../TestFiles/PrintNumber/UnitTest.vm"))) { string line = streamReader.ReadLine().Trim(); Assert.IsTrue(string.Equals(line, "goto SomeLabel", StringComparison.InvariantCulture)); } }
public void WriteArithmeticTest() { string outputPath = "../../../TestFiles/PrintNumber/UnitTest.vm"; using (VmWriter vmWriter = new VmWriter(outputPath)) { vmWriter.WriteArithmetic(ArithmeticCommand.Add); } using (StreamReader streamReader = new StreamReader(File.OpenRead("../../../TestFiles/PrintNumber/UnitTest.vm"))) { string line = streamReader.ReadLine().Trim(); Assert.IsTrue(string.Equals(line, "add", StringComparison.InvariantCulture)); } }
public void Compile() { IList <Pair <string, string> > tokens = null; using (Tokenizer tokenizer = new Tokenizer(this.inputPath)) { tokens = tokenizer.GetTokens(); } tokens = tokens.Where(t => t.Value1 != "Comment").ToList(); using (VmWriter vmWriter = new VmWriter(GetOutputPath())) { CompilationEngineVm compilationEngineVm = new CompilationEngineVm(tokens, vmWriter, Path.GetFileNameWithoutExtension(inputPath)); compilationEngineVm.CompileClass(); } }
public void WritePushTest() { string outputPath = "../../../TestFiles/PrintNumber/UnitTest.vm"; using(VmWriter vmWriter = new VmWriter(outputPath)) { vmWriter.WritePush(Segment.Argument, 1); } using (StreamReader streamReader = new StreamReader(File.OpenRead("../../../TestFiles/PrintNumber/UnitTest.vm"))) { string line = streamReader.ReadLine().Trim(); Assert.IsTrue(string.Equals(line, "push Argument 1", StringComparison.InvariantCulture)); } }