From 88607be70e9ed06e72b9c804c5be60f3beff1834 Mon Sep 17 00:00:00 2001 From: Ludovic Lagouardette Date: Wed, 22 Jun 2022 09:00:23 +0200 Subject: [PATCH] Remastered architecture of project and tests --- SuperBASIC.sln | 8 +++- BasicNumber.cs => SuperBASIC/BasicNumber.cs | 2 +- Bytecode.cs => SuperBASIC/Bytecode.cs | 0 {Functions => SuperBASIC/Functions}/Add.cs | 2 +- .../Functions}/Compare.cs | 2 +- .../Functions}/Constants.cs | 4 +- {Functions => SuperBASIC/Functions}/Goto.cs | 4 +- {Functions => SuperBASIC/Functions}/Memory.cs | 10 ++--- .../Functions}/Multiply.cs | 2 +- {Functions => SuperBASIC/Functions}/Print.cs | 2 +- IFunction.cs => SuperBASIC/IFunction.cs | 2 +- LICENCE => SuperBASIC/LICENCE | 0 Library.cs => SuperBASIC/Library.cs | 2 +- Parser.cs => SuperBASIC/Parser.cs | 0 Program.cs => SuperBASIC/Program.cs | 0 Runtime.cs => SuperBASIC/Runtime.cs | 2 +- .../SuperBASIC.csproj | 0 Test.basic => SuperBASIC/Test.basic | 0 .../CasDeTest/PrebuiltTest-TestA.basic | 11 ++++++ TestsSuperBASIC/Mock/MockPrint.cs | 20 ++++++++++ TestsSuperBASIC/PrebuiltTest.cs | 37 +++++++++++++++++++ TestsSuperBASIC/TestsSuperBASIC.csproj | 26 +++++++++++++ 22 files changed, 118 insertions(+), 18 deletions(-) rename BasicNumber.cs => SuperBASIC/BasicNumber.cs (98%) rename Bytecode.cs => SuperBASIC/Bytecode.cs (100%) rename {Functions => SuperBASIC/Functions}/Add.cs (87%) rename {Functions => SuperBASIC/Functions}/Compare.cs (86%) rename {Functions => SuperBASIC/Functions}/Constants.cs (82%) rename {Functions => SuperBASIC/Functions}/Goto.cs (88%) rename {Functions => SuperBASIC/Functions}/Memory.cs (85%) rename {Functions => SuperBASIC/Functions}/Multiply.cs (85%) rename {Functions => SuperBASIC/Functions}/Print.cs (87%) rename IFunction.cs => SuperBASIC/IFunction.cs (84%) rename LICENCE => SuperBASIC/LICENCE (100%) rename Library.cs => SuperBASIC/Library.cs (96%) rename Parser.cs => SuperBASIC/Parser.cs (100%) rename Program.cs => SuperBASIC/Program.cs (100%) rename Runtime.cs => SuperBASIC/Runtime.cs (97%) rename SuperBASIC.csproj => SuperBASIC/SuperBASIC.csproj (100%) rename Test.basic => SuperBASIC/Test.basic (100%) create mode 100644 TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic create mode 100644 TestsSuperBASIC/Mock/MockPrint.cs create mode 100644 TestsSuperBASIC/PrebuiltTest.cs create mode 100644 TestsSuperBASIC/TestsSuperBASIC.csproj diff --git a/SuperBASIC.sln b/SuperBASIC.sln index d445c26..e328fb0 100644 --- a/SuperBASIC.sln +++ b/SuperBASIC.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30907.101 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperBASIC", "SuperBASIC.csproj", "{51942D92-4C96-4FD9-AA5B-C35661E3B063}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SuperBASIC", "SuperBASIC\SuperBASIC.csproj", "{51942D92-4C96-4FD9-AA5B-C35661E3B063}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsSuperBASIC", "TestsSuperBASIC\TestsSuperBASIC.csproj", "{68535611-B607-4476-B887-0B8D713F3A4D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {51942D92-4C96-4FD9-AA5B-C35661E3B063}.Debug|Any CPU.Build.0 = Debug|Any CPU {51942D92-4C96-4FD9-AA5B-C35661E3B063}.Release|Any CPU.ActiveCfg = Release|Any CPU {51942D92-4C96-4FD9-AA5B-C35661E3B063}.Release|Any CPU.Build.0 = Release|Any CPU + {68535611-B607-4476-B887-0B8D713F3A4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68535611-B607-4476-B887-0B8D713F3A4D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68535611-B607-4476-B887-0B8D713F3A4D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68535611-B607-4476-B887-0B8D713F3A4D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BasicNumber.cs b/SuperBASIC/BasicNumber.cs similarity index 98% rename from BasicNumber.cs rename to SuperBASIC/BasicNumber.cs index 4523990..48dae23 100644 --- a/BasicNumber.cs +++ b/SuperBASIC/BasicNumber.cs @@ -11,7 +11,7 @@ namespace SuperBASIC Memory }; - struct BasicNumber + public struct BasicNumber { internal NumberType type; diff --git a/Bytecode.cs b/SuperBASIC/Bytecode.cs similarity index 100% rename from Bytecode.cs rename to SuperBASIC/Bytecode.cs diff --git a/Functions/Add.cs b/SuperBASIC/Functions/Add.cs similarity index 87% rename from Functions/Add.cs rename to SuperBASIC/Functions/Add.cs index 8a13eca..6489541 100644 --- a/Functions/Add.cs +++ b/SuperBASIC/Functions/Add.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC.Functions { - class Add : IFunction + public class Add : IFunction { float IFunction.Apply(List arguments) { diff --git a/Functions/Compare.cs b/SuperBASIC/Functions/Compare.cs similarity index 86% rename from Functions/Compare.cs rename to SuperBASIC/Functions/Compare.cs index fd4267e..248ff08 100644 --- a/Functions/Compare.cs +++ b/SuperBASIC/Functions/Compare.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC.Functions { - class Compare : IFunction + public class Compare : IFunction { float IFunction.Apply(List arguments) { diff --git a/Functions/Constants.cs b/SuperBASIC/Functions/Constants.cs similarity index 82% rename from Functions/Constants.cs rename to SuperBASIC/Functions/Constants.cs index fc7bda7..c733c40 100644 --- a/Functions/Constants.cs +++ b/SuperBASIC/Functions/Constants.cs @@ -4,14 +4,14 @@ using System.Text; namespace SuperBASIC.Functions { - class Pi : IFunction + public class Pi : IFunction { float IFunction.Apply(List arguments) { return (float)Math.PI; } } - class Euler : IFunction + public class Euler : IFunction { float IFunction.Apply(List arguments) { diff --git a/Functions/Goto.cs b/SuperBASIC/Functions/Goto.cs similarity index 88% rename from Functions/Goto.cs rename to SuperBASIC/Functions/Goto.cs index a4eb11a..f721320 100644 --- a/Functions/Goto.cs +++ b/SuperBASIC/Functions/Goto.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC.Functions { - class Goto : IFunction + public class Goto : IFunction { public float Apply(List arguments) { @@ -13,7 +13,7 @@ namespace SuperBASIC.Functions return arguments[0].runtime.register; } } - class JumpZero : IFunction + public class JumpZero : IFunction { public float Apply(List arguments) { diff --git a/Functions/Memory.cs b/SuperBASIC/Functions/Memory.cs similarity index 85% rename from Functions/Memory.cs rename to SuperBASIC/Functions/Memory.cs index 7250df1..eca61a5 100644 --- a/Functions/Memory.cs +++ b/SuperBASIC/Functions/Memory.cs @@ -5,12 +5,12 @@ using System.Text; namespace SuperBASIC.Functions { #if MEMORY - static class Memory + static public class Memory { internal static float[] memory = new float[Int16.MaxValue]; - internal static float MemoryGet(Int16 pos) => memory[pos]; - internal static float MemorySet(Int16 pos, float value) + public static float MemoryGet(Int16 pos) => memory[pos]; + public static float MemorySet(Int16 pos, float value) { memory[pos] = value; return value; @@ -30,7 +30,7 @@ namespace SuperBASIC.Functions } - class MemoryLoad : IFunction + public class MemoryLoad : IFunction { float IFunction.Apply(List arguments) { @@ -42,7 +42,7 @@ namespace SuperBASIC.Functions throw new Memory.BadMemoryAccess("Could not access requested memory"); } } - class MemoryStore : IFunction + public class MemoryStore : IFunction { float IFunction.Apply(List arguments) { diff --git a/Functions/Multiply.cs b/SuperBASIC/Functions/Multiply.cs similarity index 85% rename from Functions/Multiply.cs rename to SuperBASIC/Functions/Multiply.cs index e433515..a2b11d5 100644 --- a/Functions/Multiply.cs +++ b/SuperBASIC/Functions/Multiply.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC.Functions { - class Multiply : IFunction + public class Multiply : IFunction { float IFunction.Apply(List arguments) { diff --git a/Functions/Print.cs b/SuperBASIC/Functions/Print.cs similarity index 87% rename from Functions/Print.cs rename to SuperBASIC/Functions/Print.cs index 87f7b70..f718f37 100644 --- a/Functions/Print.cs +++ b/SuperBASIC/Functions/Print.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC.Functions { - class Print : IFunction + public class Print : IFunction { float IFunction.Apply(List arguments) { diff --git a/IFunction.cs b/SuperBASIC/IFunction.cs similarity index 84% rename from IFunction.cs rename to SuperBASIC/IFunction.cs index 006d617..bcf83e2 100644 --- a/IFunction.cs +++ b/SuperBASIC/IFunction.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC { - interface IFunction + public interface IFunction { public float Apply(List arguments); } diff --git a/LICENCE b/SuperBASIC/LICENCE similarity index 100% rename from LICENCE rename to SuperBASIC/LICENCE diff --git a/Library.cs b/SuperBASIC/Library.cs similarity index 96% rename from Library.cs rename to SuperBASIC/Library.cs index dee7876..6eec468 100644 --- a/Library.cs +++ b/SuperBASIC/Library.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC { - class Library + public class Library { internal List functions; internal List arities; diff --git a/Parser.cs b/SuperBASIC/Parser.cs similarity index 100% rename from Parser.cs rename to SuperBASIC/Parser.cs diff --git a/Program.cs b/SuperBASIC/Program.cs similarity index 100% rename from Program.cs rename to SuperBASIC/Program.cs diff --git a/Runtime.cs b/SuperBASIC/Runtime.cs similarity index 97% rename from Runtime.cs rename to SuperBASIC/Runtime.cs index 4a2e08c..3ce76dd 100644 --- a/Runtime.cs +++ b/SuperBASIC/Runtime.cs @@ -4,7 +4,7 @@ using System.Text; namespace SuperBASIC { - class Runtime + public class Runtime { public float register; internal Library lib; diff --git a/SuperBASIC.csproj b/SuperBASIC/SuperBASIC.csproj similarity index 100% rename from SuperBASIC.csproj rename to SuperBASIC/SuperBASIC.csproj diff --git a/Test.basic b/SuperBASIC/Test.basic similarity index 100% rename from Test.basic rename to SuperBASIC/Test.basic diff --git a/TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic b/TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic new file mode 100644 index 0000000..5c768cd --- /dev/null +++ b/TestsSuperBASIC/CasDeTest/PrebuiltTest-TestA.basic @@ -0,0 +1,11 @@ +MEMSTORE 1 0 +MEMSTORE 0 10 +WHILE MEMLOAD 0 +MEMLOAD 0 +ADD $ -1 +MEMSTORE 0 $ +MEMLOAD 1 +ADD $ 1 +MEMSTORE 1 $ +PRINT M1 +WEND \ No newline at end of file diff --git a/TestsSuperBASIC/Mock/MockPrint.cs b/TestsSuperBASIC/Mock/MockPrint.cs new file mode 100644 index 0000000..13496d6 --- /dev/null +++ b/TestsSuperBASIC/Mock/MockPrint.cs @@ -0,0 +1,20 @@ +using SuperBASIC; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TestsSuperBASIC.Mock +{ + class MockPrint : SuperBASIC.IFunction + { + public List output = new List(); + + float IFunction.Apply(List arguments) + { + output.Add(arguments[0]); + return 0; + } + } +} diff --git a/TestsSuperBASIC/PrebuiltTest.cs b/TestsSuperBASIC/PrebuiltTest.cs new file mode 100644 index 0000000..21081b4 --- /dev/null +++ b/TestsSuperBASIC/PrebuiltTest.cs @@ -0,0 +1,37 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SuperBASIC; +using System.IO; +using System.Linq; + +namespace TestsSuperBASIC +{ + [TestClass] + public class PrebuiltTest + { + [TestMethod] + public void TestA() + { + + Library lib = new Library(); + var printer = new Mock.MockPrint(); + lib.AddFunction(printer, 1, "PRINT"); + + lib.AddFunction(new SuperBASIC.Functions.MemoryLoad(), 1, "MEMLOAD"); + lib.AddFunction(new SuperBASIC.Functions.MemoryStore(), 2, "MEMSTORE"); + lib.AddFunction(new SuperBASIC.Functions.Multiply(), 2, "MULTIPLY"); + lib.AddFunction(new SuperBASIC.Functions.Add(), 2, "ADD"); + lib.AddFunction(new SuperBASIC.Functions.Compare(), 2, "COMPARE"); + lib.AddFunction(new SuperBASIC.Functions.JumpZero(), 2, "JZ"); + lib.AddFunction(new SuperBASIC.Functions.Goto(), 1, "GOTO"); + lib.AddFunction(new SuperBASIC.Functions.Pi(), 0, "PI"); + lib.AddFunction(new SuperBASIC.Functions.Euler(), 0, "EULER"); + Runtime r = new Runtime(lib); + r.OpenFile(Directory.GetCurrentDirectory() + "\\CasDeTest\\PrebuiltTest-TestA.basic"); + r.Run(); + foreach(var (expected, received) in Enumerable.Range(1,10).Zip(printer.output)) + { + Assert.AreEqual(expected, received); + } + } + } +} diff --git a/TestsSuperBASIC/TestsSuperBASIC.csproj b/TestsSuperBASIC/TestsSuperBASIC.csproj new file mode 100644 index 0000000..9ecf08c --- /dev/null +++ b/TestsSuperBASIC/TestsSuperBASIC.csproj @@ -0,0 +1,26 @@ + + + + net5.0 + + false + + + + + + + + + + + + + + + + PreserveNewest + + + +