From 53cead0bab8c0d3b91488f26563cb4a229eaeb2b Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sun, 9 Jul 2017 16:15:44 -0400 Subject: [PATCH] Remove vm crash return and use error instead. --- client/main.c | 6 +----- core/vm.c | 7 ++----- include/gst/gst.h | 4 +--- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/client/main.c b/client/main.c index 38bdfe54..d77ee253 100644 --- a/client/main.c +++ b/client/main.c @@ -91,11 +91,7 @@ static int debug_compile_and_run(Gst *vm, GstValue ast, int64_t flags) { } /* Execute function */ if (gst_run(vm, func)) { - if (vm->crash) { - printf_flags(flags, "31", "vm crash: %s\n", vm->crash); - } else { - printf_flags(flags, "31", "vm error: %s\n", (const char *)gst_to_string(vm, vm->ret)); - } + printf_flags(flags, "31", "vm error: %s\n", (const char *)gst_to_string(vm, vm->ret)); return 1; } return 0; diff --git a/core/vm.c b/core/vm.c index e17667c6..81c982af 100644 --- a/core/vm.c +++ b/core/vm.c @@ -36,7 +36,6 @@ int gst_continue(Gst *vm) { #define gst_exit(vm, r) return ((vm)->ret = (r), GST_RETURN_OK) #define gst_error(vm, e) do { (vm)->ret = gst_string_cv((vm), (e)); goto vm_error; } while (0) -#define gst_crash(vm, e) return ((vm)->crash = (e), GST_RETURN_CRASH) #define gst_assert(vm, cond, e) do {if (!(cond)){gst_error((vm), (e));}} while (0) /* Intialize local state */ @@ -452,8 +451,6 @@ int gst_run(Gst *vm, GstValue callee) { } else { /* Create new thread */ vm->thread = gst_thread(vm, callee, 64); - if (vm->thread == NULL) - return GST_RETURN_CRASH; } if (callee.type == GST_CFUNCTION) { vm->ret.type = GST_NIL; @@ -461,7 +458,8 @@ int gst_run(Gst *vm, GstValue callee) { } else if (callee.type == GST_FUNCTION) { result = gst_continue(vm); } else { - return GST_RETURN_CRASH; + vm->ret = gst_string_cv(vm, "expected function"); + return GST_RETURN_ERROR; } /* Handle yields */ while (result == GST_RETURN_OK && vm->thread->status == GST_THREAD_PENDING) { @@ -503,7 +501,6 @@ uint32_t gst_count_args(Gst *vm) { /* Initialize the VM */ void gst_init(Gst *vm) { vm->ret.type = GST_NIL; - vm->crash = NULL; /* Garbage collection */ vm->blocks = NULL; vm->nextCollection = 0; diff --git a/include/gst/gst.h b/include/gst/gst.h index 2e3dc186..559ed7ad 100644 --- a/include/gst/gst.h +++ b/include/gst/gst.h @@ -294,7 +294,6 @@ struct GstUserdataHeader { /* VM return status from c function */ #define GST_RETURN_OK 0 #define GST_RETURN_ERROR 1 -#define GST_RETURN_CRASH 2 /* The VM state */ struct Gst { @@ -314,8 +313,7 @@ struct Gst { GstTable *registry; GstTable *env; /* Return state */ - const char *crash; - GstValue ret; /* Returned value from gst_start. */ + GstValue ret; }; /* The type of a ParseState */