diff --git a/lang/b/lib/b.h b/lang/b/lib/b.h index 571c1794b..1125452cd 100644 --- a/lang/b/lib/b.h +++ b/lang/b/lib/b.h @@ -19,4 +19,10 @@ extern FILE* output_unit; #define END 4 +extern uintptr_t* bmodule_main[]; + +extern void patch_addresses(uintptr_t** p); + +extern void binit(void); + #endif diff --git a/lang/b/lib/init.c b/lang/b/lib/init.c new file mode 100644 index 000000000..b7ad01f08 --- /dev/null +++ b/lang/b/lib/init.c @@ -0,0 +1,10 @@ +#include "b.h" +#include +#include +#include + +void binit(void) +{ + patch_addresses(bmodule_main); +} + diff --git a/lang/b/lib/main.c b/lang/b/lib/main.c index 404e1fd9d..b583a4309 100644 --- a/lang/b/lib/main.c +++ b/lang/b/lib/main.c @@ -3,7 +3,6 @@ #include #include -extern uintptr_t* b_module_main[]; extern intptr_t i_main(intptr_t argc, const char* argv[]); FILE* input_unit; @@ -155,7 +154,7 @@ uintptr_t b_getstr = (uintptr_t)i_getstr; uintptr_t b_flush = (uintptr_t)i_flush; uintptr_t b_printf = (uintptr_t)i_printf; -static uintptr_t* b_module_stdlib[] = +static uintptr_t* bmodule_stdlib[] = { &b_char, &b_lchar, @@ -168,7 +167,7 @@ static uintptr_t* b_module_stdlib[] = 0 }; -static void patch_addresses(uintptr_t** p) +void patch_addresses(uintptr_t** p) { while (*p) { @@ -179,8 +178,8 @@ static void patch_addresses(uintptr_t** p) int main(int argc, const char* argv[]) { - patch_addresses(b_module_main); - patch_addresses(b_module_stdlib); + patch_addresses(bmodule_stdlib); + binit(); input_unit = stdin; output_unit = stdout; return i_main(argc, NULL);