aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-11 18:07:15 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-11 19:07:13 +0200
commit6d4f167b97306e0fb1691b9da653ec28e7094bc1 (patch)
tree647b19b33342eed5150696d29c32c480ca73f39b /src
parent4b7c178466da23d5c76308af6a06ae5de9125d84 (diff)
Code reshuffling
Diffstat (limited to 'src')
-rw-r--r--src/alloc.h2
-rw-r--r--src/codegen.c1
-rw-r--r--src/common.h13
-rw-r--r--src/errors.h2
-rw-r--r--src/parser.c5
-rw-r--r--src/types.h5
-rw-r--r--src/unicode.h14
7 files changed, 33 insertions, 9 deletions
diff --git a/src/alloc.h b/src/alloc.h
index 8e8b365..301971c 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -3,6 +3,8 @@
#include <stddef.h>
+#include "common.h"
+
/* Allocate a buffer of NMEMB elements of size SIZE. If PTR is non-null then
reallocate the buffer it points to. Aborts on out-of-memory or overflow. */
void *bufalloc(void *ptr, size_t nmemb, size_t size)
diff --git a/src/codegen.c b/src/codegen.c
index abdf311..ec7a3ef 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -7,6 +7,7 @@
#include "alloc.h"
#include "codegen.h"
+#include "common.h"
#include "errors.h"
#include "parser.h"
diff --git a/src/common.h b/src/common.h
new file mode 100644
index 0000000..be88f0b
--- /dev/null
+++ b/src/common.h
@@ -0,0 +1,13 @@
+#ifndef ORYX_COMMON_H
+#define ORYX_COMMON_H
+
+#ifdef __GNUC__
+# define likely(x) __builtin_expect(!!(x), 1)
+# define unlikely(x) __builtin_expect(!!(x), 0)
+#else
+# define __attribute__(x)
+# define likely(x) (x)
+# define unlikely(x) (x)
+#endif
+
+#endif /* !ORYX_COMMON_H */
diff --git a/src/errors.h b/src/errors.h
index eebd607..669e4e5 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -3,6 +3,8 @@
#include <stdnoreturn.h>
+#include "common.h"
+
noreturn void err(const char *, ...) __attribute__((format(printf, 1, 2)));
#endif /* !ORYX_ERRORS_H */
diff --git a/src/parser.c b/src/parser.c
index d194bac..a1028aa 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -7,6 +7,7 @@
#include <string.h>
#include "alloc.h"
+#include "common.h"
#include "errors.h"
#include "parser.h"
@@ -22,9 +23,9 @@ static parsefn parseblk,
parsestmt,
parsetype;
-static idx_t_ astalloc(struct ast *);
static struct ast mkast(void);
-static void astresz(struct ast *);
+static idx_t_ astalloc(struct ast *) __attribute__((nonnull));
+static void astresz(struct ast *) __attribute__((nonnull));
static size_t toksidx;
diff --git a/src/types.h b/src/types.h
index 34441b5..443aa12 100644
--- a/src/types.h
+++ b/src/types.h
@@ -4,8 +4,11 @@
#include <stddef.h>
#include <stdint.h>
-typedef unsigned char uchar;
typedef uint32_t idx_t_;
+typedef uint32_t rune;
+typedef unsigned char uchar;
+
+#define RUNE_C(x) UINT32_C(x)
struct strview {
const uchar *p;
diff --git a/src/unicode.h b/src/unicode.h
index 36bbc81..8c38409 100644
--- a/src/unicode.h
+++ b/src/unicode.h
@@ -3,10 +3,9 @@
#include <stdbool.h>
#include <stddef.h>
-#include <stdint.h>
-#define RUNE_C(x) UINT32_C(x)
-typedef uint32_t rune;
+#include "common.h"
+#include "types.h"
/* Assert that CH has the Unicode Pattern_White_Space property */
bool rune_is_pat_ws(rune ch) __attribute__((const));
@@ -21,17 +20,20 @@ bool rune_is_xidc(rune ch) __attribute__((const));
/* Decode the first UTF-8 rune in S, and point S to the next rune in the stream.
This function assumes that S points to a buffer that’s padded to a length of
4 bytes, and doesn’t perform any form of input validation. */
-rune utf8_decode(const unsigned char **s);
+rune utf8_decode(const uchar **s)
+ __attribute__((nonnull));
/* Return the offset of the first invalid byte in the UTF-8 string S of length
LEN. This function assumes that S points to a buffer that’s padded to a
length of 4 bytes (although LEN should not reflect any added padding). */
-size_t utf8_validate_off(const unsigned char *s, size_t len);
+size_t utf8_validate_off(const uchar *s, size_t len)
+ __attribute__((nonnull));
#if ORYX_SIMD
/* Assert whether the UTF-8 string S of length LEN is valid, using SIMD
intristics to speed-up computation. */
-bool utf8_validate_simd(const unsigned char *s, size_t len);
+bool utf8_validate_simd(const uchar *s, size_t len)
+ __attribute__((nonnull));
#endif
#endif /* !ORYX_UNICODE_H */