mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Renamed TypeCode_Single to TypeCode_Float. Float struct interop fixes.
This commit is contained in:
parent
14c3d0cd35
commit
2fe209447e
20 changed files with 595 additions and 69 deletions
|
@ -14,8 +14,8 @@ LibPaths = ["$(ProjectDir)/CLib/Debug/CLib.lib"]
|
|||
|
||||
[Configs.Test.Linux64]
|
||||
OtherLinkFlags = "$(LinkFlags) $(ProjectDir)/CLib/main.o -Wl,--export-dynamic"
|
||||
PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -c -o $(ProjectDir)/CLib/main.o"]
|
||||
PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -g -c -o $(ProjectDir)/CLib/main.o"]
|
||||
|
||||
[Configs.Test.macOS]
|
||||
OtherLinkFlags = "$(LinkFlags) $(ProjectDir)/CLib/main.o"
|
||||
PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -c -o $(ProjectDir)/CLib/main.o"]
|
||||
PreBuildCmds = ["/usr/bin/c++ $(ProjectDir)/CLib/main.cpp -g -c -o $(ProjectDir)/CLib/main.o"]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
|
@ -199,16 +200,168 @@ namespace Tests
|
|||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct StructK
|
||||
{
|
||||
float mX;
|
||||
float mY;
|
||||
};
|
||||
|
||||
struct StructL
|
||||
{
|
||||
float mX;
|
||||
float mY;
|
||||
float mZ;
|
||||
};
|
||||
|
||||
struct StructM
|
||||
{
|
||||
float mX;
|
||||
float mY;
|
||||
float mZ;
|
||||
float mW;
|
||||
};
|
||||
|
||||
struct StructN
|
||||
{
|
||||
float mX;
|
||||
float mY;
|
||||
float mZ;
|
||||
float mW;
|
||||
float mU;
|
||||
};
|
||||
|
||||
struct StructO
|
||||
{
|
||||
float mX;
|
||||
int mY;
|
||||
};
|
||||
|
||||
struct StructP
|
||||
{
|
||||
float mX;
|
||||
float mY;
|
||||
int mZ;
|
||||
};
|
||||
|
||||
struct StructQ
|
||||
{
|
||||
float mX;
|
||||
float mY;
|
||||
int mZ;
|
||||
int mW;
|
||||
};
|
||||
|
||||
struct StructR
|
||||
{
|
||||
double mX;
|
||||
double mY;
|
||||
};
|
||||
|
||||
struct StructS
|
||||
{
|
||||
float mX;
|
||||
double mY;
|
||||
};
|
||||
|
||||
struct StructT
|
||||
{
|
||||
double mX;
|
||||
double mY;
|
||||
double mZ;
|
||||
};
|
||||
|
||||
struct StructU
|
||||
{
|
||||
StructK mK;
|
||||
};
|
||||
|
||||
struct StructV
|
||||
{
|
||||
int64_t mX;
|
||||
short mY;
|
||||
};
|
||||
|
||||
struct StructW
|
||||
{
|
||||
float mX;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
using namespace Tests;
|
||||
|
||||
extern "C" int Func0(int a, int b)
|
||||
{
|
||||
{
|
||||
return a + b * 100;
|
||||
}
|
||||
|
||||
extern "C" int Func0K(int a, Interop::StructK b)
|
||||
{
|
||||
//printf("Func0K: %d %f %f\n", a, b.mX, b.mY);
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0L(int a, Interop::StructL b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0M(int a, Interop::StructM b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0N(int a, Interop::StructN b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0O(int a, Interop::StructO b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0P(int a, Interop::StructP b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0Q(int a, Interop::StructQ b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0R(int a, Interop::StructR b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0S(int a, Interop::StructS b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0T(int a, Interop::StructT b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0U(int a, Interop::StructU b)
|
||||
{
|
||||
return a + (int)b.mK.mX * 100 + (int)b.mK.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0V(int a, Interop::StructV b)
|
||||
{
|
||||
return a + (int)b.mX * 100 + (int)b.mY * 10000;
|
||||
}
|
||||
|
||||
extern "C" int Func0W(int a, Interop::StructW b)
|
||||
{
|
||||
return a + (int)b.mX * 100;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" int Func1A(Interop::StructA arg0, Interop::StructA arg1, int arg2)
|
||||
|
|
|
@ -131,8 +131,133 @@ namespace Tests
|
|||
public extern StructJ MethodJ1(StructJ sa, int32 arg0) mut;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
public struct StructK
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructL
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public float mZ;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructM
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public float mZ;
|
||||
public float mW;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructN
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public float mZ;
|
||||
public float mW;
|
||||
public float mU;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructO
|
||||
{
|
||||
public float mX;
|
||||
public int32 mY;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructP
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public int32 mZ;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructQ
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public int32 mZ;
|
||||
public int32 mW;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructR
|
||||
{
|
||||
public double mX;
|
||||
public double mY;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructS
|
||||
{
|
||||
public float mX;
|
||||
public double mY;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructT
|
||||
{
|
||||
public double mX;
|
||||
public double mY;
|
||||
public double mZ;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructU
|
||||
{
|
||||
public StructK mK;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructV
|
||||
{
|
||||
public int64 mX;
|
||||
public int16 mY;
|
||||
}
|
||||
|
||||
[CRepr]
|
||||
struct StructW
|
||||
{
|
||||
public float mX;
|
||||
}
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0(int32 a, int32 b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0K(int32 a, StructK b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0L(int32 a, StructL b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0M(int32 a, StructM b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0N(int32 a, StructN b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0O(int32 a, StructO b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0P(int32 a, StructP b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0Q(int32 a, StructQ b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0R(int32 a, StructR b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0S(int32 a, StructS b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0T(int32 a, StructT b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0U(int32 a, StructU b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0V(int32 a, StructV b);
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func0W(int32 a, StructW b);
|
||||
|
||||
[LinkName(.C)]
|
||||
public static extern int32 Func1A(StructA arg0, StructA arg1, int32 arg2);
|
||||
|
@ -175,6 +300,20 @@ namespace Tests
|
|||
[LinkName(.C)]
|
||||
public static extern StructJ Func4J(StructJ arg0, StructJ arg1, StructJ arg2, StructJ arg3);
|
||||
|
||||
static int32 LocalFunc0K(int32 a, StructK b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0L(int32 a, StructL b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0M(int32 a, StructM b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0N(int32 a, StructN b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0O(int32 a, StructO b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0P(int32 a, StructP b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0Q(int32 a, StructQ b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0R(int32 a, StructR b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0S(int32 a, StructS b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||
static int32 LocalFunc0T(int32 a, StructT b) => a + (int32)b.mX * 100 + (int32)b.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 LocalFunc0W(int32 a, StructW b) => a + (int32)b.mX * 100;
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
@ -225,8 +364,82 @@ namespace Tests
|
|||
StructI si1 = default;
|
||||
si1.mA = 91;
|
||||
|
||||
Test.Assert(Func0(12, 34) == 3412);
|
||||
StructK sk = .() { mX = 3, mY = 4};
|
||||
StructL sl = .() { mX = 3, mY = 4};
|
||||
StructM sm = .() { mX = 3, mY = 4};
|
||||
StructN sn = .() { mX = 3, mY = 4};
|
||||
StructO so = .() { mX = 3, mY = 4};
|
||||
StructP sp = .() { mX = 3, mY = 4};
|
||||
StructQ sq = .() { mX = 3, mY = 4};
|
||||
StructR sr = .() { mX = 3, mY = 4};
|
||||
StructS ss = .() { mX = 3, mY = 4};
|
||||
StructT st = .() { mX = 3, mY = 4};
|
||||
StructU su = .() { mK = .(){mX = 3, mY = 4}};
|
||||
StructV sv = .() { mX = 3, mY = 4};
|
||||
StructW sw = .() { mX = 3 };
|
||||
|
||||
void StartTest(String str)
|
||||
{
|
||||
//Console.WriteLine(str);
|
||||
}
|
||||
|
||||
StartTest("Func0");
|
||||
Test.Assert(Func0(12, 34) == 3412);
|
||||
StartTest("Func0K");
|
||||
Test.Assert(Func0K(12, sk) == 40312);
|
||||
StartTest("Func0L");
|
||||
Test.Assert(Func0L(12, sl) == 40312);
|
||||
StartTest("Func0M");
|
||||
Test.Assert(Func0M(12, sm) == 40312);
|
||||
StartTest("Func0N");
|
||||
Test.Assert(Func0N(12, sn) == 40312);
|
||||
StartTest("Func0O");
|
||||
Test.Assert(Func0O(12, so) == 40312);
|
||||
StartTest("Func0P");
|
||||
Test.Assert(Func0P(12, sp) == 40312);
|
||||
StartTest("Func0Q");
|
||||
Test.Assert(Func0Q(12, sq) == 40312);
|
||||
StartTest("Func0R");
|
||||
Test.Assert(Func0R(12, sr) == 40312);
|
||||
StartTest("Func0S");
|
||||
Test.Assert(Func0S(12, ss) == 40312);
|
||||
StartTest("Func0T");
|
||||
Test.Assert(Func0T(12, st) == 40312);
|
||||
StartTest("Func0U");
|
||||
Test.Assert(Func0U(12, su) == 40312);
|
||||
StartTest("Func0V");
|
||||
Test.Assert(Func0V(12, sv) == 40312);
|
||||
StartTest("Func0W");
|
||||
Test.Assert(Func0W(12, sw) == 312);
|
||||
|
||||
StartTest("LocalFunc0K");
|
||||
Test.Assert(LocalFunc0K(12, sk) == 40312);
|
||||
StartTest("LocalFunc0L");
|
||||
Test.Assert(LocalFunc0L(12, sl) == 40312);
|
||||
StartTest("LocalFunc0M");
|
||||
Test.Assert(LocalFunc0M(12, sm) == 40312);
|
||||
StartTest("LocalFunc0N");
|
||||
Test.Assert(LocalFunc0N(12, sn) == 40312);
|
||||
StartTest("LocalFunc0O");
|
||||
Test.Assert(LocalFunc0O(12, so) == 40312);
|
||||
StartTest("LocalFunc0P");
|
||||
Test.Assert(LocalFunc0P(12, sp) == 40312);
|
||||
StartTest("LocalFunc0Q");
|
||||
Test.Assert(LocalFunc0Q(12, sq) == 40312);
|
||||
StartTest("LocalFunc0R");
|
||||
Test.Assert(LocalFunc0R(12, sr) == 40312);
|
||||
StartTest("LocalFunc0S");
|
||||
Test.Assert(LocalFunc0S(12, ss) == 40312);
|
||||
StartTest("LocalFunc0T");
|
||||
Test.Assert(LocalFunc0T(12, st) == 40312);
|
||||
StartTest("LocalFunc0U");
|
||||
Test.Assert(LocalFunc0U(12, su) == 40312);
|
||||
StartTest("LocalFunc0V");
|
||||
Test.Assert(LocalFunc0V(12, sv) == 40312);
|
||||
StartTest("LocalFunc0W");
|
||||
Test.Assert(LocalFunc0W(12, sw) == 312);
|
||||
|
||||
StartTest("Func1A");
|
||||
Test.Assert(Func1A(sa0, sa1, 12) == 121110);
|
||||
Test.Assert(sa0.MethodA0(12) == 1012);
|
||||
Test.Assert(sa0.MethodA1(sa1, 12).mA == 33);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue