Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
errors.h
Go to the documentation of this file.
1/* -*- C -*-
2 * Serene programming language
3 * Copyright (C) 2019-2026 Sameer Rahmani <[email protected]>
4 *
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19// IMPORTANT NOTE:
20// By Convention, all the data structures that in anyway may, interacting with
21// them may result in an error, must use the ERROR_HEADER macro as the first
22// member. For example:
23//
24// typedef struct foo {
25// ERROR_HEADER
26// bar other;
27// ...
28// } foo;
29//
30// Following this convention let you use the error handling helpers from this
31// header uniformly across the runtime library.
32
33#pragma once
34
35#define ERROR_HEADER srn_error_t *maybe_error
36
37typedef struct srn_context_t srn_context_t;
38
39#ifdef SRN_WITH_SERENE
40typedef struct srn_value_t srn_value_t;
41typedef struct srn_metadata_t srn_metadata_t;
42#endif
43
54
59
61 const char *msg);
62
63#ifdef SRN_WITH_SERENE
64srn_value_t *srn_errors_err_to_value(srn_context_t *ctx,
65 srn_metadata_t *metadata,
66 srn_error_t *err);
67/// Create an error as a value. In compare to `srn_errors_make` this function
68/// populates the `sr_value_t` data structure, so the returning value can be
69/// used in Serene lang directly.
70srn_value_t *srn_errors_make_error(srn_context_t *ctx, srn_metadata_t *metadata,
71 srn_error_tag_t tag, const char *msg);
72#endif
73
74#define ERR(ctx, err, msg) srn_errors_make(ctx, err, msg)
srn_error_tag_t
Definition errors.h:44
@ CORRUPTED_SEQ
When the memory layout of a seq is incorrect.
Definition errors.h:48
@ EMPTY_NAMESPACE_NAME
Definition errors.h:50
@ STRING_LENGTH_LIMIT_EXCEEDED
Definition errors.h:52
@ ABSURD
Definition errors.h:45
@ FAILED_TO_ADD_MODULE
Failed to add a module to the jit engine.
Definition errors.h:49
@ INDEX_OUT_OF_BOUND
Definition errors.h:47
@ SEQ_LIMIT_REACHED
Definition errors.h:46
@ EMPTY_SYMBOL_NAME
Definition errors.h:51
srn_error_t * srn_errors_make(const srn_context_t *ctx, srn_error_tag_t tag, const char *msg)
Definition errors.c:28
char * msg
Definition errors.h:57
srn_error_tag_t tag
Definition errors.h:56