mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Remove vm crash return and use error instead.
This commit is contained in:
		| @@ -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)); | ||||
|         } | ||||
|         return 1; | ||||
|     } | ||||
|     return 0; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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 */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 bakpakin
					bakpakin