Skip to content

Commit

Permalink
Merge pull request #9 from Mooshua/workspace
Browse files Browse the repository at this point in the history
Completely disable specifying host type and implementation.
  • Loading branch information
Mooshua authored Aug 11, 2023
2 parents dfb4767 + e142f16 commit 5cc9a02
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
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;

Check warning on line 16 in Lilikoi.Tests/HelloWorld/HelloWorldHost.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'ConsoleImpl' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

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";
}
}
}
}
16 changes: 8 additions & 8 deletions Lilikoi.Tests/Lilikoi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AgileObjects.ReadableExpressions" Version="3.3.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.3.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.2"/>
<PackageReference Include="AgileObjects.ReadableExpressions" Version="3.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Lilikoi\Lilikoi.csproj"/>
<ProjectReference Include="..\Lilikoi\Lilikoi.csproj" />
</ItemGroup>


<ItemGroup>
<Folder Include="Parameters"/>
<Folder Include="Parameters" />
</ItemGroup>

</Project>
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;
}
}
Loading

0 comments on commit 5cc9a02

Please sign in to comment.