git: 68344c9c6c69 - main - loader: separate lang init from scripting init
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 20 May 2024 04:08:34 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=68344c9c6c69fc604b402eee420285356f7a677f commit 68344c9c6c69fc604b402eee420285356f7a677f Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2024-05-19 17:48:14 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-05-20 04:05:40 +0000 loader: separate lang init from scripting init Create interp_preinit() to initialize the scripting language to run scripts. Make sure you can call it multiple times, but only the first one has effect, After it's call, you can run scripts in the scripting language. At the moment, no functional change. Sponsored by: Netflix --- stand/common/bootstrap.h | 3 ++- stand/common/interp.c | 1 + stand/common/interp_forth.c | 13 +++++++++++-- stand/common/interp_lua.c | 23 +++++++++++++++++++++-- stand/common/interp_simple.c | 5 +++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h index b7d6e538f9be..79ce0b023b7a 100644 --- a/stand/common/bootstrap.h +++ b/stand/common/bootstrap.h @@ -54,7 +54,8 @@ bool interp_has_builtin_cmd(const char *cmd); /* Called by interp.c for interp_*.c embedded interpreters */ int interp_include(const char *); /* Execute commands from filename */ -void interp_init(void); /* Initialize interpreater */ +void interp_preinit(void); /* Initialize interpreater execution engine */ +void interp_init(void); /* Initialize interpreater and run main script */ int interp_run(const char *); /* Run a single command */ /* interp_backslash.c */ diff --git a/stand/common/interp.c b/stand/common/interp.c index c6ac01ea099b..5d20822e037d 100644 --- a/stand/common/interp.c +++ b/stand/common/interp.c @@ -60,6 +60,7 @@ interact(void) * we need to switch interpreters. */ interp_identifier = bootprog_interp; + interp_preinit(); interp_init(); printf("\n"); diff --git a/stand/common/interp_forth.c b/stand/common/interp_forth.c index 854addb22d5c..388a20e319b3 100644 --- a/stand/common/interp_forth.c +++ b/stand/common/interp_forth.c @@ -337,12 +337,21 @@ bf_run(const char *line) return (result); } +static bool preinit_run = false; + void -interp_init(void) +interp_preinit(void) { - + if (preinit_run) + return; setenv("script.lang", "forth", 1); bf_init(); + preinit_run = true; +} + +void +interp_init(void) +{ /* Read our default configuration. */ interp_include("/boot/loader.rc"); } diff --git a/stand/common/interp_lua.c b/stand/common/interp_lua.c index aa759aa99ec1..2a61bb9d04af 100644 --- a/stand/common/interp_lua.c +++ b/stand/common/interp_lua.c @@ -96,17 +96,21 @@ static const luaL_Reg loadedlibs[] = { {NULL, NULL} }; +static bool preinit_done = false; + void -interp_init(void) +interp_preinit(void) { lua_State *luap; struct interp_lua_softc *softc = &lua_softc; - const char *filename; const luaL_Reg *lib; lua_init_md_t **fnpp; TSENTER(); + if (preinit_done) + return; + setenv("script.lang", "lua", 1); LDBG("creating context"); @@ -126,6 +130,21 @@ interp_init(void) LUA_FOREACH_SET(fnpp) (*fnpp)(luap); + preinit_done = true; + + TSEXIT(); +} + +void +interp_init(void) +{ + lua_State *luap; + struct interp_lua_softc *softc = &lua_softc; + const char *filename; + + TSENTER(); + + luap = softc->luap; filename = getenv("loader_lua"); if (filename == NULL) filename = LOADER_LUA; diff --git a/stand/common/interp_simple.c b/stand/common/interp_simple.c index d675da0aa61e..437739a3bcc4 100644 --- a/stand/common/interp_simple.c +++ b/stand/common/interp_simple.c @@ -34,6 +34,11 @@ INTERP_DEFINE("simp"); +void +interp_preinit(void) +{ +} + void interp_init(void) {