meta: re-organise tests
This commit is contained in:
+42
-14
@@ -1,22 +1,50 @@
|
||||
#include <dlfcn.h>
|
||||
#include <fx/reflection/function.h>
|
||||
#include <fx/value.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static double test_function(int a, double b, int c, ...)
|
||||
{
|
||||
#if 1
|
||||
va_list args;
|
||||
va_start(args, c);
|
||||
int d = va_arg(args, int);
|
||||
double e = va_arg(args, double);
|
||||
int f = va_arg(args, int);
|
||||
printf("a=%d, b=%lf, c=%d, d=%d, e=%lf, f=%d\n", a, b, c, d, e, f);
|
||||
return (a + b + c + d + e + f) + 0.5;
|
||||
#else
|
||||
printf("a=%d, b=%lf, c=%d\n", a, b, c);
|
||||
return 32;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
printf("dynamic loader\n");
|
||||
void *assembly = dlopen(argv[1], RTLD_LAZY);
|
||||
if (!assembly) {
|
||||
printf("cannot load %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
fx_value_type arg_types[] = {
|
||||
FX_VALUE_TYPE_INT,
|
||||
FX_VALUE_TYPE_DOUBLE,
|
||||
FX_VALUE_TYPE_INT,
|
||||
};
|
||||
|
||||
const void *(*asm_info)(void) = dlsym(assembly, "__fx_assembly_get");
|
||||
if (!asm_info) {
|
||||
printf("cannot find assembly info for %s", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
fx_function *func = fx_function_create(
|
||||
"test_function",
|
||||
FX_FUNCTION_F_VARARG,
|
||||
(fx_function_impl)test_function,
|
||||
arg_types,
|
||||
3,
|
||||
FX_VALUE_TYPE_DOUBLE);
|
||||
|
||||
asm_info();
|
||||
printf("OK\n");
|
||||
fx_value args[] = {
|
||||
FX_VALUE_INT(1),
|
||||
FX_VALUE_DOUBLE(2.5),
|
||||
FX_VALUE_INT(3),
|
||||
FX_VALUE_INT(4),
|
||||
FX_VALUE_DOUBLE(5.5),
|
||||
FX_VALUE_INT(6),
|
||||
};
|
||||
|
||||
fx_value result = FX_VALUE_EMPTY;
|
||||
int r = fx_function_invoke(func, args, 6, &result);
|
||||
printf("%lf\n", result.v_double);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user