Explorar o código

Fixed Linux interop issue

Brian Fiete %!s(int64=5) %!d(string=hai) anos
pai
achega
0e6a001091

+ 7 - 10
IDEHelper/Compiler/BfModule.cpp

@@ -17179,8 +17179,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
 			UpdateSrcPos(methodDef->mBody);	
 			UpdateSrcPos(methodDef->mBody);	
 		else if (mCurTypeInstance->mTypeDef->mTypeDeclaration != NULL)
 		else if (mCurTypeInstance->mTypeDef->mTypeDeclaration != NULL)
 			UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration);			
 			UpdateSrcPos(mCurTypeInstance->mTypeDef->mTypeDeclaration);			
-
-		int declArgIdx = 0;
+		
 		localIdx = 0;
 		localIdx = 0;
 		argIdx = 0;
 		argIdx = 0;
 		
 		
@@ -17201,6 +17200,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
 			if ((isThis) && (thisType->IsValuelessType()))
 			if ((isThis) && (thisType->IsValuelessType()))
 				isThis = false;
 				isThis = false;
 
 
+			if (paramVar->mValue.IsArg())
+				BF_ASSERT(paramVar->mValue.mId == argIdx);
+
 			BfIRMDNode diVariable;
 			BfIRMDNode diVariable;
 			if (wantsDIData)
 			if (wantsDIData)
 			{
 			{
@@ -17293,12 +17295,10 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
 							auto primType = mBfIRBuilder->GetPrimitiveType(loweredTypeCode);
 							auto primType = mBfIRBuilder->GetPrimitiveType(loweredTypeCode);
 							auto primPtrType = mBfIRBuilder->GetPointerTo(primType);
 							auto primPtrType = mBfIRBuilder->GetPointerTo(primType);
 							auto primPtrVal = mBfIRBuilder->CreateBitCast(paramVar->mAddr, primPtrType);
 							auto primPtrVal = mBfIRBuilder->CreateBitCast(paramVar->mAddr, primPtrType);
-							mBfIRBuilder->CreateStore(paramVar->mValue, primPtrVal);
-
+							mBfIRBuilder->CreateStore(paramVar->mValue, primPtrVal);							
+							
 							if (loweredTypeCode2 != BfTypeCode_None)
 							if (loweredTypeCode2 != BfTypeCode_None)
 							{
 							{
-								declArgIdx++;
-
 								auto primType2 = mBfIRBuilder->GetPrimitiveType(loweredTypeCode2);
 								auto primType2 = mBfIRBuilder->GetPrimitiveType(loweredTypeCode2);
 								auto primPtrType2 = mBfIRBuilder->GetPointerTo(primType2);
 								auto primPtrType2 = mBfIRBuilder->GetPointerTo(primType2);
 								BfIRValue primPtrVal2;
 								BfIRValue primPtrVal2;
@@ -17324,9 +17324,6 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
 				}
 				}
 			}
 			}
 			
 			
-			if (!isThis)		
-				declArgIdx++;						
-
 			if (methodDef->mBody != NULL)
 			if (methodDef->mBody != NULL)
 				UpdateSrcPos(methodDef->mBody);
 				UpdateSrcPos(methodDef->mBody);
 			else if (methodDef->mDeclaringType->mTypeDeclaration != NULL)
 			else if (methodDef->mDeclaringType->mTypeDeclaration != NULL)
@@ -17490,7 +17487,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
 				BfTypeCode loweredTypeCode = BfTypeCode_None;
 				BfTypeCode loweredTypeCode = BfTypeCode_None;
 				BfTypeCode loweredTypeCode2 = BfTypeCode_None;
 				BfTypeCode loweredTypeCode2 = BfTypeCode_None;
 				paramVar->mResolvedType->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2);
 				paramVar->mResolvedType->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2);
-				if (loweredTypeCode != BfTypeCode_None)
+				if (loweredTypeCode2 != BfTypeCode_None)
 					argIdx++;
 					argIdx++;
 			}
 			}
 			else if (!paramVar->mResolvedType->IsValuelessType())
 			else if (!paramVar->mResolvedType->IsValuelessType())

+ 1 - 1
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -10148,7 +10148,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
 
 
 						if (methodInst->GetParamCount() != 1)
 						if (methodInst->GetParamCount() != 1)
 						{
 						{
-							BF_ASSERT(mCompiler->mPassInstance->HasFailed());
+							AssertErrorState();							
 							continue;
 							continue;
 						}
 						}
 
 

+ 5 - 0
IDEHelper/Tests/CLib/main.cpp

@@ -362,6 +362,11 @@ extern "C" int Func0W(int a, Interop::StructW b)
 	return a + (int)b.mX * 100;
 	return a + (int)b.mX * 100;
 }
 }
 
 
+extern "C" int Func0KM(Interop::StructK a, Interop::StructM b, Interop::StructK c)
+{
+	return (int)a.mX + (int)b.mX * 100 + (int)c.mX * 1000;
+}
+
 //////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////
 
 
 extern "C" int Func1A(Interop::StructA arg0, Interop::StructA arg1, int arg2)
 extern "C" int Func1A(Interop::StructA arg0, Interop::StructA arg1, int arg2)

+ 11 - 3
IDEHelper/Tests/src/Interop.bf

@@ -258,6 +258,8 @@ namespace Tests
 		public static extern int32 Func0V(int32 a, StructV b);
 		public static extern int32 Func0V(int32 a, StructV b);
 		[LinkName(.C)]
 		[LinkName(.C)]
 		public static extern int32 Func0W(int32 a, StructW b);
 		public static extern int32 Func0W(int32 a, StructW b);
