aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtins/array.c6
-rw-r--r--builtins/array.h2
-rw-r--r--builtins/datatypes.h2
-rw-r--r--builtins/table.c82
-rw-r--r--builtins/table.h62
-rw-r--r--builtins/text.c6
-rw-r--r--builtins/text.h2
-rw-r--r--builtins/types.h4
-rw-r--r--compile.c36
-rw-r--r--environment.c14
-rw-r--r--environment.h8
-rw-r--r--parse.c2
-rw-r--r--repl.c8
-rw-r--r--tomo.c12
-rw-r--r--typecheck.c2
-rw-r--r--types.c12
16 files changed, 130 insertions, 130 deletions
diff --git a/builtins/array.c b/builtins/array.c
index 6b191bc8..32aeab23 100644
--- a/builtins/array.c
+++ b/builtins/array.c
@@ -278,10 +278,10 @@ public void *Array$random(Array_t arr)
return arr.data + arr.stride*index;
}
-public table_t Array$counts(Array_t arr, const TypeInfo *type)
+public Table_t Array$counts(Array_t arr, const TypeInfo *type)
{
- table_t counts = {};
- const TypeInfo count_type = {.size=sizeof(table_t), .align=__alignof__(table_t),
+ Table_t counts = {};
+ const TypeInfo count_type = {.size=sizeof(Table_t), .align=__alignof__(Table_t),
.tag=TableInfo, .TableInfo.key=type->ArrayInfo.item, .TableInfo.value=&$Int};
for (int64_t i = 0; i < arr.length; i++) {
void *key = arr.data + i*arr.stride;
diff --git a/builtins/array.h b/builtins/array.h
index ce2fb563..98e949c8 100644
--- a/builtins/array.h
+++ b/builtins/array.h
@@ -77,7 +77,7 @@ Array_t Array$shuffled(Array_t arr, int64_t padded_item_size);
void *Array$random(Array_t arr);
#define Array$random_value(arr, t) ({ Array_t _arr = arr; if (_arr.length == 0) fail("Cannot get a random value from an empty array!"); *(t*)Array$random(_arr); })
Array_t Array$sample(Array_t arr, Int_t n, Array_t weights, int64_t padded_item_size);
-table_t Array$counts(Array_t arr, const TypeInfo *type);
+Table_t Array$counts(Array_t arr, const TypeInfo *type);
void Array$clear(Array_t *array);
void Array$compact(Array_t *arr, int64_t padded_item_size);
bool Array$has(Array_t array, void *item, const TypeInfo *type);
diff --git a/builtins/datatypes.h b/builtins/datatypes.h
index fa8a52fc..f8852c33 100644
--- a/builtins/datatypes.h
+++ b/builtins/datatypes.h
@@ -54,7 +54,7 @@ typedef struct table_s {
Array_t entries;
bucket_info_t *bucket_info;
struct table_s *fallback;
-} table_t;
+} Table_t;
typedef struct {
void *fn, *userdata;
diff --git a/builtins/table.c b/builtins/table.c
index 75b4027d..b0b95af7 100644
--- a/builtins/table.c
+++ b/builtins/table.c
@@ -53,8 +53,8 @@ static const TypeInfo MemoryPointer = {
};
const TypeInfo CStrToVoidStarTable = {
- .size=sizeof(table_t),
- .align=__alignof__(table_t),
+ .size=sizeof(Table_t),
+ .align=__alignof__(Table_t),
.tag=TableInfo,
.TableInfo={.key=&$CString, .value=&MemoryPointer},
};
@@ -83,7 +83,7 @@ static inline size_t value_offset(const TypeInfo *info)
return offset;
}
-static inline void hshow(const table_t *t)
+static inline void hshow(const Table_t *t)
{
hdebug("{");
for (uint32_t i = 0; t->bucket_info && i < t->bucket_info->count; i++) {
@@ -96,7 +96,7 @@ static inline void hshow(const table_t *t)
hdebug("}\n");
}
-static void maybe_copy_on_write(table_t *t, const TypeInfo *type)
+static void maybe_copy_on_write(Table_t *t, const TypeInfo *type)
{
if (t->entries.data_refcount != 0)
Array$compact(&t->entries, entry_size(type));
@@ -109,7 +109,7 @@ static void maybe_copy_on_write(table_t *t, const TypeInfo *type)
}
// Return address of value or NULL
-public void *Table$get_raw(table_t t, const void *key, const TypeInfo *type)
+public void *Table$get_raw(Table_t t, const void *key, const TypeInfo *type)
{
assert(type->tag == TableInfo);
if (!key || !t.bucket_info) return NULL;
@@ -131,17 +131,17 @@ public void *Table$get_raw(table_t t, const void *key, const TypeInfo *type)
return NULL;
}
-public void *Table$get(table_t t, const void *key, const TypeInfo *type)
+public void *Table$get(Table_t t, const void *key, const TypeInfo *type)
{
assert(type->tag == TableInfo);
- for (const table_t *iter = &t; iter; iter = iter->fallback) {
+ for (const Table_t *iter = &t; iter; iter = iter->fallback) {
void *ret = Table$get_raw(*iter, key, type);
if (ret) return ret;
}
return NULL;
}
-static void Table$set_bucket(table_t *t, const void *entry, int32_t index, const TypeInfo *type)
+static void Table$set_bucket(Table_t *t, const void *entry, int32_t index, const TypeInfo *type)
{
assert(t->bucket_info);
hshow(t);
@@ -195,7 +195,7 @@ static void Table$set_bucket(table_t *t, const void *entry, int32_t index, const
hshow(t);
}
-static void hashmap_resize_buckets(table_t *t, uint32_t new_capacity, const TypeInfo *type)
+static void hashmap_resize_buckets(Table_t *t, uint32_t new_capacity, const TypeInfo *type)
{
if (__builtin_expect(new_capacity > TABLE_MAX_BUCKETS, 0))
fail("Table has exceeded the maximum table size (2^31) and cannot grow further!");
@@ -217,7 +217,7 @@ static void hashmap_resize_buckets(table_t *t, uint32_t new_capacity, const Type
}
// Return address of value
-public void *Table$reserve(table_t *t, const void *key, const void *value, const TypeInfo *type)
+public void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo *type)
{
assert(type->tag == TableInfo);
if (!t || !key) return NULL;
@@ -253,7 +253,7 @@ public void *Table$reserve(table_t *t, const void *key, const void *value, const
}
if (!value && value_size > 0) {
- for (table_t *iter = t->fallback; iter; iter = iter->fallback) {
+ for (Table_t *iter = t->fallback; iter; iter = iter->fallback) {
value = Table$get_raw(*iter, key, type);
if (value) break;
}
@@ -276,13 +276,13 @@ public void *Table$reserve(table_t *t, const void *key, const void *value, const
return entry + value_offset(type);
}
-public void Table$set(table_t *t, const void *key, const void *value, const TypeInfo *type)
+public void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo *type)
{
assert(type->tag == TableInfo);
(void)Table$reserve(t, key, value, type);
}
-public void Table$remove(table_t *t, const void *key, const TypeInfo *type)
+public void Table$remove(Table_t *t, const void *key, const TypeInfo *type)
{
assert(type->tag == TableInfo);
if (!t || Table$length(*t) == 0) return;
@@ -374,26 +374,26 @@ public void Table$remove(table_t *t, const void *key, const TypeInfo *type)
hshow(t);
}
-public void *Table$entry(table_t t, int64_t n)
+public void *Table$entry(Table_t t, int64_t n)
{
if (n < 1 || n > Table$length(t))
return NULL;
return GET_ENTRY(t, n-1);
}
-public void Table$clear(table_t *t)
+public void Table$clear(Table_t *t)
{
- memset(t, 0, sizeof(table_t));
+ memset(t, 0, sizeof(Table_t));
}
-public table_t Table$sorted(table_t t, const TypeInfo *type)
+public Table_t Table$sorted(Table_t t, const TypeInfo *type)
{
closure_t cmp = (closure_t){.fn=generic_compare, .userdata=(void*)type->TableInfo.key};
Array_t entries = Array$sorted(t.entries, cmp, entry_size(type));
return Table$from_entries(entries, type);
}
-public bool Table$equal(const table_t *x, const table_t *y, const TypeInfo *type)
+public bool Table$equal(const Table_t *x, const Table_t *y, const TypeInfo *type)
{
if (x == y) return true;
@@ -407,7 +407,7 @@ public bool Table$equal(const table_t *x, const table_t *y, const TypeInfo *type
return (Table$compare(x, y, type) == 0);
}
-public int32_t Table$compare(const table_t *x, const table_t *y, const TypeInfo *type)
+public int32_t Table$compare(const Table_t *x, const Table_t *y, const TypeInfo *type)
{
if (x == y) return 0;
@@ -438,7 +438,7 @@ public int32_t Table$compare(const table_t *x, const table_t *y, const TypeInfo
return 0;
}
-public uint32_t Table$hash(const table_t *t, const TypeInfo *type)
+public uint32_t Table$hash(const Table_t *t, const TypeInfo *type)
{
assert(type->tag == TableInfo);
// Table hashes are computed as:
@@ -455,7 +455,7 @@ public uint32_t Table$hash(const table_t *t, const TypeInfo *type)
return hash;
}
-public Text_t Table$as_text(const table_t *t, bool colorize, const TypeInfo *type)
+public Text_t Table$as_text(const Table_t *t, bool colorize, const TypeInfo *type)
{
assert(type->tag == TableInfo);
auto table = type->TableInfo;
@@ -494,13 +494,13 @@ public Text_t Table$as_text(const table_t *t, bool colorize, const TypeInfo *typ
return text;
}
-public table_t Table$from_entries(Array_t entries, const TypeInfo *type)
+public Table_t Table$from_entries(Array_t entries, const TypeInfo *type)
{
assert(type->tag == TableInfo);
if (entries.length == 0)
- return (table_t){};
+ return (Table_t){};
- table_t t = {};
+ Table_t t = {};
int64_t length = entries.length + entries.length / 4;
int64_t alloc_size = sizeof(bucket_info_t) + sizeof(bucket_t[length]);
t.bucket_info = GC_MALLOC_ATOMIC(alloc_size);
@@ -517,10 +517,10 @@ public table_t Table$from_entries(Array_t entries, const TypeInfo *type)
}
// Overlap is "set intersection" in formal terms
-public table_t Table$overlap(table_t a, table_t b, const TypeInfo *type)
+public Table_t Table$overlap(Table_t a, Table_t b, const TypeInfo *type)
{
// Return a table such that t[k]==a[k] for all k such that a:has(k), b:has(k), and a[k]==b[k]
- table_t result = {};
+ Table_t result = {};
const size_t offset = value_offset(type);
for (int64_t i = 0; i < Table$length(a); i++) {
void *key = GET_ENTRY(a, i);
@@ -531,7 +531,7 @@ public table_t Table$overlap(table_t a, table_t b, const TypeInfo *type)
}
if (a.fallback) {
- result.fallback = new(table_t);
+ result.fallback = new(Table_t);
*result.fallback = Table$overlap(*a.fallback, b, type);
}
@@ -539,10 +539,10 @@ public table_t Table$overlap(table_t a, table_t b, const TypeInfo *type)
}
// With is "set union" in formal terms
-public table_t Table$with(table_t a, table_t b, const TypeInfo *type)
+public Table_t Table$with(Table_t a, Table_t b, const TypeInfo *type)
{
// return a table such that t[k]==b[k] for all k such that b:has(k), and t[k]==a[k] for all k such that a:has(k) and not b:has(k)
- table_t result = {};
+ Table_t result = {};
const size_t offset = value_offset(type);
for (int64_t i = 0; i < Table$length(a); i++) {
void *key = GET_ENTRY(a, i);
@@ -554,7 +554,7 @@ public table_t Table$with(table_t a, table_t b, const TypeInfo *type)
}
if (a.fallback && b.fallback) {
- result.fallback = new(table_t);
+ result.fallback = new(Table_t);
*result.fallback = Table$with(*a.fallback, *b.fallback, type);
} else {
result.fallback = a.fallback ? a.fallback : b.fallback;
@@ -564,10 +564,10 @@ public table_t Table$with(table_t a, table_t b, const TypeInfo *type)
}
// Without is "set difference" in formal terms
-public table_t Table$without(table_t a, table_t b, const TypeInfo *type)
+public Table_t Table$without(Table_t a, Table_t b, const TypeInfo *type)
{
// Return a table such that t[k]==a[k] for all k such that not b:has(k) or b[k] != a[k]
- table_t result = {};
+ Table_t result = {};
const size_t offset = value_offset(type);
for (int64_t i = 0; i < Table$length(a); i++) {
void *key = GET_ENTRY(a, i);
@@ -578,14 +578,14 @@ public table_t Table$without(table_t a, table_t b, const TypeInfo *type)
}
if (a.fallback) {
- result.fallback = new(table_t);
+ result.fallback = new(Table_t);
*result.fallback = Table$without(*a.fallback, b, type);
}
return result;
}
-public bool Table$is_subset_of(table_t a, table_t b, bool strict, const TypeInfo *type)
+public bool Table$is_subset_of(Table_t a, Table_t b, bool strict, const TypeInfo *type)
{
if (a.entries.length > b.entries.length || (strict && a.entries.length == b.entries.length))
return false;
@@ -597,39 +597,39 @@ public bool Table$is_subset_of(table_t a, table_t b, bool strict, const TypeInfo
return true;
}
-public bool Table$is_superset_of(table_t a, table_t b, bool strict, const TypeInfo *type)
+public bool Table$is_superset_of(Table_t a, Table_t b, bool strict, const TypeInfo *type)
{
return Table$is_subset_of(b, a, strict, type);
}
-public void *Table$str_get(table_t t, const char *key)
+public void *Table$str_get(Table_t t, const char *key)
{
void **ret = Table$get(t, &key, &CStrToVoidStarTable);
return ret ? *ret : NULL;
}
-public void *Table$str_get_raw(table_t t, const char *key)
+public void *Table$str_get_raw(Table_t t, const char *key)
{
void **ret = Table$get_raw(t, &key, &CStrToVoidStarTable);
return ret ? *ret : NULL;
}
-public void *Table$str_reserve(table_t *t, const char *key, const void *value)
+public void *Table$str_reserve(Table_t *t, const char *key, const void *value)
{
return Table$reserve(t, &key, &value, &CStrToVoidStarTable);
}
-public void Table$str_set(table_t *t, const char *key, const void *value)
+public void Table$str_set(Table_t *t, const char *key, const void *value)
{
Table$set(t, &key, &value, &CStrToVoidStarTable);
}
-public void Table$str_remove(table_t *t, const char *key)
+public void Table$str_remove(Table_t *t, const char *key)
{
return Table$remove(t, &key, &CStrToVoidStarTable);
}
-public void *Table$str_entry(table_t t, int64_t n)
+public void *Table$str_entry(Table_t t, int64_t n)
{
return Table$entry(t, n);
}
diff --git a/builtins/table.h b/builtins/table.h
index def2c7b3..d7afb56f 100644
--- a/builtins/table.h
+++ b/builtins/table.h
@@ -13,7 +13,7 @@
#define Table(key_t, val_t, key_info, value_info, fb, N, ...) ({ \
struct { key_t k; val_t v; } ents[N] = {__VA_ARGS__}; \
- table_t table = Table$from_entries((Array_t){ \
+ Table_t table = Table$from_entries((Array_t){ \
.data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \
.length=sizeof(ents)/sizeof(ents[0]), \
.stride=(void*)&ents[1] - (void*)&ents[0], \
@@ -22,66 +22,66 @@
table; })
#define Set(item_t, item_info, N, ...) ({ \
item_t ents[N] = {__VA_ARGS__}; \
- table_t set = Table$from_entries((Array_t){ \
+ Table_t set = Table$from_entries((Array_t){ \
.data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \
.length=sizeof(ents)/sizeof(ents[0]), \
.stride=(void*)&ents[1] - (void*)&ents[0], \
}, $SetInfo(item_info)); \
set; })
-table_t Table$from_entries(Array_t entries, const TypeInfo *type);
-void *Table$get(table_t t, const void *key, const TypeInfo *type);
+Table_t Table$from_entries(Array_t entries, const TypeInfo *type);
+void *Table$get(Table_t t, const void *key, const TypeInfo *type);
#define Table$get_value_or_fail(table_expr, key_t, val_t, key_expr, info_expr, start, end) ({ \
- const table_t t = table_expr; key_t k = key_expr; const TypeInfo* info = info_expr; \
+ const Table_t t = table_expr; key_t k = key_expr; const TypeInfo* info = info_expr; \
val_t *v = Table$get(t, &k, info); \
if (__builtin_expect(v == NULL, 0)) \
fail_source(__SOURCE_FILE__, start, end, "The key %r is not in this table\n", generic_as_text(&k, no, info->TableInfo.key)); \
*v; })
#define Table$get_value_or_default(table_expr, key_t, val_t, key_expr, default_val, info_expr) ({ \
- const table_t t = table_expr; const key_t k = key_expr; \
+ const Table_t t = table_expr; const key_t k = key_expr; \
val_t *v = Table$get(t, &k, info_expr); \
v ? *v : default_val; })
#define Table$has_value(table_expr, key_expr, info_expr) ({ \
- const table_t t = table_expr; __typeof(key_expr) k = key_expr; \
+ const Table_t t = table_expr; __typeof(key_expr) k = key_expr; \
(Table$get(t, &k, info_expr) != NULL); })
-void *Table$get_raw(table_t t, const void *key, const TypeInfo *type);
-void *Table$entry(table_t t, int64_t n);
-void *Table$reserve(table_t *t, const void *key, const void *value, const TypeInfo *type);
-void Table$set(table_t *t, const void *key, const void *value, const TypeInfo *type);
+void *Table$get_raw(Table_t t, const void *key, const TypeInfo *type);
+void *Table$entry(Table_t t, int64_t n);
+void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo *type);
+void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo *type);
#define Table$set_value(t, key_expr, value_expr, type) ({ __typeof(key_expr) k = key_expr; __typeof(value_expr) v = value_expr; \
Table$set(t, &k, &v, type); })
#define Table$reserve_value(t, key_expr, type) ({ __typeof(key_expr) k = key_expr; Table$reserve(t, &k, NULL, type); })
#define Table$bump(t_expr, key_expr, amount_expr, type) ({ __typeof(key_expr) key = key_expr; \
- table_t *t = t_expr; \
+ Table_t *t = t_expr; \
__typeof(amount_expr) *val = Table$get_raw(*t, &key, type); \
if (val) *val += amount_expr; \
else { __typeof(amount_expr) init = amount_expr; Table$set(t, &key, &init, type); } (void)0; })
-void Table$remove(table_t *t, const void *key, const TypeInfo *type);
+void Table$remove(Table_t *t, const void *key, const TypeInfo *type);
#define Table$remove_value(t, key_expr, type) ({ __typeof(key_expr) k = key_expr; Table$remove(t, &k, type); })
-table_t Table$overlap(table_t a, table_t b, const TypeInfo *type);
-table_t Table$with(table_t a, table_t b, const TypeInfo *type);
-table_t Table$without(table_t a, table_t b, const TypeInfo *type);
-bool Table$is_subset_of(table_t a, table_t b, bool strict, const TypeInfo *type);
-bool Table$is_superset_of(table_t a, table_t b, bool strict, const TypeInfo *type);
+Table_t Table$overlap(Table_t a, Table_t b, const TypeInfo *type);
+Table_t Table$with(Table_t a, Table_t b, const TypeInfo *type);
+Table_t Table$without(Table_t a, Table_t b, const TypeInfo *type);
+bool Table$is_subset_of(Table_t a, Table_t b, bool strict, const TypeInfo *type);
+bool Table$is_superset_of(Table_t a, Table_t b, bool strict, const TypeInfo *type);
-void Table$clear(table_t *t);
-table_t Table$sorted(table_t t, const TypeInfo *type);
-void Table$mark_copy_on_write(table_t *t);
+void Table$clear(Table_t *t);
+Table_t Table$sorted(Table_t t, const TypeInfo *type);
+void Table$mark_copy_on_write(Table_t *t);
#define TABLE_INCREF(t) ({ ARRAY_INCREF((t).entries); if ((t).bucket_info) (t).bucket_info->data_refcount += ((t).bucket_info->data_refcount < TABLE_MAX_DATA_REFCOUNT); })
#define TABLE_COPY(t) ({ TABLE_INCREF(t); t; })
-int32_t Table$compare(const table_t *x, const table_t *y, const TypeInfo *type);
-bool Table$equal(const table_t *x, const table_t *y, const TypeInfo *type);
-uint32_t Table$hash(const table_t *t, const TypeInfo *type);
-Text_t Table$as_text(const table_t *t, bool colorize, const TypeInfo *type);
+int32_t Table$compare(const Table_t *x, const Table_t *y, const TypeInfo *type);
+bool Table$equal(const Table_t *x, const Table_t *y, const TypeInfo *type);
+uint32_t Table$hash(const Table_t *t, const TypeInfo *type);
+Text_t Table$as_text(const Table_t *t, bool colorize, const TypeInfo *type);
-void *Table$str_entry(table_t t, int64_t n);
-void *Table$str_get(table_t t, const char *key);
-void *Table$str_get_raw(table_t t, const char *key);
-void Table$str_set(table_t *t, const char *key, const void *value);
-void *Table$str_reserve(table_t *t, const char *key, const void *value);
-void Table$str_remove(table_t *t, const char *key);
+void *Table$str_entry(Table_t t, int64_t n);
+void *Table$str_get(Table_t t, const char *key);
+void *Table$str_get_raw(Table_t t, const char *key);
+void Table$str_set(Table_t *t, const char *key, const void *value);
+void *Table$str_reserve(Table_t *t, const char *key, const void *value);
+void Table$str_remove(Table_t *t, const char *key);
#define Table$length(t) ((t).entries.length)
diff --git a/builtins/text.c b/builtins/text.c
index 577fbdc9..4bca6516 100644
--- a/builtins/text.c
+++ b/builtins/text.c
@@ -89,7 +89,7 @@ typedef struct {
#define MAX_BACKREFS 100
// Synthetic grapheme clusters (clusters of more than one codepoint):
-static table_t grapheme_ids_by_codepoints = {}; // uint32_t* length-prefixed codepoints -> int32_t ID
+static Table_t grapheme_ids_by_codepoints = {}; // uint32_t* length-prefixed codepoints -> int32_t ID
// This will hold a dynamically growing array of synthetic graphemes:
static synthetic_grapheme_t *synthetic_graphemes = NULL;
@@ -125,7 +125,7 @@ static const TypeInfo GraphemeClusterInfo = {
};
static const TypeInfo GraphemeIDLookupTableInfo = {
- .size=sizeof(table_t), .align=__alignof__(table_t),
+ .size=sizeof(Table_t), .align=__alignof__(Table_t),
.tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&$Int32},
};
@@ -1942,7 +1942,7 @@ public Text_t Text$map(Text_t text, Pattern_t pattern, closure_t fn)
return ret;
}
-public Text_t Text$replace_all(Text_t text, table_t replacements, Text_t backref_pat, bool recursive)
+public Text_t Text$replace_all(Text_t text, Table_t replacements, Text_t backref_pat, bool recursive)
{
if (replacements.entries.length == 0) return text;
diff --git a/builtins/text.h b/builtins/text.h
index af34c03a..a8ca85fc 100644
--- a/builtins/text.h
+++ b/builtins/text.h
@@ -34,7 +34,7 @@ Text_t Text$title(Text_t text);
Text_t Text$as_text(const void *text, bool colorize, const TypeInfo *info);
Text_t Text$quoted(Text_t str, bool colorize);
Text_t Text$replace(Text_t str, Pattern_t pat, Text_t replacement, Pattern_t backref_pat, bool recursive);
-Text_t Text$replace_all(Text_t text, table_t replacements, Pattern_t backref_pat, bool recursive);
+Text_t Text$replace_all(Text_t text, Table_t replacements, Pattern_t backref_pat, bool recursive);
Array_t Text$split(Text_t text, Pattern_t pattern);
Int_t Text$find(Text_t text, Pattern_t pattern, Int_t i, int64_t *match_length);
Array_t Text$find_all(Text_t text, Pattern_t pattern);
diff --git a/builtins/types.h b/builtins/types.h
index 61c2891d..24640f89 100644
--- a/builtins/types.h
+++ b/builtins/types.h
@@ -57,11 +57,11 @@ typedef struct TypeInfo {
.tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info, .is_optional=opt}})
#define $ArrayInfo(item_info) &((TypeInfo){.size=sizeof(Array_t), .align=__alignof__(Array_t), \
.tag=ArrayInfo, .ArrayInfo.item=item_info})
-#define $SetInfo(item_info) &((TypeInfo){.size=sizeof(table_t), .align=__alignof__(table_t), \
+#define $SetInfo(item_info) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
.tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&$Void})
#define $ChannelInfo(item_info) &((TypeInfo){.size=sizeof(channel_t), .align=__alignof__(channel_t), \
.tag=ChannelInfo, .ChannelInfo.item=item_info})
-#define $TableInfo(key_expr, value_expr) &((TypeInfo){.size=sizeof(table_t), .align=__alignof__(table_t), \
+#define $TableInfo(key_expr, value_expr) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
.tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr})
#define $FunctionInfo(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \
.tag=FunctionInfo, .FunctionInfo.type_str=typestr})
diff --git a/compile.c b/compile.c
index 3e319e15..7ecd614a 100644
--- a/compile.c
+++ b/compile.c
@@ -101,7 +101,7 @@ CORD compile_maybe_incref(env_t *env, ast_t *ast)
}
-static table_t *get_closed_vars(env_t *env, ast_t *lambda_ast)
+static Table_t *get_closed_vars(env_t *env, ast_t *lambda_ast)
{
auto lambda = Match(lambda_ast, Lambda);
env_t *body_scope = fresh_scope(env);
@@ -114,7 +114,7 @@ static table_t *get_closed_vars(env_t *env, ast_t *lambda_ast)
fn_ctx_t fn_ctx = (fn_ctx_t){
.parent=env->fn_ctx,
.closure_scope=env->locals,
- .closed_vars=new(table_t),
+ .closed_vars=new(Table_t),
};
body_scope->fn_ctx = &fn_ctx;
body_scope->locals->fallback = env->globals;
@@ -170,9 +170,9 @@ CORD compile_type(type_t *t)
return text->lang ? CORD_all(namespace_prefix(text->env->libname, text->env->namespace->parent), text->lang, "_t") : "Text_t";
}
case ArrayType: return "Array_t";
- case SetType: return "table_t";
+ case SetType: return "Table_t";
case ChannelType: return "channel_t*";
- case TableType: return "table_t";
+ case TableType: return "Table_t";
case FunctionType: {
auto fn = Match(t, FunctionType);
CORD code = CORD_all(compile_type(fn->ret), " (*)(");
@@ -739,7 +739,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
"extern const TypeInfo ", namespace_prefix(env->libname, env->namespace), arg_type_name, ";\n");
CORD wrapper = CORD_all(
is_private ? CORD_EMPTY : "public ", ret_type_code, " ", name, arg_signature, "{\n"
- "static table_t cache = {};\n",
+ "static Table_t cache = {};\n",
compile_type(args_t), " args = {", all_args, "};\n"
"const TypeInfo *table_type = $TableInfo(", compile_type_info(env, args_t), ", ", compile_type_info(env, ret_t), ");\n",
compile_declaration(Type(PointerType, .pointed=ret_t, .is_optional=true), "cached"), " = Table$get_raw(cache, &args, table_type);\n"
@@ -809,7 +809,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
case Pass: return ";";
case Defer: {
ast_t *body = Match(ast, Defer)->body;
- table_t *closed_vars = get_closed_vars(env, FakeAST(Lambda, .args=NULL, .body=body));
+ Table_t *closed_vars = get_closed_vars(env, FakeAST(Lambda, .args=NULL, .body=body));
static int defer_id = 0;
env_t *defer_env = fresh_scope(env);
@@ -1389,7 +1389,7 @@ CORD compile_int_to_type(env_t *env, ast_t *ast, type_t *target)
CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t *call_args)
{
- table_t used_args = {};
+ Table_t used_args = {};
CORD code = CORD_EMPTY;
env_t *default_scope = global_scope(env);
for (arg_t *spec_arg = spec_args; spec_arg; spec_arg = spec_arg->next) {
@@ -2037,7 +2037,7 @@ CORD compile(env_t *env, ast_t *ast)
case Table: {
auto table = Match(ast, Table);
if (!table->entries) {
- CORD code = "((table_t){";
+ CORD code = "((Table_t){";
if (table->fallback)
code = CORD_all(code, ".fallback=", compile(env, table->fallback),",");
return CORD_cat(code, "})");
@@ -2081,7 +2081,7 @@ CORD compile(env_t *env, ast_t *ast)
env_t *scope = fresh_scope(env);
scope->comprehension_var = heap_strf("table$%ld", comp_num++);
- CORD code = CORD_all("({ table_t ", scope->comprehension_var, " = {");
+ CORD code = CORD_all("({ Table_t ", scope->comprehension_var, " = {");
if (table->fallback)
code = CORD_all(code, ".fallback=heap(", compile(env, table->fallback), "), ");
@@ -2107,7 +2107,7 @@ CORD compile(env_t *env, ast_t *ast)
case Set: {
auto set = Match(ast, Set);
if (!set->items)
- return "((table_t){})";
+ return "((Table_t){})";
type_t *set_type = get_type(env, ast);
type_t *item_type = Match(set_type, SetType)->item_type;
@@ -2139,7 +2139,7 @@ CORD compile(env_t *env, ast_t *ast)
env_t *scope = fresh_scope(env);
scope->comprehension_var = heap_strf("set$%ld", comp_num++);
- CORD code = CORD_all("({ table_t ", scope->comprehension_var, " = {};");
+ CORD code = CORD_all("({ Table_t ", scope->comprehension_var, " = {};");
set_binding(scope, scope->comprehension_var, new(binding_t, .type=set_type, .code=scope->comprehension_var));
for (ast_list_t *item = set->items; item; item = item->next) {
if (item->ast->tag == Comprehension) {
@@ -2178,7 +2178,7 @@ CORD compile(env_t *env, ast_t *ast)
fn_ctx_t fn_ctx = (fn_ctx_t){
.parent=env->fn_ctx,
.closure_scope=env->locals,
- .closed_vars=new(table_t),
+ .closed_vars=new(Table_t),
};
body_scope->fn_ctx = &fn_ctx;
body_scope->locals->fallback = env->globals;
@@ -2205,7 +2205,7 @@ CORD compile(env_t *env, ast_t *ast)
CORD args_typedef = compile_statement_typedefs(env, ast);
env->code->local_typedefs = CORD_all(env->code->local_typedefs, args_typedef);
- table_t *closed_vars = get_closed_vars(env, ast);
+ Table_t *closed_vars = get_closed_vars(env, ast);
CORD userdata;
if (Table$length(*closed_vars) == 0) {
code = CORD_cat(code, "void *userdata)");
@@ -2419,7 +2419,7 @@ CORD compile(env_t *env, ast_t *ast)
compile_type_info(env, self_value_t), ")");
} else if (streq(call->name, "add_all")) {
arg_t *arg_spec = new(arg_t, .name="items", .type=Type(ArrayType, .item_type=Match(self_value_t, SetType)->item_type));
- return CORD_all("({ table_t *set = ", compile_to_pointer_depth(env, call->self, 1, false), "; ",
+ return CORD_all("({ Table_t *set = ", compile_to_pointer_depth(env, call->self, 1, false), "; ",
"Array_t to_add = ", compile_arguments(env, ast, arg_spec, call->args), "; ",
"for (int64_t i = 0; i < to_add.length; i++)\n"
"Table$set(set, to_add.data + i*to_add.stride, NULL, ", compile_type_info(env, self_value_t), ");\n",
@@ -2431,7 +2431,7 @@ CORD compile(env_t *env, ast_t *ast)
compile_type_info(env, self_value_t), ")");
} else if (streq(call->name, "remove_all")) {
arg_t *arg_spec = new(arg_t, .name="items", .type=Type(ArrayType, .item_type=Match(self_value_t, SetType)->item_type));
- return CORD_all("({ table_t *set = ", compile_to_pointer_depth(env, call->self, 1, false), "; ",
+ return CORD_all("({ Table_t *set = ", compile_to_pointer_depth(env, call->self, 1, false), "; ",
"Array_t to_add = ", compile_arguments(env, ast, arg_spec, call->args), "; ",
"for (int64_t i = 0; i < to_add.length; i++)\n"
"Table$remove(set, to_add.data + i*to_add.stride, ", compile_type_info(env, self_value_t), ");\n",
@@ -2739,7 +2739,7 @@ CORD compile(env_t *env, ast_t *ast)
case TypeInfoType: {
auto info = Match(value_t, TypeInfoType);
if (f->field[0] == '_') {
- for (table_t *locals = env->locals; locals; locals = locals->fallback) {
+ for (Table_t *locals = env->locals; locals; locals = locals->fallback) {
if (locals == info->env->locals)
goto is_inside_type;
}
@@ -2850,7 +2850,7 @@ CORD compile(env_t *env, ast_t *ast)
if (ptr->pointed->tag == ArrayType) {
return CORD_all("({ Array_t *arr = ", compile(env, indexing->indexed), "; ARRAY_INCREF(*arr); *arr; })");
} else if (ptr->pointed->tag == TableType || ptr->pointed->tag == SetType) {
- return CORD_all("({ table_t *t = ", compile(env, indexing->indexed), "; TABLE_INCREF(*t); *t; })");
+ return CORD_all("({ Table_t *t = ", compile(env, indexing->indexed), "; TABLE_INCREF(*t); *t; })");
} else {
return CORD_all("*(", compile(env, indexing->indexed), ")");
}
@@ -3431,7 +3431,7 @@ CORD compile_statement_typedefs(env_t *env, ast_t *ast)
}
case Lambda: {
auto lambda = Match(ast, Lambda);
- table_t *closed_vars = get_closed_vars(env, ast);
+ Table_t *closed_vars = get_closed_vars(env, ast);
if (Table$length(*closed_vars) == 0)
return CORD_EMPTY;
diff --git a/environment.c b/environment.c
index b0869cee..260bb586 100644
--- a/environment.c
+++ b/environment.c
@@ -17,10 +17,10 @@ env_t *new_compilation_unit(CORD *libname)
{
env_t *env = new(env_t);
env->code = new(compilation_unit_t);
- env->types = new(table_t);
- env->globals = new(table_t);
- env->locals = new(table_t, .fallback=env->globals);
- env->imports = new(table_t);
+ env->types = new(Table_t);
+ env->globals = new(Table_t);
+ env->locals = new(Table_t, .fallback=env->globals);
+ env->imports = new(Table_t);
env->libname = libname;
if (!TEXT_TYPE)
@@ -352,7 +352,7 @@ env_t *global_scope(env_t *env)
{
env_t *scope = new(env_t);
*scope = *env;
- scope->locals = new(table_t, .fallback=env->globals);
+ scope->locals = new(Table_t, .fallback=env->globals);
return scope;
}
@@ -360,7 +360,7 @@ env_t *fresh_scope(env_t *env)
{
env_t *scope = new(env_t);
*scope = *env;
- scope->locals = new(table_t, .fallback=env->locals);
+ scope->locals = new(Table_t, .fallback=env->locals);
return scope;
}
@@ -479,7 +479,7 @@ env_t *namespace_env(env_t *env, const char *namespace_name)
env_t *ns_env = new(env_t);
*ns_env = *env;
- ns_env->locals = new(table_t, .fallback=env->locals);
+ ns_env->locals = new(Table_t, .fallback=env->locals);
ns_env->namespace = new(namespace_t, .name=namespace_name, .parent=env->namespace);
return ns_env;
}
diff --git a/environment.h b/environment.h
index 98d61d84..86b8cc6c 100644
--- a/environment.h
+++ b/environment.h
@@ -18,8 +18,8 @@ typedef struct {
typedef struct fn_ctx_s {
struct fn_ctx_s *parent;
type_t *return_type;
- table_t *closure_scope;
- table_t *closed_vars;
+ Table_t *closure_scope;
+ Table_t *closed_vars;
} fn_ctx_t;
typedef struct deferral_s {
@@ -42,11 +42,11 @@ typedef struct namespace_s {
} namespace_t;
typedef struct env_s {
- table_t *types, *globals, *locals;
+ Table_t *types, *globals, *locals;
// Lookup table for env_t* where the key is:
// - Resolved path for local imports (so that `use ./foo.tm` is the same as `use ./baz/../foo.tm`)
// - Raw 'use' string for module imports
- table_t *imports;
+ Table_t *imports;
compilation_unit_t *code;
fn_ctx_t *fn_ctx;
loop_ctx_t *loop_ctx;
diff --git a/parse.c b/parse.c
index 22bb883d..2f3a8c3d 100644
--- a/parse.c
+++ b/parse.c
@@ -2228,7 +2228,7 @@ ast_t *parse_file(const char *path, jmp_buf *on_err) {
// hold more than PARSE_CACHE_SIZE entries (see below), but each entry's
// AST holds onto a reference to the file it came from, so they could
// potentially be somewhat large.
- static table_t cached = {};
+ static Table_t cached = {};
ast_t *ast = Table$str_get(cached, path);
if (ast) return ast;
diff --git a/repl.c b/repl.c
index 68934fac..d5b207b3 100644
--- a/repl.c
+++ b/repl.c
@@ -129,7 +129,7 @@ const TypeInfo *type_to_type_info(type_t *t)
const TypeInfo *key_info = type_to_type_info(Match(t, TableType)->key_type);
const TypeInfo *value_info = type_to_type_info(Match(t, TableType)->value_type);
const TypeInfo table_info = {
- .size=sizeof(table_t), .align=__alignof__(table_t),
+ .size=sizeof(Table_t), .align=__alignof__(Table_t),
.tag=TableInfo, .TableInfo.key=key_info, .TableInfo.value=value_info};
return memcpy(GC_MALLOC(sizeof(TypeInfo)), &table_info, sizeof(TypeInfo));
}
@@ -481,7 +481,7 @@ void eval(env_t *env, ast_t *ast, void *dest)
break;
}
case TableType: {
- table_t table;
+ Table_t table;
eval(env, index->indexed, &table);
type_t *key_type = Match(indexed_t, TableType)->key_type;
size_t key_size = type_size(key_type);
@@ -520,7 +520,7 @@ void eval(env_t *env, ast_t *ast, void *dest)
case Table: {
assert(t->tag == TableType);
auto table_ast = Match(ast, Table);
- table_t table = {};
+ Table_t table = {};
size_t key_size = type_size(Match(t, TableType)->key_type);
size_t value_size = type_size(Match(t, TableType)->value_type);
char key_buf[key_size] = {};
@@ -535,7 +535,7 @@ void eval(env_t *env, ast_t *ast, void *dest)
}
if (table_ast->fallback)
eval(env, table_ast->fallback, &table.fallback);
- memcpy(dest, &table, sizeof(table_t));
+ memcpy(dest, &table, sizeof(Table_t));
break;
}
case Block: {
diff --git a/tomo.c b/tomo.c
index 4f353ce0..92815075 100644
--- a/tomo.c
+++ b/tomo.c
@@ -32,7 +32,7 @@ static int transpile_header(env_t *base_env, const char *filename, bool force_re
static int transpile_code(env_t *base_env, const char *filename, bool force_retranspile);
static int compile_object_file(const char *filename, bool force_recompile);
static int compile_executable(env_t *base_env, const char *filename, CORD object_files);
-static void build_file_dependency_graph(const char *filename, table_t *to_compile, table_t *to_link);
+static void build_file_dependency_graph(const char *filename, Table_t *to_compile, Table_t *to_link);
int main(int argc, char *argv[])
{
@@ -125,9 +125,9 @@ int main(int argc, char *argv[])
CORD compilation_library_name = CORD_EMPTY;
env_t *env = new_compilation_unit(&compilation_library_name);
- table_t dependency_files = {};
- table_t to_link = {};
- table_t argument_files = {};
+ Table_t dependency_files = {};
+ Table_t to_link = {};
+ Table_t argument_files = {};
for (int i = after_flags; i < argc; i++) {
const char *resolved = resolve_path(argv[i], ".", ".");
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
if (status != 0) return status;
}
- env->imports = new(table_t);
+ env->imports = new(Table_t);
struct child_s {
struct child_s *next;
@@ -298,7 +298,7 @@ int main(int argc, char *argv[])
}
}
-void build_file_dependency_graph(const char *filename, table_t *to_compile, table_t *to_link)
+void build_file_dependency_graph(const char *filename, Table_t *to_compile, Table_t *to_link)
{
if (Table$str_get(*to_compile, filename))
return;
diff --git a/typecheck.c b/typecheck.c
index 19860017..a832df6e 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -371,7 +371,7 @@ void bind_statement(env_t *env, ast_t *statement)
case Use: {
env_t *module_env = load_module(env, statement);
if (!module_env) break;
- for (table_t *bindings = module_env->locals; bindings != module_env->globals; bindings = bindings->fallback) {
+ for (Table_t *bindings = module_env->locals; bindings != module_env->globals; bindings = bindings->fallback) {
for (int64_t i = 1; i <= Table$length(*bindings); i++) {
struct {const char *name; binding_t *binding; } *entry = Table$entry(*bindings, i);
if (entry->name[0] == '_' || streq(entry->name, "main"))
diff --git a/types.c b/types.c
index f9a4a1f3..99a7c954 100644
--- a/types.c
+++ b/types.c
@@ -379,7 +379,7 @@ bool can_leave_uninitialized(type_t *t)
}
}
-static bool _can_have_cycles(type_t *t, table_t *seen)
+static bool _can_have_cycles(type_t *t, Table_t *seen)
{
switch (t->tag) {
case ArrayType: return _can_have_cycles(Match(t, ArrayType)->item_type, seen);
@@ -410,7 +410,7 @@ static bool _can_have_cycles(type_t *t, table_t *seen)
bool can_have_cycles(type_t *t)
{
- table_t seen = {0};
+ Table_t seen = {0};
return _can_have_cycles(t, &seen);
}
@@ -488,9 +488,9 @@ size_t type_size(type_t *t)
case NumType: return Match(t, NumType)->bits == TYPE_NBITS64 ? sizeof(double) : sizeof(float);
case TextType: return sizeof(Text_t);
case ArrayType: return sizeof(Array_t);
- case SetType: return sizeof(table_t);
+ case SetType: return sizeof(Table_t);
case ChannelType: return sizeof(channel_t*);
- case TableType: return sizeof(table_t);
+ case TableType: return sizeof(Table_t);
case FunctionType: return sizeof(void*);
case ClosureType: return sizeof(struct {void *fn, *userdata;});
case PointerType: return sizeof(void*);
@@ -550,10 +550,10 @@ size_t type_align(type_t *t)
}
case NumType: return Match(t, NumType)->bits == TYPE_NBITS64 ? __alignof__(double) : __alignof__(float);
case TextType: return __alignof__(Text_t);
- case SetType: return __alignof__(table_t);
+ case SetType: return __alignof__(Table_t);
case ArrayType: return __alignof__(Array_t);
case ChannelType: return __alignof__(channel_t*);
- case TableType: return __alignof__(table_t);
+ case TableType: return __alignof__(Table_t);
case FunctionType: return __alignof__(void*);
case ClosureType: return __alignof__(struct {void *fn, *userdata;});
case PointerType: return __alignof__(void*);