diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-08-12 00:54:27 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-08-12 01:23:27 +0200 |
commit | b41cb2d7b7cc1a10f4f68f9c8f544f916f448822 (patch) | |
tree | 3c284b97e970c7cd5f17d13f31ba4d7df028bb69 /main.c | |
parent | 85d7885e226ed79dc071e0cef73ccc918144a8f5 (diff) |
main: introduce -g flag to allow enabling periodic gc from cli
Implement a new flag `-g` which takes an interval value and enables the
periodic GC with the given interval for cyclic object structures in the
VM if specified.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -54,6 +54,10 @@ print_usage(const char *app) "-t\n" " Enable VM execution tracing.\n\n" + "-g interval\n" + " Perform periodic garbage collection every `interval` object\n" + " allocations.\n\n" + "-S\n" " Enable strict mode.\n\n" @@ -130,6 +134,9 @@ compile(uc_vm_t *vm, uc_source_t *src, FILE *precompile, bool strip, char *inter goto out; } + if (vm->gc_interval) + uc_vm_gc_start(vm, vm->gc_interval); + rc = uc_vm_execute(vm, program, &res); switch (rc) { @@ -468,7 +475,7 @@ appname(const char *argv0) int main(int argc, char **argv) { - const char *optspec = "he:tST::RD:F:U:l:L:c::o:s"; + const char *optspec = "he:tg:ST::RD:F:U:l:L:c::o:s"; char *interp = "/usr/bin/env ucode"; uc_source_t *source = NULL; FILE *precompile = NULL; @@ -554,6 +561,10 @@ main(int argc, char **argv) uc_vm_trace_set(&vm, 1); break; + case 'g': + vm.gc_interval = atoi(optarg); + break; + case 'D': if (!parse_define_string(optarg, uc_vm_scope_get(&vm))) { rv = 1; |