Reduct  v4.1.3-1-gd06c383
A functional and immutable language.
Loading...
Searching...
No Matches
defs.h
Go to the documentation of this file.
1#ifndef REDUCT_DEFS_H
2#define REDUCT_DEFS_H 1
3
4#include <stddef.h>
5#include <stdint.h>
6
7struct reduct;
8struct reduct_list;
9struct reduct_builder;
10struct reduct_list;
11
12#if defined(_WIN32) || defined(__CYGWIN__)
13#ifdef REDUCT_BUILD_LIB
14#define REDUCT_API __declspec(dllexport)
15#elif defined(REDUCT_USE_LIB)
16#define REDUCT_API __declspec(dllimport)
17#else
18#define REDUCT_API
19#endif
20#else
21#if __GNUC__ >= 4
22#define REDUCT_API __attribute__((visibility("default")))
23#else
24#define REDUCT_API
25#endif
26#endif
27
28#ifdef _WIN32
29#include <windows.h>
30typedef HMODULE reduct_lib_t;
31#define REDUCT_LIB_OPEN(_path) LoadLibraryA(_path)
32#define REDUCT_LIB_CLOSE(_lib) FreeLibrary(_lib)
33#define REDUCT_LIB_SYM(_lib, _name) GetProcAddress(_lib, _name)
34#define REDUCT_LIB_ERROR() "Windows Error"
35#else
36#include <dlfcn.h>
37#include <unistd.h>
38typedef void* reduct_lib_t;
39#define REDUCT_LIB_OPEN(_path) dlopen(_path, RTLD_NOW | RTLD_GLOBAL)
40#define REDUCT_LIB_CLOSE(_lib) dlclose(_lib)
41#define REDUCT_LIB_SYM(_lib, _name) dlsym(_lib, _name)
42#define REDUCT_LIB_ERROR() dlerror()
43#endif
44
45#if defined(__GNUC__) || defined(__clang__)
46#define REDUCT_LIKELY(_x) __builtin_expect(!!(_x), 1)
47#define REDUCT_UNLIKELY(_x) __builtin_expect(!!(_x), 0)
48#define REDUCT_NORETURN __attribute__((noreturn))
49#define REDUCT_ALWAYS_INLINE __attribute__((always_inline))
50#define REDUCT_ALIGNED(_x) __attribute__((aligned(_x)))
51#elif defined(_MSC_VER)
52#define REDUCT_LIKELY(_x) (_x)
53#define REDUCT_UNLIKELY(_x) (_x)
54#define REDUCT_NORETURN __declspec(noreturn)
55#define REDUCT_ALWAYS_INLINE __forceinline
56#define REDUCT_ALIGNED(_x) __declspec(align(_x))
57#else
58#define REDUCT_LIKELY(_x) (_x)
59#define REDUCT_UNLIKELY(_x) (_x)
60#define REDUCT_NORETURN
61#define REDUCT_ALWAYS_INLINE
62#endif
63
64#define REDUCT_MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b))
65#define REDUCT_MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))
66#define REDUCT_CLAMP(_v, _min, _max) (REDUCT_MAX(_min, REDUCT_MIN(_v, _max)))
67#define REDUCT_LERP(_a, _b, _t) ((_a) + ((_b) - (_a)) * (_t))
68
69#define REDUCT_UNUSED(_x) ((void)(_x))
70
71/**
72 * @brief PI constant.
73 */
74#define REDUCT_PI 3.14159265358979323846
75
76/**
77 * @brief E constant.
78 */
79#define REDUCT_E 2.7182818284590452354
80
81/**
82 * @brief INFINITY constant.
83 */
84#define REDUCT_INF \
85 (((union { \
86 uint64_t u; \
87 double f; \
88 }){0x7FF0000000000000ULL}) \
89 .f)
90
91/**
92 * @brief NAN constant.
93 */
94#define REDUCT_NAN \
95 (((union { \
96 uint64_t u; \
97 double f; \
98 }){0x7FF8000000000000ULL}) \
99 .f)
100
101/**
102 * @brief Maximum path length for Reduct.
103 */
104#define REDUCT_PATH_MAX 1024
105
106/**
107 * @brief Container of macro.
108 *
109 * Used to get the pointer to a structure from a pointer to one of its members.
110 *
111 * @param _ptr The pointer to the member.
112 * @param _type The type of the structure.
113 * @param _member The name of the member.
114 */
115#define REDUCT_CONTAINER_OF(_ptr, _type, _member) ((_type*)((char*)(_ptr) - offsetof(_type, _member)))
116
117/**
118 * @brief Handle type.
119 */
120typedef struct
121{
122 uint64_t _value;
124
125/**
126 * @brief Native function pointer type.
127 */
128typedef reduct_handle_t (*reduct_native_fn)(struct reduct* reduct, size_t argc, reduct_handle_t* argv);
129
130/**
131 * @brief Intrinsic handler function type.
132 */
133typedef struct reduct_rvsdg_origin* (
134 *reduct_native_intrinsic_fn)(struct reduct_builder* builder, struct reduct_list* expr);
135
136#define REDUCT_ALIGNMENT 64 ///< The memory alignment for items.
137
138#define REDUCT_ROUND_UP(_val, _align) (((_val) + (_align) - 1) & ~((_align) - 1))
139
140#endif
reduct_handle_t(* reduct_native_fn)(struct reduct *reduct, size_t argc, reduct_handle_t *argv)
Native function pointer type.
Definition defs.h:128
struct reduct_rvsdg_origin *(* reduct_native_intrinsic_fn)(struct reduct_builder *builder, struct reduct_list *expr)
Intrinsic handler function type.
Definition defs.h:134
void * reduct_lib_t
Definition defs.h:38
Handle type.
Definition defs.h:121
uint64_t _value
Definition defs.h:122