add format order test and fix reg order for windows

This commit is contained in:
water 2020-09-15 18:49:55 -04:00
parent bb854dd81e
commit ca3acdb5ec
3 changed files with 30 additions and 1 deletions

View file

@ -386,6 +386,28 @@ Ptr<Function> make_function_from_c_win32(void* func) {
return mem.cast<Function>(); return mem.cast<Function>();
} }
Ptr<Function> make_function_for_format_from_c_win32(void* func) {
// allocate a function object on the global heap
auto mem = Ptr<u8>(
alloc_heap_object(s7.offset + FIX_SYM_GLOBAL_HEAP, *(s7 + FIX_SYM_FUNCTION_TYPE), 0x80));
auto f = (uint64_t)func;
auto fp = (u8*)&f;
int i = 0;
// we will put the function address in RAX with a movabs rax, imm8
mem.c()[i++] = 0x48;
mem.c()[i++] = 0xb8;
for (int j = 0; j < 8; j++) {
mem.c()[i++] = fp[j];
}
for (auto x : {0x48, 0x83, 0xEC, 0x28, 0xFF, 0xD0, 0x48, 0x83, 0xC4, 0x28, 0xC3}) {
mem.c()[i++] = x;
}
return mem.cast<Function>();
}
/*! /*!
* Create a GOAL function from a C function. This doesn't export it as a global function, it just * Create a GOAL function from a C function. This doesn't export it as a global function, it just
* creates a function object on the global heap. * creates a function object on the global heap.
@ -1778,7 +1800,7 @@ s32 InitHeapAndSymbol() {
#ifdef __linux__ #ifdef __linux__
make_function_symbol_from_c("_format", (void*)_format_linux); make_function_symbol_from_c("_format", (void*)_format_linux);
#elif _WIN32 #elif _WIN32
make_function_symbol_from_c("_format", (void*)_format_win32); make_function_for_format_from_c_win32("_format", (void*)_format_win32);
#endif #endif
// allocations // allocations

View file

@ -0,0 +1,5 @@
(define-extern _format function)
(define format _format)
(format #t "test ~D ~D ~D ~D ~D ~D~%" 1 2 3 4 5 6)
0

View file

@ -253,6 +253,8 @@ TEST(CompilerAndRuntime, CompilerTests) {
runner.run_test("test-factorial-loop.gc", {"3628800\n"}); runner.run_test("test-factorial-loop.gc", {"3628800\n"});
runner.run_test("test-protect.gc", {"33\n"}); runner.run_test("test-protect.gc", {"33\n"});
runner.run_test("test-format-reg-order.gc", {"test 1 2 3 4 5 6\n0\n"});
// expected = // expected =
// "test newline\nnewline\ntest tilde ~ \ntest A print boxed-string: \"boxed string!\"\ntest // "test newline\nnewline\ntest tilde ~ \ntest A print boxed-string: \"boxed string!\"\ntest
// A " "print symbol: a-symbol\ntest A make boxed object longer: \"srt\"!\ntest A // A " "print symbol: a-symbol\ntest A make boxed object longer: \"srt\"!\ntest A