Skip to content

Commit 18ef78f

Browse files
committed
Another ffi try
1 parent e655d21 commit 18ef78f

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -rdynamic for backtrace support
22

3-
OPTIMIZATION := -O3 # -O1 -O2 -O3 does not compile (in FFI)
3+
OPTIMIZATION := -O3
44
SHARED_FLAGS := -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Werror $(OPTIMIZATION) -std=c++17 -ggdb
55

66
ifdef OS

src/executer/ExternalFunctions.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ qword_t ExternalFunctions::call(size_t id, const Arguments& args) {
279279

280280
"jmp label_do_call\n" // Skip the function and call the method
281281

282-
// Function bring_next_value_into_rax
283282
"bring_next_value_into_rax:\n"
284283
// These chacks would be nice to have here, but the call somehow segfaults then
285284
// " cmpq $0, (%%R10)\n" // Check if type is None (0)
@@ -291,9 +290,9 @@ qword_t ExternalFunctions::call(size_t id, const Arguments& args) {
291290
// End of bring_next_value_into_rax
292291

293292
"label_do_call:"
294-
"movq $0, %%rax\n" // Indicate no vector registers used
295-
"call *%[fn_tag]\n"
296-
"movq %%rax, %[result_tag]\n"
293+
" movq $0, %%rax\n" // Indicate no vector registers used
294+
" call *%[fn_tag]\n"
295+
" movq %%rax, %[result_tag]\n"
297296

298297
// Restore stack
299298
"movq %%rbp, %%rsp\n"
@@ -314,13 +313,18 @@ qword_t ExternalFunctions::call(size_t id, const Arguments& args) {
314313
return 0;
315314
}
316315

316+
if (func.returnType == ret_type::Number) {
317+
int iresult = 0;
318+
std::memcpy(&iresult, &result, sizeof(int));
319+
return iresult;
320+
}
321+
317322
/*if (func.returnType == ret_type::Float) {
318323
float fresult;
319324
std::memcpy(&fresult, &result, sizeof(float));
320325
return fresult;
321326
}*/
322327
// if (func.returnType == ret_type::Ptr)
323-
// if (func.returnType == ret_type::Number)
324328

325329
return result;
326330
}

0 commit comments

Comments
 (0)