Skip to content

Commit

Permalink
Completely disable specifying host type and implementation.
Browse files Browse the repository at this point in the history
Hosts should be in a completely undefined state after being used by the container, so having this extra functionality really doesn't make sense.
This is a pretty big breaking change throughout the API.
  • Loading branch information
Mooshua committed Aug 11, 2023
1 parent 88f585f commit f4e1cfb
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Benchmarks::SimpleInjectHost.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand All @@ -22,13 +22,13 @@ public bool Execute()
return Injected.Execute();
}

public static Func<SimpleInjectHost, bool, bool> Build()
public static Func<bool, bool> Build()
{
return LilikoiMethod.FromMethodInfo(typeof(SimpleInjectHost).GetMethod(nameof(Execute)))
.Input<bool>()
.Output<bool>()
.Build()
.Finish()
.Compile<SimpleInjectHost, bool, bool>();
.Compile<bool, bool>();
}
}
}
6 changes: 3 additions & 3 deletions Lilikoi.Benchmarks/Mahogany/CompileBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Benchmarks::CompileBenchmarks.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand All @@ -23,8 +23,8 @@ namespace Lilikoi.Benchmarks.Mahogany;
public class CompileBenchmarks
{
[Benchmark()]
public Func<SimpleInjectHost, bool, bool> Simple()
public Func<bool, bool> Simple()
{
return SimpleInjectHost.Build();
}
}
}
9 changes: 4 additions & 5 deletions Lilikoi.Benchmarks/Mahogany/RunBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Benchmarks::RunBenchmarks.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand All @@ -25,8 +25,7 @@ namespace Lilikoi.Benchmarks.Mahogany;
[MemoryDiagnoser(true)]
public class RunBenchmarks
{
public Func<SimpleInjectHost, bool, bool> SimpleContainer;
public SimpleInjectHost SimpleHost = new();
public Func<bool, bool> SimpleContainer;

[GlobalSetup]
public void Setup()
Expand All @@ -37,6 +36,6 @@ public void Setup()
[Benchmark()]
public bool Simple()
{
return SimpleContainer(SimpleHost, true);
return SimpleContainer(true);
}
}
}
10 changes: 7 additions & 3 deletions Lilikoi.Tests/HelloWorld/HelloWorldHost.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::HelloWorldHost.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand All @@ -11,7 +11,7 @@

namespace Lilikoi.Tests.HelloWorld;

public class HelloWorldHost
public class HelloWorldHost : IDisposable
{
[Console] public ConsoleInj ConsoleImpl;

Expand All @@ -21,4 +21,8 @@ public object HelloWorld()

return ConsoleImpl;
}
}

public void Dispose()
{
}
}
6 changes: 3 additions & 3 deletions Lilikoi.Tests/HelloWorld/HelloWorldTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::HelloWorldTest.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -34,6 +34,6 @@ public async Task HelloWorld()

Console.WriteLine(build.ToString());

build.Run<HelloWorldHost, object, object>(new HelloWorldHost(), new object());
build.Run<object, object>(new object());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::AllMethodsCalledTest.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -36,7 +36,7 @@ public void AllMethodsCalled()

Console.WriteLine(build.ToString());

build.Run<AllMethodsCalledHost, AllMethodsCalledCounter, object>(new AllMethodsCalledHost(), Instance);
build.Run<AllMethodsCalledCounter, object>(Instance);


Assert.IsTrue(Instance.InjectCalled, "Injection was not invoked");
Expand All @@ -53,4 +53,4 @@ public class AllMethodsCalledCounter
public bool InjectCalled = false;
public bool ParameterCalled = false;
}
}
}
6 changes: 3 additions & 3 deletions Lilikoi.Tests/Injections/UnaccessibleProperties.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::UnaccessibleProperties.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 24.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -33,7 +33,7 @@ public void UnaccessablePropertiesStillInject()

Console.WriteLine(build.ToString());

build.Run<Host, string, string>(new Host(), "Input");
build.Run<string, string>( "Input");

