diff --git a/source/Cosmos.IL2CPU/AppAssembler.cs b/source/Cosmos.IL2CPU/AppAssembler.cs index e4c69b303..e8e38971c 100644 --- a/source/Cosmos.IL2CPU/AppAssembler.cs +++ b/source/Cosmos.IL2CPU/AppAssembler.cs @@ -935,7 +935,15 @@ public unsafe void GenerateVMTCode(HashSet aTypesSet, HashSet XS.Push((uint)(xType.IsValueType && !xType.IsByRef && !xType.IsPointer && !xType.IsPrimitive ? 1 : 0)); LdStr.PushString(Assembler, xType.Name); - LdStr.PushString(Assembler, xType.AssemblyQualifiedName); + + if (xType.AssemblyQualifiedName != null) + { + LdStr.PushString(Assembler, xType.AssemblyQualifiedName); + } + else { + // AssemblyQualifiedName is null for generic types + LdStr.PushString(Assembler, ""); + } Call(VTablesImplRefs.SetTypeInfoRef); @@ -1192,7 +1200,17 @@ public void ProcessField(FieldInfo aField) /// The plug internal void GenerateMethodForward(Il2cpuMethodInfo aFrom, Il2cpuMethodInfo aTo) { - var xMethodLabel = ILOp.GetLabel(aFrom); + string xMethodLabel; + + try + { + xMethodLabel = ILOp.GetLabel(aFrom); + } + catch + { + throw new Exception("Unable to generate method forwarding stub for method: " + aFrom.MethodLabel + ", to " + aTo.MethodLabel); + } + var xEndOfMethodLabel = xMethodLabel + EndOfMethodLabelNameNormal; // todo: completely get rid of this kind of trampoline code diff --git a/source/Cosmos.IL2CPU/CompilerEngine.cs b/source/Cosmos.IL2CPU/CompilerEngine.cs index 523584d76..0fd9d7984 100644 --- a/source/Cosmos.IL2CPU/CompilerEngine.cs +++ b/source/Cosmos.IL2CPU/CompilerEngine.cs @@ -28,7 +28,7 @@ internal class CompilerEngine public static TypeResolver TypeResolver { get; private set; } public static string KernelPkg { get; set; } - + private ICompilerEngineSettings mSettings; private AssemblyLoadContext _assemblyLoadContext; @@ -67,14 +67,14 @@ public CompilerEngine(ICompilerEngineSettings aSettings) if (!File.Exists(mSettings.TargetAssembly)) { - throw new FileNotFoundException("The target assembly path is invalid!", mSettings.TargetAssembly); + throw new FileNotFoundException($@"The target assembly path is invalid! {mSettings.TargetAssembly}", mSettings.TargetAssembly); } foreach (var xReference in mSettings.References) { if (!File.Exists(xReference)) { - throw new FileNotFoundException("A reference assembly path is invalid!", xReference); + throw new FileNotFoundException($@"A reference assembly path is invalid! {xReference}", xReference); } } @@ -82,7 +82,7 @@ public CompilerEngine(ICompilerEngineSettings aSettings) { if (!File.Exists(xPlugsReference)) { - throw new FileNotFoundException("A plugs reference assembly path is invalid!", xPlugsReference); + throw new FileNotFoundException($@"A plugs reference assembly path is invalid! {xPlugsReference}", xPlugsReference); } } diff --git a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj index de66c4cc4..3aef98837 100644 --- a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj +++ b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 True CA1707;CA1716;$(NoWarn) @@ -18,7 +18,7 @@ - + diff --git a/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs b/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs index 0cd436de9..8b62d3faf 100644 --- a/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs +++ b/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs @@ -1,5 +1,7 @@ using System; - +using XSharp; +using Cosmos.IL2CPU.ILOpCodes; +using IL2CPU.API; namespace Cosmos.IL2CPU.X86.IL { @@ -10,37 +12,8 @@ public Ldvirtftn(XSharp.Assembler.Assembler aAsmblr):base(aAsmblr) { } - public override void Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) { - DoNullReferenceCheck(Assembler, DebugEnabled, 0); - throw new NotImplementedException(); - } - - - // using System; - // using System.IO; - // - // - // using CPU = XSharp.Assembler.x86; - // - // namespace Cosmos.IL2CPU.IL.X86 { - // [XSharp.Assembler.OpCode(OpCodeEnum.Ldvirtftn)] - // public class Ldvirtftn: Op { - // private string mNextLabel; - // private string mCurLabel; - // private uint mCurOffset; - // private MethodInformation mMethodInformation; - // public Ldvirtftn(ILReader aReader, MethodInformation aMethodInfo) - // : base(aReader, aMethodInfo) { - // mMethodInformation = aMethodInfo; - // mCurOffset = aReader.Position; - // mCurLabel = IL.Op.GetInstructionLabel(aReader); - // mNextLabel = IL.Op.GetInstructionLabel(aReader.NextPosition); - // } - // public override void DoAssemble() { - // EmitNotImplementedException(Assembler, GetServiceProvider(), "Ldvirtftn: This has not been implemented at all yet!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel); - // } - // } - // } - + public override void Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) { + XS.Push(LabelName.Get(((OpMethod)aOpCode).Value)); + } } } diff --git a/source/Cosmos.IL2CPU/ILOpCode.cs b/source/Cosmos.IL2CPU/ILOpCode.cs index 5b1592bed..919d7b73a 100644 --- a/source/Cosmos.IL2CPU/ILOpCode.cs +++ b/source/Cosmos.IL2CPU/ILOpCode.cs @@ -345,8 +345,14 @@ public void DoStackAnalysis(Stack aStack, ref uint aStackOffset) foreach (var xPushItem in StackPushTypes) { - aStack.Push(xPushItem); - aStackOffset += ILOp.Align(ILOp.SizeOfType(xPushItem), 4); + if (xPushItem != null) + { + aStack.Push(xPushItem); + aStackOffset += ILOp.Align(ILOp.SizeOfType(xPushItem), 4); + } + else { + throw new Exception("Tried pushing null item to stack while processing " + OpCode + " opcode."); + } } } diff --git a/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs b/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs index 740e3546b..09f9c6513 100644 --- a/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs +++ b/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs @@ -87,6 +87,9 @@ protected override void DoInitStackAnalysis(MethodBase aMethod) case Code.Ldftn: StackPushTypes[0] = typeof(IntPtr); return; + case Code.Ldvirtftn: + StackPushTypes[0] = typeof(IntPtr); + return; default: break; diff --git a/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs b/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs index f96ec8920..83db0764d 100644 --- a/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs +++ b/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs @@ -856,11 +856,11 @@ public override void DoInterpretStackTypes() { return; } - if (!StackPopTypes[0].IsByRef && !StackPopTypes[0].IsPointer) + if (!StackPopTypes[0].IsByRef && !StackPopTypes[0].IsPointer && StackPopTypes[0] != typeof(IntPtr)) { throw new Exception("Invalid ref type: " + StackPopTypes[0].FullName); } - if (StackPopTypes[0].IsPointer) + if (StackPopTypes[0].IsPointer || StackPopTypes[0] == typeof(IntPtr)) { StackPushTypes[0] = typeof(object); } diff --git a/source/Cosmos.IL2CPU/ILScanner.cs b/source/Cosmos.IL2CPU/ILScanner.cs index ad9d15dc5..f4ace1bb2 100644 --- a/source/Cosmos.IL2CPU/ILScanner.cs +++ b/source/Cosmos.IL2CPU/ILScanner.cs @@ -647,7 +647,12 @@ protected void ScanType(Type aType) if (aType.IsGenericType && new string[] { "IList", "ICollection", "IEnumerable", "IReadOnlyList", "IReadOnlyCollection" } .Any(i => aType.Name.Contains(i))) { - Queue(aType.GenericTypeArguments[0].MakeArrayType(), aType, "CallVirt of Generic Interface for Array"); + // i dont know if i should throw or skip + // if (aType.GenericTypeArguments.Length == 0) throw new Exception($@"{aType}: aType.GenericTypeArguments.Length == 0", new IndexOutOfRangeException()); + if (aType.GenericTypeArguments.Length == 1) + { + Queue(aType.GenericTypeArguments[0].MakeArrayType(), aType, "CallVirt of Generic Interface for Array"); + } } // Add immediate ancestor type diff --git a/source/Cosmos.IL2CPU/PlugManager.cs b/source/Cosmos.IL2CPU/PlugManager.cs index 3dc5bf0b9..54545b7fe 100644 --- a/source/Cosmos.IL2CPU/PlugManager.cs +++ b/source/Cosmos.IL2CPU/PlugManager.cs @@ -97,7 +97,7 @@ public void FindPlugImpls(IEnumerable assemblies) { if (!xAttrib.IsOptional) { - throw new Exception("Error", ex); + throw new Exception($@"Error [{xAttrib.TargetName}]", ex); } continue; } diff --git a/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj b/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj index 72214a1f6..b526a3a16 100644 --- a/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj +++ b/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 True IL2CPU debug symbols APIs. True diff --git a/source/IL2CPU/IL2CPU.csproj b/source/IL2CPU/IL2CPU.csproj index 5c8d0bb4c..6a5577a0d 100644 --- a/source/IL2CPU/IL2CPU.csproj +++ b/source/IL2CPU/IL2CPU.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe IL2CPU compiler. True diff --git a/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj b/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj index 93b3076d4..d465e0f90 100644 --- a/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj +++ b/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false