diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-26 21:28:19 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-26 21:28:19 -0500 |
commit | 93337b93661a3298d2c915fc38bf9348bcd99207 (patch) | |
tree | 4dd6154a2b155f04e2c87cb46beb7b32c1ee166b | |
parent | 4aeae5a6d0ecec5558b69492e489535e41b49649 (diff) |
removed unneeded functions
-rw-r--r-- | blockarr.c | 76 | ||||
-rw-r--r-- | data_structures.c | 4 | ||||
-rw-r--r-- | eval.c | 21 | ||||
-rw-r--r-- | identifiers.c | 22 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | toc.c | 1 | ||||
-rw-r--r-- | types.c | 2 | ||||
-rw-r--r-- | types.h | 6 |
8 files changed, 4 insertions, 129 deletions
diff --git a/blockarr.c b/blockarr.c deleted file mode 100644 index f5e82e8..0000000 --- a/blockarr.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright (C) 2019, 2020 Leo Tenenbaum. - This file is part of toc. toc is distributed under version 3 of the GNU General Public License, without any warranty whatsoever. - You should have received a copy of the GNU General Public License along with toc. If not, see <https://www.gnu.org/licenses/>. -*/ -/* -A block array is an array of blocks of T. -They ensure that pointers to values in the array are not invalidated -when something is added to the array. -*/ - -/* -Note: the block size must be a power of 2, to use right shifting instead of division -(for optimization)! -*/ -static void block_arr_create(BlockArr *arr, int lg_block_sz, size_t item_sz) { - arr->blocks = NULL; - arr->item_sz = item_sz; - arr->lg_block_sz = lg_block_sz; -} - -static void *block_arr_add(BlockArr *arr) { - ArrBlock *last_block; - last_block = arr_last(arr->blocks); - if (arr->blocks == NULL || - (unsigned long)last_block->n >= (1UL << arr->lg_block_sz)) { - ArrBlock *block; - /* no blocks yet / ran out of blocks*/ - block = arr_add(&arr->blocks); - block->n = 1; - size_t bytes = arr->item_sz << arr->lg_block_sz; - block->data = err_malloc(bytes); - return block->data; - } else { - return (char *)last_block->data + arr->item_sz * (last_block->n++); - } -} - -static U64 block_arr_len(BlockArr *arr) { - ArrBlock *last_block; - if (!arr->blocks) return 0; - last_block = arr->blocks + (arr_len(arr->blocks) - 1); - U64 len = (arr_len(arr->blocks)-1) * (((U64)1)<<arr->lg_block_sz); - len += last_block->n; - return len; -} - -static inline void *block_arr_get(BlockArr *arr, size_t index) { - size_t block_index = index >> arr->lg_block_sz; - ArrBlock *block = &arr->blocks[block_index]; - return (char*)block->data + arr->item_sz * index; -} - -static void block_arr_free(BlockArr *arr) { - arr_foreach(arr->blocks, ArrBlock, block) { - free(block->data); - } - arr_clear(&arr->blocks); -} - -#ifdef TOC_DEBUG -static void block_arr_test(void) { - BlockArr a; - int *ps[100]; - block_arr_create(&a, 3, sizeof(int)); - for (int i = 0; i < 100; ++i) { - int *p = block_arr_add(&a); - *p = i; - ps[i] = p; - } - for (int i = 0; i < 100; ++i) { - assert(*ps[i] == i); - } - block_arr_free(&a); -} -#endif diff --git a/data_structures.c b/data_structures.c index 1aac916..c736662 100644 --- a/data_structures.c +++ b/data_structures.c @@ -219,7 +219,7 @@ You shouldn't rely on this, though, e.g. by doing #define arr_remove_lasta(arr, a) arr_remove_lasta_((void **)(arr), sizeof **(arr), (a)) #define arr_copya(out, in, a) do { assert(sizeof *(in) == sizeof **(out)); arr_copya_((void **)(out), (in), sizeof **(out), (a)); } while(0) -#ifdef TOC_DEBUG +#ifdef RUN_TESTS static void arr_test(void) { int *foos = NULL; for (int i = 0; i < 10; ++i) { @@ -356,7 +356,7 @@ static inline void *str_hash_table_get(StrHashTable *t, const char *str, size_t return slot->data; } -#ifdef TOC_DEBUG +#ifdef RUN_TESTS static void str_hash_table_test(void) { StrHashTable t; str_hash_table_create(&t, sizeof(int), NULL); @@ -962,27 +962,6 @@ static Value val_zero(Type *t) { return val; } -static Value val_alloc(Allocator *a, Type *t) { - Value val; - switch (t->kind) { - case TYPE_STRUCT: - val.struc = allocr_malloc(a, compiler_sizeof(t)); - break; - case TYPE_ARR: - val.arr = allocr_calloc(a, t->arr.n, compiler_sizeof(t->arr.of)); - break; -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wsometimes-uninitialized" -#endif - default: break; - } - return val; -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -} - static bool val_is_nonnegative(Value *v, Type *t) { switch (t->builtin) { case BUILTIN_BOOL: assert(0); return false; diff --git a/identifiers.c b/identifiers.c index 187d723..cd4364e 100644 --- a/identifiers.c +++ b/identifiers.c @@ -46,11 +46,6 @@ static size_t ident_str_len(char *s) { return ident_str_len_advance(&s); } -static U64 ident_hash(char **s) { - char *original = *s; - return str_hash(original, ident_str_len_advance(s)); -} - /* are these strings equal, up to the first non-ident character? */ static bool ident_str_eq_str(const char *s, const char *t) { while (is_ident(*s) && is_ident(*t)) { @@ -64,21 +59,6 @@ static inline bool ident_eq_str(Identifier i, const char *s) { return ident_str_eq_str(i->str, s); } - - -static IdentSlot **ident_slots_insert(IdentSlot **slots, char *s, size_t i) { - IdentSlot **slot; - size_t nslots = arr_len(slots); - while (1) { - slot = &slots[i]; - if (!*slot) break; - if (s && ident_eq_str(*slot, s)) - break; - i = (i+1) % nslots; - } - return slot; -} - /* moves s to the char after the identifier */ /* inserts if does not exist. reads until non-ident char is found. */ /* advances past identifier */ @@ -200,7 +180,7 @@ static inline Block *ident_scope(Identifier i) { return i->idents->scope; } -#ifdef TOC_DEBUG +#ifdef RUN_TESTS static void idents_test(void) { Identifiers ids; char b[] = "foo_variable bar"; @@ -8,7 +8,6 @@ /* TODO: -compile without Wno-unused-function run stuff at compile time without assigning it to a constant better #foreign system- something like f := #foreign fn (int,float, #C int); --- @@ -125,7 +125,6 @@ static inline bool type_is_slicechar(Type *t) { #include "data_structures.c" #include "location.c" #include "err.c" -#include "blockarr.c" static size_t compiler_alignof(Type *t); static size_t compiler_sizeof(Type *t); #include "instance_table.c" @@ -110,7 +110,7 @@ static size_t compiler_alignof(Type *t) { assert(t->flags & TYPE_IS_RESOLVED); switch (t->kind) { case TYPE_BUILTIN: - return compiler_sizeof_builtin(t->builtin); + return compiler_alignof_builtin(t->builtin); case TYPE_VOID: return 1; case TYPE_FN: @@ -132,12 +132,6 @@ typedef struct ArrBlock { size_t n; /* number of things in this block so far */ } ArrBlock; -typedef struct BlockArr { - size_t item_sz; - int lg_block_sz; - ArrBlock *blocks; -} BlockArr; - /* initialize to 0 */ typedef struct HashTable { void *data; |