From: Brendan Hansen Date: Wed, 16 Sep 2020 01:12:24 +0000 (-0500) Subject: switched to using TCC as the compiler compiler X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b68abf9d70cc5135a6ba90fa6b9704b1aeb0e0d8;p=onyx.git switched to using TCC as the compiler compiler --- diff --git a/CHANGELOG b/CHANGELOG index a506ae97..9df5ac0e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,10 +3,12 @@ Release v0.0.3 Additions: * Added polymorphic structs * Added polymorphic structs to polymorphic pattern matching +* Added I32Map polymorphic structure to core library Removals: Changes: +* Switched to using TCC as the primary compiler, while maintaining support for GCC. Bug fixes: * Fixed error message index for struct literal member type mismatch. diff --git a/Makefile b/Makefile index 4778e4be..b0dbe870 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -RELEASE=0 +RELEASE=1 OBJ_FILES=\ build/onyxlex.o \ @@ -15,7 +15,7 @@ OBJ_FILES=\ build/onyxdoc.o \ build/onyx.o -CC=gcc +CC=tcc INCLUDES=-I./include LIBS= TARGET=./onyx diff --git a/include/bh.h b/include/bh.h index c37366d9..9878f698 100644 --- a/include/bh.h +++ b/include/bh.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -54,41 +55,13 @@ typedef double f64; //------------------------------------------------------------------------------------- // Better character functions //------------------------------------------------------------------------------------- -inline b32 char_is_alpha(const char a) { - return ('a' <= a && a <= 'z') || ('A' <= a && a <= 'Z'); -} - -inline char charset_contains(const char* charset, char ch) { - while (*charset) { - if (*charset == ch) return ch; - charset++; - } - - return 0; -} - -inline b32 char_is_num(const char a) { - return ('0' <= a && a <= '9'); -} - -inline b32 char_is_alphanum(const char a) { - return char_is_alpha(a) || char_is_num(a); -} - -inline b32 char_is_whitespace(const char a) { - return charset_contains(" \t\r\n", a); -} - -inline b32 char_in_range(const char lo, const char hi, const char a) { - return lo <= a <= hi; -} - -inline i64 chars_match(char* ptr1, char* ptr2) { - i64 len = 0; - while (*ptr2 != '\0' && *ptr1 == *ptr2) ptr1++, ptr2++, len++; - return *ptr2 == '\0' ? len : 0; -} - +b32 char_is_alpha(const char a); +b32 char_is_num(const char a); +b32 char_is_alphanum(const char a); +char charset_contains(const char* charset, char ch); +b32 char_is_whitespace(const char a); +b32 char_in_range(const char lo, const char hi, const char a); +i64 chars_match(char* ptr1, char* ptr2); @@ -447,7 +420,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_aligned_alloc(size_t alignment, size_t size, const char* file, u64 line); +void* bh__debug_memalign(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); @@ -459,9 +432,9 @@ void* bh__debug_malloc(size_t size, const char* file, u64 line) { return p; } -void* bh__debug_aligned_alloc(size_t alignment, size_t size, const char* file, u64 line) { - void* p = aligned_alloc(alignment, size); - bh_printf("[DEBUG] %p = aligned_alloc(%d, %d) at %s:%d\n", p, alignment, size, file, line); +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; } @@ -479,7 +452,7 @@ 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 aligned_alloc(alignment, size) (bh__debug_aligned_alloc(alignment, 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__)) @@ -815,14 +788,41 @@ BH_ALLOCATOR_PROC(bh_managed_heap_allocator_proc); //------------------------------------------------------------------------------------- // CHAR FUNCTIONS //------------------------------------------------------------------------------------- -extern inline b32 char_is_alpha(const char a); -extern inline b32 char_is_num(const char a); -extern inline b32 char_is_alphanum(const char a); -extern inline char charset_contains(const char* charset, char ch); -extern inline b32 char_is_whitespace(const char a); -extern inline b32 char_in_range(const char lo, const char hi, const char a); -extern inline i64 chars_match(char* ptr1, char* ptr2); +b32 char_is_alpha(const char a) { + return ('a' <= a && a <= 'z') || ('A' <= a && a <= 'Z'); +} + +char charset_contains(const char* charset, char ch) { + while (*charset) { + if (*charset == ch) return ch; + charset++; + } + + return 0; +} + +b32 char_is_num(const char a) { + return ('0' <= a && a <= '9'); +} + +b32 char_is_alphanum(const char a) { + return char_is_alpha(a) || char_is_num(a); +} + +b32 char_is_whitespace(const char a) { + return charset_contains(" \t\r\n", a); +} + +b32 char_in_range(const char lo, const char hi, const char a) { + return lo <= a <= hi; +} + +i64 chars_match(char* ptr1, char* ptr2) { + i64 len = 0; + while (*ptr2 != '\0' && *ptr1 == *ptr2) ptr1++, ptr2++, len++; + return *ptr2 == '\0' ? len : 0; +} @@ -869,7 +869,7 @@ BH_ALLOCATOR_PROC(bh_heap_allocator_proc) { switch (action) { case bh_allocator_action_alloc: { - retval = aligned_alloc(alignment, size); + retval = memalign(alignment, size); if (flags & bh_allocator_flag_clear && retval != NULL) { memset(retval, 0, size); @@ -920,7 +920,7 @@ BH_ALLOCATOR_PROC(bh_managed_heap_allocator_proc) { switch (action) { case bh_allocator_action_alloc: { - retval = aligned_alloc(alignment, size); + retval = memalign(alignment, size); if (flags & bh_allocator_flag_clear && retval != NULL) { memset(retval, 0, size); diff --git a/onyx b/onyx index 5c8bea0a..d5bdd4ef 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_struct.onyx b/progs/poly_struct.onyx index 5941a5bf..f2781ccc 100644 --- a/progs/poly_struct.onyx +++ b/progs/poly_struct.onyx @@ -7,6 +7,7 @@ use package core main :: proc (args: [] cstring) { imap : I32Map(^string); i32map_init(^imap); + defer i32map_free(^imap); hello := "Hello "; world := "World!"; diff --git a/src/onyxparser.c b/src/onyxparser.c index 66ec3cb7..1e2cd9fc 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -442,7 +442,7 @@ static AstTyped* parse_factor(OnyxParser* parser) { AstStrLit* filename = make_node(AstStrLit, Ast_Kind_StrLit); filename->token = str_token; - filename->addr = 0; + filename->addr = 0; add_node_to_process(parser, (AstNode *) filename); retval = (AstTyped *) filename;