+		[LinkName(.C)]
+		public static extern int32 Func0KM(StructK a, StructM b, StructK c);
 
 
 		[LinkName(.C)]
 		[LinkName(.C)]
 		public static extern int32 Func1A(StructA arg0, StructA arg1, int32 arg2);
 		public static extern int32 Func1A(StructA arg0, StructA arg1, int32 arg2);
@@ -313,6 +315,7 @@ namespace Tests
 		static int32 LocalFunc0U(int32 a, StructU b) => a + (int32)b.mK.mX * 100 + (int32)b.mK.mY * 10000;
 		static int32 LocalFunc0U(int32 a, StructU b) => a + (int32)b.mK.mX * 100 + (int32)b.mK.mY * 10000;
 		static int32 LocalFunc0V(int32 a, StructV b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
 		static int32 LocalFunc0V(int32 a, StructV b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
 		static int32 LocalFunc0W(int32 a, StructW b) => a + (int32)b.mX * 100;
 		static int32 LocalFunc0W(int32 a, StructW b) => a + (int32)b.mX * 100;
+		static int32 LocalFunc0KM(StructK a, StructM b, StructK c) => (int32)a.mX + (int32)b.mX * 100 + (int32)c.mX * 1000;
 
 
 		[Test]
 		[Test]
 		public static void TestBasics()
 		public static void TestBasics()
@@ -365,8 +368,9 @@ namespace Tests
 			si1.mA = 91;
 			si1.mA = 91;
 
 
 			StructK sk = .() { mX = 3, mY = 4};
 			StructK sk = .() { mX = 3, mY = 4};
+			StructK sk2 = .() { mX = 11, mY = 12 };
 			StructL sl = .() { mX = 3, mY = 4};
 			StructL sl = .() { mX = 3, mY = 4};
-			StructM sm = .() { mX = 3, mY = 4};
+			StructM sm = .() { mX = 5, mY = 6, mZ = 7, mW = 8 };
 			StructN sn = .() { mX = 3, mY = 4};
 			StructN sn = .() { mX = 3, mY = 4};
 			StructO so = .() { mX = 3, mY = 4};
 			StructO so = .() { mX = 3, mY = 4};
 			StructP sp = .() { mX = 3, mY = 4};
 			StructP sp = .() { mX = 3, mY = 4};
@@ -390,7 +394,7 @@ namespace Tests
 			StartTest("Func0L");
 			StartTest("Func0L");
 			Test.Assert(Func0L(12, sl) == 40312);
 			Test.Assert(Func0L(12, sl) == 40312);
 			StartTest("Func0M");
 			StartTest("Func0M");
-			Test.Assert(Func0M(12, sm) == 40312);
+			Test.Assert(Func0M(12, sm) == 60512);
 			StartTest("Func0N");
 			StartTest("Func0N");
 			Test.Assert(Func0N(12, sn) == 40312);
 			Test.Assert(Func0N(12, sn) == 40312);
 			StartTest("Func0O");
 			StartTest("Func0O");
@@ -411,13 +415,15 @@ namespace Tests
 			Test.Assert(Func0V(12, sv) == 40312);
 			Test.Assert(Func0V(12, sv) == 40312);
 			StartTest("Func0W");
 			StartTest("Func0W");
 			Test.Assert(Func0W(12, sw) == 312);
 			Test.Assert(Func0W(12, sw) == 312);
+			StartTest("Func0KM");
+			Test.Assert(Func0KM(sk, sm, sk2) == 11503);
 
 
 			StartTest("LocalFunc0K");
 			StartTest("LocalFunc0K");
 			Test.Assert(LocalFunc0K(12, sk) == 40312);
 			Test.Assert(LocalFunc0K(12, sk) == 40312);
 			StartTest("LocalFunc0L");
 			StartTest("LocalFunc0L");
 			Test.Assert(LocalFunc0L(12, sl) == 40312);
 			Test.Assert(LocalFunc0L(12, sl) == 40312);
 			StartTest("LocalFunc0M");
 			StartTest("LocalFunc0M");
-			Test.Assert(LocalFunc0M(12, sm) == 40312);
+			Test.Assert(LocalFunc0M(12, sm) == 60512);
 			StartTest("LocalFunc0N");
 			StartTest("LocalFunc0N");
 			Test.Assert(LocalFunc0N(12, sn) == 40312);
 			Test.Assert(LocalFunc0N(12, sn) == 40312);
 			StartTest("LocalFunc0O");
 			StartTest("LocalFunc0O");
@@ -438,6 +444,8 @@ namespace Tests
 			Test.Assert(LocalFunc0V(12, sv) == 40312);
 			Test.Assert(LocalFunc0V(12, sv) == 40312);
 			StartTest("LocalFunc0W");
 			StartTest("LocalFunc0W");
 			Test.Assert(LocalFunc0W(12, sw) == 312);
 			Test.Assert(LocalFunc0W(12, sw) == 312);
+			StartTest("Func0KM");
+			Test.Assert(LocalFunc0KM(sk, sm, sk2) == 11503);
 
 
 			StartTest("Func1A");
 			StartTest("Func1A");
 			Test.Assert(Func1A(sa0, sa1, 12) == 121110);
 			Test.Assert(Func1A(sa0, sa1, 12) == 121110);