From: Brendan Hansen Date: Mon, 4 Jan 2021 01:45:14 +0000 (-0600) Subject: working towards Windows compilation X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5275a75403917073d98b0af828b336e2b1890369;p=onyx.git working towards Windows compilation --- diff --git a/bin/onyx b/bin/onyx index a49b7e57..8e103c11 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..69b090ae --- /dev/null +++ b/build.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +C_FILES="onyx onyxbuiltins onyxchecker onyxclone onyxdoc onyxentities onyxerrors onyxlex onyxparser onyxsempass onyxsymres onyxtypes onyxutils onyxwasm" +TARGET='./bin/onyx' +CC='gcc' +FLAGS='-O3 -I./include' +BUILD_DIR='./build' + +mkdir -p '$BUILD_DIR' + +for file in $C_FILES ; do + echo "Compiling $file.c" + $CC -o build/$file.o $FLAGS -c src/$file.c +done + +ALL_FILES="$(for file in $C_FILES ; do printf "$BUILD_DIR/%s.o " $file ; done)" +echo "Linking $TARGET" +$CC -o $TARGET $FLAGS $ALL_FILES + + +CORE_DIR='/usr/share/onyx' +sudo mkdir -p "$CORE_DIR" +echo "Installing core libs" +sudo cp -r ./core/ "$CORE_DIR" + + +# Otherwise the prompt ends on the same line +printf "\n" \ No newline at end of file diff --git a/include/bh.h b/include/bh.h index 1e39372e..60687e99 100644 --- a/include/bh.h +++ b/include/bh.h @@ -5,17 +5,21 @@ #define _LARGEFILE64_SOURCE #include -#include #include #include #include #include +#ifdef __unix__ + #include +#endif + #include #include #include // TODO: Replace with needed functions #include #include +#include //------------------------------------------------------------------------------------- // Better types @@ -421,7 +425,7 @@ isize bh_snprintf_va(char *str, isize n, char const *fmt, va_list va); #ifdef BH_DEBUG void* bh__debug_malloc(size_t size, const char* file, u64 line); -void* bh__debug_memalign(size_t alignment, size_t size, const char* file, u64 line); +i32 bh__debug_posix_memalign(void** ret, size_t alignment, size_t size, const char* file, u64 line); void bh__debug_free(void* ptr, const char* file, u64 line); void* bh__debug_realloc(void* ptr, size_t size, const char* file, u64 line); @@ -433,10 +437,10 @@ void* bh__debug_malloc(size_t size, const char* file, u64 line) { return p; } -void* bh__debug_memalign(size_t alignment, size_t size, const char* file, u64 line) { - void* p = memalign(alignment, size); - bh_printf("[DEBUG] %p = memalign(%d, %d) at %s:%d\n", p, alignment, size, file, line); - return p; +i32 bh__debug_posix_memalign(void** ret, size_t alignment, size_t size, const char* file, u64 line) { + i32 success = posix_memalign(ret, alignment, size); + bh_printf("[DEBUG] %p = posix_memalign(%d, %d) at %s:%d\n", *ret, alignment, size, file, line); + return success; } void bh__debug_free(void* ptr, const char* file, u64 line) { @@ -452,10 +456,10 @@ void* bh__debug_realloc(void* ptr, size_t size, const char* file, u64 line) { #endif -#define malloc(size) (bh__debug_malloc(size, __FILE__, __LINE__)) -#define memalign(alignment, size) (bh__debug_memalign(alignment, size, __FILE__, __LINE__)) -#define free(ptr) (bh__debug_free(ptr, __FILE__, __LINE__)) -#define realloc(ptr, size) (bh__debug_realloc(ptr, size, __FILE__, __LINE__)) +#define malloc(size) (bh__debug_malloc(size, __FILE__, __LINE__)) +#define posix_memalign(ret, alignment, size) (bh__debug_posix_memalign(ret, alignment, size, __FILE__, __LINE__)) +#define free(ptr) (bh__debug_free(ptr, __FILE__, __LINE__)) +#define realloc(ptr, size) (bh__debug_realloc(ptr, size, __FILE__, __LINE__)) #endif @@ -876,7 +880,7 @@ BH_ALLOCATOR_PROC(bh_heap_allocator_proc) { switch (action) { case bh_allocator_action_alloc: { - retval = memalign(alignment, size); + i32 success = posix_memalign(&retval, alignment, size); if (flags & bh_allocator_flag_clear && retval != NULL) { memset(retval, 0, size); @@ -927,7 +931,7 @@ BH_ALLOCATOR_PROC(bh_managed_heap_allocator_proc) { switch (action) { case bh_allocator_action_alloc: { - retval = memalign(alignment, size); + i32 success = posix_memalign(&retval, alignment, size); if (flags & bh_allocator_flag_clear && retval != NULL) { memset(retval, 0, size); @@ -1050,7 +1054,7 @@ void bh_scratch_init(bh_scratch* scratch, bh_allocator backing, isize scratch_si scratch->backing = backing; scratch->memory = memory; scratch->curr = memory; - scratch->end = memory + scratch_size; + scratch->end = bh_pointer_add(memory, scratch_size); } void bh_scratch_free(bh_scratch* scratch) { @@ -1074,12 +1078,12 @@ BH_ALLOCATOR_PROC(bh_scratch_allocator_proc) { switch (action) { case bh_allocator_action_alloc: { - if (size > scratch->end - scratch->memory) { + if (size > ((u8 *) scratch->end) - ((u8 *) scratch->memory)) { return NULL; } retval = scratch->curr; - scratch->curr += size; + scratch->curr = bh_pointer_add(scratch->curr, size); if (scratch->curr >= scratch->end) { scratch->curr = scratch->memory; @@ -1090,12 +1094,12 @@ BH_ALLOCATOR_PROC(bh_scratch_allocator_proc) { case bh_allocator_action_free: break; case bh_allocator_action_resize: { - if (size > scratch->end - scratch->memory) { + if (size > ((u8 *) scratch->end) - ((u8 *) scratch->memory)) { return NULL; } retval = scratch->curr; - scratch->curr += size; + scratch->curr = bh_pointer_add(scratch->curr, size); if (scratch->curr >= scratch->end) { scratch->curr = scratch->memory; diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 5c319b36..315ab55b 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -426,8 +426,8 @@ typedef enum VarArgKind { AstKind kind; \ u32 flags; \ OnyxToken *token; \ - AstNode *next; -struct AstNode { AstNode_base }; + AstNode *next +struct AstNode { AstNode_base; }; // NOTE: 'type_node' is filled out by the parser. // For a type such as '^^i32', the tree would look something like @@ -443,8 +443,8 @@ struct AstNode { AstNode_base }; #define AstTyped_base \ AstNode_base; \ AstType *type_node; \ - Type *type; -struct AstTyped { AstTyped_base }; + Type *type +struct AstTyped { AstTyped_base; }; // Expression Nodes struct AstBinaryOp { AstTyped_base; BinaryOp operation; AstTyped *left, *right; }; @@ -605,8 +605,8 @@ struct AstSwitch { AstKind kind; \ u32 flags; \ OnyxToken* token; \ - char* name; -struct AstType { AstType_base }; + char* name +struct AstType { AstType_base; }; struct AstBasicType { AstType_base; Type* type; }; struct AstPointerType { AstType_base; AstType* elem; }; diff --git a/src/onyx.c b/src/onyx.c index 1b015aa1..a300ba85 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -16,6 +16,8 @@ #ifndef CORE_INSTALLATION #ifdef __unix__ #define CORE_INSTALLATION "/usr/share/onyx" + #elif _WIN32 + #define CORE_INSTALLATION "C:\\Program Files\\Onyx" #endif #endif @@ -224,9 +226,15 @@ static char* lookup_included_file(CompilerState* cs, char* filename) { bh_snprintf(fn, 128, "%s", filename); } +#ifdef __unix__ + #define DIR_SEPARATOR '/' +#elif _WIN32 + #define DIR_SEPARATOR '\\' +#endif + bh_arr_each(const char *, folder, cs->options->included_folders) { - if ((*folder)[strlen(*folder) - 1] != '/') - bh_snprintf(path, 256, "%s/%s", *folder, fn); + if ((*folder)[strlen(*folder) - 1] != DIR_SEPARATOR) + bh_snprintf(path, 256, "%s%c%s", *folder, DIR_SEPARATOR, fn); else bh_snprintf(path, 256, "%s%s", *folder, fn); @@ -234,6 +242,8 @@ static char* lookup_included_file(CompilerState* cs, char* filename) { } return fn; + +#undef DIR_SEPARATOR } static ParseResults parse_source_file(CompilerState* compiler_state, bh_file_contents* file_contents) {