diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-02-06 00:12:48 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-02-07 00:04:35 +0100 |
commit | 3a49192f3a1e8a5d348cdbfccd0a16d74ba61e3d (patch) | |
tree | 6d8a4b620b362ab4f707678a5b626a85e1531c0b /examples/state-reset.c | |
parent | 5bd764a35aeaf50b54957bfa94ba94198514baf0 (diff) |
treewide: rework function memory model
- Instead of treating individual program functions as managed ucode types,
demote uc_function_t values to pointers into a uc_program_t entity
- Promote uc_program_t to a managed type
- Let uc_closure_t claim references to the owning program of the enclosed
uc_function_t
- Redefine public APIs uc_compile() and uc_vm_execute() APIs to return and
expect an uc_program_t object respectively
- Remove vallist indirection for function loading and let the compiler
emit the function id directly when producing function construction code
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'examples/state-reset.c')
-rw-r--r-- | examples/state-reset.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/examples/state-reset.c b/examples/state-reset.c index 692aa76..ce61e7f 100644 --- a/examples/state-reset.c +++ b/examples/state-reset.c @@ -23,7 +23,7 @@ #define MULTILINE_STRING(...) #__VA_ARGS__ -static const char *program = MULTILINE_STRING( +static const char *program_code = MULTILINE_STRING( {% /* the global test variable should've been reset since the previous run */ print("Global variable is null? " + (global.test == null) + "\n"); @@ -43,17 +43,17 @@ int main(int argc, char **argv) int exit_code = 0; /* create a source buffer containing the program code */ - uc_source_t *src = uc_source_new_buffer("my program", strdup(program), strlen(program)); + uc_source_t *src = uc_source_new_buffer("my program", strdup(program_code), strlen(program_code)); /* compile source buffer into function */ char *syntax_error = NULL; - uc_function_t *progfunc = uc_compile(&config, src, &syntax_error); + uc_program_t *program = uc_compile(&config, src, &syntax_error); /* release source buffer */ uc_source_put(src); /* check if compilation failed */ - if (!progfunc) { + if (!program) { fprintf(stderr, "Failed to compile program: %s\n", syntax_error); return 1; @@ -70,11 +70,8 @@ int main(int argc, char **argv) printf("Iteration %d: ", i + 1); - /* take additional reference to progfunc to avoid freeing it after execution */ - ucv_get(&progfunc->header); - /* execute program function */ - int return_code = uc_vm_execute(&vm, progfunc, NULL); + int return_code = uc_vm_execute(&vm, program, NULL); /* handle return status */ if (return_code == ERROR_COMPILE || return_code == ERROR_RUNTIME) { @@ -88,7 +85,7 @@ int main(int argc, char **argv) } /* release program function */ - ucv_put(&progfunc->header); + uc_program_put(program); return exit_code; } |