summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-03-20 23:34:56 +0100
committerGitHub <noreply@github.com>2022-03-20 23:34:56 +0100
commita88aca97633c2ec58987a76a5a8d910c37680e07 (patch)
treedee32d4bba166995bdb32d4cf8f1fcad8bcead4d /include
parent807060a5d2d40113d9d78bf9e3866efb3de4c442 (diff)
parentab46fdfe742e754a8a56207ce1fc5653085696ad (diff)
Merge pull request #52 from jow-/portability-fixes
Portability fixes for macOS
Diffstat (limited to 'include')
-rw-r--r--include/endian.h23
-rw-r--r--include/ucode/chunk.h6
-rw-r--r--include/ucode/compiler.h13
-rw-r--r--include/ucode/lexer.h6
-rw-r--r--include/ucode/lib.h6
-rw-r--r--include/ucode/module.h6
-rw-r--r--include/ucode/program.h6
-rw-r--r--include/ucode/source.h6
-rw-r--r--include/ucode/types.h6
-rw-r--r--include/ucode/util.h6
-rw-r--r--include/ucode/vallist.h14
-rw-r--r--include/ucode/vm.h6
12 files changed, 58 insertions, 46 deletions
diff --git a/include/endian.h b/include/endian.h
new file mode 100644
index 0000000..198cf7c
--- /dev/null
+++ b/include/endian.h
@@ -0,0 +1,23 @@
+#ifdef __APPLE__
+
+# include <machine/endian.h>
+# include <libkern/OSByteOrder.h>
+
+# define htobe16(x) OSSwapHostToBigInt16(x)
+# define htole16(x) OSSwapHostToLittleInt16(x)
+# define be16toh(x) OSSwapBigToHostInt16(x)
+# define le16toh(x) OSSwapLittleToHostInt16(x)
+
+# define htobe32(x) OSSwapHostToBigInt32(x)
+# define htole32(x) OSSwapHostToLittleInt32(x)
+# define be32toh(x) OSSwapBigToHostInt32(x)
+# define le32toh(x) OSSwapLittleToHostInt32(x)
+
+# define htobe64(x) OSSwapHostToBigInt64(x)
+# define htole64(x) OSSwapHostToLittleInt64(x)
+# define be64toh(x) OSSwapBigToHostInt64(x)
+# define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#else
+# include_next <endian.h>
+#endif
diff --git a/include/ucode/chunk.h b/include/ucode/chunk.h
index 6804eeb..78d5ec6 100644
--- a/include/ucode/chunk.h
+++ b/include/ucode/chunk.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __CHUNK_H_
-#define __CHUNK_H_
+#ifndef UCODE_CHUNK_H
+#define UCODE_CHUNK_H
#include <stdint.h>
#include <stddef.h>
@@ -34,4 +34,4 @@ size_t uc_chunk_debug_get_srcpos(uc_chunk_t *chunk, size_t off);
void uc_chunk_debug_add_variable(uc_chunk_t *chunk, size_t from, size_t to, size_t slot, bool upval, uc_value_t *name);
uc_value_t *uc_chunk_debug_get_variable(uc_chunk_t *chunk, size_t off, size_t slot, bool upval);
-#endif /* __CHUNK_H_ */
+#endif /* UCODE_CHUNK_H */
diff --git a/include/ucode/compiler.h b/include/ucode/compiler.h
index ffe7caf..a85b48b 100644
--- a/include/ucode/compiler.h
+++ b/include/ucode/compiler.h
@@ -14,18 +14,13 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __COMPILER_H_
-#define __COMPILER_H_
+#ifndef UCODE_COMPILER_H
+#define UCODE_COMPILER_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
-
-#ifdef JSONC
- #include <json.h>
-#else
- #include <json-c/json.h>
-#endif
+#include <json-c/json.h>
#include "source.h"
#include "lexer.h"
@@ -138,4 +133,4 @@ uc_program_t *uc_compile(uc_parse_config_t *config, uc_source_t *source, char **
if (compiler->exprstack) \
compiler->exprstack = compiler->exprstack->parent
-#endif /* __COMPILER_H_ */
+#endif /* UCODE_COMPILER_H */
diff --git a/include/ucode/lexer.h b/include/ucode/lexer.h
index aa5d78b..134f5ef 100644
--- a/include/ucode/lexer.h
+++ b/include/ucode/lexer.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __LEXER_H_
-#define __LEXER_H_
+#ifndef UCODE_LEXER_H
+#define UCODE_LEXER_H
#include "source.h"
#include "types.h"
@@ -183,4 +183,4 @@ bool utf8enc(char **out, int *rem, int code);
const char *
uc_tokenname(unsigned type);
-#endif /* __LEXER_H_ */
+#endif /* UCODE_LEXER_H */
diff --git a/include/ucode/lib.h b/include/ucode/lib.h
index 4b70635..095956a 100644
--- a/include/ucode/lib.h
+++ b/include/ucode/lib.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __LIB_H_
-#define __LIB_H_
+#ifndef UCODE_LIB_H
+#define UCODE_LIB_H
#include "vm.h"
#include "lexer.h"
@@ -103,4 +103,4 @@ _uc_function_list_register(uc_value_t *object, const uc_function_list_t *list, s
#define uc_function_list_register(object, functions) \
_uc_function_list_register(object, functions, ARRAY_SIZE(functions))
-#endif /* __LIB_H_ */
+#endif /* UCODE_LIB_H */
diff --git a/include/ucode/module.h b/include/ucode/module.h
index 1814b3a..5e68436 100644
--- a/include/ucode/module.h
+++ b/include/ucode/module.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __MODULE_H_
-#define __MODULE_H_
+#ifndef UCODE_MODULE_H
+#define UCODE_MODULE_H
#include "lib.h"
#include "vm.h"
@@ -30,4 +30,4 @@ void uc_module_entry(uc_vm_t *vm, uc_value_t *scope)
uc_module_init(vm, scope);
}
-#endif /* __MODULE_H_ */
+#endif /* UCODE_MODULE_H */
diff --git a/include/ucode/program.h b/include/ucode/program.h
index 2b2817b..e8b96ed 100644
--- a/include/ucode/program.h
+++ b/include/ucode/program.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __PROGRAM_H_
-#define __PROGRAM_H_
+#ifndef UCODE_PROGRAM_H
+#define UCODE_PROGRAM_H
#include "types.h"
@@ -61,4 +61,4 @@ uc_program_t *uc_program_load(uc_source_t *, char **);
uc_function_t *uc_program_entry(uc_program_t *);
-#endif /* __PROGRAM_H_ */
+#endif /* UCODE_PROGRAM_H */
diff --git a/include/ucode/source.h b/include/ucode/source.h
index e0339a4..6f9a8d7 100644
--- a/include/ucode/source.h
+++ b/include/ucode/source.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __SOURCE_H_
-#define __SOURCE_H_
+#ifndef UCODE_SOURCE_H
+#define UCODE_SOURCE_H
#include <stdint.h>
#include <stddef.h>
@@ -54,4 +54,4 @@ void uc_source_line_update(uc_source_t *source, size_t off);
void uc_source_runpath_set(uc_source_t *source, const char *runpath);
-#endif /* __SOURCE_H_ */
+#endif /* UCODE_SOURCE_H */
diff --git a/include/ucode/types.h b/include/ucode/types.h
index 8e2030a..d1e01a1 100644
--- a/include/ucode/types.h
+++ b/include/ucode/types.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __TYPES_H_
-#define __TYPES_H_
+#ifndef UCODE_TYPES_H
+#define UCODE_TYPES_H
#include <stdbool.h>
#include <stdint.h>
@@ -501,4 +501,4 @@ void ucv_gc(uc_vm_t *);
void ucv_freeall(uc_vm_t *);
-#endif /* __TYPES_H_ */
+#endif /* UCODE_TYPES_H */
diff --git a/include/ucode/util.h b/include/ucode/util.h
index 1ad13bd..3203499 100644
--- a/include/ucode/util.h
+++ b/include/ucode/util.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __UTIL_H_
-#define __UTIL_H_
+#ifndef UCODE_UTIL_H
+#define UCODE_UTIL_H
#include <stdio.h>
#include <stddef.h>
@@ -159,4 +159,4 @@ static inline struct printbuf *xprintbuf_new(void) {
return pb;
}
-#endif /* __UTIL_H_ */
+#endif /* UCODE_UTIL_H */
diff --git a/include/ucode/vallist.h b/include/ucode/vallist.h
index f3f1b06..53750bd 100644
--- a/include/ucode/vallist.h
+++ b/include/ucode/vallist.h
@@ -14,20 +14,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __VALUE_H_
-#define __VALUE_H_
+#ifndef UCODE_VALUE_H
+#define UCODE_VALUE_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
-
-#ifdef JSONC
- #include <json.h>
-#else
- #include <json-c/json.h>
-#endif
-
#include <stdio.h>
+#include <json-c/json.h>
#include "types.h"
@@ -52,4 +46,4 @@ ssize_t uc_vallist_add(uc_value_list_t *list, uc_value_t *value);
uc_value_type_t uc_vallist_type(uc_value_list_t *list, size_t idx);
uc_value_t *uc_vallist_get(uc_value_list_t *list, size_t idx);
-#endif /* __VALUE_H_ */
+#endif /* UCODE_VALUE_H */
diff --git a/include/ucode/vm.h b/include/ucode/vm.h
index 24818a1..8377446 100644
--- a/include/ucode/vm.h
+++ b/include/ucode/vm.h
@@ -14,8 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef __VM_H_
-#define __VM_H_
+#ifndef UCODE_VM_H
+#define UCODE_VM_H
#include <stdbool.h>
#include <stdarg.h>
@@ -144,4 +144,4 @@ uc_vm_raise_exception(uc_vm_t *vm, uc_exception_type_t type, const char *fmt, ..
uc_vm_status_t uc_vm_execute(uc_vm_t *vm, uc_program_t *fn, uc_value_t **retval);
uc_value_t *uc_vm_invoke(uc_vm_t *vm, const char *fname, size_t nargs, ...);
-#endif /* __VM_H_ */
+#endif /* UCODE_VM_H */