diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-07-05 16:26:54 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 15:49:14 +0200 |
commit | 38ff6dedec5fea8e896a0fc821a0e5db62d029ba (patch) | |
tree | cc95cace811b4bb858fa5f7c61402dc887f30096 /main.c | |
parent | d5bc22338f6ed30a1d59b160d7118701f28c0d05 (diff) |
main: preload modules ourselves
Module preloading is a cli frontend specific feature, it does not belong
into the VM API, therfore do the module preloading directly in main.c to
allow removing the corresponding VM code in a subsequent commit.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -78,10 +78,11 @@ parse(uc_parse_config *config, uc_source *src, uc_value_t *env, uc_value_t *modules, int argc, char **argv) { - uc_value_t *globals = NULL, *arr; + uc_value_t *globals = NULL, *arr, *name, *mod; uc_function_t *entry; uc_vm vm = { 0 }; int i, rc = 0; + size_t idx; char *err; uc_vm_init(&vm, config); @@ -115,7 +116,16 @@ parse(uc_parse_config *config, uc_source *src, /* load std functions into global scope */ uc_load_stdlib(globals); - rc = uc_vm_execute(&vm, entry, modules); + /* preload modules */ + for (idx = 0; idx < ucv_array_length(modules); idx++) { + name = ucv_array_get(modules, idx); + mod = uc_vm_invoke(&vm, "require", 1, name); + + if (mod) + register_variable(globals, ucv_string_get(name), mod); + } + + rc = uc_vm_execute(&vm, entry, NULL); if (rc) { rc = 1; |