mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Remove vm crash return and use error instead.
This commit is contained in:
parent
de9d7bcfdc
commit
53cead0bab
@ -91,11 +91,7 @@ static int debug_compile_and_run(Gst *vm, GstValue ast, int64_t flags) {
|
|||||||
}
|
}
|
||||||
/* Execute function */
|
/* Execute function */
|
||||||
if (gst_run(vm, func)) {
|
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 1;
|
||||||
}
|
}
|
||||||
return 0;
|
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_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_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)
|
#define gst_assert(vm, cond, e) do {if (!(cond)){gst_error((vm), (e));}} while (0)
|
||||||
|
|
||||||
/* Intialize local state */
|
/* Intialize local state */
|
||||||
@ -452,8 +451,6 @@ int gst_run(Gst *vm, GstValue callee) {
|
|||||||
} else {
|
} else {
|
||||||
/* Create new thread */
|
/* Create new thread */
|
||||||
vm->thread = gst_thread(vm, callee, 64);
|
vm->thread = gst_thread(vm, callee, 64);
|
||||||
if (vm->thread == NULL)
|
|
||||||
return GST_RETURN_CRASH;
|
|
||||||
}
|
}
|
||||||
if (callee.type == GST_CFUNCTION) {
|
if (callee.type == GST_CFUNCTION) {
|
||||||
vm->ret.type = GST_NIL;
|
vm->ret.type = GST_NIL;
|
||||||
@ -461,7 +458,8 @@ int gst_run(Gst *vm, GstValue callee) {
|
|||||||
} else if (callee.type == GST_FUNCTION) {
|
} else if (callee.type == GST_FUNCTION) {
|
||||||
result = gst_continue(vm);
|
result = gst_continue(vm);
|
||||||
} else {
|
} else {
|
||||||
return GST_RETURN_CRASH;
|
vm->ret = gst_string_cv(vm, "expected function");
|
||||||
|
return GST_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
/* Handle yields */
|
/* Handle yields */
|
||||||
while (result == GST_RETURN_OK && vm->thread->status == GST_THREAD_PENDING) {
|
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 */
|
/* Initialize the VM */
|
||||||
void gst_init(Gst *vm) {
|
void gst_init(Gst *vm) {
|
||||||
vm->ret.type = GST_NIL;
|
vm->ret.type = GST_NIL;
|
||||||
vm->crash = NULL;
|
|
||||||
/* Garbage collection */
|
/* Garbage collection */
|
||||||
vm->blocks = NULL;
|
vm->blocks = NULL;
|
||||||
vm->nextCollection = 0;
|
vm->nextCollection = 0;
|
||||||
|
@ -294,7 +294,6 @@ struct GstUserdataHeader {
|
|||||||
/* VM return status from c function */
|
/* VM return status from c function */
|
||||||
#define GST_RETURN_OK 0
|
#define GST_RETURN_OK 0
|
||||||
#define GST_RETURN_ERROR 1
|
#define GST_RETURN_ERROR 1
|
||||||
#define GST_RETURN_CRASH 2
|
|
||||||
|
|
||||||
/* The VM state */
|
/* The VM state */
|
||||||
struct Gst {
|
struct Gst {
|
||||||
@ -314,8 +313,7 @@ struct Gst {
|
|||||||
GstTable *registry;
|
GstTable *registry;
|
||||||
GstTable *env;
|
GstTable *env;
|
||||||
/* Return state */
|
/* Return state */
|
||||||
const char *crash;
|
GstValue ret;
|
||||||
GstValue ret; /* Returned value from gst_start. */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The type of a ParseState */
|
/* The type of a ParseState */
|
||||||
|
Loading…
Reference in New Issue
Block a user