1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 14:44:48 +00:00

Make sure void return types work as expected.

This commit is contained in:
Calvin Rose 2022-06-10 12:33:01 -05:00
parent a5def77bfe
commit 49bfe80191
3 changed files with 19 additions and 0 deletions

View File

@ -77,3 +77,11 @@ big struct_big(int i, double d) {
ret.c = ret.a + ret.b + 1000; ret.c = ret.a + ret.b + 1000;
return ret; return ret;
} }
void void_fn(void) {
printf("void fn ran\n");
}
void void_ret_fn(int x) {
printf("void fn ran: %d\n", x);
}

View File

@ -62,10 +62,17 @@
[i d] [i d]
(native-call struct-big-fn-pointer struct-big-fn-sig i d)) (native-call struct-big-fn-pointer struct-big-fn-sig i d))
(def void-fn-pointer (native-lookup module "void_fn"))
(def void-fn-sig (native-signature :default :void))
(defn void-fn
[]
(native-call void-fn-pointer void-fn-sig))
# #
# Call functions # Call functions
# #
(pp (void-fn))
(pp (int-fn 10 20)) (pp (int-fn 10 20))
(pp (double-fn 1.5 2.5 3.5)) (pp (double-fn 1.5 2.5 3.5))
(pp (double-many 1 2 3 4 5 6)) (pp (double-many 1 2 3 4 5 6))

View File

@ -473,6 +473,7 @@ static JanetFFIWordSpec sysv64_classify(JanetFFIType type) {
return clazz; return clazz;
} }
case JANET_FFI_TYPE_VOID: case JANET_FFI_TYPE_VOID:
return JANET_SYSV64_NO_CLASS;
default: default:
janet_panic("nyi"); janet_panic("nyi");
return JANET_SYSV64_NO_CLASS; return JANET_SYSV64_NO_CLASS;
@ -519,6 +520,9 @@ JANET_CORE_FN(cfun_ffi_signature,
mappings[i].type = decode_ffi_type(argv[i + 2]); mappings[i].type = decode_ffi_type(argv[i + 2]);
mappings[i].offset = 0; mappings[i].offset = 0;
mappings[i].spec = sysv64_classify(mappings[i].type); mappings[i].spec = sysv64_classify(mappings[i].type);
if (mappings[i].spec == JANET_SYSV64_NO_CLASS) {
janet_panic("unexpected void parameter");
}
size_t el_size = (type_size(mappings[i].type) + 7) / 8; size_t el_size = (type_size(mappings[i].type) + 7) / 8;
switch (mappings[i].spec) { switch (mappings[i].spec) {
default: default: