From a01523a89378036da8390dc99699056f4f954436 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 31 Dec 2016 17:39:51 +0000 Subject: [PATCH] Allow programs to override binit() (so they can register their own modules). --- lang/b/lib/b.h | 6 ++++++ lang/b/lib/init.c | 10 ++++++++++ lang/b/lib/main.c | 9 ++++----- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 lang/b/lib/init.c 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);