Slightly nicer errors in the codegen
This commit is contained in:
@@ -7,12 +7,25 @@
|
||||
#include "../parser/SolsNode.h"
|
||||
#include "../include/estr.h"
|
||||
#include "../include/uthash.h"
|
||||
#include "../include/ansii.h"
|
||||
|
||||
// FIXME add proper erroring function
|
||||
char* createCodegenError(char* what) {
|
||||
Estr estr = CREATE_ESTR(what);
|
||||
APPEND_ESTR(estr, "\nthats an error");
|
||||
return estr.str;
|
||||
// FIXME show multiple lines for the error
|
||||
char* createCodegenError(SolsNode* node, char* what) {
|
||||
Estr err = CREATE_ESTR(ESC_BOLD ESC_RED_FG "error: " ESC_RESET ESC_BOLD);
|
||||
APPEND_ESTR(err, what);
|
||||
APPEND_ESTR(err, "\n" ESC_RESET);
|
||||
APPEND_ESTR(err, ESC_CYAN_FG "-> " ESC_RESET);
|
||||
APPEND_ESTR(err, "on line ");
|
||||
|
||||
char line_buf[16];
|
||||
snprintf(line_buf, sizeof(line_buf), "%zu", node->line.num);
|
||||
APPEND_ESTR(err, line_buf);
|
||||
APPEND_ESTR(err, "\n\n");
|
||||
|
||||
APPEND_ESTR(err, node->line.content);
|
||||
APPEND_ESTR(err, "\n");
|
||||
|
||||
return err.str;
|
||||
}
|
||||
|
||||
ResultType(SolsType, charptr) getNodeType(SolsNode* node, SolsScope* scope) {
|
||||
@@ -680,7 +693,7 @@ ResultType(GroundProgram, charptr) generateCode(SolsNode* node, SolsScope* scope
|
||||
for (size_t i = 0; i < node->children.count; i++) {
|
||||
ResultType(GroundProgram, charptr) generated = generateCode(&node->children.at[i], scope);
|
||||
if (generated.error) {
|
||||
return Error(GroundProgram, charptr, createCodegenError(generated.as.error));
|
||||
return Error(GroundProgram, charptr, createCodegenError(&node->children.at[i], generated.as.error));
|
||||
}
|
||||
for (size_t j = 0; j < generated.as.success.size; j++) {
|
||||
groundAddInstructionToProgram(&program, generated.as.success.instructions[j]);
|
||||
|
||||
Reference in New Issue
Block a user