summaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-07-05 20:22:39 +0200
committerJo-Philipp Wich <jo@mein.io>2021-07-11 15:49:14 +0200
commit2f77657ae97f84edcd665c4cfe00ef91b9cde1bc (patch)
treebc786e60d2a743310f037a8bff595c9252011887 /main.c
parent111645aa965717adb40604e53d0bab07e25c1b27 (diff)
vm: extend API to allow returning result value from VM execution
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/main.c b/main.c
index 88a53f5..6c763cd 100644
--- a/main.c
+++ b/main.c
@@ -78,7 +78,7 @@ 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, *name, *mod;
+ uc_value_t *globals = NULL, *res = NULL, *arr, *name, *mod;
uc_function_t *entry;
uc_vm vm = { 0 };
int i, rc = 0;
@@ -92,7 +92,7 @@ parse(uc_parse_config *config, uc_source *src,
if (!entry) {
fprintf(stderr, "%s", err);
free(err);
- rc = 2;
+ rc = -1;
goto out;
}
@@ -125,15 +125,25 @@ parse(uc_parse_config *config, uc_source *src,
register_variable(globals, ucv_string_get(name), mod);
}
- rc = uc_vm_execute(&vm, entry);
+ rc = uc_vm_execute(&vm, entry, &res);
- if (rc) {
- rc = 1;
- goto out;
+ switch (rc) {
+ case STATUS_OK:
+ rc = 0;
+ break;
+
+ case ERROR_COMPILE:
+ rc = -1;
+ break;
+
+ case ERROR_RUNTIME:
+ rc = -2;
+ break;
}
out:
uc_vm_free(&vm);
+ ucv_put(res);
return rc;
}