From 93f3ae110622308020398507594d503f3b485d53 Mon Sep 17 00:00:00 2001 From: cpunch Date: Thu, 28 Dec 2023 22:56:57 -0600 Subject: [PATCH] cvm.c:cosmoV_printError -> cosmoV_printBacktrace --- main.c | 12 +++++------- src/cobj.h | 2 +- src/cvm.c | 4 ++-- src/cvm.h | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index b8824ab..9346503 100644 --- a/main.c +++ b/main.c @@ -50,13 +50,11 @@ static bool interpret(CState *state, const char *script, const char *mod) // cosmoV_compileString pushes the result onto the stack (COBJ_ERROR or COBJ_CLOSURE) if (cosmoV_compileString(state, script, mod)) { - // 0 args being passed, 0 results expected - if (!cosmoV_pcall(state, 0, 0)) { - cosmoV_printError(state, cosmoV_readError(*cosmoV_pop(state))); + cosmoV_printBacktrace(state, cosmoV_readError(*cosmoV_pop(state))); return false; } } else { - cosmoV_printError(state, cosmoV_readError(*cosmoV_pop(state))); + cosmoV_printBacktrace(state, cosmoV_readError(*cosmoV_pop(state))); return false; } @@ -158,7 +156,7 @@ void compileScript(CState *state, const char *in, const char *out) CObjFunction *func = cosmoV_readClosure(*cosmoV_getTop(state, 0))->function; cosmoD_dump(state, func, fileWriter, (void *)fout); } else { - cosmoV_printError(state, cosmoV_readError(*cosmoV_pop(state))); + cosmoV_printBacktrace(state, cosmoV_readError(*cosmoV_pop(state))); } free(script); @@ -171,13 +169,13 @@ void loadScript(CState *state, const char *in) { FILE *file = fopen(in, "rb"); if (!cosmoV_undump(state, fileReader, file)) { - cosmoV_printError(state, cosmoV_readError(*cosmoV_pop(state))); + cosmoV_printBacktrace(state, cosmoV_readError(*cosmoV_pop(state))); return; }; printf("[!] loaded %s!\n", in); if (!cosmoV_pcall(state, 0, 0)) - cosmoV_printError(state, cosmoV_readError(*cosmoV_pop(state))); + cosmoV_printBacktrace(state, cosmoV_readError(*cosmoV_pop(state))); fclose(file); } diff --git a/src/cobj.h b/src/cobj.h index 055d8fa..e74926c 100644 --- a/src/cobj.h +++ b/src/cobj.h @@ -55,7 +55,7 @@ struct CObjError CCallFrame *frames; int frameCount; int line; // reserved for parser errors - bool parserError; // if true, cosmoV_printError will format the error to the lexer + bool parserError; // if true, cosmoV_printBacktrace will format the error to the lexer }; struct CObjObject diff --git a/src/cvm.c b/src/cvm.c index 40c91c9..5645442 100644 --- a/src/cvm.c +++ b/src/cvm.c @@ -78,7 +78,7 @@ bool cosmoV_compileString(CState *state, const char *src, const char *name) return false; } -void cosmoV_printError(CState *state, CObjError *err) +void cosmoV_printBacktrace(CState *state, CObjError *err) { // print stack trace for (int i = 0; i < err->frameCount; i++) { @@ -129,7 +129,7 @@ void cosmoV_throw(CState *state) } else { cosmoV_pushValue(state, val); fprintf(stderr, "Unhandled panic! "); - cosmoV_printError(state, error); + cosmoV_printBacktrace(state, error); exit(1); } } diff --git a/src/cvm.h b/src/cvm.h index 347a781..1402518 100644 --- a/src/cvm.h +++ b/src/cvm.h @@ -33,7 +33,7 @@ COSMO_API CObjObject *cosmoV_makeObject(CState *state, int pairs); COSMO_API void cosmoV_makeTable(CState *state, int pairs); COSMO_API void cosmoV_concat(CState *state, int vals); COSMO_API void cosmoV_pushFString(CState *state, const char *format, ...); -COSMO_API void cosmoV_printError(CState *state, CObjError *err); +COSMO_API void cosmoV_printBacktrace(CState *state, CObjError *err); COSMO_API void cosmoV_throw(CState *state); COSMO_API void cosmoV_error(CState *state, const char *format, ...); COSMO_API void cosmoV_insert(CState *state, int indx, CValue val);