frontend: update api usage with diagnostic support
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
#include <blue/cmd.h>
|
||||
#include <blue/term.h>
|
||||
#include <errno.h>
|
||||
#include <ivy/diag.h>
|
||||
#include <ivy/file.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <ivy/lang/codegen.h>
|
||||
#include <ivy/lang/diag.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <mie/convert.h>
|
||||
#include <mie/ctx.h>
|
||||
@@ -52,15 +54,30 @@ static int compile_file(const char *path, const b_arglist *args)
|
||||
> 0;
|
||||
bool show_ir
|
||||
= b_arglist_get_count(args, OPT_SHOW_IR, B_COMMAND_INVALID_ID) > 0;
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
FILE *fp = fopen(path, "r");
|
||||
if (!fp) {
|
||||
struct ivy_file *src = NULL;
|
||||
status = ivy_file_open(path, &src);
|
||||
if (!src) {
|
||||
b_err("cannot open source file '%s'", path);
|
||||
b_i("reason: %s", strerror(errno));
|
||||
b_i("reason: %s", ivy_status_to_string(status));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct ivy_file *src = ivy_file_from_fp(fp);
|
||||
struct ivy_diag_stream diag_stream;
|
||||
ivy_diag_stream_init_tty(&diag_stream, b_stdtty);
|
||||
|
||||
struct ivy_diag_ctx *diag = NULL;
|
||||
status = ivy_diag_ctx_create(&diag);
|
||||
if (status != IVY_OK) {
|
||||
b_err("failed to initialise Ivy diagnostic context");
|
||||
ivy_file_close(src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ivy_lang_diag_ctx_init(diag);
|
||||
ivy_diag_ctx_set_line_source(diag, &src->f_base);
|
||||
|
||||
struct ivy_lexer *lex = NULL;
|
||||
if (ivy_lexer_create(&lex) != IVY_OK) {
|
||||
b_err("failed to initialise Ivy lexer");
|
||||
@@ -69,7 +86,7 @@ static int compile_file(const char *path, const b_arglist *args)
|
||||
}
|
||||
|
||||
ivy_lexer_set_source(lex, &src->f_base);
|
||||
enum ivy_status status = IVY_OK;
|
||||
ivy_lexer_set_diag_ctx(lex, diag);
|
||||
|
||||
struct ivy_parser *parser = NULL;
|
||||
status = ivy_parser_create(&parser);
|
||||
@@ -102,9 +119,13 @@ static int compile_file(const char *path, const b_arglist *args)
|
||||
}
|
||||
|
||||
if (status != IVY_OK) {
|
||||
ivy_diag_ctx_write(
|
||||
diag, IVY_DIAG_FORMAT_PRETTY, &diag_stream);
|
||||
#if 0
|
||||
b_err("failed to parse '%s'", path);
|
||||
b_i("reason: lex error (%s)",
|
||||
ivy_status_to_string(ivy_lexer_get_status(lex)));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user