cvm.c:cosmoV_printError -> cosmoV_printBacktrace

This commit is contained in:
cpunch 2023-12-28 22:56:57 -06:00
parent 4816e64612
commit 93f3ae1106
4 changed files with 9 additions and 11 deletions

12
main.c
View File

@ -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);
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);