Allow programs to override binit() (so they can register their own modules).

This commit is contained in:
David Given 2016-12-31 17:39:51 +00:00
parent 1beedca590
commit a01523a893
3 changed files with 20 additions and 5 deletions

View file

@ -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

10
lang/b/lib/init.c Normal file
View file

@ -0,0 +1,10 @@
#include "b.h"
#include <stdarg.h>
#include <string.h>
#include <limits.h>
void binit(void)
{
patch_addresses(bmodule_main);
}

View file

@ -3,7 +3,6 @@
#include <string.h>
#include <limits.h>
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);