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