Assert.Fail("Entry point not executed");
}
Expand All @@ -58,4 +58,4 @@ public string Entry()
return "Entry";
}
}
}
}
6 changes: 3 additions & 3 deletions Lilikoi.Tests/Mutator/Wildcards/WildcardTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::WildcardTest.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 02.02.2023
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -33,7 +33,7 @@ public void CanInjectWildcard()
.Finish();

var host = new WildcardHost();
var value = container.Run<WildcardHost, object, string>(host, host);
var value = container.Run<object, string>(host);

Assert.AreEqual(WILDCARD_VALUE, value);
}
Expand Down Expand Up @@ -62,4 +62,4 @@ public string Entry(string thing)
return thing;
}
}
}
}
6 changes: 3 additions & 3 deletions Lilikoi.Tests/Wraps/SelfInject.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::SelfInject.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 24.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -34,7 +34,7 @@ public void BasicSelfInject()

Console.WriteLine(build.ToString());

var output = build.Run<Host, object, string>(new Host(), new object());
var output = build.Run<object, string>( new object());

Assert.Fail("Did not evaluate Assert.Pass() in WrapWithInjectionAttribute.");
}
Expand Down Expand Up @@ -85,4 +85,4 @@ public string Entry()
return "Entry";
}
}
}
}
12 changes: 6 additions & 6 deletions Lilikoi.Tests/Wraps/WrapTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi.Tests::WrapTests.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 24.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -31,7 +31,7 @@ public void Halts()

Console.WriteLine(build.ToString());

var output = build.Run<DummyHost, object, string>(new DummyHost(), new object());
var output = build.Run<object, string>(new object());

Assert.AreEqual("Before", output);
}
Expand All @@ -50,7 +50,7 @@ public void Continues()

Console.WriteLine(build.ToString());

var output = build.Run<DummyHost, object, string>(new DummyHost(), new object());
var output = build.Run<object, string>( new object());

Assert.Fail("Reached exit point without passing");
}
Expand All @@ -69,7 +69,7 @@ public void Modifies()

Console.WriteLine(build.ToString());

var output = build.Run<DummyHost, object, string>(new DummyHost(), new object());
var output = build.Run< object, string>(new object());

Assert.AreEqual("After", output);
}
Expand All @@ -88,7 +88,7 @@ public void ModifiesInput()

Console.WriteLine(build.ToString());

var output = build.Run<DummyHost, string, string>(new DummyHost(), "Input");
var output = build.Run<string, string>("Input");

Assert.Fail("Reached exit point without passing");
}
Expand Down Expand Up @@ -123,4 +123,4 @@ public string ShouldModifyInput(string input)
return "Entry";
}
}
}
}
10 changes: 8 additions & 2 deletions Lilikoi/Compiler/Mahogany/MahoganyCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi::MahoganyCompiler.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -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(
Expand All @@ -251,4 +257,4 @@ public void Apex()
}

#endregion
}
}
4 changes: 2 additions & 2 deletions Lilikoi/Compiler/Mahogany/MahoganyMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down
33 changes: 33 additions & 0 deletions Lilikoi/Compiler/Mahogany/Steps/MahoganyCreateHostStep.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
6 changes: 4 additions & 2 deletions Lilikoi/Compiler/Public/LilikoiCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ========================
// Lilikoi::LilikoiCompiler.cs
// (c) 2023. Distributed under the MIT License
//
//
// -> Created: 22.12.2022
// -> Bumped: 06.02.2023
// ========================
Expand Down Expand Up @@ -42,7 +42,9 @@ public LilikoiContainer Finish()
{
Mutators();

Internal.HostFor();
Internal.ParameterSafety();

Internal.InjectionsFor(Internal.Method.Host);

foreach (var implicitWrap in ImplicitWraps)
Expand All @@ -58,4 +60,4 @@ public LilikoiContainer Finish()

return new LilikoiContainer(Smuggler, Internal.Method.Lambda());
}
}
}

0 comments on commit f4e1cfb

Please sign in to comment.