From cc99e7440e7a87a328ce09ca1ef931f674d72acb Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 8 May 2025 20:31:28 +0100 Subject: [PATCH] lang: add diagnostic definitions --- lang/CMakeLists.txt | 2 +- lang/diag.c | 26 ++++++++++++++++++++++++++ lang/include/ivy/lang/diag.h | 20 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 lang/diag.c create mode 100644 lang/include/ivy/lang/diag.h diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index d26b2d3..a77fc60 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -11,5 +11,5 @@ else () endif () target_include_directories(ivy-lang PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/) -target_link_libraries(ivy-lang mie ivy-common Bluelib::Core Bluelib::Object Bluelib::Term) +target_link_libraries(ivy-lang mie ivy-diag ivy-common Bluelib::Core Bluelib::Object Bluelib::Term) target_compile_definitions(ivy-lang PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC}) diff --git a/lang/diag.c b/lang/diag.c new file mode 100644 index 0000000..bcd1fd6 --- /dev/null +++ b/lang/diag.c @@ -0,0 +1,26 @@ +#include +#include + +#define ERROR_CLASS(id, title) \ + [id] = {.c_type = IVY_DIAG_ERROR, .c_title = (title)} + +#define MSG(id, content) [id] = {.msg_content = (content)} + +static const struct ivy_diag_class diag_classes[] = { + ERROR_CLASS(IVY_LANG_E_UNRECOGNISED_SYMBOL, "Unrecognised symbol"), +}; +static const size_t nr_diag_classes = sizeof diag_classes / sizeof diag_classes[0]; + +static const struct ivy_diag_msg diag_msg[] = { + MSG(IVY_LANG_MSG_UNKNOWN_SYMBOL_ENCOUNTERED, + "encountered a symbol that is not part of the Ivy syntax."), +}; +static const size_t nr_diag_msg = sizeof diag_msg / sizeof diag_msg[0]; + +enum ivy_status ivy_lang_diag_ctx_init(struct ivy_diag_ctx *ctx) +{ + ivy_diag_ctx_set_class_definitions(ctx, diag_classes, nr_diag_msg); + ivy_diag_ctx_set_msg_definitions(ctx, diag_msg, nr_diag_msg); + + return IVY_OK; +} diff --git a/lang/include/ivy/lang/diag.h b/lang/include/ivy/lang/diag.h new file mode 100644 index 0000000..d6e3209 --- /dev/null +++ b/lang/include/ivy/lang/diag.h @@ -0,0 +1,20 @@ +#ifndef IVY_LANG_DIAG_H_ +#define IVY_LANG_DIAG_H_ + +#include + +struct ivy_diag_ctx; + +enum ivy_lang_diag_code { + IVY_LANG_E_NONE = 0, + IVY_LANG_E_UNRECOGNISED_SYMBOL, +}; + +enum ivy_lang_diag_msg { + IVY_LANG_MSG_NONE = 0, + IVY_LANG_MSG_UNKNOWN_SYMBOL_ENCOUNTERED, +}; + +IVY_API enum ivy_status ivy_lang_diag_ctx_init(struct ivy_diag_ctx *ctx); + +#endif