summaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-07-05 16:26:54 +0200
committerJo-Philipp Wich <jo@mein.io>2021-07-11 15:49:14 +0200
commit38ff6dedec5fea8e896a0fc821a0e5db62d029ba (patch)
treecc95cace811b4bb858fa5f7c61402dc887f30096 /main.c
parentd5bc22338f6ed30a1d59b160d7118701f28c0d05 (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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/main.c b/main.c
index 41b608e..e466360 100644
--- a/main.c
+++ b/main.c
@@ -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;