diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8a8144a..c3193d2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - framework-version: [ 'net47', 'net48', 'net6.0', 'net7.0' ] + framework-version: [ 'net6.0', 'net7.0' ] steps: diff --git a/Lilikoi.Benchmarks/Mahogany/Applications/InjectSimple/SimpleInjectHost.cs b/Lilikoi.Benchmarks/Mahogany/Applications/InjectSimple/SimpleInjectHost.cs index 0bdbe09..fcec056 100644 --- a/Lilikoi.Benchmarks/Mahogany/Applications/InjectSimple/SimpleInjectHost.cs +++ b/Lilikoi.Benchmarks/Mahogany/Applications/InjectSimple/SimpleInjectHost.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Benchmarks::SimpleInjectHost.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -22,13 +22,13 @@ public bool Execute() return Injected.Execute(); } - public static Func Build() + public static Func Build() { return LilikoiMethod.FromMethodInfo(typeof(SimpleInjectHost).GetMethod(nameof(Execute))) .Input() .Output() .Build() .Finish() - .Compile(); + .Compile(); } -} \ No newline at end of file +} diff --git a/Lilikoi.Benchmarks/Mahogany/CompileBenchmarks.cs b/Lilikoi.Benchmarks/Mahogany/CompileBenchmarks.cs index 3651564..e28b069 100644 --- a/Lilikoi.Benchmarks/Mahogany/CompileBenchmarks.cs +++ b/Lilikoi.Benchmarks/Mahogany/CompileBenchmarks.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Benchmarks::CompileBenchmarks.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -23,8 +23,8 @@ namespace Lilikoi.Benchmarks.Mahogany; public class CompileBenchmarks { [Benchmark()] - public Func Simple() + public Func Simple() { return SimpleInjectHost.Build(); } -} \ No newline at end of file +} diff --git a/Lilikoi.Benchmarks/Mahogany/RunBenchmarks.cs b/Lilikoi.Benchmarks/Mahogany/RunBenchmarks.cs index 7268a78..ef15487 100644 --- a/Lilikoi.Benchmarks/Mahogany/RunBenchmarks.cs +++ b/Lilikoi.Benchmarks/Mahogany/RunBenchmarks.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Benchmarks::RunBenchmarks.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -25,8 +25,7 @@ namespace Lilikoi.Benchmarks.Mahogany; [MemoryDiagnoser(true)] public class RunBenchmarks { - public Func SimpleContainer; - public SimpleInjectHost SimpleHost = new(); + public Func SimpleContainer; [GlobalSetup] public void Setup() @@ -37,6 +36,6 @@ public void Setup() [Benchmark()] public bool Simple() { - return SimpleContainer(SimpleHost, true); + return SimpleContainer(true); } -} \ No newline at end of file +} diff --git a/Lilikoi.Tests/HelloWorld/HelloWorldHost.cs b/Lilikoi.Tests/HelloWorld/HelloWorldHost.cs index 0f056d8..36b9da7 100644 --- a/Lilikoi.Tests/HelloWorld/HelloWorldHost.cs +++ b/Lilikoi.Tests/HelloWorld/HelloWorldHost.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::HelloWorldHost.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -11,7 +11,7 @@ namespace Lilikoi.Tests.HelloWorld; -public class HelloWorldHost +public class HelloWorldHost : IDisposable { [Console] public ConsoleInj ConsoleImpl; @@ -21,4 +21,8 @@ public object HelloWorld() return ConsoleImpl; } -} \ No newline at end of file + + public void Dispose() + { + } +} diff --git a/Lilikoi.Tests/HelloWorld/HelloWorldTest.cs b/Lilikoi.Tests/HelloWorld/HelloWorldTest.cs index 0074baa..e9a8039 100644 --- a/Lilikoi.Tests/HelloWorld/HelloWorldTest.cs +++ b/Lilikoi.Tests/HelloWorld/HelloWorldTest.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::HelloWorldTest.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -34,6 +34,6 @@ public async Task HelloWorld() Console.WriteLine(build.ToString()); - build.Run(new HelloWorldHost(), new object()); + build.Run(new object()); } -} \ No newline at end of file +} diff --git a/Lilikoi.Tests/Injections/AllMethodsCalled/AllMethodsCalledTest.cs b/Lilikoi.Tests/Injections/AllMethodsCalled/AllMethodsCalledTest.cs index 01c62d6..3d5720e 100644 --- a/Lilikoi.Tests/Injections/AllMethodsCalled/AllMethodsCalledTest.cs +++ b/Lilikoi.Tests/Injections/AllMethodsCalled/AllMethodsCalledTest.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::AllMethodsCalledTest.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -36,7 +36,7 @@ public void AllMethodsCalled() Console.WriteLine(build.ToString()); - build.Run(new AllMethodsCalledHost(), Instance); + build.Run(Instance); Assert.IsTrue(Instance.InjectCalled, "Injection was not invoked"); @@ -53,4 +53,4 @@ public class AllMethodsCalledCounter public bool InjectCalled = false; public bool ParameterCalled = false; } -} \ No newline at end of file +} diff --git a/Lilikoi.Tests/Injections/UnaccessibleProperties.cs b/Lilikoi.Tests/Injections/UnaccessibleProperties.cs index e583ec2..60d642f 100644 --- a/Lilikoi.Tests/Injections/UnaccessibleProperties.cs +++ b/Lilikoi.Tests/Injections/UnaccessibleProperties.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::UnaccessibleProperties.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 24.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -33,7 +33,7 @@ public void UnaccessablePropertiesStillInject() Console.WriteLine(build.ToString()); - build.Run(new Host(), "Input"); + build.Run( "Input"); Assert.Fail("Entry point not executed"); } @@ -58,4 +58,4 @@ public string Entry() return "Entry"; } } -} \ No newline at end of file +} diff --git a/Lilikoi.Tests/Lilikoi.Tests.csproj b/Lilikoi.Tests/Lilikoi.Tests.csproj index 125f6a1..87cb834 100644 --- a/Lilikoi.Tests/Lilikoi.Tests.csproj +++ b/Lilikoi.Tests/Lilikoi.Tests.csproj @@ -12,22 +12,22 @@ - - - - - - + + + + + + - + - + diff --git a/Lilikoi.Tests/Mutator/Wildcards/WildcardTest.cs b/Lilikoi.Tests/Mutator/Wildcards/WildcardTest.cs index 60805c2..003962e 100644 --- a/Lilikoi.Tests/Mutator/Wildcards/WildcardTest.cs +++ b/Lilikoi.Tests/Mutator/Wildcards/WildcardTest.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::WildcardTest.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 02.02.2023 // -> Bumped: 06.02.2023 // ======================== @@ -33,7 +33,7 @@ public void CanInjectWildcard() .Finish(); var host = new WildcardHost(); - var value = container.Run(host, host); + var value = container.Run(host); Assert.AreEqual(WILDCARD_VALUE, value); } @@ -62,4 +62,4 @@ public string Entry(string thing) return thing; } } -} \ No newline at end of file +} diff --git a/Lilikoi.Tests/Wraps/SelfInject.cs b/Lilikoi.Tests/Wraps/SelfInject.cs index aba383b..e83bca6 100644 --- a/Lilikoi.Tests/Wraps/SelfInject.cs +++ b/Lilikoi.Tests/Wraps/SelfInject.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::SelfInject.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 24.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -34,7 +34,7 @@ public void BasicSelfInject() Console.WriteLine(build.ToString()); - var output = build.Run(new Host(), new object()); + var output = build.Run( new object()); Assert.Fail("Did not evaluate Assert.Pass() in WrapWithInjectionAttribute."); } @@ -85,4 +85,4 @@ public string Entry() return "Entry"; } } -} \ No newline at end of file +} diff --git a/Lilikoi.Tests/Wraps/WrapTests.cs b/Lilikoi.Tests/Wraps/WrapTests.cs index d50a2b1..6b8c03f 100644 --- a/Lilikoi.Tests/Wraps/WrapTests.cs +++ b/Lilikoi.Tests/Wraps/WrapTests.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi.Tests::WrapTests.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 24.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -31,7 +31,7 @@ public void Halts() Console.WriteLine(build.ToString()); - var output = build.Run(new DummyHost(), new object()); + var output = build.Run(new object()); Assert.AreEqual("Before", output); } @@ -50,7 +50,7 @@ public void Continues() Console.WriteLine(build.ToString()); - var output = build.Run(new DummyHost(), new object()); + var output = build.Run( new object()); Assert.Fail("Reached exit point without passing"); } @@ -69,7 +69,7 @@ public void Modifies() Console.WriteLine(build.ToString()); - var output = build.Run(new DummyHost(), new object()); + var output = build.Run< object, string>(new object()); Assert.AreEqual("After", output); } @@ -88,7 +88,7 @@ public void ModifiesInput() Console.WriteLine(build.ToString()); - var output = build.Run(new DummyHost(), "Input"); + var output = build.Run("Input"); Assert.Fail("Reached exit point without passing"); } @@ -123,4 +123,4 @@ public string ShouldModifyInput(string input) return "Entry"; } } -} \ No newline at end of file +} diff --git a/Lilikoi/Compiler/Mahogany/MahoganyCompiler.cs b/Lilikoi/Compiler/Mahogany/MahoganyCompiler.cs index b14908d..fcaed3c 100644 --- a/Lilikoi/Compiler/Mahogany/MahoganyCompiler.cs +++ b/Lilikoi/Compiler/Mahogany/MahoganyCompiler.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi::MahoganyCompiler.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -231,6 +231,12 @@ public void ParametersFor() } } + public void HostFor() + { + var step = new MahoganyCreateHostStep(Method); + Stack.Push(step.Generate(), Expression.Empty()); + } + public void ParameterSafety() { Method.Append( @@ -251,4 +257,4 @@ public void Apex() } #endregion -} \ No newline at end of file +} diff --git a/Lilikoi/Compiler/Mahogany/MahoganyMethod.cs b/Lilikoi/Compiler/Mahogany/MahoganyMethod.cs index 3d011eb..1403932 100644 --- a/Lilikoi/Compiler/Mahogany/MahoganyMethod.cs +++ b/Lilikoi/Compiler/Mahogany/MahoganyMethod.cs @@ -90,13 +90,13 @@ public LambdaExpression Lambda() var func = typeof(Func<,,>).MakeGenericType(Host, Input, Result); var internalVariables = new[] { - //Named(MahoganyConstants.HOST_VAR), Named(MahoganyConstants.INPUT_VAR), + // Named(MahoganyConstants.INPUT_VAR), + Named(MahoganyConstants.HOST_VAR), Named(MahoganyConstants.OUTPUT_VAR) }; var parameters = new[] { - Named(MahoganyConstants.HOST_VAR), Named(MahoganyConstants.INPUT_VAR) }; diff --git a/Lilikoi/Compiler/Mahogany/Steps/MahoganyCreateHostStep.cs b/Lilikoi/Compiler/Mahogany/Steps/MahoganyCreateHostStep.cs new file mode 100644 index 0000000..c8fb8a2 --- /dev/null +++ b/Lilikoi/Compiler/Mahogany/Steps/MahoganyCreateHostStep.cs @@ -0,0 +1,33 @@ +// ======================== +// Lilikoi::MahoganyCreateHostStep.cs +// (c) 2023. Distributed under the MIT License +// +// -> Created: 10.08.2023 +// -> Bumped: 10.08.2023 +// ======================== +using System.Linq.Expressions; +using System.Reflection; + +using Lilikoi.Attributes.Builders; + +namespace Lilikoi.Compiler.Mahogany.Steps; + +public class MahoganyCreateHostStep +{ + public MahoganyCreateHostStep(MahoganyMethod method) + { + Method = method; + } + + public MahoganyMethod Method { get; set; } + + public Expression Generate() + { + var host = Method.Named(MahoganyConstants.HOST_VAR); + + var creation = Expression.New(Method.Host); + var assignment = Expression.Assign(host, creation); + + return assignment; + } +} diff --git a/Lilikoi/Compiler/Public/LilikoiCompiler.cs b/Lilikoi/Compiler/Public/LilikoiCompiler.cs index 0fbd6f8..64de61c 100644 --- a/Lilikoi/Compiler/Public/LilikoiCompiler.cs +++ b/Lilikoi/Compiler/Public/LilikoiCompiler.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi::LilikoiCompiler.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -42,7 +42,9 @@ public LilikoiContainer Finish() { Mutators(); + Internal.HostFor(); Internal.ParameterSafety(); + Internal.InjectionsFor(Internal.Method.Host); foreach (var implicitWrap in ImplicitWraps) @@ -58,4 +60,4 @@ public LilikoiContainer Finish() return new LilikoiContainer(Smuggler, Internal.Method.Lambda()); } -} \ No newline at end of file +} diff --git a/Lilikoi/Compiler/Public/LilikoiContainer.cs b/Lilikoi/Compiler/Public/LilikoiContainer.cs index 4b39a83..5deb99a 100644 --- a/Lilikoi/Compiler/Public/LilikoiContainer.cs +++ b/Lilikoi/Compiler/Public/LilikoiContainer.cs @@ -1,7 +1,7 @@ // ======================== // Lilikoi::LilikoiContainer.cs // (c) 2023. Distributed under the MIT License -// +// // -> Created: 22.12.2022 // -> Bumped: 06.02.2023 // ======================== @@ -26,16 +26,16 @@ internal LilikoiContainer(Mount self, LambdaExpression body) : base(self) private Delegate Memoized { get; set; } - public TOut Run(THost host, TIn input) + public TOut Run(TIn input) { if (Memoized is null) - Memoized = Compile(); + Memoized = Compile(); - return (Memoized as Func)(host, input); + return (Memoized as Func)(input); } - public Func Compile() + public Func Compile() { - return Body.Compile(false) as Func; + return Body.Compile(false) as Func; } -} \ No newline at end of file +} diff --git a/Lilikoi/Lilikoi.csproj b/Lilikoi/Lilikoi.csproj index 4f06aed..3bb4cc6 100644 --- a/Lilikoi/Lilikoi.csproj +++ b/Lilikoi/Lilikoi.csproj @@ -43,9 +43,9 @@ - - - + + +