c interop type foundation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
Buffer :: c_struct {
|
||||
data *c_char
|
||||
length c_ulong
|
||||
}
|
||||
|
||||
get_buffer :: c_func() @Buffer
|
||||
verify :: c_func(
|
||||
char_value c_char,
|
||||
schar_value c_schar,
|
||||
uchar_value c_uchar,
|
||||
short_value c_short,
|
||||
ushort_value c_ushort,
|
||||
int_value c_int,
|
||||
uint_value c_uint,
|
||||
long_value c_long,
|
||||
ulong_value c_ulong,
|
||||
longlong_value c_longlong,
|
||||
ulonglong_value c_ulonglong,
|
||||
float_value c_float,
|
||||
double_value c_double,
|
||||
longdouble_value c_longdouble,
|
||||
) i32
|
||||
|
||||
main :: func() i32 {
|
||||
buffer @Buffer :: get_buffer()
|
||||
_ = buffer^.data
|
||||
_ = buffer^.length
|
||||
return verify(1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, 12.0, 13.0, 14.0)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
struct Buffer {
|
||||
const char *data;
|
||||
unsigned long length;
|
||||
};
|
||||
|
||||
static const struct Buffer buffer = {"ok", 2};
|
||||
|
||||
const struct Buffer *get_buffer(void) {
|
||||
return &buffer;
|
||||
}
|
||||
|
||||
int verify(
|
||||
char char_value,
|
||||
signed char schar_value,
|
||||
unsigned char uchar_value,
|
||||
short short_value,
|
||||
unsigned short ushort_value,
|
||||
int int_value,
|
||||
unsigned int uint_value,
|
||||
long long_value,
|
||||
unsigned long ulong_value,
|
||||
long long longlong_value,
|
||||
unsigned long long ulonglong_value,
|
||||
float float_value,
|
||||
double double_value,
|
||||
long double longdouble_value
|
||||
) {
|
||||
return char_value == 1 &&
|
||||
schar_value == -2 &&
|
||||
uchar_value == 3 &&
|
||||
short_value == -4 &&
|
||||
ushort_value == 5 &&
|
||||
int_value == -6 &&
|
||||
uint_value == 7 &&
|
||||
long_value == -8 &&
|
||||
ulong_value == 9 &&
|
||||
longlong_value == -10 &&
|
||||
ulonglong_value == 11 &&
|
||||
float_value == 12.0f &&
|
||||
double_value == 13.0 &&
|
||||
longdouble_value == 14.0L;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
foreign_add :: c func(a, b i32) i32
|
||||
foreign_add :: c_func(a, b i32) i32
|
||||
|
||||
main :: func() i32 {
|
||||
return foreign_add(20, 22)
|
||||
|
||||
Reference in New Issue
Block a user