Allow programs to override binit() (so they can register their own modules).
This commit is contained in:
parent
1beedca590
commit
a01523a893
3 changed files with 20 additions and 5 deletions
|
@ -19,4 +19,10 @@ extern FILE* output_unit;
|
||||||
|
|
||||||
#define END 4
|
#define END 4
|
||||||
|
|
||||||
|
extern uintptr_t* bmodule_main[];
|
||||||
|
|
||||||
|
extern void patch_addresses(uintptr_t** p);
|
||||||
|
|
||||||
|
extern void binit(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
10
lang/b/lib/init.c
Normal file
10
lang/b/lib/init.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include "b.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
void binit(void)
|
||||||
|
{
|
||||||
|
patch_addresses(bmodule_main);
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
extern uintptr_t* b_module_main[];
|
|
||||||
extern intptr_t i_main(intptr_t argc, const char* argv[]);
|
extern intptr_t i_main(intptr_t argc, const char* argv[]);
|
||||||
|
|
||||||
FILE* input_unit;
|
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_flush = (uintptr_t)i_flush;
|
||||||
uintptr_t b_printf = (uintptr_t)i_printf;
|
uintptr_t b_printf = (uintptr_t)i_printf;
|
||||||
|
|
||||||
static uintptr_t* b_module_stdlib[] =
|
static uintptr_t* bmodule_stdlib[] =
|
||||||
{
|
{
|
||||||
&b_char,
|
&b_char,
|
||||||
&b_lchar,
|
&b_lchar,
|
||||||
|
@ -168,7 +167,7 @@ static uintptr_t* b_module_stdlib[] =
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
static void patch_addresses(uintptr_t** p)
|
void patch_addresses(uintptr_t** p)
|
||||||
{
|
{
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
|
@ -179,8 +178,8 @@ static void patch_addresses(uintptr_t** p)
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
patch_addresses(b_module_main);
|
patch_addresses(bmodule_stdlib);
|
||||||
patch_addresses(b_module_stdlib);
|
binit();
|
||||||
input_unit = stdin;
|
input_unit = stdin;
|
||||||
output_unit = stdout;
|
output_unit = stdout;
|
||||||
return i_main(argc, NULL);
|
return i_main(argc, NULL);
|
||||||
|
|
Loading…
Reference in a new issue