Skip to content

Commit

Permalink
cvm.c:cosmoV_printError -> cosmoV_printBacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
CPunch committed Dec 29, 2023
1 parent 4816e64 commit 93f3ae1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93f3ae1

Please sign in to comment.