diff --git a/lib/c3/0.1/integer.facts b/lib/c3/0.1/integer.facts
index ff8d8e7..bcd4506 100644
--- a/lib/c3/0.1/integer.facts
+++ b/lib/c3/0.1/integer.facts
@@ -2,4 +2,4 @@
version: 1}
replace {Integer, :is_a, :module}
replace {Integer, :symbol, Integer.cast}
-replace {Integer.cast, :cfn, cfn Integer "integer_cast" (Tag, Result)}
+replace {Integer.cast, :cfn, cfn Integer "integer_init_cast" (Result, Tag)}
diff --git a/lib/c3/0.1/list.facts b/lib/c3/0.1/list.facts
index 75d8a22..c78be55 100644
--- a/lib/c3/0.1/list.facts
+++ b/lib/c3/0.1/list.facts
@@ -4,7 +4,7 @@ add {List, :is_a, :module}
add {List, :symbol, List.cast}
add {List, :symbol, List.map}
add {List, :symbol, List.reverse}
-replace {List.cast, :cfn, cfn List "list_cast" (Tag, Result)}
+replace {List.cast, :cfn, cfn List "list_init_cast" (Result, Tag)}
replace {List.map, :fn, fn {
([], _) {
[]
diff --git a/lib/c3/0.1/u16.facts b/lib/c3/0.1/u16.facts
index ee7d50c..9212fde 100644
--- a/lib/c3/0.1/u16.facts
+++ b/lib/c3/0.1/u16.facts
@@ -2,4 +2,4 @@
version: 1}
replace {U16, :is_a, :module}
replace {U16, :symbol, U16.cast}
-replace {U16.cast, :cfn, cfn U16 "u16_cast" (Tag, Result)}
+replace {U16.cast, :cfn, cfn U16 "u16_init_cast" (Result, Tag)}
diff --git a/lib/c3/0.1/u32.facts b/lib/c3/0.1/u32.facts
index 29e6146..25750f2 100644
--- a/lib/c3/0.1/u32.facts
+++ b/lib/c3/0.1/u32.facts
@@ -2,4 +2,4 @@
version: 1}
replace {U32, :is_a, :module}
replace {U32, :symbol, U32.cast}
-replace {U32.cast, :cfn, cfn U32 "u32_cast" (Tag, Result)}
+replace {U32.cast, :cfn, cfn U32 "u32_init_cast" (Result, Tag)}
diff --git a/lib/c3/0.1/u64.facts b/lib/c3/0.1/u64.facts
index 7cea2fe..4f208a2 100644
--- a/lib/c3/0.1/u64.facts
+++ b/lib/c3/0.1/u64.facts
@@ -2,4 +2,4 @@
version: 1}
replace {U64, :is_a, :module}
replace {U64, :symbol, U64.cast}
-replace {U64.cast, :cfn, cfn U64 "u64_cast" (Tag, Result)}
+replace {U64.cast, :cfn, cfn U64 "u64_init_cast" (Result, Tag)}
diff --git a/lib/c3/0.1/u8.facts b/lib/c3/0.1/u8.facts
index 39e73d0..09b368e 100644
--- a/lib/c3/0.1/u8.facts
+++ b/lib/c3/0.1/u8.facts
@@ -2,4 +2,4 @@
version: 1}
replace {U8, :is_a, :module}
replace {U8, :symbol, U8.cast}
-replace {U8.cast, :cfn, cfn U8 "u8_cast" (Tag, Result)}
+replace {U8.cast, :cfn, cfn U8 "u8_init_cast" (Result, Tag)}
diff --git a/libc3/array.c b/libc3/array.c
index 58a2321..af7533d 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -59,9 +59,10 @@ void array_clean (s_array *a)
assert(a);
free(a->dimensions);
if (a->data) {
- clean = sym_to_clean(a->type);
- size = sym_type_size(a->type);
- if (clean) {
+ if (sym_to_clean(a->type, &clean) &&
+ clean &&
+ sym_type_size(a->type, &size) &&
+ size) {
data = a->data;
i = 0;
while (i < a->count) {
@@ -115,9 +116,12 @@ s_array * array_data_set (s_array *a, const uw *address,
assert(a);
assert(address);
assert(data);
- if ((a_data = array_data(a, address))) {
- init_copy = sym_to_init_copy(a->type);
- if (init_copy(a_data, data) != a_data)
+ a_data = array_data(a, address);
+ if (a_data) {
+ if (! sym_to_init_copy(a->type, &init_copy))
+ return NULL;
+ if (init_copy &&
+ ! init_copy(a_data, data))
return NULL;
return a;
}
@@ -128,16 +132,16 @@ s_tag * array_data_tag (s_tag *a, const s_tag *address, s_tag *dest)
{
void *a_data;
f_init_copy init_copy;
- void *dest_data;
+ void *tmp_data;
+ s_tag tmp = {0};
assert(a->type == TAG_ARRAY);
assert(address->type == TAG_ARRAY);
- if ((a_data = array_data(&a->data.array,
- address->data.array.data))) {
- tag_init(dest);
- init_copy = sym_to_init_copy(a->data.array.type);
- sym_to_tag_type(a->data.array.type, &dest->type);
- dest_data = tag_to_pointer(dest, a->data.array.type);
- if (init_copy(dest_data, a_data) != dest_data)
+ a_data = array_data(&a->data.array, address->data.array.data);
+ if (a_data) {
+ if (! sym_to_init_copy(a->data.array.type, &init_copy) ||
+ ! sym_to_tag_type(a->data.array.type, &tmp.type) ||
+ ! tag_to_pointer(&tmp, a->data.array.type, &tmp_data) ||
+ ! init_copy(tmp_data, a_data))
return NULL;
return dest;
}
@@ -150,6 +154,7 @@ s_array * array_init (s_array *a, const s_sym *type, uw dimension,
uw count = 1;
uw i = 0;
uw item_size;
+ s_array tmp = {0};
assert(a);
assert(type);
assert(sym_is_module(type));
@@ -166,27 +171,36 @@ s_array * array_init (s_array *a, const s_sym *type, uw dimension,
i++;
}
#endif
- a->dimension = dimension;
- a->dimensions = calloc(dimension, sizeof(s_array_dimension));
+ tmp.dimension = dimension;
+ tmp.dimensions = calloc(dimension, sizeof(s_array_dimension));
i = 0;
while (i < dimension) {
- a->dimensions[i].count = dimensions[i];
+ tmp.dimensions[i].count = dimensions[i];
count *= dimensions[i];
i++;
}
i--;
- a->type = type;
- item_size = sym_type_size(type);
- a->dimensions[i].item_size = item_size;
+ tmp.type = type;
+ if (! sym_type_size(type, &item_size)) {
+ free(tmp.dimensions);
+ return NULL;
+ }
+ if (! item_size) {
+ warnx("array_init: zero item size");
+ assert(! "array_init: zero item size");
+ return NULL;
+ }
+ tmp.dimensions[i].item_size = item_size;
while (i > 0) {
i--;
- a->dimensions[i].item_size = a->dimensions[i + 1].count *
- a->dimensions[i + 1].item_size;
+ tmp.dimensions[i].item_size = tmp.dimensions[i + 1].count *
+ tmp.dimensions[i + 1].item_size;
}
- a->size = a->dimensions[0].count * a->dimensions[0].item_size;
- a->count = count;
- a->data = NULL;
- a->tags = NULL;
+ tmp.size = tmp.dimensions[0].count * tmp.dimensions[0].item_size;
+ tmp.count = count;
+ tmp.data = NULL;
+ tmp.tags = NULL;
+ *a = tmp;
return a;
}
@@ -218,10 +232,26 @@ s_array * array_init_1 (s_array *array, s8 *p)
return array;
}
+s_array * array_init_cast (s_array *array, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_ARRAY:
+ return array_init_copy(array, &tag->data.array);
+ default:
+ break;
+ }
+ err_write_1("array_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Array");
+ assert(! "array_init_cast: cannot cast to Array");
+ return NULL;
+}
+
s_array * array_init_copy (s_array *a, const s_array *src)
{
+ f_clean clean;
f_init_copy init_copy;
- u8 *data_a;
+ u8 *data_tmp;
u8 *data_src;
uw i = 0;
uw item_size;
@@ -232,8 +262,8 @@ s_array * array_init_copy (s_array *a, const s_array *src)
assert(src->dimensions);
(void) i;
if (! src->dimension) {
+ err_puts("array_init_copy: zero dimension");
assert(! "array_init_copy: zero dimension");
- errx(1, "array_init_copy: zero dimension");
return NULL;
}
#ifdef DEBUG
@@ -255,36 +285,61 @@ s_array * array_init_copy (s_array *a, const s_array *src)
tmp.size = src->size;
tmp.type = src->type;
if (src->data) {
- if (! (tmp.data = calloc(1, src->size)))
- errx(1, "array_init_copy: out of memory");
- init_copy = sym_to_init_copy(src->type);
- data_a = tmp.data;
+ tmp.data = calloc(1, src->size);
+ if (! tmp.data) {
+ warnx("array_init_copy: failed to allocate memory");
+ assert(! "array_init_copy: failed to allocate memory");
+ free(tmp.dimensions);
+ return NULL;
+ }
+ if (! sym_to_init_copy(src->type, &init_copy)) {
+ free(tmp.dimensions);
+ return NULL;
+ }
+ data_tmp = tmp.data;
data_src = src->data;
i = 0;
item_size = src->dimensions[src->dimension - 1].item_size;
while (i < src->count) {
- if (init_copy(data_a, data_src) != data_a) {
- return NULL;
- }
- data_a += item_size;
+ if (! init_copy(data_tmp, data_src))
+ goto ko_data;
+ data_tmp += item_size;
data_src += item_size;
i++;
}
}
- else
- tmp.data = NULL;
- if (src->tags) {
+ else if (src->tags) {
tmp.tags = calloc(src->count, sizeof(s_tag));
+ if (! tmp.tags) {
+ warn("array_init_copy: failed to allocate memory");
+ assert(! "array_init_copy: failed to allocate memory");
+ free(tmp.dimensions);
+ return NULL;
+ }
i = 0;
while (i < src->count) {
- tag_init_copy(tmp.tags + i, src->tags + i);
+ if (! tag_init_copy(tmp.tags + i, src->tags + i))
+ goto ko_tags;
i++;
}
}
- else
- tmp.tags = NULL;
*a = tmp;
return a;
+ ko_data:
+ if (i && sym_to_clean(src->type, &clean) && clean) {
+ while (--i) {
+ data_tmp -= item_size;
+ clean(data_tmp);
+ }
+ }
+ free(tmp.data);
+ free(tmp.dimensions);
+ return NULL;
+ ko_tags:
+ if (i)
+ while (--i)
+ tag_clean(tmp.tags + i);
+ return NULL;
}
s_str * array_inspect (const s_array *array, s_str *dest)
diff --git a/libc3/bool.c b/libc3/bool.c
index 123155f..26b3338 100644
--- a/libc3/bool.c
+++ b/libc3/bool.c
@@ -14,7 +14,38 @@
#include "bool.h"
#include "buf.h"
#include "buf_inspect.h"
+#include "integer.h"
#include "io.h"
+#include "tag_type.h"
+
+bool * bool_init_cast (bool *b, const s_tag *tag)
+{
+ assert(b);
+ assert(tag);
+ switch (tag->type) {
+ case TAG_BOOL: *b = tag->data.bool; return b;
+ case TAG_CHARACTER: *b = (bool) tag->data.character; return b;
+ case TAG_F32: *b = (bool) tag->data.f32; return b;
+ case TAG_F64: *b = (bool) tag->data.f64; return b;
+ case TAG_INTEGER: *b = integer_to_u8(&tag->data.integer); return b;
+ case TAG_S8: *b = (bool) tag->data.s8; return b;
+ case TAG_S16: *b = (bool) tag->data.s16; return b;
+ case TAG_S32: *b = (bool) tag->data.s32; return b;
+ case TAG_S64: *b = (bool) tag->data.s64; return b;
+ case TAG_SW: *b = (bool) tag->data.sw; return b;
+ case TAG_U8: *b = (bool) tag->data.u8; return b;
+ case TAG_U16: *b = (bool) tag->data.u16; return b;
+ case TAG_U32: *b = (bool) tag->data.u32; return b;
+ case TAG_U64: *b = (bool) tag->data.u64; return b;
+ case TAG_UW: *b = (bool) tag->data.uw; return b;
+ default: break;
+ }
+ err_write_1("bool_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Bool");
+ assert(! "bool_cast: cannot cast to Bool");
+ return NULL;
+}
bool * bool_init_copy (bool *dest, const bool *src)
{
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index befdb79..77a6cbe 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -71,13 +71,16 @@ sw buf_inspect_array_data (s_buf *buf, const s_array *array)
sw r;
assert(buf);
assert(array);
- address = calloc(array->dimension, sizeof(uw));
+ // TODO: buf_inspect_array_data_rec_data
+ // TODO: buf_inspect_array_data_rec_tags
if (array->data) {
data = array->data;
- inspect = sym_to_buf_inspect(array->type);
+ if (! sym_to_buf_inspect(array->type, &inspect))
+ return -1;
}
else
tag = array->tags;
+ address = calloc(array->dimension, sizeof(uw));
r = buf_inspect_array_data_rec(buf, array, (const u8 **) &data,
inspect, (const s_tag **) &tag,
address, 0);
@@ -141,13 +144,14 @@ sw buf_inspect_array_data_size (const s_array *array)
s_tag *tag = NULL;
sw r;
assert(array);
- address = calloc(array->dimension, sizeof(uw));
if (array->data) {
data = array->data;
- inspect_size = sym_to_buf_inspect_size(array->type);
+ if (! sym_to_buf_inspect_size(array->type, &inspect_size))
+ return -1;
}
else
tag = array->tags;
+ address = calloc(array->dimension, sizeof(uw));
r = buf_inspect_array_data_size_rec(array, (const u8 **) &data,
inspect_size,
(const s_tag **) &tag,
@@ -532,7 +536,7 @@ sw buf_inspect_paren_sym (s_buf *buf, const s_sym *sym)
if ((r = buf_write_1(buf, "(")) <= 0)
goto clean;
result += r;
- if ((r = buf_inspect_sym(buf, sym)) <= 0)
+ if ((r = buf_inspect_sym(buf, &sym)) <= 0)
goto clean;
result += r;
if ((r = buf_write_1(buf, ")")) <= 0)
@@ -549,7 +553,7 @@ sw buf_inspect_paren_sym_size (const s_sym *sym)
sw result = 0;
assert(sym);
result += strlen("(");
- if ((r = buf_inspect_sym_size(sym)) <= 0)
+ if ((r = buf_inspect_sym_size(&sym)) <= 0)
goto clean;
result += r;
result += strlen(")");
@@ -566,7 +570,7 @@ sw buf_inspect_cfn (s_buf *buf, const s_cfn *cfn)
if ((r = buf_write_1(buf, "cfn ")) < 0)
return r;
result += r;
- if ((r = buf_inspect_sym(buf, cfn->result_type)) < 0)
+ if ((r = buf_inspect_sym(buf, &cfn->result_type)) < 0)
return r;
result += r;
if ((r = buf_write_1(buf, " ")) < 0)
@@ -578,7 +582,8 @@ sw buf_inspect_cfn (s_buf *buf, const s_cfn *cfn)
if ((r = buf_write_1(buf, " ")) < 0)
return r;
result += r;
- if ((r = buf_inspect_list_paren(buf, (const s_list **) &cfn->arg_types)) < 0)
+ if ((r = buf_inspect_list_paren(buf, (const s_list * const *)
+ &cfn->arg_types)) < 0)
return r;
result += r;
return result;
@@ -993,7 +998,7 @@ sw buf_inspect_ident (s_buf *buf, const s_ident *ident)
assert(ident);
result = 0;
if (ident->module) {
- if ((r = buf_inspect_sym(buf, ident->module)) < 0)
+ if ((r = buf_inspect_sym(buf, &ident->module)) < 0)
return r;
result += r;
if ((r = buf_write_1(buf, ".")) < 0)
@@ -1048,7 +1053,7 @@ sw buf_inspect_ident_size (const s_ident *ident)
sw result = 0;
assert(ident);
if (ident->module) {
- if ((r = buf_inspect_sym_size(ident->module)) < 0)
+ if ((r = buf_inspect_sym_size(&ident->module)) < 0)
return r;
result += r;
result += strlen(".");
@@ -1150,7 +1155,7 @@ sw buf_inspect_list (s_buf *buf, const s_list **x)
return result;
}
-sw buf_inspect_list_paren (s_buf *buf, const s_list **x)
+sw buf_inspect_list_paren (s_buf *buf, const s_list * const *x)
{
const s_list *i;
sw r;
@@ -1189,7 +1194,7 @@ sw buf_inspect_list_paren (s_buf *buf, const s_list **x)
return result;
}
-sw buf_inspect_list_size (const s_list **list)
+sw buf_inspect_list_size (const s_list * const *list)
{
const s_list *i;
sw r;
@@ -1728,7 +1733,8 @@ sw buf_inspect_struct (s_buf *buf, const s_struct *s)
return r;
result += r;
if (s->data) {
- buf_inspect = tag_type_to_buf_inspect(s->type.map.value[i].type);
+ if (! tag_type_to_buf_inspect(s->type.map.value[i].type, &buf_inspect))
+ return -1;
if ((r = buf_inspect(buf, (s8 *) s->data + s->type.offset[i])) < 0)
return r;
result += r;
@@ -1764,11 +1770,14 @@ sw buf_inspect_struct_size (const s_struct *s)
return -1;
}
-sw buf_inspect_sym (s_buf *buf, const s_sym *x)
+sw buf_inspect_sym (s_buf *buf, const s_sym * const *sym)
{
sw r;
sw size;
+ const s_sym *x;
assert(buf);
+ assert(sym);
+ x = *sym;
assert(x);
if (x->str.size == 0)
return buf_write_1(buf, ":\"\"");
@@ -1783,9 +1792,12 @@ sw buf_inspect_sym (s_buf *buf, const s_sym *x)
return size;
}
-sw buf_inspect_sym_size (const s_sym *x)
+sw buf_inspect_sym_size (const s_sym * const *sym)
{
const sw colon_size = 1;
+ const s_sym *x;
+ assert(sym);
+ x = *sym;
assert(x);
if (x->str.size == 0)
return 3;
@@ -1852,15 +1864,15 @@ sw buf_inspect_tag (s_buf *buf, const s_tag *tag)
case TAG_SW: return buf_inspect_sw(buf, &tag->data.sw);
case TAG_STR: return buf_inspect_str(buf, &tag->data.str);
case TAG_STRUCT: return buf_inspect_struct(buf, &tag->data.struct_);
- case TAG_SYM: return buf_inspect_sym(buf, tag->data.sym);
+ case TAG_SYM: return buf_inspect_sym(buf, &tag->data.sym);
case TAG_TUPLE: return buf_inspect_tuple(buf, &tag->data.tuple);
case TAG_U8: return buf_inspect_u8(buf, &tag->data.u8);
case TAG_U16: return buf_inspect_u16(buf, &tag->data.u16);
case TAG_U32: return buf_inspect_u32(buf, &tag->data.u32);
case TAG_U64: return buf_inspect_u64(buf, &tag->data.u64);
case TAG_UW: return buf_inspect_uw(buf, &tag->data.uw);
- case TAG_VAR: return buf_inspect_var(buf, tag);
- case TAG_VOID: return buf_inspect_void(buf, &tag);
+ case TAG_VAR: return buf_inspect_var(buf, NULL);
+ case TAG_VOID: return buf_inspect_void(buf, NULL);
}
err_puts("buf_inspect_tag: unknown tag_type");
assert(! "buf_inspect_tag: unknown tag type");
@@ -1899,15 +1911,15 @@ sw buf_inspect_tag_size (const s_tag *tag)
case TAG_SW: return buf_inspect_sw_size(&tag->data.sw);
case TAG_STR: return buf_inspect_str_size(&tag->data.str);
case TAG_STRUCT: return buf_inspect_struct_size(&tag->data.struct_);
- case TAG_SYM: return buf_inspect_sym_size(tag->data.sym);
+ case TAG_SYM: return buf_inspect_sym_size(&tag->data.sym);
case TAG_TUPLE: return buf_inspect_tuple_size(&tag->data.tuple);
case TAG_U8: return buf_inspect_u8_size(&tag->data.u8);
case TAG_U16: return buf_inspect_u16_size(&tag->data.u16);
case TAG_U32: return buf_inspect_u32_size(&tag->data.u32);
case TAG_U64: return buf_inspect_u64_size(&tag->data.u64);
case TAG_UW: return buf_inspect_uw_size(&tag->data.uw);
- case TAG_VAR: return buf_inspect_var_size(tag);
- case TAG_VOID: return buf_inspect_void_size(tag);
+ case TAG_VAR: return buf_inspect_var_size(NULL);
+ case TAG_VOID: return buf_inspect_void_size(NULL);
}
err_puts("buf_inspect_tag_size: unknown tag type");
assert(! "buf_inspect_tag_size: unknown tag type");
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index 96e21a8..3c0eff1 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -94,8 +94,8 @@ sw buf_inspect_ident_size (const s_ident *ident);
sw buf_inspect_integer (s_buf *buf, const s_integer *x);
sw buf_inspect_integer_size (const s_integer *x);
sw buf_inspect_list (s_buf *buf, const s_list **list);
-sw buf_inspect_list_paren (s_buf *buf, const s_list **list);
-sw buf_inspect_list_size (const s_list **list);
+sw buf_inspect_list_paren (s_buf *buf, const s_list * const *list);
+sw buf_inspect_list_size (const s_list * const *list);
sw buf_inspect_list_tag (s_buf *buf, const s_tag *tag);
sw buf_inspect_list_tag_size (const s_tag *tag);
sw buf_inspect_map (s_buf *buf, const s_map *map);
@@ -125,10 +125,10 @@ sw buf_inspect_str_reserved_size (const s_str *str);
sw buf_inspect_str_size (const s_str *str);
sw buf_inspect_struct (s_buf *buf, const s_struct *s);
sw buf_inspect_struct_size (const s_struct *s);
-sw buf_inspect_sym (s_buf *buf, const s_sym *sym);
+sw buf_inspect_sym (s_buf *buf, const s_sym * const *sym);
sw buf_inspect_sym_reserved (s_buf *buf, const s_sym *sym);
sw buf_inspect_sym_reserved_size (const s_sym *sym);
-sw buf_inspect_sym_size (const s_sym *sym);
+sw buf_inspect_sym_size (const s_sym * const *sym);
sw buf_inspect_tag (s_buf *buf, const s_tag *tag);
sw buf_inspect_tag_size (const s_tag *tag);
sw buf_inspect_tag_type (s_buf *buf, e_tag_type type);
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index a5d7d9c..f68d7b9 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -257,8 +257,14 @@ sw buf_parse_array_dimensions (s_buf *buf, s_array *dest)
assert(buf);
assert(dest);
tmp = *dest;
+ if (! sym_type_size(tmp.type, &size))
+ return -1;
+ if (! size) {
+ err_puts("buf_parse_array_dimensions: zero item size");
+ assert(! "buf_parse_array_dimensions: zero item size");
+ return -1;
+ }
address = calloc(tmp.dimension, sizeof(sw));
- size = sym_type_size(tmp.type);
tmp.dimensions[tmp.dimension - 1].item_size = size;
if ((r = buf_parse_array_dimensions_rec(buf, &tmp, address,
0)) <= 0) {
@@ -2134,7 +2140,7 @@ sw buf_parse_module_name (s_buf *buf, const s_sym **dest)
goto restore;
}
result += r;
- if ((r = buf_inspect_sym(&tmp, sym)) < 0)
+ if ((r = buf_inspect_sym(&tmp, &sym)) < 0)
goto clean;
save.rpos = buf->rpos;
while ((r = buf_read_1(buf, ".")) > 0 &&
@@ -2143,7 +2149,7 @@ sw buf_parse_module_name (s_buf *buf, const s_sym **dest)
result += r + 1;
save.rpos = buf->rpos;
if ((r = buf_write_1(&tmp, ".")) < 0 ||
- (r = buf_inspect_sym(&tmp, sym)) < 0)
+ (r = buf_inspect_sym(&tmp, &sym)) < 0)
goto clean;
}
buf_save_restore_rpos(buf, &save);
diff --git a/libc3/cfn.c b/libc3/cfn.c
index ca3a4a3..14a7661 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -23,7 +23,7 @@
#include "tag_type.h"
#include "type.h"
-s_tag * cfn_tag_init (s_tag *tag, const s_sym *type);
+static s_tag * cfn_tag_init (s_tag *tag, const s_sym *type);
s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
{
@@ -35,7 +35,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
s_list *cfn_arg_types;
sw i = 0;
sw num_args;
- void *result;
+ void *result = NULL;
s_tag tmp;
s_tag tmp2;
assert(cfn);
@@ -47,22 +47,30 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
arity, num_args);
return NULL;
}
+ cfn_tag_init(&tmp, cfn->result_type);
if (cfn->cif.rtype == &ffi_type_pointer) {
- cfn_tag_init(&tmp, cfn->result_type);
/* make result point to result_pointer */
- result_pointer = tag_to_ffi_pointer(&tmp, cfn->result_type);
+ if (! tag_to_ffi_pointer(&tmp, cfn->result_type, (void **) &result_pointer))
+ return NULL;
result = &result_pointer;
}
else {
- cfn_tag_init(&tmp, cfn->result_type);
/* make result point to tmp value */
- result = tag_to_ffi_pointer(&tmp, cfn->result_type);
+ if (! tag_to_ffi_pointer(&tmp, cfn->result_type, result))
+ return NULL;
}
if (cfn->arity) {
- if (! (arg_pointers = calloc(sizeof(void *), cfn->arity + 1)))
- err(1, "cfn_apply");
- if (! (arg_values = calloc(sizeof(void *), cfn->arity + 1)))
- err(1, "cfn_apply");
+ arg_pointers = calloc(cfn->arity + 1, sizeof(void *));
+ if (! arg_pointers) {
+ warn("cfn_apply: arg_pointers");
+ return NULL;
+ }
+ arg_values = calloc(cfn->arity + 1, sizeof(void *));
+ if (! arg_values) {
+ warn("cfn_apply: arg_values");
+ free(arg_pointers);
+ return NULL;
+ }
cfn_arg_types = cfn->arg_types;
a = args;
while (cfn_arg_types) {
@@ -71,21 +79,25 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
cfn_arg_types->tag.data.sym == sym_1("&result")) {
cfn_tag_init(&tmp2, cfn->result_type);
if (cfn->cif.rtype == &ffi_type_pointer) {
- arg_pointers[i] = tag_to_ffi_pointer(&tmp2, cfn->result_type);
+ if (! tag_to_ffi_pointer(&tmp2, cfn->result_type, arg_pointers + i))
+ goto ko;
arg_values[i] = &arg_pointers[i];
}
else
- arg_values[i] = tag_to_ffi_pointer(&tmp2, cfn->result_type);
+ if (! tag_to_ffi_pointer(&tmp2, cfn->result_type, arg_values + i))
+ goto ko;
}
else {
if (cfn->cif.arg_types[i] == &ffi_type_pointer) {
- arg_pointers[i] =
- tag_to_ffi_pointer(&a->tag, cfn_arg_types->tag.data.sym);
+ if (! tag_to_ffi_pointer(&a->tag, cfn_arg_types->tag.data.sym,
+ arg_pointers + i))
+ goto ko;
arg_values[i] = &arg_pointers[i];
}
else
- arg_values[i] =
- tag_to_ffi_pointer(&a->tag, cfn_arg_types->tag.data.sym);
+ if (! tag_to_ffi_pointer(&a->tag, cfn_arg_types->tag.data.sym,
+ arg_values + i))
+ goto ko;
a = list_next(a);
}
cfn_arg_types = list_next(cfn_arg_types);
@@ -107,6 +119,10 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
free(arg_pointers);
free(arg_values);
return dest;
+ ko:
+ free(arg_pointers);
+ free(arg_values);
+ return NULL;
}
void cfn_clean (s_cfn *cfn)
@@ -119,23 +135,32 @@ void cfn_clean (s_cfn *cfn)
s_cfn * cfn_init_copy (s_cfn *cfn, const s_cfn *src)
{
+ s_cfn tmp = {0};
assert(src);
assert(cfn);
- cfn->name = src->name;
- cfn->arg_result = src->arg_result;
- list_init_copy(&cfn->arg_types, (const s_list **) &src->arg_types);
- cfn->arity = src->arity;
- cfn->cif = src->cif;
+ tmp.name = src->name;
+ tmp.arg_result = src->arg_result;
+ if (! list_init_copy(&tmp.arg_types,
+ (const s_list * const *) &src->arg_types))
+ return NULL;
+ tmp.arity = src->arity;
+ tmp.cif = src->cif;
if (src->arity) {
- cfn->cif.arg_types = calloc(src->cif.nargs + 1,
- sizeof(ffi_type *));
- memcpy(cfn->cif.arg_types, src->cif.arg_types,
+ tmp.cif.arg_types = calloc(src->cif.nargs + 1, sizeof(ffi_type *));
+ if (! tmp.cif.arg_types) {
+ warn("cfn_init_copy: cif.arg_types");
+ assert(! "cfn_init_copy: cif.arg_types: failed to allocate memory");
+ list_delete_all(tmp.arg_types);
+ return NULL;
+ }
+ memcpy(tmp.cif.arg_types, src->cif.arg_types,
(src->cif.nargs + 1) * sizeof(ffi_type *));
}
- cfn->result_type = src->result_type;
- cfn->ptr = src->ptr;
- cfn->macro = src->macro;
- cfn->special_operator = src->special_operator;
+ tmp.result_type = src->result_type;
+ tmp.ptr = src->ptr;
+ tmp.macro = src->macro;
+ tmp.special_operator = src->special_operator;
+ *cfn = tmp;
return cfn;
}
@@ -166,6 +191,21 @@ s_cfn * cfn_init (s_cfn *cfn, const s_sym *name, s_list *arg_types,
return cfn;
}
+s_cfn * cfn_init_cast (s_cfn *cfn, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_CFN:
+ return cfn_init_copy(cfn, &tag->data.cfn);
+ default:
+ break;
+ }
+ err_write_1("cfn_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Cfn");
+ assert(! "cfn_init_cast: cannot cast to Cfn");
+ return NULL;
+}
+
s_cfn * cfn_link (s_cfn *cfn)
{
assert(cfn);
@@ -195,16 +235,13 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
ffi_type *result_ffi_type;
ffi_status status;
assert(cfn);
- if (! (result_ffi_type = sym_to_ffi_type(cfn->result_type, NULL))) {
- assert(! "cfn_prep_cif: sym_to_ffi_type");
- errx(1, "cfn_prep_cif: sym_to_ffi_type: %s",
- cfn->result_type->str.ptr.ps8);
+ if (! sym_to_ffi_type(cfn->result_type, NULL, &result_ffi_type))
return NULL;
- }
if (cfn->arity) {
- if (! (arg_ffi_type = calloc(sizeof(ffi_type *), cfn->arity + 1))) {
- assert(! "cfn_prep_cif: arg_ffi_type");
- err(1, "cfn_prep_cif: arg_ffi_type");
+ arg_ffi_type = calloc(cfn->arity + 1, sizeof(ffi_type *));
+ if (! arg_ffi_type) {
+ warn("cfn_prep_cif: arg_ffi_type: failed to allocate memory");
+ assert(! "cfn_prep_cif: arg_ffi_type: failed to allocate memory");
return NULL;
}
a = cfn->arg_types;
@@ -215,12 +252,11 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
errx(1, "cfn_prep_cif: invalid type: %s",
tag_type_to_string(a->tag.type));
}
- if (! (arg_ffi_type[i] = sym_to_ffi_type(a->tag.data.sym, result_ffi_type))) {
+ if (! sym_to_ffi_type(a->tag.data.sym, result_ffi_type, arg_ffi_type + i)) {
free(arg_ffi_type);
return NULL;
}
- if (a->tag.data.sym == sym_1("Result") ||
- a->tag.data.sym == sym_1("&result")) {
+ if (a->tag.data.sym == sym_1("Result")) {
cfn->arg_result = true;
arg_ffi_type[i] = &ffi_type_pointer;
result_ffi_type = &ffi_type_pointer;
diff --git a/libc3/character.c b/libc3/character.c
index 5655efc..0290562 100644
--- a/libc3/character.c
+++ b/libc3/character.c
@@ -10,9 +10,11 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include "character.h"
+#include "integer.h"
#include "str.h"
+#include "tag_type.h"
#include "ucd.h"
character character_1 (const s8 *p)
@@ -25,6 +27,34 @@ character character_1 (const s8 *p)
return c;
}
+character * character_init_cast (character *c, const s_tag *tag)
+{
+ assert(c);
+ assert(tag);
+ switch (tag->type) {
+ case TAG_CHARACTER: *c = tag->data.character; return c;
+ case TAG_F32: *c = (character) tag->data.f32; return c;
+ case TAG_F64: *c = (character) tag->data.f64; return c;
+ case TAG_INTEGER: *c = integer_to_u32(&tag->data.integer); return c;
+ case TAG_S8: *c = (character) tag->data.s8; return c;
+ case TAG_S16: *c = (character) tag->data.s16; return c;
+ case TAG_S32: *c = (character) tag->data.s32; return c;
+ case TAG_S64: *c = (character) tag->data.s64; return c;
+ case TAG_SW: *c = (character) tag->data.sw; return c;
+ case TAG_U8: *c = (character) tag->data.u8; return c;
+ case TAG_U16: *c = (character) tag->data.u16; return c;
+ case TAG_U32: *c = (character) tag->data.u32; return c;
+ case TAG_U64: *c = (character) tag->data.u64; return c;
+ case TAG_UW: *c = (character) tag->data.uw; return c;
+ default: break;
+ }
+ err_write_1("character_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Character");
+ assert(! "character_cast: cannot cast to Character");
+ return NULL;
+}
+
character * character_init_copy (character *c, const character *src)
{
assert(c);
diff --git a/libc3/env.c b/libc3/env.c
index 0533d4a..91abb54 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -128,7 +128,8 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
assert(! "env_eval_array: failed to allocate memory");
return false;
}
- init_cast = sym_to_init_cast(tmp.type);
+ if (! sym_to_init_cast(tmp.type, &init_cast))
+ goto ko;
data = tmp.data;
tag = tmp.tags;
i = 0;
@@ -684,7 +685,8 @@ bool env_eval_struct (s_env *env, const s_struct *s, s_tag *dest)
while (i < t->type.map.count) {
if (! env_eval_tag(env, s->tag + i, &tag))
goto ko;
- init_cast = tag_type_to_init_cast(tag.type);
+ if (! tag_type_to_init_cast(tag.type, &init_cast))
+ goto ko_tag;
if (tag.type != t->type.map.value[i].type && ! init_cast) {
warnx("env_eval_struct:"
" invalid type %s for key %s, expected %s.",
diff --git a/libc3/f32.c b/libc3/f32.c
index dac366f..f044402 100644
--- a/libc3/f32.c
+++ b/libc3/f32.c
@@ -87,7 +87,7 @@ f32 * f32_random (f32 *x)
{
u32 i;
const u32 max = (1 << 24) - 1;
- u32_random_uniform(max, &i);
+ u32_random_uniform(&i, max);
*x = (f32) i / max;
return x;
}
diff --git a/libc3/f64.c b/libc3/f64.c
index 5c4f31b..45e62dd 100644
--- a/libc3/f64.c
+++ b/libc3/f64.c
@@ -90,7 +90,7 @@ f64 * f64_random (f64 *x)
{
u64 i;
const u64 max = ((u64) 1 << 53) - 1;
- u64_random_uniform(max, &i);
+ u64_random_uniform(&i, max);
*x = (f64) i / max;
return x;
}
diff --git a/libc3/fact.c b/libc3/fact.c
index 5f9df74..b6063eb 100644
--- a/libc3/fact.c
+++ b/libc3/fact.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <err.h>
#include "buf.h"
#include "buf_inspect.h"
@@ -38,6 +38,21 @@ s_fact * fact_init (s_fact *fact, const s_tag *subject,
return fact;
}
+s_fact * fact_init_cast (s_fact *fact, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_FACT:
+ return fact_init_copy(fact, &tag->data.fact);
+ default:
+ break;
+ }
+ err_write_1("fact_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Fact");
+ assert(! "fact_init_cast: cannot cast to Fact");
+ return NULL;
+}
+
s_fact * fact_init_copy (s_fact *fact, const s_fact *src)
{
assert(src);
diff --git a/libc3/fn.c b/libc3/fn.c
index d345f6f..26d7040 100644
--- a/libc3/fn.c
+++ b/libc3/fn.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <err.h>
#include <stdlib.h>
#include <string.h>
@@ -22,6 +22,7 @@
#include "fn.h"
#include "fn_clause.h"
#include "list.h"
+#include "tag_type.h"
void fn_clean (s_fn *fn)
{
@@ -58,6 +59,21 @@ s_fn * fn_init_1 (s_fn *fn, s8 *p)
return fn;
}
+s_fn * fn_init_cast (s_fn *fn, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_FN:
+ return fn_init_copy(fn, &tag->data.fn);
+ default:
+ break;
+ }
+ err_write_1("fn_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Fn");
+ assert(! "fn_init_cast: cannot cast to Fn");
+ return NULL;
+}
+
s_fn * fn_init_copy (s_fn *fn, const s_fn *src)
{
fn_clause_copy(src->clauses, &fn->clauses);
diff --git a/libc3/hash.c b/libc3/hash.c
index 07f4b01..33826de 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -302,8 +302,9 @@ void hash_update_struct (t_hash *hash, const s_struct *s)
hash_update(hash, &s->type.map.count, sizeof(s->type.map.count));
while (i < s->type.map.count) {
hash_update_tag(hash, s->type.map.key + i);
- hash_update_value =
- tag_type_to_hash_update(s->type.map.value[i].type);
+ if (! tag_type_to_hash_update(s->type.map.value[i].type,
+ &hash_update_value))
+ exit(1);
hash_update_value(hash, (s8 *) s->data + s->type.offset[i]);
i++;
}
diff --git a/libc3/ident.c b/libc3/ident.c
index 12967f3..1e043ce 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -188,6 +188,22 @@ s_ident * ident_init_1 (s_ident *ident, const s8 *p)
return ident;
}
+s_ident * ident_init_cast (s_ident *ident, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_IDENT:
+ *ident = tag->data.ident;
+ return ident;
+ default:
+ break;
+ }
+ err_write_1("ident_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Ident");
+ assert(! "ident_init_cast: cannot cast to Ident");
+ return NULL;
+}
+
s_ident * ident_init_copy (s_ident *ident, const s_ident *src)
{
ident->module = src->module;
diff --git a/libc3/io.c b/libc3/io.c
index 41b6eb7..cab65fa 100644
--- a/libc3/io.c
+++ b/libc3/io.c
@@ -109,13 +109,15 @@ DEF_ERR_IO_INSPECT(fact, const s_fact *)
DEF_ERR_IO_INSPECT(fn_pattern, const s_list *)
DEF_ERR_IO_INSPECT(list, const s_list **)
DEF_ERR_IO_INSPECT(map, const s_map *)
-DEF_ERR_IO_INSPECT(str, const s_str *)
-DEF_ERR_IO_INSPECT(tag, const s_tag *)
DEF_ERR_IO_INSPECT(s8, const s8 *)
DEF_ERR_IO_INSPECT(s16, const s16 *)
DEF_ERR_IO_INSPECT(s32, const s32 *)
DEF_ERR_IO_INSPECT(s64, const s64 *)
+DEF_ERR_IO_INSPECT(str, const s_str *)
DEF_ERR_IO_INSPECT(sw, const sw *)
+DEF_ERR_IO_INSPECT(sym, const s_sym **)
+DEF_ERR_IO_INSPECT(tag, const s_tag *)
+DEF_ERR_IO_INSPECT(tuple, const s_tuple *)
DEF_ERR_IO_INSPECT(u8, const u8 *)
DEF_ERR_IO_INSPECT(u16, const u16 *)
DEF_ERR_IO_INSPECT(u32, const u32 *)
diff --git a/libc3/io.h b/libc3/io.h
index 620ee0f..71675b8 100644
--- a/libc3/io.h
+++ b/libc3/io.h
@@ -36,18 +36,29 @@ sw io_puts (const s8 *x);
sw io_write_1 (const s8 *x);
PROTOTYPES_ERR_IO_INSPECT(array, const s_array *);
+PROTOTYPES_ERR_IO_INSPECT(bool, const bool *);
+PROTOTYPES_ERR_IO_INSPECT(call, const s_call *);
+PROTOTYPES_ERR_IO_INSPECT(cfn, const s_cfn *);
+PROTOTYPES_ERR_IO_INSPECT(character, const character *);
+PROTOTYPES_ERR_IO_INSPECT(f32, const f32 *);
+PROTOTYPES_ERR_IO_INSPECT(f64, const f64 *);
PROTOTYPES_ERR_IO_INSPECT(fact, const s_fact *);
PROTOTYPES_ERR_IO_INSPECT(facts_spec, const p_facts_spec);
+PROTOTYPES_ERR_IO_INSPECT(fn, const s_fn *);
PROTOTYPES_ERR_IO_INSPECT(fn_pattern, const s_list *);
+PROTOTYPES_ERR_IO_INSPECT(ident, const s_ident *);
+PROTOTYPES_ERR_IO_INSPECT(integer, const s_integer *);
PROTOTYPES_ERR_IO_INSPECT(list, const s_list **);
PROTOTYPES_ERR_IO_INSPECT(map, const s_map *);
-PROTOTYPES_ERR_IO_INSPECT(str, const s_str *);
-PROTOTYPES_ERR_IO_INSPECT(tag, const s_tag *);
PROTOTYPES_ERR_IO_INSPECT(s8, const s8 *);
PROTOTYPES_ERR_IO_INSPECT(s16, const s16 *);
PROTOTYPES_ERR_IO_INSPECT(s32, const s32 *);
PROTOTYPES_ERR_IO_INSPECT(s64, const s64 *);
+PROTOTYPES_ERR_IO_INSPECT(str, const s_str *);
PROTOTYPES_ERR_IO_INSPECT(sw, const sw *);
+PROTOTYPES_ERR_IO_INSPECT(sym, const s_sym **);
+PROTOTYPES_ERR_IO_INSPECT(tag, const s_tag *);
+PROTOTYPES_ERR_IO_INSPECT(tuple, const s_tuple *);
PROTOTYPES_ERR_IO_INSPECT(u8, const u8 *);
PROTOTYPES_ERR_IO_INSPECT(u16, const u16 *);
PROTOTYPES_ERR_IO_INSPECT(u32, const u32 *);
diff --git a/libc3/list.c b/libc3/list.c
index e7fb81f..9484c87 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -38,16 +38,6 @@ void list_clean (s_list **list)
}
}
-s_list ** list_cast (const s_tag *tag, s_list **list)
-{
- assert(tag);
- if (tag->type == TAG_LIST) {
- list_init_copy(list, (const s_list **) &tag->data.list);
- return list;
- }
- return NULL;
-}
-
s_list * list_delete (s_list *list)
{
s_list *next = NULL;
@@ -84,8 +74,24 @@ s_list * list_init_1 (s_list *list, const s8 *p, s_list *next)
return list;
}
+s_list ** list_init_cast (s_list **list, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_LIST:
+ return list_init_copy(list,
+ (const s_list * const *) &tag->data.list);
+ default:
+ break;
+ }
+ err_write_1("list_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to List");
+ assert(! "list_init_cast: cannot cast to List");
+ return NULL;
+}
+
/* FIXME: does not work on circular lists */
-s_list ** list_init_copy (s_list **list, const s_list **src)
+s_list ** list_init_copy (s_list **list, const s_list * const *src)
{
s_list **i;
s_list *next;
@@ -262,41 +268,62 @@ s_list * list_new_str_1 (s8 *x_free, const s8 *x, s_list *next)
s_array * list_to_array (s_list *list, const s_sym *type,
s_array *dest)
{
- f_init_copy init_copy;
+ f_clean clean;
s8 *data;
void *data_list;
+ f_init_copy init_copy;
s_list *l;
uw len;
uw size;
+ s_array tmp = {0};
assert(list);
assert(dest);
len = list_length(list);
- size = sym_type_size(type);
- dest->dimension = 1;
- dest->type = type;
- if (! (dest->dimensions = calloc(1, sizeof(s_array_dimension)))) {
+ if (! sym_type_size(type, &size))
+ return NULL;
+ tmp.dimension = 1;
+ tmp.type = type;
+ if (! (tmp.dimensions = calloc(1, sizeof(s_array_dimension)))) {
err_puts("list_to_array: out of memory: 1");
assert(! "list_to_array: out of memory: 1");
return NULL;
}
- dest->count = len;
- dest->dimensions[0].count = len;
- dest->dimensions[0].item_size = size;
- dest->size = len * size;
- if (! (data = dest->data = calloc(len, size))) {
+ tmp.count = len;
+ tmp.dimensions[0].count = len;
+ tmp.dimensions[0].item_size = size;
+ tmp.size = len * size;
+ tmp.data = data = calloc(len, size);
+ if (! tmp.data) {
err_puts("list_to_array: out of memory: 2");
assert(! "list_to_array: out of memory: 2");
+ free(tmp.dimensions);
+ return NULL;
+ }
+ if (! sym_to_init_copy(type, &init_copy)) {
+ free(tmp.data);
+ free(tmp.dimensions);
return NULL;
}
- init_copy = sym_to_init_copy(type);
l = list;
while (l) {
- data_list = tag_to_pointer(&l->tag, type);
- init_copy(data, data_list);
+ if (! tag_to_pointer(&l->tag, type, &data_list) ||
+ ! data_list ||
+ ! init_copy(data, data_list))
+ goto ko;
data += size;
l = list_next(l);
}
return dest;
+ ko:
+ if (sym_to_clean(type, &clean) && clean) {
+ while (data > (s8 *) tmp.data) {
+ data -= size;
+ clean(data);
+ }
+ }
+ free(tmp.data);
+ free(tmp.dimensions);
+ return NULL;
}
s_list ** list_remove_void (s_list **list)
diff --git a/libc3/list.h b/libc3/list.h
index f7dbab2..e295843 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -29,7 +29,7 @@ void list_clean (s_list **list);
s_list * list_init (s_list *list, s_list *next);
s_list * list_init_1 (s_list *list, const s8 *p, s_list *next);
s_list ** list_init_cast (s_list **list, const s_tag *tag);
-s_list ** list_init_copy (s_list **list, const s_list **src);
+s_list ** list_init_copy (s_list **list, const s_list * const *src);
s_list * list_init_copy_tag (s_list *list, const s_tag *tag,
s_list *next);
s_list * list_init_eval (s_list *list, const s8 *p);
diff --git a/libc3/ptag.c b/libc3/ptag.c
index 944e042..da28f7b 100644
--- a/libc3/ptag.c
+++ b/libc3/ptag.c
@@ -10,9 +10,25 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <err.h>
#include "ptag.h"
+#include "tag_type.h"
+
+p_tag * ptag_init_cast (p_tag *ptag, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_PTAG:
+ return ptag_init_copy(ptag, &tag->data.ptag);
+ default:
+ break;
+ }
+ err_write_1("ptag_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Ptag");
+ assert(! "ptag_init_cast: cannot cast to Ptag");
+ return NULL;
+}
p_tag * ptag_init_copy (p_tag *dest, const p_tag *src)
{
diff --git a/libc3/ptr.c b/libc3/ptr.c
index 0306f59..9e8a66c 100644
--- a/libc3/ptr.c
+++ b/libc3/ptr.c
@@ -10,10 +10,12 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <err.h>
#include <stdlib.h>
+#include "integer.h"
#include "ptr.h"
+#include "tag_type.h"
void ptr_delete (u_ptr_w *ptr)
{
@@ -30,6 +32,34 @@ u_ptr_w * ptr_init (u_ptr_w *ptr, void *p)
return ptr;
}
+u_ptr_w * ptr_init_cast (u_ptr_w *p, const s_tag *tag)
+{
+ assert(tag);
+ assert(p);
+ switch (tag->type) {
+ case TAG_F32: p->p = (void *) ((uw) tag->data.f32); return p;
+ case TAG_F64: p->p = (void *) ((uw) tag->data.f64); return p;
+ case TAG_INTEGER:
+ p->p = (void *) integer_to_uw(&tag->data.integer); return p;
+ case TAG_PTR: p->p = tag->data.ptr.p; return p;
+ case TAG_PTR_FREE: p->p = tag->data.ptr_free.p; return p;
+ case TAG_S8: p->p = (void *) ((uw) tag->data.s8); return p;
+ case TAG_S16: p->p = (void *) ((uw) tag->data.s16); return p;
+ case TAG_S32: p->p = (void *) ((uw) tag->data.s32); return p;
+ case TAG_S64: p->p = (void *) ((uw) tag->data.s64); return p;
+ case TAG_SW: p->p = (void *) ((uw) tag->data.sw); return p;
+ case TAG_U8: p->p = (void *) ((uw) tag->data.u8); return p;
+ case TAG_U16: p->p = (void *) ((uw) tag->data.u16); return p;
+ case TAG_U32: p->p = (void *) ((uw) tag->data.u32); return p;
+ case TAG_U64: p->p = (void *) ((uw) tag->data.u64); return p;
+ case TAG_UW: p->p = (void *) ((uw) tag->data.uw); return p;
+ default: break;
+ }
+ warnx("ptr_cast: cannot cast %s to Ptr",
+ tag_type_to_string(tag->type));
+ return NULL;
+}
+
u_ptr_w * ptr_init_copy (u_ptr_w *ptr, const u_ptr_w *src)
{
u_ptr_w tmp = {0};
diff --git a/libc3/ptr_free.c b/libc3/ptr_free.c
index 1c758cc..2a2e4bf 100644
--- a/libc3/ptr_free.c
+++ b/libc3/ptr_free.c
@@ -17,27 +17,27 @@
#include "ptr_free.h"
#include "tag_type.h"
-u_ptr_w * ptr_free_cast (const s_tag *tag, u_ptr_w *dest)
+u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_tag *tag)
{
assert(tag);
- assert(dest);
+ assert(p);
switch (tag->type) {
- case TAG_F32: dest->p = (void *) ((uw) tag->data.f32); return dest;
- case TAG_F64: dest->p = (void *) ((uw) tag->data.f64); return dest;
+ case TAG_F32: p->p = (void *) ((uw) tag->data.f32); return p;
+ case TAG_F64: p->p = (void *) ((uw) tag->data.f64); return p;
case TAG_INTEGER:
- dest->p = (void *) integer_to_uw(&tag->data.integer); return dest;
- case TAG_PTR: dest->p = tag->data.ptr.p; return dest;
- case TAG_PTR_FREE: dest->p = tag->data.ptr_free.p; return dest;
- case TAG_S8: dest->p = (void *) ((uw) tag->data.s8); return dest;
- case TAG_S16: dest->p = (void *) ((uw) tag->data.s16); return dest;
- case TAG_S32: dest->p = (void *) ((uw) tag->data.s32); return dest;
- case TAG_S64: dest->p = (void *) ((uw) tag->data.s64); return dest;
- case TAG_SW: dest->p = (void *) ((uw) tag->data.sw); return dest;
- case TAG_U8: dest->p = (void *) ((uw) tag->data.u8); return dest;
- case TAG_U16: dest->p = (void *) ((uw) tag->data.u16); return dest;
- case TAG_U32: dest->p = (void *) ((uw) tag->data.u32); return dest;
- case TAG_U64: dest->p = (void *) ((uw) tag->data.u64); return dest;
- case TAG_UW: dest->p = (void *) ((uw) tag->data.uw); return dest;
+ p->p = (void *) integer_to_uw(&tag->data.integer); return p;
+ case TAG_PTR: p->p = tag->data.ptr.p; return p;
+ case TAG_PTR_FREE: p->p = tag->data.ptr_free.p; return p;
+ case TAG_S8: p->p = (void *) ((uw) tag->data.s8); return p;
+ case TAG_S16: p->p = (void *) ((uw) tag->data.s16); return p;
+ case TAG_S32: p->p = (void *) ((uw) tag->data.s32); return p;
+ case TAG_S64: p->p = (void *) ((uw) tag->data.s64); return p;
+ case TAG_SW: p->p = (void *) ((uw) tag->data.sw); return p;
+ case TAG_U8: p->p = (void *) ((uw) tag->data.u8); return p;
+ case TAG_U16: p->p = (void *) ((uw) tag->data.u16); return p;
+ case TAG_U32: p->p = (void *) ((uw) tag->data.u32); return p;
+ case TAG_U64: p->p = (void *) ((uw) tag->data.u64); return p;
+ case TAG_UW: p->p = (void *) ((uw) tag->data.uw); return p;
default: break;
}
warnx("ptr_free_cast: cannot cast %s to PtrFree",
diff --git a/libc3/quote.c b/libc3/quote.c
index 21c1bbf..0f8f508 100644
--- a/libc3/quote.c
+++ b/libc3/quote.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <stdlib.h>
#include "quote.h"
#include "tag.h"
@@ -27,6 +27,21 @@ s_quote * quote_init (s_quote *quote, const s_tag *tag)
return quote;
}
+s_quote * quote_init_cast (s_quote *quote, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_QUOTE:
+ return quote_init_copy(quote, &tag->data.quote);
+ default:
+ break;
+ }
+ err_write_1("quote_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Quote");
+ assert(! "quote_init_cast: cannot cast to Quote");
+ return NULL;
+}
+
s_quote * quote_init_copy (s_quote *quote, const s_quote *src)
{
quote->tag = tag_new_copy(src->tag);
diff --git a/libc3/s.c.in b/libc3/s.c.in
index 65bf0fa..519a4fd 100644
--- a/libc3/s.c.in
+++ b/libc3/s.c.in
@@ -19,72 +19,73 @@
#include "tag_type.h"
#include "s_bits$.h"
-s_bits$ * s_bits$_cast (s_tag *tag, s_bits$ *dest)
+s_bits$ * s_bits$_init_cast (s_bits$ *s, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *s = tag->data.bool ? 1 : 0;
+ return s;
case TAG_CHARACTER:
- *dest = (s_bits$) tag->data.character;
- return dest;
+ *s = (s_bits$) tag->data.character;
+ return s;
case TAG_F32:
- *dest = (s_bits$) tag->data.f32;
- return dest;
+ *s = (s_bits$) tag->data.f32;
+ return s;
case TAG_F64:
- *dest = (s_bits$) tag->data.f64;
- return dest;
+ *s = (s_bits$) tag->data.f64;
+ return s;
case TAG_INTEGER:
- *dest = integer_to_s_bits$(&tag->data.integer);
- return dest;
+ *s = integer_to_s_bits$(&tag->data.integer);
+ return s;
case TAG_SW:
- *dest = (s_bits$) tag->data.sw;
- return dest;
+ *s = (s_bits$) tag->data.sw;
+ return s;
case TAG_S64:
- *dest = (s_bits$) tag->data.s64;
- return dest;
+ *s = (s_bits$) tag->data.s64;
+ return s;
case TAG_S32:
- *dest = (s_bits$) tag->data.s32;
- return dest;
+ *s = (s_bits$) tag->data.s32;
+ return s;
case TAG_S16:
- *dest = (s_bits$) tag->data.s16;
- return dest;
+ *s = (s_bits$) tag->data.s16;
+ return s;
case TAG_S8:
- *dest = (s_bits$) tag->data.s8;
- return dest;
+ *s = (s_bits$) tag->data.s8;
+ return s;
case TAG_U8:
- *dest = (s_bits$) tag->data.u8;
- return dest;
+ *s = (s_bits$) tag->data.u8;
+ return s;
case TAG_U16:
- *dest = (s_bits$) tag->data.u16;
- return dest;
+ *s = (s_bits$) tag->data.u16;
+ return s;
case TAG_U32:
- *dest = (s_bits$) tag->data.u32;
- return dest;
+ *s = (s_bits$) tag->data.u32;
+ return s;
case TAG_U64:
- *dest = (s_bits$) tag->data.u64;
- return dest;
+ *s = (s_bits$) tag->data.u64;
+ return s;
case TAG_UW:
- *dest = (s_bits$) tag->data.uw;
- return dest;
+ *s = (s_bits$) tag->data.uw;
+ return s;
default:
break;
}
- errx(1, "s_bits$_cast: cannot cast %s to s_bits$",
- tag_type_to_string(tag->type));
- return 0;
+ warnx("s_bits$_cast: cannot cast %s to s_bits$",
+ tag_type_to_string(tag->type));
+ assert(! "s_bits$_cast: cannot cast to s_bits$");
+ return NULL;
}
-s_bits$ * s_bits$_init_copy (s_bits$ *dest, const s_bits$ *src)
+s_bits$ * s_bits$_init_copy (s_bits$ *s, const s_bits$ *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(s);
+ *s = *src;
+ return s;
}
-s_bits$ * s_bits$_random (s_bits$ *dest)
+s_bits$ * s_bits$_random (s_bits$ *s)
{
- arc4random_buf(dest, sizeof(s_bits$));
- return dest;
+ arc4random_buf(s, sizeof(s_bits$));
+ return s;
}
diff --git a/libc3/s.h.in b/libc3/s.h.in
index 6367b2d..f023cfb 100644
--- a/libc3/s.h.in
+++ b/libc3/s.h.in
@@ -16,8 +16,8 @@
#include "types.h"
-s_bits$ * s_bits$_init_cast (s_bits$ *dest, const s_tag *tag);
-s_bits$ * s_bits$_init_copy (s_bits$ *dest, const s_bits$ *src);
-s_bits$ * s_bits$_random (s_bits$ *dest);
+s_bits$ * s_bits$_init_cast (s_bits$ *s, const s_tag *tag);
+s_bits$ * s_bits$_init_copy (s_bits$ *s, const s_bits$ *src);
+s_bits$ * s_bits$_random (s_bits$ *s);
#endif /* LIBC3_S_BITS$_H */
diff --git a/libc3/s16.c b/libc3/s16.c
index da1e46c..276a988 100644
--- a/libc3/s16.c
+++ b/libc3/s16.c
@@ -19,72 +19,73 @@
#include "tag_type.h"
#include "s16.h"
-s16 * s16_cast (s_tag *tag, s16 *dest)
+s16 * s16_init_cast (s16 *s, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *s = tag->data.bool ? 1 : 0;
+ return s;
case TAG_CHARACTER:
- *dest = (s16) tag->data.character;
- return dest;
+ *s = (s16) tag->data.character;
+ return s;
case TAG_F32:
- *dest = (s16) tag->data.f32;
- return dest;
+ *s = (s16) tag->data.f32;
+ return s;
case TAG_F64:
- *dest = (s16) tag->data.f64;
- return dest;
+ *s = (s16) tag->data.f64;
+ return s;
case TAG_INTEGER:
- *dest = integer_to_s16(&tag->data.integer);
- return dest;
+ *s = integer_to_s16(&tag->data.integer);
+ return s;
case TAG_SW:
- *dest = (s16) tag->data.sw;
- return dest;
+ *s = (s16) tag->data.sw;
+ return s;
case TAG_S64:
- *dest = (s16) tag->data.s64;
- return dest;
+ *s = (s16) tag->data.s64;
+ return s;
case TAG_S32:
- *dest = (s16) tag->data.s32;
- return dest;
+ *s = (s16) tag->data.s32;
+ return s;
case TAG_S16:
- *dest = (s16) tag->data.s16;
- return dest;
+ *s = (s16) tag->data.s16;
+ return s;
case TAG_S8:
- *dest = (s16) tag->data.s8;
- return dest;
+ *s = (s16) tag->data.s8;
+ return s;
case TAG_U8:
- *dest = (s16) tag->data.u8;
- return dest;
+ *s = (s16) tag->data.u8;
+ return s;
case TAG_U16:
- *dest = (s16) tag->data.u16;
- return dest;
+ *s = (s16) tag->data.u16;
+ return s;
case TAG_U32:
- *dest = (s16) tag->data.u32;
- return dest;
+ *s = (s16) tag->data.u32;
+ return s;
case TAG_U64:
- *dest = (s16) tag->data.u64;
- return dest;
+ *s = (s16) tag->data.u64;
+ return s;
case TAG_UW:
- *dest = (s16) tag->data.uw;
- return dest;
+ *s = (s16) tag->data.uw;
+ return s;
default:
break;
}
- errx(1, "s16_cast: cannot cast %s to s16",
- tag_type_to_string(tag->type));
- return 0;
+ warnx("s16_cast: cannot cast %s to s16",
+ tag_type_to_string(tag->type));
+ assert(! "s16_cast: cannot cast to s16");
+ return NULL;
}
-s16 * s16_init_copy (s16 *dest, const s16 *src)
+s16 * s16_init_copy (s16 *s, const s16 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(s);
+ *s = *src;
+ return s;
}
-s16 * s16_random (s16 *dest)
+s16 * s16_random (s16 *s)
{
- arc4random_buf(dest, sizeof(s16));
- return dest;
+ arc4random_buf(s, sizeof(s16));
+ return s;
}
diff --git a/libc3/s16.h b/libc3/s16.h
index a146866..3b82ff9 100644
--- a/libc3/s16.h
+++ b/libc3/s16.h
@@ -16,8 +16,8 @@
#include "types.h"
-s16 * s16_init_cast (s16 *dest, const s_tag *tag);
-s16 * s16_init_copy (s16 *dest, const s16 *src);
-s16 * s16_random (s16 *dest);
+s16 * s16_init_cast (s16 *s, const s_tag *tag);
+s16 * s16_init_copy (s16 *s, const s16 *src);
+s16 * s16_random (s16 *s);
#endif /* LIBC3_S16_H */
diff --git a/libc3/s32.c b/libc3/s32.c
index 31bc407..a17163f 100644
--- a/libc3/s32.c
+++ b/libc3/s32.c
@@ -19,72 +19,73 @@
#include "tag_type.h"
#include "s32.h"
-s32 * s32_cast (s_tag *tag, s32 *dest)
+s32 * s32_init_cast (s32 *s, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *s = tag->data.bool ? 1 : 0;
+ return s;
case TAG_CHARACTER:
- *dest = (s32) tag->data.character;
- return dest;
+ *s = (s32) tag->data.character;
+ return s;
case TAG_F32:
- *dest = (s32) tag->data.f32;
- return dest;
+ *s = (s32) tag->data.f32;
+ return s;
case TAG_F64:
- *dest = (s32) tag->data.f64;
- return dest;
+ *s = (s32) tag->data.f64;
+ return s;
case TAG_INTEGER:
- *dest = integer_to_s32(&tag->data.integer);
- return dest;
+ *s = integer_to_s32(&tag->data.integer);
+ return s;
case TAG_SW:
- *dest = (s32) tag->data.sw;
- return dest;
+ *s = (s32) tag->data.sw;
+ return s;
case TAG_S64:
- *dest = (s32) tag->data.s64;
- return dest;
+ *s = (s32) tag->data.s64;
+ return s;
case TAG_S32:
- *dest = (s32) tag->data.s32;
- return dest;
+ *s = (s32) tag->data.s32;
+ return s;
case TAG_S16:
- *dest = (s32) tag->data.s16;
- return dest;
+ *s = (s32) tag->data.s16;
+ return s;
case TAG_S8:
- *dest = (s32) tag->data.s8;
- return dest;
+ *s = (s32) tag->data.s8;
+ return s;
case TAG_U8:
- *dest = (s32) tag->data.u8;
- return dest;
+ *s = (s32) tag->data.u8;
+ return s;
case TAG_U16:
- *dest = (s32) tag->data.u16;
- return dest;
+ *s = (s32) tag->data.u16;
+ return s;
case TAG_U32:
- *dest = (s32) tag->data.u32;
- return dest;
+ *s = (s32) tag->data.u32;
+ return s;
case TAG_U64:
- *dest = (s32) tag->data.u64;
- return dest;
+ *s = (s32) tag->data.u64;
+ return s;
case TAG_UW:
- *dest = (s32) tag->data.uw;
- return dest;
+ *s = (s32) tag->data.uw;
+ return s;
default:
break;
}
- errx(1, "s32_cast: cannot cast %s to s32",
- tag_type_to_string(tag->type));
- return 0;
+ warnx("s32_cast: cannot cast %s to s32",
+ tag_type_to_string(tag->type));
+ assert(! "s32_cast: cannot cast to s32");
+ return NULL;
}
-s32 * s32_init_copy (s32 *dest, const s32 *src)
+s32 * s32_init_copy (s32 *s, const s32 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(s);
+ *s = *src;
+ return s;
}
-s32 * s32_random (s32 *dest)
+s32 * s32_random (s32 *s)
{
- arc4random_buf(dest, sizeof(s32));
- return dest;
+ arc4random_buf(s, sizeof(s32));
+ return s;
}
diff --git a/libc3/s32.h b/libc3/s32.h
index 434b2b4..24649d0 100644
--- a/libc3/s32.h
+++ b/libc3/s32.h
@@ -16,8 +16,8 @@
#include "types.h"
-s32 * s32_init_cast (s32 *dest, const s_tag *tag);
-s32 * s32_init_copy (s32 *dest, const s32 *src);
-s32 * s32_random (s32 *dest);
+s32 * s32_init_cast (s32 *s, const s_tag *tag);
+s32 * s32_init_copy (s32 *s, const s32 *src);
+s32 * s32_random (s32 *s);
#endif /* LIBC3_S32_H */
diff --git a/libc3/s64.c b/libc3/s64.c
index 668d0ac..0fdf730 100644
--- a/libc3/s64.c
+++ b/libc3/s64.c
@@ -19,72 +19,73 @@
#include "tag_type.h"
#include "s64.h"
-s64 * s64_cast (s_tag *tag, s64 *dest)
+s64 * s64_init_cast (s64 *s, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *s = tag->data.bool ? 1 : 0;
+ return s;
case TAG_CHARACTER:
- *dest = (s64) tag->data.character;
- return dest;
+ *s = (s64) tag->data.character;
+ return s;
case TAG_F32:
- *dest = (s64) tag->data.f32;
- return dest;
+ *s = (s64) tag->data.f32;
+ return s;
case TAG_F64:
- *dest = (s64) tag->data.f64;
- return dest;
+ *s = (s64) tag->data.f64;
+ return s;
case TAG_INTEGER:
- *dest = integer_to_s64(&tag->data.integer);
- return dest;
+ *s = integer_to_s64(&tag->data.integer);
+ return s;
case TAG_SW:
- *dest = (s64) tag->data.sw;
- return dest;
+ *s = (s64) tag->data.sw;
+ return s;
case TAG_S64:
- *dest = (s64) tag->data.s64;
- return dest;
+ *s = (s64) tag->data.s64;
+ return s;
case TAG_S32:
- *dest = (s64) tag->data.s32;
- return dest;
+ *s = (s64) tag->data.s32;
+ return s;
case TAG_S16:
- *dest = (s64) tag->data.s16;
- return dest;
+ *s = (s64) tag->data.s16;
+ return s;
case TAG_S8:
- *dest = (s64) tag->data.s8;
- return dest;
+ *s = (s64) tag->data.s8;
+ return s;
case TAG_U8:
- *dest = (s64) tag->data.u8;
- return dest;
+ *s = (s64) tag->data.u8;
+ return s;
case TAG_U16:
- *dest = (s64) tag->data.u16;
- return dest;
+ *s = (s64) tag->data.u16;
+ return s;
case TAG_U32:
- *dest = (s64) tag->data.u32;
- return dest;
+ *s = (s64) tag->data.u32;
+ return s;
case TAG_U64:
- *dest = (s64) tag->data.u64;
- return dest;
+ *s = (s64) tag->data.u64;
+ return s;
case TAG_UW:
- *dest = (s64) tag->data.uw;
- return dest;
+ *s = (s64) tag->data.uw;
+ return s;
default:
break;
}
- errx(1, "s64_cast: cannot cast %s to s64",
- tag_type_to_string(tag->type));
- return 0;
+ warnx("s64_cast: cannot cast %s to s64",
+ tag_type_to_string(tag->type));
+ assert(! "s64_cast: cannot cast to s64");
+ return NULL;
}
-s64 * s64_init_copy (s64 *dest, const s64 *src)
+s64 * s64_init_copy (s64 *s, const s64 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(s);
+ *s = *src;
+ return s;
}
-s64 * s64_random (s64 *dest)
+s64 * s64_random (s64 *s)
{
- arc4random_buf(dest, sizeof(s64));
- return dest;
+ arc4random_buf(s, sizeof(s64));
+ return s;
}
diff --git a/libc3/s64.h b/libc3/s64.h
index 46ac92c..4266e8c 100644
--- a/libc3/s64.h
+++ b/libc3/s64.h
@@ -16,8 +16,8 @@
#include "types.h"
-s64 * s64_init_cast (s64 *dest, const s_tag *tag);
-s64 * s64_init_copy (s64 *dest, const s64 *src);
-s64 * s64_random (s64 *dest);
+s64 * s64_init_cast (s64 *s, const s_tag *tag);
+s64 * s64_init_copy (s64 *s, const s64 *src);
+s64 * s64_random (s64 *s);
#endif /* LIBC3_S64_H */
diff --git a/libc3/s8.c b/libc3/s8.c
index eb7ec40..543ad14 100644
--- a/libc3/s8.c
+++ b/libc3/s8.c
@@ -19,72 +19,73 @@
#include "tag_type.h"
#include "s8.h"
-s8 * s8_cast (s_tag *tag, s8 *dest)
+s8 * s8_init_cast (s8 *s, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *s = tag->data.bool ? 1 : 0;
+ return s;
case TAG_CHARACTER:
- *dest = (s8) tag->data.character;
- return dest;
+ *s = (s8) tag->data.character;
+ return s;
case TAG_F32:
- *dest = (s8) tag->data.f32;
- return dest;
+ *s = (s8) tag->data.f32;
+ return s;
case TAG_F64:
- *dest = (s8) tag->data.f64;
- return dest;
+ *s = (s8) tag->data.f64;
+ return s;
case TAG_INTEGER:
- *dest = integer_to_s8(&tag->data.integer);
- return dest;
+ *s = integer_to_s8(&tag->data.integer);
+ return s;
case TAG_SW:
- *dest = (s8) tag->data.sw;
- return dest;
+ *s = (s8) tag->data.sw;
+ return s;
case TAG_S64:
- *dest = (s8) tag->data.s64;
- return dest;
+ *s = (s8) tag->data.s64;
+ return s;
case TAG_S32:
- *dest = (s8) tag->data.s32;
- return dest;
+ *s = (s8) tag->data.s32;
+ return s;
case TAG_S16:
- *dest = (s8) tag->data.s16;
- return dest;
+ *s = (s8) tag->data.s16;
+ return s;
case TAG_S8:
- *dest = (s8) tag->data.s8;
- return dest;
+ *s = (s8) tag->data.s8;
+ return s;
case TAG_U8:
- *dest = (s8) tag->data.u8;
- return dest;
+ *s = (s8) tag->data.u8;
+ return s;
case TAG_U16:
- *dest = (s8) tag->data.u16;
- return dest;
+ *s = (s8) tag->data.u16;
+ return s;
case TAG_U32:
- *dest = (s8) tag->data.u32;
- return dest;
+ *s = (s8) tag->data.u32;
+ return s;
case TAG_U64:
- *dest = (s8) tag->data.u64;
- return dest;
+ *s = (s8) tag->data.u64;
+ return s;
case TAG_UW:
- *dest = (s8) tag->data.uw;
- return dest;
+ *s = (s8) tag->data.uw;
+ return s;
default:
break;
}
- errx(1, "s8_cast: cannot cast %s to s8",
- tag_type_to_string(tag->type));
- return 0;
+ warnx("s8_cast: cannot cast %s to s8",
+ tag_type_to_string(tag->type));
+ assert(! "s8_cast: cannot cast to s8");
+ return NULL;
}
-s8 * s8_init_copy (s8 *dest, const s8 *src)
+s8 * s8_init_copy (s8 *s, const s8 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(s);
+ *s = *src;
+ return s;
}
-s8 * s8_random (s8 *dest)
+s8 * s8_random (s8 *s)
{
- arc4random_buf(dest, sizeof(s8));
- return dest;
+ arc4random_buf(s, sizeof(s8));
+ return s;
}
diff --git a/libc3/s8.h b/libc3/s8.h
index 7c84127..c8a1adb 100644
--- a/libc3/s8.h
+++ b/libc3/s8.h
@@ -16,8 +16,8 @@
#include "types.h"
-s8 * s8_init_cast (s8 *dest, const s_tag *tag);
-s8 * s8_init_copy (s8 *dest, const s8 *src);
-s8 * s8_random (s8 *dest);
+s8 * s8_init_cast (s8 *s, const s_tag *tag);
+s8 * s8_init_copy (s8 *s, const s8 *src);
+s8 * s8_random (s8 *s);
#endif /* LIBC3_S8_H */
diff --git a/libc3/str.c b/libc3/str.c
index 02629cb..6dffba0 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -10,7 +10,7 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#include <assert.h>
+#include "assert.h"
#include <err.h>
#include <stdarg.h>
#include <stdio.h>
@@ -22,6 +22,7 @@
#include "ident.h"
#include "str.h"
#include "sym.h"
+#include "tag_type.h"
sw str_character (const s_str *str, uw position, character *dest)
{
@@ -124,6 +125,25 @@ s_str * str_init_alloc (s_str *str, uw size, const s8 *p)
return str;
}
+s_str * str_init_cast (s_str *str, const s_tag *tag)
+{
+ assert(str);
+ assert(tag);
+ switch (tag->type) {
+ case TAG_STR:
+ return str_init_copy(str, &tag->data.str);
+ case TAG_SYM:
+ return str_init_copy(str, &tag->data.sym->str);
+ default:
+ break;
+ }
+ err_write_1("str_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Str");
+ assert(! "str_init_cast: cannot cast to Str");
+ return NULL;
+}
+
s_str * str_init_copy (s_str *str, const s_str *src)
{
assert(str);
diff --git a/libc3/struct.c b/libc3/struct.c
index 63a7e73..0118cb9 100644
--- a/libc3/struct.c
+++ b/libc3/struct.c
@@ -51,12 +51,11 @@ void struct_clean (s_struct *s)
if (data) {
i = 0;
while (i < s->type.map.count) {
- if (tag_type(s->type.map.value + i, &sym)) {
- clean = sym_to_clean(sym);
- if (clean)
- clean(data + s->type.offset[i]);
- i++;
- }
+ if (tag_type(s->type.map.value + i, &sym) &&
+ sym_to_clean(sym, &clean) &&
+ clean)
+ clean(data + s->type.offset[i]);
+ i++;
}
if (s->free_data)
free(data);
@@ -120,9 +119,13 @@ s_struct * struct_init_cast (s_struct *s, const s_tag *tag)
{
assert(s);
assert(tag);
- if (tag->type == TAG_STRUCT)
+ switch (tag->type) {
+ case TAG_STRUCT:
return struct_init_copy(s, &tag->data.struct_);
- warnx("struct_init_cast: cannot cast %s to struct",
+ default:
+ break;
+ }
+ warnx("struct_init_cast: cannot cast %s to Struct",
tag_type_to_string(tag->type));
return NULL;
}
@@ -144,17 +147,20 @@ s_struct * struct_init_copy (s_struct *s, const s_struct *src)
i = 0;
while (i < tmp.type.map.count) {
if (tag_type(tmp.type.map.value + i, &sym)) {
- init_copy = sym_to_init_copy(sym);
+ if (! sym_to_init_copy(sym, &init_copy))
+ goto ko;
if (init_copy) {
if (! init_copy((s8 *) tmp.data + tmp.type.offset[i],
(s8 *) src->data + tmp.type.offset[i]))
goto ko;
}
else {
- size = tag_size(tmp.type.map.value + i);
- memcpy((s8 *) tmp.data + tmp.type.offset[i],
- (s8 *) src->data + tmp.type.offset[i],
- size);
+ if (! tag_size(tmp.type.map.value + i, &size))
+ goto ko;
+ if (size)
+ memcpy((s8 *) tmp.data + tmp.type.offset[i],
+ (s8 *) src->data + tmp.type.offset[i],
+ size);
}
}
i++;
@@ -300,6 +306,7 @@ s_struct * struct_set (s_struct *s, const s_sym *key,
const void *data_src;
uw i;
f_init_copy init_copy;
+ uw size;
e_tag_type type;
assert(s);
assert(s->type.map.count);
@@ -310,14 +317,25 @@ s_struct * struct_set (s_struct *s, const s_sym *key,
if (s->type.map.key[i].type == TAG_SYM &&
s->type.map.key[i].data.sym == key) {
type = s->type.map.value[i].type;
- clean = tag_type_to_clean(type);
- init_copy = tag_type_to_init_copy(type);
+ if (! tag_type_to_clean(type, &clean) ||
+ ! tag_type_to_init_copy(type, &init_copy))
+ return NULL;
data = (s8 *) s->data + s->type.offset[i];
- clean(data);
- data_src = tag_to_const_pointer(value, tag_type_to_sym(type));
- if (! init_copy(data, data_src))
+ if (! tag_to_const_pointer(value, tag_type_to_sym(type), &data_src))
return NULL;
- return s;
+ if (clean)
+ clean(data);
+ if (init_copy) {
+ if (! init_copy(data, data_src))
+ return NULL;
+ return s;
+ }
+ else {
+ if (! tag_size(s->type.map.value + i, &size))
+ return NULL;
+ if (size)
+ memcpy((s8 *) data + s->type.offset[i], data_src, size);
+ }
}
i++;
}
diff --git a/libc3/struct_type.c b/libc3/struct_type.c
index 1f93dcb..a4c0858 100644
--- a/libc3/struct_type.c
+++ b/libc3/struct_type.c
@@ -46,6 +46,7 @@ s_struct_type * struct_type_init (s_struct_type *st, const s_sym *module,
uw offset;
const s_list *s;
uw size;
+ const s_tuple *tuple;
assert(st);
assert(module);
assert(spec);
@@ -69,9 +70,14 @@ s_struct_type * struct_type_init (s_struct_type *st, const s_sym *module,
free(st->offset);
return NULL;
}
- tag_init_copy(st->map.key + i, s->tag.data.tuple.tag + 0);
- tag_init_copy(st->map.value + i, s->tag.data.tuple.tag + 1);
- size = tag_size(st->map.value + i);
+ tuple = &s->tag.data.tuple;
+ if (! tag_size(tuple->tag + 1, &size)) {
+ map_clean(&st->map);
+ free(st->offset);
+ return NULL;
+ }
+ tag_init_copy(st->map.key + i, tuple->tag + 0);
+ tag_init_copy(st->map.value + i, tuple->tag + 1);
offset = struct_type_padding(offset, size);
st->offset[i] = offset;
offset += size;
diff --git a/libc3/sw.c b/libc3/sw.c
index ee74817..a3a8833 100644
--- a/libc3/sw.c
+++ b/libc3/sw.c
@@ -19,72 +19,73 @@
#include "tag_type.h"
#include "sw.h"
-sw * sw_cast (s_tag *tag, sw *dest)
+sw * sw_init_cast (sw *s, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *s = tag->data.bool ? 1 : 0;
+ return s;
case TAG_CHARACTER:
- *dest = (sw) tag->data.character;
- return dest;
+ *s = (sw) tag->data.character;
+ return s;
case TAG_F32:
- *dest = (sw) tag->data.f32;
- return dest;
+ *s = (sw) tag->data.f32;
+ return s;
case TAG_F64:
- *dest = (sw) tag->data.f64;
- return dest;
+ *s = (sw) tag->data.f64;
+ return s;
case TAG_INTEGER:
- *dest = integer_to_sw(&tag->data.integer);
- return dest;
+ *s = integer_to_sw(&tag->data.integer);
+ return s;
case TAG_SW:
- *dest = (sw) tag->data.sw;
- return dest;
+ *s = (sw) tag->data.sw;
+ return s;
case TAG_S64:
- *dest = (sw) tag->data.s64;
- return dest;
+ *s = (sw) tag->data.s64;
+ return s;
case TAG_S32:
- *dest = (sw) tag->data.s32;
- return dest;
+ *s = (sw) tag->data.s32;
+ return s;
case TAG_S16:
- *dest = (sw) tag->data.s16;
- return dest;
+ *s = (sw) tag->data.s16;
+ return s;
case TAG_S8:
- *dest = (sw) tag->data.s8;
- return dest;
+ *s = (sw) tag->data.s8;
+ return s;
case TAG_U8:
- *dest = (sw) tag->data.u8;
- return dest;
+ *s = (sw) tag->data.u8;
+ return s;
case TAG_U16:
- *dest = (sw) tag->data.u16;
- return dest;
+ *s = (sw) tag->data.u16;
+ return s;
case TAG_U32:
- *dest = (sw) tag->data.u32;
- return dest;
+ *s = (sw) tag->data.u32;
+ return s;
case TAG_U64:
- *dest = (sw) tag->data.u64;
- return dest;
+ *s = (sw) tag->data.u64;
+ return s;
case TAG_UW:
- *dest = (sw) tag->data.uw;
- return dest;
+ *s = (sw) tag->data.uw;
+ return s;
default:
break;
}
- errx(1, "sw_cast: cannot cast %s to sw",
- tag_type_to_string(tag->type));
- return 0;
+ warnx("sw_cast: cannot cast %s to sw",
+ tag_type_to_string(tag->type));
+ assert(! "sw_cast: cannot cast to sw");
+ return NULL;
}
-sw * sw_init_copy (sw *dest, const sw *src)
+sw * sw_init_copy (sw *s, const sw *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(s);
+ *s = *src;
+ return s;
}
-sw * sw_random (sw *dest)
+sw * sw_random (sw *s)
{
- arc4random_buf(dest, sizeof(sw));
- return dest;
+ arc4random_buf(s, sizeof(sw));
+ return s;
}
diff --git a/libc3/sw.h b/libc3/sw.h
index cb7cb11..df80d6e 100644
--- a/libc3/sw.h
+++ b/libc3/sw.h
@@ -16,8 +16,8 @@
#include "types.h"
-sw * sw_init_cast (sw *dest, const s_tag *tag);
-sw * sw_init_copy (sw *dest, const sw *src);
-sw * sw_random (sw *dest);
+sw * sw_init_cast (sw *s, const s_tag *tag);
+sw * sw_init_copy (sw *s, const sw *src);
+sw * sw_random (sw *s);
#endif /* LIBC3_SW_H */
diff --git a/libc3/sym.c b/libc3/sym.c
index fda45ae..60329d2 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -108,6 +108,25 @@ const s_sym ** sym_init_1 (const s_sym **sym, const s8 *p)
return sym;
}
+const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *tag)
+{
+ assert(sym);
+ assert(tag);
+ switch (tag->type) {
+ case TAG_STR:
+ return sym_init_str(sym, &tag->data.str);
+ case TAG_SYM:
+ return sym_init_copy(sym, &tag->data.sym);
+ default:
+ break;
+ }
+ err_write_1("sym_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Sym");
+ assert(! "sym_init_cast: cannot cast to Sym");
+ return NULL;
+}
+
const s_sym ** sym_init_copy (const s_sym **sym,
const s_sym * const *src)
{
@@ -117,17 +136,29 @@ const s_sym ** sym_init_copy (const s_sym **sym,
return sym;
}
+const s_sym ** sym_init_str (const s_sym **sym, const s_str *src)
+{
+ const s_sym *tmp;
+ tmp = sym_find(src);
+ if (! tmp)
+ tmp = sym_new(src);
+ if (! tmp)
+ return NULL;
+ *sym = tmp;
+ return sym;
+}
+
s_str * sym_inspect (const s_sym *sym, s_str *dest)
{
sw size;
s_buf tmp;
- size = buf_inspect_sym_size(sym);
+ size = buf_inspect_sym_size(&sym);
if (size < 0) {
assert(! "error");
return NULL;
}
buf_init_alloc(&tmp, size);
- buf_inspect_sym(&tmp, sym);
+ buf_inspect_sym(&tmp, &sym);
assert(tmp.wpos == tmp.size);
return buf_to_str(&tmp, dest);
}
@@ -178,411 +209,765 @@ const s_sym * sym_new (const s_str *src)
return sym;
}
-f_buf_inspect sym_to_buf_inspect (const s_sym *type)
+bool sym_to_buf_inspect (const s_sym *type, f_buf_inspect *dest)
{
- if (type == sym_1("Bool"))
- return (f_buf_inspect) buf_inspect_bool;
- if (type == sym_1("Call"))
- return (f_buf_inspect) buf_inspect_call;
- if (type == sym_1("Cfn"))
- return (f_buf_inspect) buf_inspect_cfn;
- if (type == sym_1("Character"))
- return (f_buf_inspect) buf_inspect_character;
- if (type == sym_1("F32"))
- return (f_buf_inspect) buf_inspect_f32;
- if (type == sym_1("F64"))
- return (f_buf_inspect) buf_inspect_f64;
- if (type == sym_1("Fact"))
- return (f_buf_inspect) buf_inspect_fact;
- if (type == sym_1("Fn"))
- return (f_buf_inspect) buf_inspect_fn;
- if (type == sym_1("Ident"))
- return (f_buf_inspect) buf_inspect_ident;
- if (type == sym_1("Integer"))
- return (f_buf_inspect) buf_inspect_integer;
- if (type == sym_1("Sw"))
- return (f_buf_inspect) buf_inspect_sw;
- if (type == sym_1("S64"))
- return (f_buf_inspect) buf_inspect_s64;
- if (type == sym_1("S32"))
- return (f_buf_inspect) buf_inspect_s32;
- if (type == sym_1("S16"))
- return (f_buf_inspect) buf_inspect_s16;
- if (type == sym_1("S8"))
- return (f_buf_inspect) buf_inspect_s8;
- if (type == sym_1("U8"))
- return (f_buf_inspect) buf_inspect_u8;
- if (type == sym_1("U16"))
- return (f_buf_inspect) buf_inspect_u16;
- if (type == sym_1("U32"))
- return (f_buf_inspect) buf_inspect_u32;
- if (type == sym_1("U64"))
- return (f_buf_inspect) buf_inspect_u64;
- if (type == sym_1("Uw"))
- return (f_buf_inspect) buf_inspect_uw;
- if (type == sym_1("List"))
- return (f_buf_inspect) buf_inspect_list;
- if (type == sym_1("Ptag"))
- return (f_buf_inspect) buf_inspect_ptag;
- if (type == sym_1("Ptr"))
- return (f_buf_inspect) buf_inspect_ptr;
- if (type == sym_1("PtrFree"))
- return (f_buf_inspect) buf_inspect_ptr_free;
- if (type == sym_1("Quote"))
- return (f_buf_inspect) buf_inspect_quote;
- if (type == sym_1("Str"))
- return (f_buf_inspect) buf_inspect_str;
- if (type == sym_1("Sym"))
- return (f_buf_inspect) buf_inspect_sym;
- if (type == sym_1("Tuple"))
- return (f_buf_inspect) buf_inspect_tuple;
- if (type == sym_1("Var"))
- return (f_buf_inspect) buf_inspect_var;
+ if (type == sym_1("Void")) {
+ *dest = (f_buf_inspect) buf_inspect_var;
+ return true;
+ }
+ if (type == sym_1("Bool")) {
+ *dest = (f_buf_inspect) buf_inspect_bool;
+ return true;
+ }
+ if (type == sym_1("Call")) {
+ *dest = (f_buf_inspect) buf_inspect_call;
+ return true;
+ }
+ if (type == sym_1("Cfn")) {
+ *dest = (f_buf_inspect) buf_inspect_cfn;
+ return true;
+ }
+ if (type == sym_1("Character")) {
+ *dest = (f_buf_inspect) buf_inspect_character;
+ return true;
+ }
+ if (type == sym_1("F32")) {
+ *dest = (f_buf_inspect) buf_inspect_f32;
+ return true;
+ }
+ if (type == sym_1("F64")) {
+ *dest = (f_buf_inspect) buf_inspect_f64;
+ return true;
+ }
+ if (type == sym_1("Fact")) {
+ *dest = (f_buf_inspect) buf_inspect_fact;
+ return true;
+ }
+ if (type == sym_1("Fn")) {
+ *dest = (f_buf_inspect) buf_inspect_fn;
+ return true;
+ }
+ if (type == sym_1("Ident")) {
+ *dest = (f_buf_inspect) buf_inspect_ident;
+ return true;
+ }
+ if (type == sym_1("Integer")) {
+ *dest = (f_buf_inspect) buf_inspect_integer;
+ return true;
+ }
+ if (type == sym_1("Sw")) {
+ *dest = (f_buf_inspect) buf_inspect_sw;
+ return true;
+ }
+ if (type == sym_1("S64")) {
+ *dest = (f_buf_inspect) buf_inspect_s64;
+ return true;
+ }
+ if (type == sym_1("S32")) {
+ *dest = (f_buf_inspect) buf_inspect_s32;
+ return true;
+ }
+ if (type == sym_1("S16")) {
+ *dest = (f_buf_inspect) buf_inspect_s16;
+ return true;
+ }
+ if (type == sym_1("S8")) {
+ *dest = (f_buf_inspect) buf_inspect_s8;
+ return true;
+ }
+ if (type == sym_1("U8")) {
+ *dest = (f_buf_inspect) buf_inspect_u8;
+ return true;
+ }
+ if (type == sym_1("U16")) {
+ *dest = (f_buf_inspect) buf_inspect_u16;
+ return true;
+ }
+ if (type == sym_1("U32")) {
+ *dest = (f_buf_inspect) buf_inspect_u32;
+ return true;
+ }
+ if (type == sym_1("U64")) {
+ *dest = (f_buf_inspect) buf_inspect_u64;
+ return true;
+ }
+ if (type == sym_1("Uw")) {
+ *dest = (f_buf_inspect) buf_inspect_uw;
+ return true;
+ }
+ if (type == sym_1("List")) {
+ *dest = (f_buf_inspect) buf_inspect_list;
+ return true;
+ }
+ if (type == sym_1("Ptag")) {
+ *dest = (f_buf_inspect) buf_inspect_ptag;
+ return true;
+ }
+ if (type == sym_1("Ptr")) {
+ *dest = (f_buf_inspect) buf_inspect_ptr;
+ return true;
+ }
+ if (type == sym_1("PtrFree")) {
+ *dest = (f_buf_inspect) buf_inspect_ptr_free;
+ return true;
+ }
+ if (type == sym_1("Quote")) {
+ *dest = (f_buf_inspect) buf_inspect_quote;
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = (f_buf_inspect) buf_inspect_str;
+ return true;
+ }
+ if (type == sym_1("Sym")) {
+ *dest = (f_buf_inspect) buf_inspect_sym;
+ return true;
+ }
+ if (type == sym_1("Tuple")) {
+ *dest = (f_buf_inspect) buf_inspect_tuple;
+ return true;
+ }
+ if (type == sym_1("Var")) {
+ *dest = (f_buf_inspect) buf_inspect_var;
+ return true;
+ }
err_write_1("sym_to_buf_inspect: unknown type: ");
err_write_1(type->str.ptr.ps8);
err_write_1("\n");
assert(! "sym_to_buf_inspect: unknown type");
- return NULL;
+ return false;
}
-f_buf_inspect_size sym_to_buf_inspect_size (const s_sym *type)
+bool sym_to_buf_inspect_size (const s_sym *type, f_buf_inspect_size *dest)
{
- if (type == sym_1("Bool"))
- return (f_buf_inspect_size) buf_inspect_bool_size;
- if (type == sym_1("Call"))
- return (f_buf_inspect_size) buf_inspect_call_size;
- if (type == sym_1("Cfn"))
- return (f_buf_inspect_size) buf_inspect_cfn_size;
- if (type == sym_1("Character"))
- return (f_buf_inspect_size) buf_inspect_character_size;
- if (type == sym_1("F32"))
- return (f_buf_inspect_size) buf_inspect_f32_size;
- if (type == sym_1("F64"))
- return (f_buf_inspect_size) buf_inspect_f64_size;
- if (type == sym_1("Fact"))
- return (f_buf_inspect_size) buf_inspect_fact_size;
- if (type == sym_1("Fn"))
- return (f_buf_inspect_size) buf_inspect_fn_size;
- if (type == sym_1("Ident"))
- return (f_buf_inspect_size) buf_inspect_ident_size;
- if (type == sym_1("Integer"))
- return (f_buf_inspect_size) buf_inspect_integer_size;
- if (type == sym_1("Sw"))
- return (f_buf_inspect_size) buf_inspect_sw_size;
- if (type == sym_1("S64"))
- return (f_buf_inspect_size) buf_inspect_s64_size;
- if (type == sym_1("S32"))
- return (f_buf_inspect_size) buf_inspect_s32_size;
- if (type == sym_1("S16"))
- return (f_buf_inspect_size) buf_inspect_s16_size;
- if (type == sym_1("S8"))
- return (f_buf_inspect_size) buf_inspect_s8_size;
- if (type == sym_1("U8"))
- return (f_buf_inspect_size) buf_inspect_u8_size;
- if (type == sym_1("U16"))
- return (f_buf_inspect_size) buf_inspect_u16_size;
- if (type == sym_1("U32"))
- return (f_buf_inspect_size) buf_inspect_u32_size;
- if (type == sym_1("U64"))
- return (f_buf_inspect_size) buf_inspect_u64_size;
- if (type == sym_1("Uw"))
- return (f_buf_inspect_size) buf_inspect_uw_size;
- if (type == sym_1("List"))
- return (f_buf_inspect_size) buf_inspect_list_size;
- if (type == sym_1("Ptag"))
- return (f_buf_inspect_size) buf_inspect_ptag_size;
- if (type == sym_1("Ptr"))
- return (f_buf_inspect_size) buf_inspect_ptr_size;
- if (type == sym_1("PtrFree"))
- return (f_buf_inspect_size) buf_inspect_ptr_free_size;
- if (type == sym_1("Quote"))
- return (f_buf_inspect_size) buf_inspect_quote_size;
- if (type == sym_1("Str"))
- return (f_buf_inspect_size) buf_inspect_str_size;
- if (type == sym_1("Sym"))
- return (f_buf_inspect_size) buf_inspect_sym_size;
- if (type == sym_1("Tuple"))
- return (f_buf_inspect_size) buf_inspect_tuple_size;
- if (type == sym_1("Var"))
- return (f_buf_inspect_size) buf_inspect_var_size;
- if (type == sym_1("Void"))
- return (f_buf_inspect_size) buf_inspect_void_size;
+ if (type == sym_1("Bool")) {
+ *dest = (f_buf_inspect_size) buf_inspect_bool_size;
+ return true;
+ }
+ if (type == sym_1("Call")) {
+ *dest = (f_buf_inspect_size) buf_inspect_call_size;
+ return true;
+ }
+ if (type == sym_1("Cfn")) {
+ *dest = (f_buf_inspect_size) buf_inspect_cfn_size;
+ return true;
+ }
+ if (type == sym_1("Character")) {
+ *dest = (f_buf_inspect_size) buf_inspect_character_size;
+ return true;
+ }
+ if (type == sym_1("F32")) {
+ *dest = (f_buf_inspect_size) buf_inspect_f32_size;
+ return true;
+ }
+ if (type == sym_1("F64")) {
+ *dest = (f_buf_inspect_size) buf_inspect_f64_size;
+ return true;
+ }
+ if (type == sym_1("Fact")) {
+ *dest = (f_buf_inspect_size) buf_inspect_fact_size;
+ return true;
+ }
+ if (type == sym_1("Fn")) {
+ *dest = (f_buf_inspect_size) buf_inspect_fn_size;
+ return true;
+ }
+ if (type == sym_1("Ident")) {
+ *dest = (f_buf_inspect_size) buf_inspect_ident_size;
+ return true;
+ }
+ if (type == sym_1("Integer")) {
+ *dest = (f_buf_inspect_size) buf_inspect_integer_size;
+ return true;
+ }
+ if (type == sym_1("Sw")) {
+ *dest = (f_buf_inspect_size) buf_inspect_sw_size;
+ return true;
+ }
+ if (type == sym_1("S64")) {
+ *dest = (f_buf_inspect_size) buf_inspect_s64_size;
+ return true;
+ }
+ if (type == sym_1("S32")) {
+ *dest = (f_buf_inspect_size) buf_inspect_s32_size;
+ return true;
+ }
+ if (type == sym_1("S16")) {
+ *dest = (f_buf_inspect_size) buf_inspect_s16_size;
+ return true;
+ }
+ if (type == sym_1("S8")) {
+ *dest = (f_buf_inspect_size) buf_inspect_s8_size;
+ return true;
+ }
+ if (type == sym_1("U8")) {
+ *dest = (f_buf_inspect_size) buf_inspect_u8_size;
+ return true;
+ }
+ if (type == sym_1("U16")) {
+ *dest = (f_buf_inspect_size) buf_inspect_u16_size;
+ return true;
+ }
+ if (type == sym_1("U32")) {
+ *dest = (f_buf_inspect_size) buf_inspect_u32_size;
+ return true;
+ }
+ if (type == sym_1("U64")) {
+ *dest = (f_buf_inspect_size) buf_inspect_u64_size;
+ return true;
+ }
+ if (type == sym_1("Uw")) {
+ *dest = (f_buf_inspect_size) buf_inspect_uw_size;
+ return true;
+ }
+ if (type == sym_1("List")) {
+ *dest = (f_buf_inspect_size) buf_inspect_list_size;
+ return true;
+ }
+ if (type == sym_1("Ptag")) {
+ *dest = (f_buf_inspect_size) buf_inspect_ptag_size;
+ return true;
+ }
+ if (type == sym_1("Ptr")) {
+ *dest = (f_buf_inspect_size) buf_inspect_ptr_size;
+ return true;
+ }
+ if (type == sym_1("PtrFree")) {
+ *dest = (f_buf_inspect_size) buf_inspect_ptr_free_size;
+ return true;
+
+ }
+ if (type == sym_1("Quote")) {
+ *dest = (f_buf_inspect_size) buf_inspect_quote_size;
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = (f_buf_inspect_size) buf_inspect_str_size;
+ return true;
+ }
+ if (type == sym_1("Sym")) {
+ *dest = (f_buf_inspect_size) buf_inspect_sym_size;
+ return true;
+ }
+ if (type == sym_1("Tuple")) {
+ *dest = (f_buf_inspect_size) buf_inspect_tuple_size;
+ return true;
+ }
+ if (type == sym_1("Var")) {
+ *dest = (f_buf_inspect_size) buf_inspect_var_size;
+ return true;
+ }
+ if (type == sym_1("Void")) {
+ *dest = (f_buf_inspect_size) buf_inspect_void_size;
+ return true;
+ }
err_write_1("sym_to_buf_inspect_size: unknown type: ");
- err_write_1(type->str.ptr.ps8);
+ err_inspect_sym(&type);
err_write_1("\n");
assert(! "sym_to_buf_inspect_size: unknown type");
- return NULL;
+ return false;
}
-f_clean sym_to_clean (const s_sym *type)
+bool sym_to_clean (const s_sym *type, f_clean *dest)
{
- if (type == sym_1("Bool"))
- return NULL;
- if (type == sym_1("Call"))
- return (f_clean) call_clean;
- if (type == sym_1("Cfn"))
- return (f_clean) cfn_clean;
- if (type == sym_1("Character"))
- return NULL;
- if (type == sym_1("F32"))
- return NULL;
- if (type == sym_1("F64"))
- return NULL;
- if (type == sym_1("Fact"))
- return NULL;
- if (type == sym_1("Fn"))
- return (f_clean) fn_clean;
- if (type == sym_1("Ident"))
- return NULL;
- if (type == sym_1("Integer"))
- return (f_clean) integer_clean;
- if (type == sym_1("Sw"))
- return NULL;
- if (type == sym_1("S64"))
- return NULL;
- if (type == sym_1("S32"))
- return NULL;
- if (type == sym_1("S16"))
- return NULL;
- if (type == sym_1("S8"))
- return NULL;
- if (type == sym_1("U8"))
- return NULL;
- if (type == sym_1("U16"))
- return NULL;
- if (type == sym_1("U32"))
- return NULL;
- if (type == sym_1("U64"))
- return NULL;
- if (type == sym_1("Uw"))
- return NULL;
- if (type == sym_1("List"))
- return (f_clean) list_clean;
- if (type == sym_1("Map"))
- return (f_clean) map_clean;
- if (type == sym_1("Ptag"))
- return NULL;
- if (type == sym_1("Ptr"))
- return NULL;
- if (type == sym_1("PtrFree"))
- return (f_clean) ptr_free_clean;
- if (type == sym_1("Quote"))
- return (f_clean) quote_clean;
- if (type == sym_1("Str"))
- return (f_clean) str_clean;
- if (type == sym_1("Sym"))
- return NULL;
- if (type == sym_1("Tuple"))
- return (f_clean) tuple_clean;
- if (type == sym_1("Var"))
- return NULL;
- if (type == sym_1("Void"))
- return NULL;
+ if (type == sym_1("Bool")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Call")) {
+ *dest = (f_clean) call_clean;
+ return true;
+ }
+ if (type == sym_1("Cfn")) {
+ *dest = (f_clean) cfn_clean;
+ return true;
+ }
+ if (type == sym_1("Character")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("F32")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("F64")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Fact")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Fn")) {
+ *dest = (f_clean) fn_clean;
+ return true;
+ }
+ if (type == sym_1("Ident")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Integer")) {
+ *dest = (f_clean) integer_clean;
+ return true;
+ }
+ if (type == sym_1("Sw")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("S64")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("S32")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("S16")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("S8")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("U8")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("U16")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("U32")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("U64")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Uw")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("List")) {
+ *dest = (f_clean) list_clean;
+ return true;
+ }
+ if (type == sym_1("Map")) {
+ *dest = (f_clean) map_clean;
+ return true;
+ }
+ if (type == sym_1("Ptag")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Ptr")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("PtrFree")) {
+ *dest = (f_clean) ptr_free_clean;
+ return true;
+ }
+ if (type == sym_1("Quote")) {
+ *dest = (f_clean) quote_clean;
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = (f_clean) str_clean;
+ return true;
+ }
+ if (type == sym_1("Sym")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Tuple")) {
+ *dest = (f_clean) tuple_clean;
+ return true;
+ }
+ if (type == sym_1("Var")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Void")) {
+ *dest = NULL;
+ return true;
+ }
err_write_1("sym_to_clean: unknown type: ");
- err_write_1(type->str.ptr.ps8);
+ err_inspect_sym(&type);
err_write_1("\n");
assert(! "sym_to_clean: unknown type");
- return NULL;
+ return false;
}
-ffi_type * sym_to_ffi_type (const s_sym *sym, ffi_type *result_type)
+bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
+ ffi_type **dest)
{
assert(sym);
if (sym == sym_1("Result")) {
if (! result_type) {
err_puts("sym_to_ffi_type: invalid result type: Result");
- return NULL;
+ return false;
}
- return result_type;
- }
- if (sym->str.ptr.ps8[sym->str.size - 1] == '*')
- return &ffi_type_pointer;
- if (sym == sym_1("Bool"))
- return &ffi_type_uint8;
- if (sym == sym_1("Fn"))
- return &ffi_type_pointer;
- if (sym == sym_1("Integer"))
- return &ffi_type_pointer;
- if (sym == sym_1("List"))
- return &ffi_type_pointer;
- if (sym == sym_1("Map"))
- return &ffi_type_pointer;
- if (sym == sym_1("Ptr"))
- return &ffi_type_pointer;
- if (sym == sym_1("PtrFree"))
- return &ffi_type_pointer;
- if (sym == sym_1("S8"))
- return &ffi_type_sint8;
- if (sym == sym_1("S16"))
- return &ffi_type_sint16;
- if (sym == sym_1("S32"))
- return &ffi_type_sint32;
- if (sym == sym_1("S64"))
- return &ffi_type_sint64;
- if (sym == sym_1("Str"))
- return &ffi_type_pointer;
- if (sym == sym_1("Struct"))
- return &ffi_type_pointer;
- if (sym == sym_1("Sym"))
- return &ffi_type_pointer;
- if (sym == sym_1("Sw"))
- return &ffi_type_slong;
- if (sym == sym_1("Tag"))
- return &ffi_type_pointer;
- if (sym == sym_1("U8"))
- return &ffi_type_uint8;
- if (sym == sym_1("U16"))
- return &ffi_type_uint16;
- if (sym == sym_1("U32"))
- return &ffi_type_uint32;
- if (sym == sym_1("U64"))
- return &ffi_type_uint64;
- if (sym == sym_1("Uw"))
- return &ffi_type_ulong;
- if (sym == sym_1("Void"))
- return &ffi_type_void;
+ *dest = result_type;
+ return true;
+ }
+ if (sym == sym_1("Bool")) {
+ *dest = &ffi_type_uint8;
+ return true;
+ }
+ if (sym == sym_1("Character")) {
+ *dest = &ffi_type_uint32;
+ return true;
+ }
+ if (sym == sym_1("Fn")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("Integer")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("List")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("Map")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("Ptr")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("PtrFree")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("S8")) {
+ *dest = &ffi_type_sint8;
+ return true;
+ }
+ if (sym == sym_1("S16")) {
+ *dest = &ffi_type_sint16;
+ return true;
+ }
+ if (sym == sym_1("S32")) {
+ *dest = &ffi_type_sint32;
+ return true;
+ }
+ if (sym == sym_1("S64")) {
+ *dest = &ffi_type_sint64;
+ return true;
+ }
+ if (sym == sym_1("Str")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("Struct")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("Sym")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("Sw")) {
+ *dest = &ffi_type_slong;
+ return true;
+ }
+ if (sym == sym_1("Tag")) {
+ *dest = &ffi_type_pointer;
+ return true;
+ }
+ if (sym == sym_1("U8")) {
+ *dest = &ffi_type_uint8;
+ return true;
+ }
+ if (sym == sym_1("U16")) {
+ *dest = &ffi_type_uint16;
+ return true;
+ }
+ if (sym == sym_1("U32")) {
+ *dest = &ffi_type_uint32;
+ return true;
+ }
+ if (sym == sym_1("U64")) {
+ *dest = &ffi_type_uint64;
+ return true;
+ }
+ if (sym == sym_1("Uw")) {
+ *dest = &ffi_type_ulong;
+ return true;
+ }
+ if (sym == sym_1("Void")) {
+ *dest = &ffi_type_void;
+ return true;
+ }
err_write_1("sym_to_ffi_type: unknown type: ");
- err_write_1(sym->str.ptr.ps8);
+ err_inspect_sym(&sym);
err_write_1("\n");
assert(! "sym_to_ffi_type: unknown type");
- return NULL;
+ return false;
}
-f_init_cast sym_to_init_cast (const s_sym *type)
+bool sym_to_init_cast (const s_sym *type, f_init_cast *dest)
{
- if (type == sym_1("Bool"))
- return (f_init_cast) bool_init_cast;
- if (type == sym_1("Call"))
- return (f_init_cast) call_init_cast;
- if (type == sym_1("Cfn"))
- return (f_init_cast) cfn_init_cast;
- if (type == sym_1("Character"))
- return (f_init_cast) character_init_cast;
- if (type == sym_1("F32"))
- return (f_init_cast) f32_init_cast;
- if (type == sym_1("F64"))
- return (f_init_cast) f64_init_cast;
- if (type == sym_1("Fact"))
- return (f_init_cast) fact_init_cast;
- if (type == sym_1("Fn"))
- return (f_init_cast) fn_init_cast;
- if (type == sym_1("Ident"))
- return (f_init_cast) ident_init_cast;
- if (type == sym_1("Integer"))
- return (f_init_cast) integer_init_cast;
- if (type == sym_1("List"))
- return (f_init_cast) list_init_cast;
- if (type == sym_1("Sw"))
- return (f_init_cast) sw_init_cast;
- if (type == sym_1("S64"))
- return (f_init_cast) s64_init_cast;
- if (type == sym_1("S32"))
- return (f_init_cast) s32_init_cast;
- if (type == sym_1("S16"))
- return (f_init_cast) s16_init_cast;
- if (type == sym_1("S8"))
- return (f_init_cast) s8_init_cast;
- if (type == sym_1("U8"))
- return (f_init_cast) u8_init_cast;
- if (type == sym_1("U16"))
- return (f_init_cast) u16_init_cast;
- if (type == sym_1("U32"))
- return (f_init_cast) u32_init_cast;
- if (type == sym_1("U64"))
- return (f_init_cast) u64_init_cast;
- if (type == sym_1("Uw"))
- return (f_init_cast) uw_init_cast;
- if (type == sym_1("Ptag"))
- return (f_init_cast) ptag_init_cast;
- if (type == sym_1("Ptr"))
- return (f_init_cast) ptr_init_cast;
- if (type == sym_1("PtrFree"))
- return (f_init_cast) ptr_free_init_cast;
- if (type == sym_1("Quote"))
- return (f_init_cast) quote_init_cast;
- if (type == sym_1("Str"))
- return (f_init_cast) str_init_cast;
- if (type == sym_1("Sym"))
- return (f_init_cast) sym_init_cast;
- if (type == sym_1("Tuple"))
- return (f_init_cast) tuple_init_cast;
- if (type == sym_1("Var"))
- return NULL;
- if (type == sym_1("Void"))
- return NULL;
+ if (type == sym_1("Bool")) {
+ *dest = (f_init_cast) bool_init_cast;
+ return true;
+ }
+ if (type == sym_1("Call")) {
+ *dest = (f_init_cast) call_init_cast;
+ return true;
+ }
+ if (type == sym_1("Cfn")) {
+ *dest = (f_init_cast) cfn_init_cast;
+ return true;
+ }
+ if (type == sym_1("Character")) {
+ *dest = (f_init_cast) character_init_cast;
+ return true;
+ }
+ if (type == sym_1("F32")) {
+ *dest = (f_init_cast) f32_init_cast;
+ return true;
+ }
+ if (type == sym_1("F64")) {
+ *dest = (f_init_cast) f64_init_cast;
+ return true;
+ }
+ if (type == sym_1("Fact")) {
+ *dest = (f_init_cast) fact_init_cast;
+ return true;
+ }
+ if (type == sym_1("Fn")) {
+ *dest = (f_init_cast) fn_init_cast;
+ return true;
+ }
+ if (type == sym_1("Ident")) {
+ *dest = (f_init_cast) ident_init_cast;
+ return true;
+ }
+ if (type == sym_1("Integer")) {
+ *dest = (f_init_cast) integer_init_cast;
+ return true;
+ }
+ if (type == sym_1("List")) {
+ *dest = (f_init_cast) list_init_cast;
+ return true;
+ }
+ if (type == sym_1("Sw")) {
+ *dest = (f_init_cast) sw_init_cast;
+ return true;
+ }
+ if (type == sym_1("S64")) {
+ *dest = (f_init_cast) s64_init_cast;
+ return true;
+ }
+ if (type == sym_1("S32")) {
+ *dest = (f_init_cast) s32_init_cast;
+ return true;
+ }
+ if (type == sym_1("S16")) {
+ *dest = (f_init_cast) s16_init_cast;
+ return true;
+ }
+ if (type == sym_1("S8")) {
+ *dest = (f_init_cast) s8_init_cast;
+ return true;
+ }
+ if (type == sym_1("U8")) {
+ *dest = (f_init_cast) u8_init_cast;
+ return true;
+ }
+ if (type == sym_1("U16")) {
+ *dest = (f_init_cast) u16_init_cast;
+ return true;
+ }
+ if (type == sym_1("U32")) {
+ *dest = (f_init_cast) u32_init_cast;
+ return true;
+ }
+ if (type == sym_1("U64")) {
+ *dest = (f_init_cast) u64_init_cast;
+ return true;
+ }
+ if (type == sym_1("Uw")) {
+ *dest = (f_init_cast) uw_init_cast;
+ return true;
+ }
+ if (type == sym_1("Ptag")) {
+ *dest = (f_init_cast) ptag_init_cast;
+ return true;
+ }
+ if (type == sym_1("Ptr")) {
+ *dest = (f_init_cast) ptr_init_cast;
+ return true;
+ }
+ if (type == sym_1("PtrFree")) {
+ *dest = (f_init_cast) ptr_free_init_cast;
+ return true;
+ }
+ if (type == sym_1("Quote")) {
+ *dest = (f_init_cast) quote_init_cast;
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = (f_init_cast) str_init_cast;
+ return true;
+ }
+ if (type == sym_1("Sym")) {
+ *dest = (f_init_cast) sym_init_cast;
+ return true;
+ }
+ if (type == sym_1("Tuple")) {
+ *dest = (f_init_cast) tuple_init_cast;
+ return true;
+ }
+ if (type == sym_1("Var")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Void")) {
+ *dest = NULL;
+ return true;
+ }
err_write_1("sym_to_init_cast: unknown type: ");
- err_puts(type->str.ptr.ps8);
+ err_inspect_sym(&type);
+ err_write_1("\n");
assert(! "sym_to_init_cast: unknown type");
- return NULL;
+ return false;
}
-f_init_copy sym_to_init_copy (const s_sym *type)
+bool sym_to_init_copy (const s_sym *type, f_init_copy *dest)
{
- if (type == sym_1("Bool"))
- return (f_init_copy) bool_init_copy;
- if (type == sym_1("Call"))
- return (f_init_copy) call_init_copy;
- if (type == sym_1("Cfn"))
- return (f_init_copy) cfn_init_copy;
- if (type == sym_1("Character"))
- return (f_init_copy) character_init_copy;
- if (type == sym_1("F32"))
- return (f_init_copy) f32_init_copy;
- if (type == sym_1("F64"))
- return (f_init_copy) f64_init_copy;
- if (type == sym_1("Fact"))
- return (f_init_copy) fact_init_copy;
- if (type == sym_1("Fn"))
- return (f_init_copy) fn_init_copy;
- if (type == sym_1("Ident"))
- return (f_init_copy) ident_init_copy;
- if (type == sym_1("Integer"))
- return (f_init_copy) integer_init_copy;
- if (type == sym_1("List"))
- return (f_init_copy) list_init_copy;
- if (type == sym_1("Sw"))
- return (f_init_copy) sw_init_copy;
- if (type == sym_1("S64"))
- return (f_init_copy) s64_init_copy;
- if (type == sym_1("S32"))
- return (f_init_copy) s32_init_copy;
- if (type == sym_1("S16"))
- return (f_init_copy) s16_init_copy;
- if (type == sym_1("S8"))
- return (f_init_copy) s8_init_copy;
- if (type == sym_1("U8"))
- return (f_init_copy) u8_init_copy;
- if (type == sym_1("U16"))
- return (f_init_copy) u16_init_copy;
- if (type == sym_1("U32"))
- return (f_init_copy) u32_init_copy;
- if (type == sym_1("U64"))
- return (f_init_copy) u64_init_copy;
- if (type == sym_1("Uw"))
- return (f_init_copy) uw_init_copy;
- if (type == sym_1("Ptag"))
- return (f_init_copy) ptag_init_copy;
- if (type == sym_1("Ptr"))
- return (f_init_copy) ptr_init_copy;
- if (type == sym_1("PtrFree"))
- return (f_init_copy) ptr_free_init_copy;
- if (type == sym_1("Quote"))
- return (f_init_copy) quote_init_copy;
- if (type == sym_1("Str"))
- return (f_init_copy) str_init_copy;
- if (type == sym_1("Sym"))
- return (f_init_copy) sym_init_copy;
- if (type == sym_1("Tuple"))
- return (f_init_copy) tuple_init_copy;
- if (type == sym_1("Var"))
- return (f_init_copy) var_init_copy;
- if (type == sym_1("Void"))
- return (f_init_copy) void_init_copy;
+ if (type == sym_1("Bool")) {
+ *dest = (f_init_copy) bool_init_copy;
+ return true;
+ }
+ if (type == sym_1("Call")) {
+ *dest = (f_init_copy) call_init_copy;
+ return true;
+ }
+ if (type == sym_1("Cfn")) {
+ *dest = (f_init_copy) cfn_init_copy;
+ return true;
+ }
+ if (type == sym_1("Character")) {
+ *dest = (f_init_copy) character_init_copy;
+ return true;
+ }
+ if (type == sym_1("F32")) {
+ *dest = (f_init_copy) f32_init_copy;
+ return true;
+ }
+ if (type == sym_1("F64")) {
+ *dest = (f_init_copy) f64_init_copy;
+ return true;
+ }
+ if (type == sym_1("Fact")) {
+ *dest = (f_init_copy) fact_init_copy;
+ return true;
+ }
+ if (type == sym_1("Fn")) {
+ *dest = (f_init_copy) fn_init_copy;
+ return true;
+ }
+ if (type == sym_1("Ident")) {
+ *dest = (f_init_copy) ident_init_copy;
+ return true;
+ }
+ if (type == sym_1("Integer")) {
+ *dest = (f_init_copy) integer_init_copy;
+ return true;
+ }
+ if (type == sym_1("List")) {
+ *dest = (f_init_copy) list_init_copy;
+ return true;
+ }
+ if (type == sym_1("Sw")) {
+ *dest = (f_init_copy) sw_init_copy;
+ return true;
+ }
+ if (type == sym_1("S64")) {
+ *dest = (f_init_copy) s64_init_copy;
+ return true;
+ }
+ if (type == sym_1("S32")) {
+ *dest = (f_init_copy) s32_init_copy;
+ return true;
+ }
+ if (type == sym_1("S16")) {
+ *dest = (f_init_copy) s16_init_copy;
+ return true;
+ }
+ if (type == sym_1("S8")) {
+ *dest = (f_init_copy) s8_init_copy;
+ return true;
+ }
+ if (type == sym_1("U8")) {
+ *dest = (f_init_copy) u8_init_copy;
+ return true;
+ }
+ if (type == sym_1("U16")) {
+ *dest = (f_init_copy) u16_init_copy;
+ return true;
+ }
+ if (type == sym_1("U32")) {
+ *dest = (f_init_copy) u32_init_copy;
+ return true;
+ }
+ if (type == sym_1("U64")) {
+ *dest = (f_init_copy) u64_init_copy;
+ return true;
+ }
+ if (type == sym_1("Uw")) {
+ *dest = (f_init_copy) uw_init_copy;
+ return true;
+ }
+ if (type == sym_1("Ptag")) {
+ *dest = (f_init_copy) ptag_init_copy;
+ return true;
+ }
+ if (type == sym_1("Ptr")) {
+ *dest = (f_init_copy) ptr_init_copy;
+ return true;
+ }
+ if (type == sym_1("PtrFree")) {
+ *dest = (f_init_copy) ptr_free_init_copy;
+ return true;
+ }
+ if (type == sym_1("Quote")) {
+ *dest = (f_init_copy) quote_init_copy;
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = (f_init_copy) str_init_copy;
+ return true;
+ }
+ if (type == sym_1("Sym")) {
+ *dest = (f_init_copy) sym_init_copy;
+ return true;
+ }
+ if (type == sym_1("Tuple")) {
+ *dest = (f_init_copy) tuple_init_copy;
+ return true;
+ }
+ if (type == sym_1("Var")) {
+ *dest = NULL;
+ return true;
+ }
+ if (type == sym_1("Void")) {
+ *dest = NULL;
+ return true;
+ }
err_write_1("sym_to_init_copy: unknown type: ");
- err_write_1(type->str.ptr.ps8);
+ err_inspect_sym(&type);
err_write_1("\n");
assert(! "sym_to_init_copy: unknown type");
- return NULL;
+ return false;
}
bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
@@ -704,77 +1089,137 @@ bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest)
return true;
}
err_write_1("sym_to_tag_type: unknown type: ");
- err_write_1(sym->str.ptr.ps8);
+ err_inspect_sym(&sym);
err_write_1("\n");
assert(! "sym_to_tag_type: unknown type");
return false;
}
-uw sym_type_size (const s_sym *type)
+bool sym_type_size (const s_sym *type, uw *dest)
{
- if (type == sym_1("Bool"))
- return sizeof(bool);
- if (type == sym_1("Call"))
- return sizeof(s_call);
- if (type == sym_1("Cfn"))
- return sizeof(s_cfn);
- if (type == sym_1("Character"))
- return sizeof(character);
- if (type == sym_1("F32"))
- return sizeof(f32);
- if (type == sym_1("F64"))
- return sizeof(f64);
- if (type == sym_1("Fact"))
- return sizeof(s_fact);
- if (type == sym_1("Fn"))
- return sizeof(s_fn);
- if (type == sym_1("Ident"))
- return sizeof(s_ident);
- if (type == sym_1("Integer"))
- return sizeof(s_integer);
- if (type == sym_1("List"))
- return sizeof(s_list *);
- if (type == sym_1("Ptag"))
- return sizeof(p_tag);
- if (type == sym_1("Ptr"))
- return sizeof(void *);
- if (type == sym_1("PtrFree"))
- return sizeof(void *);
- if (type == sym_1("Quote"))
- return sizeof(s_quote);
- if (type == sym_1("S8"))
- return sizeof(s8);
- if (type == sym_1("S16"))
- return sizeof(s16);
- if (type == sym_1("S32"))
- return sizeof(s32);
- if (type == sym_1("S64"))
- return sizeof(s64);
- if (type == sym_1("Str"))
- return sizeof(s_str);
- if (type == sym_1("Sw"))
- return sizeof(sw);
- if (type == sym_1("Sym"))
- return sizeof(s_sym *);
- if (type == sym_1("Tuple"))
- return sizeof(s_tuple);
- if (type == sym_1("U8"))
- return sizeof(u8);
- if (type == sym_1("U16"))
- return sizeof(u16);
- if (type == sym_1("U32"))
- return sizeof(u32);
- if (type == sym_1("U64"))
- return sizeof(u64);
- if (type == sym_1("Uw"))
- return sizeof(uw);
- if (type == sym_1("Var"))
- return sizeof(s_tag);
- if (type == sym_1("Void"))
- return 0;
+ if (type == sym_1("Bool")) {
+ *dest = sizeof(bool);
+ return true;
+ }
+ if (type == sym_1("Call")) {
+ *dest = sizeof(s_call);
+ return true;
+ }
+ if (type == sym_1("Cfn")) {
+ *dest = sizeof(s_cfn);
+ return true;
+ }
+ if (type == sym_1("Character")) {
+ *dest = sizeof(character);
+ return true;
+ }
+ if (type == sym_1("F32")) {
+ *dest = sizeof(f32);
+ return true;
+ }
+ if (type == sym_1("F64")) {
+ *dest = sizeof(f64);
+ return true;
+ }
+ if (type == sym_1("Fact")) {
+ *dest = sizeof(s_fact);
+ return true;
+ }
+ if (type == sym_1("Fn")) {
+ *dest = sizeof(s_fn);
+ return true;
+ }
+ if (type == sym_1("Ident")) {
+ *dest = sizeof(s_ident);
+ return true;
+ }
+ if (type == sym_1("Integer")) {
+ *dest = sizeof(s_integer);
+ return true;
+ }
+ if (type == sym_1("List")) {
+ *dest = sizeof(s_list *);
+ return true;
+ }
+ if (type == sym_1("Ptag")) {
+ *dest = sizeof(p_tag);
+ return true;
+ }
+ if (type == sym_1("Ptr")) {
+ *dest = sizeof(void *);
+ return true;
+ }
+ if (type == sym_1("PtrFree")) {
+ *dest = sizeof(void *);
+ return true;
+ }
+ if (type == sym_1("Quote")) {
+ *dest = sizeof(s_quote);
+ return true;
+ }
+ if (type == sym_1("S8")) {
+ *dest = sizeof(s8);
+ return true;
+ }
+ if (type == sym_1("S16")) {
+ *dest = sizeof(s16);
+ return true;
+ }
+ if (type == sym_1("S32")) {
+ *dest = sizeof(s32);
+ return true;
+ }
+ if (type == sym_1("S64")) {
+ *dest = sizeof(s64);
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = sizeof(s_str);
+ return true;
+ }
+ if (type == sym_1("Sw")) {
+ *dest = sizeof(sw);
+ return true;
+ }
+ if (type == sym_1("Sym")) {
+ *dest = sizeof(s_sym *);
+ return true;
+ }
+ if (type == sym_1("Tuple")) {
+ *dest = sizeof(s_tuple);
+ return true;
+ }
+ if (type == sym_1("U8")) {
+ *dest = sizeof(u8);
+ return true;
+ }
+ if (type == sym_1("U16")) {
+ *dest = sizeof(u16);
+ return true;
+ }
+ if (type == sym_1("U32")) {
+ *dest = sizeof(u32);
+ return true;
+ }
+ if (type == sym_1("U64")) {
+ *dest = sizeof(u64);
+ return true;
+ }
+ if (type == sym_1("Uw")) {
+ *dest = sizeof(uw);
+ return true;
+ }
+ if (type == sym_1("Var")) {
+ *dest = 0;
+ return true;
+ }
+ if (type == sym_1("Void")) {
+ *dest = 0;
+ return true;
+ }
err_write_1("sym_type_size: unknown type: ");
- err_write_1(type->str.ptr.ps8);
+ err_inspect_sym(&type);
err_write_1("\n");
assert(! "sym_type_size: unknown type");
- return 0;
+ return false;
}
diff --git a/libc3/sym.h b/libc3/sym.h
index f32f447..019e639 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -28,9 +28,10 @@
const s_sym * sym_1 (const s8 *p);
const s_sym ** sym_init_1 (const s_sym **sym, const s8 *p);
-const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *src);
+const s_sym ** sym_init_cast (const s_sym **sym, const s_tag *tag);
const s_sym ** sym_init_copy (const s_sym **sym,
const s_sym * const *src);
+const s_sym ** sym_init_str (const s_sym **sym, const s_str *src);
/* Heap-allocation functions, call sym_delete_all at exit. */
@@ -38,19 +39,21 @@ void sym_delete_all (void);
const s_sym * sym_new (const s_str *src);
/* Observers */
-bool sym_character_is_reserved (character c);
-const s_sym * sym_find (const s_str *src);
-bool sym_has_reserved_characters (const s_sym *sym);
-s_str * sym_inspect (const s_sym *sym, s_str *dest);
-bool sym_is_module (const s_sym *sym);
-f_buf_inspect sym_to_buf_inspect (const s_sym *type);
-f_buf_inspect_size sym_to_buf_inspect_size (const s_sym *type);
-f_clean sym_to_clean (const s_sym *type);
-ffi_type * sym_to_ffi_type (const s_sym *sym,
- ffi_type *result_type);
-f_init_cast sym_to_init_cast (const s_sym *type);
-f_init_copy sym_to_init_copy (const s_sym *type);
-bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest);
-uw sym_type_size (const s_sym *type);
+bool sym_character_is_reserved (character c);
+const s_sym * sym_find (const s_str *src);
+bool sym_has_reserved_characters (const s_sym *sym);
+s_str * sym_inspect (const s_sym *sym, s_str *dest);
+bool sym_is_module (const s_sym *sym);
+bool sym_to_buf_inspect (const s_sym *type,
+ f_buf_inspect *dest);
+bool sym_to_buf_inspect_size (const s_sym *type,
+ f_buf_inspect_size *dest);
+bool sym_to_clean (const s_sym *type, f_clean *dest);
+bool sym_to_ffi_type (const s_sym *sym, ffi_type *result_type,
+ ffi_type **dest);
+bool sym_to_init_cast (const s_sym *type, f_init_cast *dest);
+bool sym_to_init_copy (const s_sym *type, f_init_copy *dest);
+bool sym_to_tag_type (const s_sym *sym, e_tag_type *dest);
+bool sym_type_size (const s_sym *type, uw *size);
#endif /* LIBC3_SYM_H */
diff --git a/libc3/tag.c b/libc3/tag.c
index 6745794..0357cea 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -633,338 +633,348 @@ s_tag * tag_paren (const s_tag *tag, s_tag *dest)
return tag_init_copy(dest, tag);
}
-sw tag_size (const s_tag *tag)
+uw * tag_size (const s_tag *tag, uw *dest)
{
- const s_sym *type;
+ const s_sym *type = NULL;
+ uw tmp = 0;
assert(tag);
type = tag_type_to_sym(tag->type);
- return sym_type_size(type);
+ if (! type ||
+ ! sym_type_size(type, &tmp))
+ return NULL;
+ *dest = tmp;
+ return dest;
}
-const void * tag_to_const_pointer (const s_tag *tag, const s_sym *type)
+bool tag_to_const_pointer (const s_tag *tag, const s_sym *type,
+ const void **dest)
{
e_tag_type tag_type;
- sym_to_tag_type(type, &tag_type);
+ if (! sym_to_tag_type(type, &tag_type))
+ return false;
if (tag->type != tag_type) {
+ warnx("tag_to_const_pointer: cannot cast %s to %s",
+ tag_type_to_string(tag->type),
+ type->str.ptr.ps8);
assert(! "tag_to_const_pointer: cannot cast");
- errx(1, "tag_to_const_pointer: cannot cast %s to %s",
- tag_type_to_string(tag->type),
- type->str.ptr.ps8);
- return NULL;
+ return false;
}
- switch (tag->type) {
- case TAG_ARRAY:
- return tag->data.array.data;
- case TAG_BOOL:
- return &tag->data.bool;
- case TAG_CALL:
- return &tag->data.call;
- case TAG_CFN:
- return &tag->data.cfn;
- case TAG_CHARACTER:
- return &tag->data.character;
- case TAG_F32:
- return &tag->data.f32;
- case TAG_F64:
- return &tag->data.f64;
- case TAG_FACT:
- return &tag->data.fact;
- case TAG_FN:
- return &tag->data.fn;
- case TAG_IDENT:
- return &tag->data.ident;
- case TAG_INTEGER:
- return &tag->data.integer;
- case TAG_SW:
- return &tag->data.sw;
- case TAG_S64:
- return &tag->data.s64;
- case TAG_S32:
- return &tag->data.s32;
- case TAG_S16:
- return &tag->data.s16;
- case TAG_S8:
- return &tag->data.s8;
- case TAG_U8:
- return &tag->data.u8;
- case TAG_U16:
- return &tag->data.u16;
- case TAG_U32:
- return &tag->data.u32;
- case TAG_U64:
- return &tag->data.u64;
- case TAG_UW:
- return &tag->data.uw;
- case TAG_LIST:
- return &tag->data.list;
- case TAG_MAP:
- return &tag->data.map;
- case TAG_PTAG:
- return &tag->data.ptag;
- case TAG_PTR:
- return &tag->data.ptr.p;
- case TAG_PTR_FREE:
- return &tag->data.ptr_free.p;
- case TAG_QUOTE:
- return &tag->data.quote;
- case TAG_STR:
- return &tag->data.str;
- case TAG_STRUCT:
- return &tag->data.struct_;
- case TAG_SYM:
- return (void *) tag->data.sym;
- case TAG_TUPLE:
- return &tag->data.tuple;
- case TAG_VAR:
- return NULL;
- case TAG_VOID:
- return NULL;
+ switch (tag_type) {
+ case TAG_ARRAY: *dest = tag->data.array.data; return true;
+ case TAG_BOOL: *dest = &tag->data.bool; return true;
+ case TAG_CALL: *dest = &tag->data.call; return true;
+ case TAG_CFN: *dest = &tag->data.cfn; return true;
+ case TAG_CHARACTER: *dest = &tag->data.character; return true;
+ case TAG_F32: *dest = &tag->data.f32; return true;
+ case TAG_F64: *dest = &tag->data.f64; return true;
+ case TAG_FACT: *dest = &tag->data.fact; return true;
+ case TAG_FN: *dest = &tag->data.fn; return true;
+ case TAG_IDENT: *dest = &tag->data.ident; return true;
+ case TAG_INTEGER: *dest = &tag->data.integer; return true;
+ case TAG_SW: *dest = &tag->data.sw; return true;
+ case TAG_S64: *dest = &tag->data.s64; return true;
+ case TAG_S32: *dest = &tag->data.s32; return true;
+ case TAG_S16: *dest = &tag->data.s16; return true;
+ case TAG_S8: *dest = &tag->data.s8; return true;
+ case TAG_U8: *dest = &tag->data.u8; return true;
+ case TAG_U16: *dest = &tag->data.u16; return true;
+ case TAG_U32: *dest = &tag->data.u32; return true;
+ case TAG_U64: *dest = &tag->data.u64; return true;
+ case TAG_UW: *dest = &tag->data.uw; return true;
+ case TAG_LIST: *dest = &tag->data.list; return true;
+ case TAG_MAP: *dest = &tag->data.map; return true;
+ case TAG_PTAG: *dest = &tag->data.ptag; return true;
+ case TAG_PTR: *dest = &tag->data.ptr.p; return true;
+ case TAG_PTR_FREE: *dest = &tag->data.ptr_free.p; return true;
+ case TAG_QUOTE: *dest = &tag->data.quote; return true;
+ case TAG_STR: *dest = &tag->data.str; return true;
+ case TAG_STRUCT: *dest = &tag->data.struct_; return true;
+ case TAG_SYM: *dest = &tag->data.sym; return true;
+ case TAG_TUPLE: *dest = &tag->data.tuple; return true;
+ case TAG_VAR: *dest = NULL; return true;
+ case TAG_VOID: *dest = NULL; return true;
}
+ warnx("tag_to_const_pointer: invalid tag type: %s",
+ tag_type_to_string(tag_type));
assert(! "tag_to_const_pointer: invalid tag type");
- errx(1, "tag_to_const_pointer: invalid tag type");
- return NULL;
+ return false;
}
-void * tag_to_ffi_pointer (s_tag *tag, const s_sym *type)
+bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest)
{
- if (type == sym_1("Tag"))
- return tag;
+ if (type == sym_1("Tag")) {
+ *dest = tag;
+ return true;
+ }
switch (tag->type) {
case TAG_VOID:
- if (type == sym_1("Void"))
- return NULL;
- goto invalid_type;
+ if (type == sym_1("Void")) {
+ *dest = NULL;
+ return true;
+ }
+ goto invalid_cast;
case TAG_ARRAY:
- if (type == sym_1("Array"))
- return tag->data.array.data;
- goto invalid_type;
+ if (type == sym_1("Array")) {
+ *dest = tag->data.array.data;
+ return true;
+ }
+ goto invalid_cast;
case TAG_BOOL:
- if (type == sym_1("Bool"))
- return &tag->data.bool;
- goto invalid_type;
+ if (type == sym_1("Bool")) {
+ *dest = &tag->data.bool;
+ return true;
+ }
+ goto invalid_cast;
case TAG_CALL:
- if (type == sym_1("Call"))
- return &tag->data.call;
- goto invalid_type;
+ if (type == sym_1("Call")) {
+ *dest = &tag->data.call;
+ return true;
+ }
+ goto invalid_cast;
case TAG_CFN:
- if (type == sym_1("Cfn"))
- return &tag->data.cfn;
- goto invalid_type;
+ if (type == sym_1("Cfn")) {
+ *dest = &tag->data.cfn;
+ return true;
+ }
+ goto invalid_cast;
case TAG_CHARACTER:
- if (type == sym_1("Character"))
- return &tag->data.character;
- goto invalid_type;
+ if (type == sym_1("Character")) {
+ *dest = &tag->data.character;
+ return true;
+ }
+ goto invalid_cast;
case TAG_F32:
- if (type == sym_1("F32"))
- return &tag->data.f32;
- goto invalid_type;
+ if (type == sym_1("F32")) {
+ *dest = &tag->data.f32;
+ return true;
+ }
+ goto invalid_cast;
case TAG_F64:
- if (type == sym_1("f64"))
- return &tag->data.f64;
- goto invalid_type;
+ if (type == sym_1("f64")) {
+ *dest = &tag->data.f64;
+ return true;
+ }
+ goto invalid_cast;
case TAG_FACT:
- if (type == sym_1("Fact"))
- return &tag->data.fact;
- goto invalid_type;
+ if (type == sym_1("Fact")) {
+ *dest = &tag->data.fact;
+ return true;
+ }
+ goto invalid_cast;
case TAG_FN:
- if (type == sym_1("Fn"))
- return &tag->data.fn;
- goto invalid_type;
+ if (type == sym_1("Fn")) {
+ *dest = &tag->data.fn;
+ return true;
+ }
+ goto invalid_cast;
case TAG_IDENT:
- if (type == sym_1("Ident"))
- return &tag->data.ident;
- goto invalid_type;
+ if (type == sym_1("Ident")) {
+ *dest = &tag->data.ident;
+ return true;
+ }
+ goto invalid_cast;
case TAG_INTEGER:
- if (type == sym_1("Integer"))
- return &tag->data.integer;
- goto invalid_type;
+ if (type == sym_1("Integer")) {
+ *dest = &tag->data.integer;
+ return true;
+ }
+ goto invalid_cast;
case TAG_SW:
- if (type == sym_1("Sw"))
- return &tag->data.sw;
- goto invalid_type;
+ if (type == sym_1("Sw")) {
+ *dest = &tag->data.sw;
+ return true;
+ }
+ goto invalid_cast;
case TAG_S64:
- if (type == sym_1("S64"))
- return &tag->data.s64;
- goto invalid_type;
+ if (type == sym_1("S64")) {
+ *dest = &tag->data.s64;
+ return true;
+ }
+ goto invalid_cast;
case TAG_S32:
- if (type == sym_1("S32"))
- return &tag->data.s32;
- goto invalid_type;
+ if (type == sym_1("S32")) {
+ *dest = &tag->data.s32;
+ return true;
+ }
+ goto invalid_cast;
case TAG_S16:
- if (type == sym_1("S16"))
- return &tag->data.s16;
- goto invalid_type;
+ if (type == sym_1("S16")) {
+ *dest = &tag->data.s16;
+ return true;
+ }
+ goto invalid_cast;
case TAG_S8:
- if (type == sym_1("S8"))
- return &tag->data.s8;
- goto invalid_type;
+ if (type == sym_1("S8")) {
+ *dest = &tag->data.s8;
+ return true;
+ }
+ goto invalid_cast;
case TAG_U8:
- if (type == sym_1("U8"))
- return &tag->data.u8;
- goto invalid_type;
+ if (type == sym_1("U8")) {
+ *dest = &tag->data.u8;
+ return true;
+ }
+ goto invalid_cast;
case TAG_U16:
- if (type == sym_1("U16"))
- return &tag->data.u16;
- goto invalid_type;
+ if (type == sym_1("U16")) {
+ *dest = &tag->data.u16;
+ return true;
+ }
+ goto invalid_cast;
case TAG_U32:
- if (type == sym_1("U32"))
- return &tag->data.u32;
- goto invalid_type;
+ if (type == sym_1("U32")) {
+ *dest = &tag->data.u32;
+ return true;
+ }
+ goto invalid_cast;
case TAG_U64:
- if (type == sym_1("U64"))
- return &tag->data.u64;
- goto invalid_type;
+ if (type == sym_1("U64")) {
+ *dest = &tag->data.u64;
+ return true;
+ }
+ goto invalid_cast;
case TAG_UW:
- if (type == sym_1("Uw"))
- return &tag->data.uw;
- goto invalid_type;
+ if (type == sym_1("Uw")) {
+ *dest = &tag->data.uw;
+ return true;
+ }
+ goto invalid_cast;
case TAG_LIST:
- if (type == sym_1("List"))
- return &tag->data.list;
- goto invalid_type;
+ if (type == sym_1("List")) {
+ *dest = &tag->data.list;
+ return true;
+ }
+ goto invalid_cast;
case TAG_MAP:
- if (type == sym_1("Map"))
- return &tag->data.map;
- goto invalid_type;
+ if (type == sym_1("Map")) {
+ *dest = &tag->data.map;
+ return true;
+ }
+ goto invalid_cast;
case TAG_PTAG:
- if (type == sym_1("Ptag"))
- return (void *) tag->data.ptag;
- goto invalid_type;
+ if (type == sym_1("Ptag")) {
+ *dest = (void *) tag->data.ptag;
+ return true;
+ }
+ goto invalid_cast;
case TAG_PTR:
- if (type == sym_1("Ptr"))
- return &tag->data.ptr.p;
- goto invalid_type;
+ if (type == sym_1("Ptr")) {
+ *dest = &tag->data.ptr.p;
+ return true;
+ }
+ goto invalid_cast;
case TAG_PTR_FREE:
if (type == sym_1("Ptr") ||
- type == sym_1("PtrFree"))
- return &tag->data.ptr_free.p;
- goto invalid_type;
+ type == sym_1("PtrFree")) {
+ *dest = &tag->data.ptr_free.p;
+ return true;
+ }
+ goto invalid_cast;
case TAG_QUOTE:
- if (type == sym_1("Quote"))
- return &tag->data.quote;
- goto invalid_type;
+ if (type == sym_1("Quote")) {
+ *dest = &tag->data.quote;
+ return true;
+ }
+ goto invalid_cast;
case TAG_STR:
- if (type == sym_1("Str"))
- return &tag->data.str;
- if (type == sym_1("Char*"))
- return (void *) tag->data.str.ptr.ps8;
- goto invalid_type;
+ if (type == sym_1("Str")) {
+ *dest = &tag->data.str;
+ return true;
+ }
+ if (type == sym_1("Char*")) {
+ *dest = (void *) tag->data.str.ptr.ps8;
+ return true;
+ }
+ goto invalid_cast;
case TAG_STRUCT:
- if (type == sym_1("Struct"))
- return &tag->data.struct_;
- goto invalid_type;
+ if (type == sym_1("Struct")) {
+ *dest = &tag->data.struct_;
+ return true;
+ }
+ goto invalid_cast;
case TAG_SYM:
- if (type == sym_1("Sym"))
- return (void *) &tag->data.sym;
- if (type == sym_1("Str"))
- return (void *) &tag->data.sym->str;
- if (type == sym_1("Char*"))
- return (void *) tag->data.sym->str.ptr.ps8;
- goto invalid_type;
+ if (type == sym_1("Sym")) {
+ *dest = (void *) &tag->data.sym;
+ return true;
+ }
+ if (type == sym_1("Str")) {
+ *dest = (void *) &tag->data.sym->str;
+ return true;
+ }
+ if (type == sym_1("Char*")) {
+ *dest = (void *) tag->data.sym->str.ptr.ps8;
+ return true;
+ }
+ goto invalid_cast;
case TAG_TUPLE:
- if (type == sym_1("Tuple"))
- return &tag->data.tuple;
- goto invalid_type;
+ if (type == sym_1("Tuple")) {
+ *dest = &tag->data.tuple;
+ return true;
+ }
+ goto invalid_cast;
case TAG_VAR:
- goto invalid_type;
+ goto invalid_cast;
}
+ warnx("tag_to_ffi_pointer: invalid tag type: %d", tag->type);
assert(! "tag_to_ffi_pointer: invalid tag type");
- errx(1, "tag_to_ffi_pointer: invalid tag type");
- return NULL;
- invalid_type:
+ return false;
+ invalid_cast:
warnx("tag_to_ffi_pointer: cannot cast %s to %s",
tag_type_to_string(tag->type),
type->str.ptr.ps8);
- return NULL;
+ return false;
}
-void * tag_to_pointer (s_tag *tag, const s_sym *type)
+bool tag_to_pointer (s_tag *tag, const s_sym *type, void **dest)
{
e_tag_type tag_type;
- sym_to_tag_type(type, &tag_type);
+ if (! sym_to_tag_type(type, &tag_type))
+ return false;
if (tag->type != tag_type) {
+ warnx("tag_to_pointer: cannot cast %s to %s",
+ tag_type_to_string(tag->type),
+ type->str.ptr.ps8);
assert(! "tag_to_pointer: cannot cast");
- errx(1, "tag_to_pointer: cannot cast %s to %s",
- tag_type_to_string(tag->type),
- type->str.ptr.ps8);
- return NULL;
+ return false;
}
- switch (tag->type) {
- case TAG_VOID:
- return NULL;
- case TAG_ARRAY:
- return tag->data.array.data;
- case TAG_BOOL:
- return &tag->data.bool;
- case TAG_CALL:
- return &tag->data.call;
- case TAG_CFN:
- return &tag->data.cfn;
- case TAG_CHARACTER:
- return &tag->data.character;
- case TAG_F32:
- return &tag->data.f32;
- case TAG_F64:
- return &tag->data.f64;
- case TAG_FACT:
- return &tag->data.fact;
- case TAG_FN:
- return &tag->data.fn;
- case TAG_IDENT:
- return &tag->data.ident;
- case TAG_INTEGER:
- return &tag->data.integer;
- case TAG_SW:
- return &tag->data.sw;
- case TAG_S64:
- return &tag->data.s64;
- case TAG_S32:
- return &tag->data.s32;
- case TAG_S16:
- return &tag->data.s16;
- case TAG_S8:
- return &tag->data.s8;
- case TAG_U8:
- return &tag->data.u8;
- case TAG_U16:
- return &tag->data.u16;
- case TAG_U32:
- return &tag->data.u32;
- case TAG_U64:
- return &tag->data.u64;
- case TAG_UW:
- return &tag->data.uw;
- case TAG_LIST:
- return &tag->data.list;
- case TAG_MAP:
- return &tag->data.map;
- case TAG_PTAG:
- return &tag->data.ptag;
- case TAG_PTR:
- return &tag->data.ptr.p;
- case TAG_PTR_FREE:
- return &tag->data.ptr_free.p;
- case TAG_QUOTE:
- return &tag->data.quote;
- case TAG_STR:
- return &tag->data.str;
- case TAG_STRUCT:
- return &tag->data.struct_;
- case TAG_SYM:
- return (void *) tag->data.sym;
- case TAG_TUPLE:
- return &tag->data.tuple;
- case TAG_VAR:
- goto invalid_type;
+ switch (tag_type) {
+ case TAG_VOID: *dest = NULL; return true;
+ case TAG_ARRAY: *dest = tag->data.array.data; return true;
+ case TAG_BOOL: *dest = &tag->data.bool; return true;
+ case TAG_CALL: *dest = &tag->data.call; return true;
+ case TAG_CFN: *dest = &tag->data.cfn; return true;
+ case TAG_CHARACTER: *dest = &tag->data.character; return true;
+ case TAG_F32: *dest = &tag->data.f32; return true;
+ case TAG_F64: *dest = &tag->data.f64; return true;
+ case TAG_FACT: *dest = &tag->data.fact; return true;
+ case TAG_FN: *dest = &tag->data.fn; return true;
+ case TAG_IDENT: *dest = &tag->data.ident; return true;
+ case TAG_INTEGER: *dest = &tag->data.integer; return true;
+ case TAG_SW: *dest = &tag->data.sw; return true;
+ case TAG_S64: *dest = &tag->data.s64; return true;
+ case TAG_S32: *dest = &tag->data.s32; return true;
+ case TAG_S16: *dest = &tag->data.s16; return true;
+ case TAG_S8: *dest = &tag->data.s8; return true;
+ case TAG_U8: *dest = &tag->data.u8; return true;
+ case TAG_U16: *dest = &tag->data.u16; return true;
+ case TAG_U32: *dest = &tag->data.u32; return true;
+ case TAG_U64: *dest = &tag->data.u64; return true;
+ case TAG_UW: *dest = &tag->data.uw; return true;
+ case TAG_LIST: *dest = &tag->data.list; return true;
+ case TAG_MAP: *dest = &tag->data.map; return true;
+ case TAG_PTAG: *dest = &tag->data.ptag; return true;
+ case TAG_PTR: *dest = &tag->data.ptr.p; return true;
+ case TAG_PTR_FREE: *dest = &tag->data.ptr_free.p; return true;
+ case TAG_QUOTE: *dest = &tag->data.quote; return true;
+ case TAG_STR: *dest = &tag->data.str; return true;
+ case TAG_STRUCT: *dest = &tag->data.struct_; return true;
+ case TAG_SYM: *dest = &tag->data.sym; return true;
+ case TAG_TUPLE: *dest = &tag->data.tuple; return true;
+ case TAG_VAR: *dest = NULL; return true;
}
+ warnx("tag_to_pointer: invalid tag type: %d", tag_type);
assert(! "tag_to_pointer: invalid tag type");
- errx(1, "tag_to_pointer: invalid tag type");
- return NULL;
- invalid_type:
- warnx("tag_to_pointer: cannot cast %s to %s",
- tag_type_to_string(tag->type),
- type->str.ptr.ps8);
- return NULL;
+ return false;
}
const s_sym ** tag_type (const s_tag *tag, const s_sym **dest)
diff --git a/libc3/tag.h b/libc3/tag.h
index 989edf9..55ff36d 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -49,25 +49,26 @@ bool tag_is_bound_var (const s_tag *tag);
bool tag_is_number (const s_tag *tag);
bool tag_is_unbound_var (const s_tag *tag);
s8 tag_number_compare (const s_tag *a, const s_tag *b);
-sw tag_size (const s_tag *tag);
+uw * tag_size (const s_tag *tag, uw *dest);
ffi_type tag_to_ffi_type(const s_tag *tag);
const s_sym ** tag_type (const s_tag *tag, const s_sym **type);
/* Operators. */
-s_tag * tag_1 (s_tag *tag, const s8 *p);
-s_tag * tag_integer_cast_to_s16 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_s32 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_s64 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_s8 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_u16 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_u32 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_u64 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_cast_to_u8 (const s_tag *tag, s_tag *dest);
-s_tag * tag_integer_reduce (s_tag *tag);
-s_tag * tag_list_1 (s_tag *tag, const s8 *p);
-const void * tag_to_const_pointer (const s_tag *tag, const s_sym *type);
-void * tag_to_ffi_pointer (s_tag *tag, const s_sym *type);
-void * tag_to_pointer (s_tag *tag, const s_sym *type);
+s_tag * tag_1 (s_tag *tag, const s8 *p);
+s_tag * tag_integer_cast_to_s16 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_s32 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_s64 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_s8 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_u16 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_u32 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_u64 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_cast_to_u8 (const s_tag *tag, s_tag *dest);
+s_tag * tag_integer_reduce (s_tag *tag);
+s_tag * tag_list_1 (s_tag *tag, const s8 *p);
+bool tag_to_const_pointer (const s_tag *tag, const s_sym *type,
+ const void **dest);
+bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest);
+bool tag_to_pointer (s_tag *tag, const s_sym *type, void **dest);
/* C3 operators. */
s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest);
diff --git a/libc3/tag_type.c b/libc3/tag_type.c
index 4620fbe..c5d8e55 100644
--- a/libc3/tag_type.c
+++ b/libc3/tag_type.c
@@ -13,464 +13,295 @@
#include <err.h>
#include "c3.h"
-sw tag_type_size (e_tag_type type)
+bool tag_type_size (e_tag_type type, uw *dest)
{
switch (type) {
- case TAG_VOID:
- return 0;
- case TAG_ARRAY:
- assert(! "tag_type_size: TAG_ARRAY: not implemented");
- errx(1, "tag_type_size: TAG_ARRAY: not implemented");
- return -1;
- case TAG_BOOL:
- return sizeof(bool);
- case TAG_CALL:
- return sizeof(s_call);
- case TAG_CFN:
- return sizeof(s_cfn);
- case TAG_CHARACTER:
- return sizeof(character);
- case TAG_F32:
- return sizeof(f32);
- case TAG_F64:
- return sizeof(f64);
- case TAG_FACT:
- return sizeof(s_fact);
- case TAG_FN:
- return sizeof(s_fn);
- case TAG_IDENT:
- return sizeof(s_ident);
- case TAG_INTEGER:
- return sizeof(s_integer);
- case TAG_SW:
- return sizeof(sw);
- case TAG_S64:
- return sizeof(s64);
- case TAG_S32:
- return sizeof(s32);
- case TAG_S16:
- return sizeof(s16);
- case TAG_S8:
- return sizeof(s8);
- case TAG_U8:
- return sizeof(u8);
- case TAG_U16:
- return sizeof(u16);
- case TAG_U32:
- return sizeof(u32);
- case TAG_U64:
- return sizeof(u64);
- case TAG_UW:
- return sizeof(uw);
- case TAG_LIST:
- return sizeof(s_list *);
- case TAG_MAP:
- return sizeof(s_map);
- case TAG_PTAG:
- return sizeof(p_tag);
+ case TAG_VOID: *dest = 0; return true;
+ case TAG_ARRAY: *dest = sizeof(s_array); return true;
+ case TAG_BOOL: *dest = sizeof(bool); return true;
+ case TAG_CALL: *dest = sizeof(s_call); return true;
+ case TAG_CFN: *dest = sizeof(s_cfn); return true;
+ case TAG_CHARACTER: *dest = sizeof(character); return true;
+ case TAG_F32: *dest = sizeof(f32); return true;
+ case TAG_F64: *dest = sizeof(f64); return true;
+ case TAG_FACT: *dest = sizeof(s_fact); return true;
+ case TAG_FN: *dest = sizeof(s_fn); return true;
+ case TAG_IDENT: *dest = sizeof(s_ident); return true;
+ case TAG_INTEGER: *dest = sizeof(s_integer); return true;
+ case TAG_SW: *dest = sizeof(sw); return true;
+ case TAG_S64: *dest = sizeof(s64); return true;
+ case TAG_S32: *dest = sizeof(s32); return true;
+ case TAG_S16: *dest = sizeof(s16); return true;
+ case TAG_S8: *dest = sizeof(s8); return true;
+ case TAG_U8: *dest = sizeof(u8); return true;
+ case TAG_U16: *dest = sizeof(u16); return true;
+ case TAG_U32: *dest = sizeof(u32); return true;
+ case TAG_U64: *dest = sizeof(u64); return true;
+ case TAG_UW: *dest = sizeof(uw); return true;
+ case TAG_LIST: *dest = sizeof(s_list *); return true;
+ case TAG_MAP: *dest = sizeof(s_map); return true;
+ case TAG_PTAG: *dest = sizeof(p_tag); return true;
case TAG_PTR:
- case TAG_PTR_FREE:
- return sizeof(void *);
- case TAG_QUOTE:
- return sizeof(s_quote);
- case TAG_STR:
- return sizeof(s_str);
- case TAG_STRUCT:
- return sizeof(s_struct);
- case TAG_SYM:
- return sizeof(s_sym *);
- case TAG_TUPLE:
- return sizeof(s_tuple);
- case TAG_VAR:
- return sizeof(s_tag);
+ case TAG_PTR_FREE: *dest = sizeof(void *); return true;
+ case TAG_QUOTE: *dest = sizeof(s_quote); return true;
+ case TAG_STR: *dest = sizeof(s_str); return true;
+ case TAG_STRUCT: *dest = sizeof(s_struct); return true;
+ case TAG_SYM: *dest = sizeof(s_sym *); return true;
+ case TAG_TUPLE: *dest = sizeof(s_tuple); return true;
+ case TAG_VAR: *dest = 0; return true;
}
+ warnx("tag_type_size: invalid tag type: %d", type);
assert(! "tag_type_size: invalid tag type");
- errx(1, "tag_type_size: invalid tag type: %d", type);
- return -1;
+ return false;
}
-f_buf_inspect tag_type_to_buf_inspect (e_tag_type type)
+bool tag_type_to_buf_inspect (e_tag_type type, f_buf_inspect *dest)
{
switch (type) {
case TAG_VOID:
- return (f_buf_inspect) buf_inspect_void;
+ *dest = (f_buf_inspect) buf_inspect_void; return true;
case TAG_ARRAY:
+ *dest = (f_buf_inspect) buf_inspect_array; return true;
case TAG_BOOL:
- return (f_buf_inspect) buf_inspect_bool;
+ *dest = (f_buf_inspect) buf_inspect_bool; return true;
case TAG_CALL:
- return (f_buf_inspect) buf_inspect_call;
+ *dest = (f_buf_inspect) buf_inspect_call; return true;
case TAG_CFN:
- return (f_buf_inspect) buf_inspect_cfn;
+ *dest = (f_buf_inspect) buf_inspect_cfn; return true;
case TAG_CHARACTER:
- return (f_buf_inspect) buf_inspect_character;
+ *dest = (f_buf_inspect) buf_inspect_character; return true;
case TAG_F32:
- return (f_buf_inspect) buf_inspect_f32;
+ *dest = (f_buf_inspect) buf_inspect_f32; return true;
case TAG_F64:
- return (f_buf_inspect) buf_inspect_f64;
+ *dest = (f_buf_inspect) buf_inspect_f64; return true;
case TAG_FACT:
- return (f_buf_inspect) buf_inspect_fact;
+ *dest = (f_buf_inspect) buf_inspect_fact; return true;
case TAG_FN:
- return (f_buf_inspect) buf_inspect_fn;
+ *dest = (f_buf_inspect) buf_inspect_fn; return true;
case TAG_IDENT:
- return (f_buf_inspect) buf_inspect_ident;
+ *dest = (f_buf_inspect) buf_inspect_ident; return true;
case TAG_INTEGER:
- return (f_buf_inspect) buf_inspect_integer;
+ *dest = (f_buf_inspect) buf_inspect_integer; return true;
case TAG_SW:
- return (f_buf_inspect) buf_inspect_sw;
+ *dest = (f_buf_inspect) buf_inspect_sw; return true;
case TAG_S64:
- return (f_buf_inspect) buf_inspect_s64;
+ *dest = (f_buf_inspect) buf_inspect_s64; return true;
case TAG_S32:
- return (f_buf_inspect) buf_inspect_s32;
+ *dest = (f_buf_inspect) buf_inspect_s32; return true;
case TAG_S16:
- return (f_buf_inspect) buf_inspect_s16;
+ *dest = (f_buf_inspect) buf_inspect_s16; return true;
case TAG_S8:
- return (f_buf_inspect) buf_inspect_s8;
+ *dest = (f_buf_inspect) buf_inspect_s8; return true;
case TAG_U8:
- return (f_buf_inspect) buf_inspect_u8;
+ *dest = (f_buf_inspect) buf_inspect_u8; return true;
case TAG_U16:
- return (f_buf_inspect) buf_inspect_u16;
+ *dest = (f_buf_inspect) buf_inspect_u16; return true;
case TAG_U32:
- return (f_buf_inspect) buf_inspect_u32;
+ *dest = (f_buf_inspect) buf_inspect_u32; return true;
case TAG_U64:
- return (f_buf_inspect) buf_inspect_u64;
+ *dest = (f_buf_inspect) buf_inspect_u64; return true;
case TAG_UW:
- return (f_buf_inspect) buf_inspect_uw;
+ *dest = (f_buf_inspect) buf_inspect_uw; return true;
case TAG_LIST:
- return (f_buf_inspect) buf_inspect_list;
+ *dest = (f_buf_inspect) buf_inspect_list; return true;
case TAG_MAP:
- return (f_buf_inspect) buf_inspect_map;
+ *dest = (f_buf_inspect) buf_inspect_map; return true;
case TAG_PTAG:
- return (f_buf_inspect) buf_inspect_ptag;
+ *dest = (f_buf_inspect) buf_inspect_ptag; return true;
case TAG_PTR:
- return (f_buf_inspect) buf_inspect_ptr;
+ *dest = (f_buf_inspect) buf_inspect_ptr; return true;
case TAG_PTR_FREE:
- return (f_buf_inspect) buf_inspect_ptr_free;
+ *dest = (f_buf_inspect) buf_inspect_ptr_free; return true;
case TAG_QUOTE:
- return (f_buf_inspect) buf_inspect_quote;
+ *dest = (f_buf_inspect) buf_inspect_quote; return true;
case TAG_STR:
- return (f_buf_inspect) buf_inspect_str;
+ *dest = (f_buf_inspect) buf_inspect_str; return true;
case TAG_STRUCT:
- return (f_buf_inspect) buf_inspect_struct;
+ *dest = (f_buf_inspect) buf_inspect_struct; return true;
case TAG_SYM:
- return (f_buf_inspect) buf_inspect_sym;
+ *dest = (f_buf_inspect) buf_inspect_sym; return true;
case TAG_TUPLE:
- return (f_buf_inspect) buf_inspect_tuple;
+ *dest = (f_buf_inspect) buf_inspect_tuple; return true;
case TAG_VAR:
- return (f_buf_inspect) buf_inspect_var;
+ *dest = (f_buf_inspect) buf_inspect_var; return true;
}
+ warnx("buf_inspect: unknown tag type: %d", type);
assert(! "buf_inspect: unknown tag type");
- errx(1, "buf_inspect: unknown tag type");
- return NULL;
+ return false;
}
-f_buf_inspect_size tag_type_to_buf_inspect_size (e_tag_type type)
+bool tag_type_to_buf_inspect_size (e_tag_type type,
+ f_buf_inspect_size *p)
{
switch (type) {
case TAG_VOID:
- return (f_buf_inspect_size) buf_inspect_void_size;
+ *p = (f_buf_inspect_size) buf_inspect_void_size; return true;
case TAG_ARRAY:
- return (f_buf_inspect_size) buf_inspect_array_size;
+ *p = (f_buf_inspect_size) buf_inspect_array_size; return true;
case TAG_BOOL:
- return (f_buf_inspect_size) buf_inspect_bool_size;
+ *p = (f_buf_inspect_size) buf_inspect_bool_size; return true;
case TAG_CALL:
- return (f_buf_inspect_size) buf_inspect_call_size;
+ *p = (f_buf_inspect_size) buf_inspect_call_size; return true;
case TAG_CFN:
- return (f_buf_inspect_size) buf_inspect_cfn_size;
+ *p = (f_buf_inspect_size) buf_inspect_cfn_size; return true;
case TAG_CHARACTER:
- return (f_buf_inspect_size) buf_inspect_character_size;
+ *p = (f_buf_inspect_size) buf_inspect_character_size; return true;
case TAG_F32:
- return (f_buf_inspect_size) buf_inspect_f32_size;
+ *p = (f_buf_inspect_size) buf_inspect_f32_size; return true;
case TAG_F64:
- return (f_buf_inspect_size) buf_inspect_f64_size;
+ *p = (f_buf_inspect_size) buf_inspect_f64_size; return true;
case TAG_FACT:
- return (f_buf_inspect_size) buf_inspect_fact_size;
+ *p = (f_buf_inspect_size) buf_inspect_fact_size; return true;
case TAG_FN:
- return (f_buf_inspect_size) buf_inspect_fn_size;
+ *p = (f_buf_inspect_size) buf_inspect_fn_size; return true;
case TAG_IDENT:
- return (f_buf_inspect_size) buf_inspect_ident_size;
+ *p = (f_buf_inspect_size) buf_inspect_ident_size; return true;
case TAG_INTEGER:
- return (f_buf_inspect_size) buf_inspect_integer_size;
+ *p = (f_buf_inspect_size) buf_inspect_integer_size; return true;
case TAG_SW:
- return (f_buf_inspect_size) buf_inspect_sw_size;
+ *p = (f_buf_inspect_size) buf_inspect_sw_size; return true;
case TAG_S64:
- return (f_buf_inspect_size) buf_inspect_s64_size;
+ *p = (f_buf_inspect_size) buf_inspect_s64_size; return true;
case TAG_S32:
- return (f_buf_inspect_size) buf_inspect_s32_size;
+ *p = (f_buf_inspect_size) buf_inspect_s32_size; return true;
case TAG_S16:
- return (f_buf_inspect_size) buf_inspect_s16_size;
+ *p = (f_buf_inspect_size) buf_inspect_s16_size; return true;
case TAG_S8:
- return (f_buf_inspect_size) buf_inspect_s8_size;
+ *p = (f_buf_inspect_size) buf_inspect_s8_size; return true;
case TAG_U8:
- return (f_buf_inspect_size) buf_inspect_u8_size;
+ *p = (f_buf_inspect_size) buf_inspect_u8_size; return true;
case TAG_U16:
- return (f_buf_inspect_size) buf_inspect_u16_size;
+ *p = (f_buf_inspect_size) buf_inspect_u16_size; return true;
case TAG_U32:
- return (f_buf_inspect_size) buf_inspect_u32_size;
+ *p = (f_buf_inspect_size) buf_inspect_u32_size; return true;
case TAG_U64:
- return (f_buf_inspect_size) buf_inspect_u64_size;
+ *p = (f_buf_inspect_size) buf_inspect_u64_size; return true;
case TAG_UW:
- return (f_buf_inspect_size) buf_inspect_uw_size;
+ *p = (f_buf_inspect_size) buf_inspect_uw_size; return true;
case TAG_LIST:
- return (f_buf_inspect_size) buf_inspect_list_size;
+ *p = (f_buf_inspect_size) buf_inspect_list_size; return true;
case TAG_MAP:
- return (f_buf_inspect_size) buf_inspect_map_size;
+ *p = (f_buf_inspect_size) buf_inspect_map_size; return true;
case TAG_PTAG:
- return (f_buf_inspect_size) buf_inspect_ptag_size;
+ *p = (f_buf_inspect_size) buf_inspect_ptag_size; return true;
case TAG_PTR:
- return (f_buf_inspect_size) buf_inspect_ptr_size;
+ *p = (f_buf_inspect_size) buf_inspect_ptr_size; return true;
case TAG_PTR_FREE:
- return (f_buf_inspect_size) buf_inspect_ptr_free_size;
+ *p = (f_buf_inspect_size) buf_inspect_ptr_free_size; return true;
case TAG_QUOTE:
- return (f_buf_inspect_size) buf_inspect_quote_size;
+ *p = (f_buf_inspect_size) buf_inspect_quote_size; return true;
case TAG_STR:
- return (f_buf_inspect_size) buf_inspect_str_size;
+ *p = (f_buf_inspect_size) buf_inspect_str_size; return true;
case TAG_STRUCT:
- return (f_buf_inspect_size) buf_inspect_struct_size;
+ *p = (f_buf_inspect_size) buf_inspect_struct_size; return true;
case TAG_SYM:
- return (f_buf_inspect_size) buf_inspect_sym_size;
+ *p = (f_buf_inspect_size) buf_inspect_sym_size; return true;
case TAG_TUPLE:
- return (f_buf_inspect_size) buf_inspect_tuple_size;
+ *p = (f_buf_inspect_size) buf_inspect_tuple_size; return true;
case TAG_VAR:
- return (f_buf_inspect_size) buf_inspect_var_size;
+ *p = (f_buf_inspect_size) buf_inspect_var_size; return true;
}
+ warnx("tag_type_to_buf_inspect_size: unknown tag type: %d", type);
assert(! "tag_type_to_buf_inspect_size: unknown tag type");
- errx(1, "tag_type_to_buf_inspect_size: unknown tag type");
- return NULL;
+ return false;
}
-f_buf_parse tag_type_to_buf_parse (e_tag_type type)
+bool tag_type_to_buf_parse (e_tag_type type, f_buf_parse *p)
{
switch (type) {
- case TAG_VOID:
- return (f_buf_parse) buf_parse_void;
- case TAG_ARRAY:
- return (f_buf_parse) buf_parse_array;
- case TAG_BOOL:
- return (f_buf_parse) buf_parse_bool;
- case TAG_CALL:
- return (f_buf_parse) buf_parse_call;
- case TAG_CFN:
- return (f_buf_parse) buf_parse_cfn;
- case TAG_CHARACTER:
- return (f_buf_parse) buf_parse_character;
- case TAG_F32:
- return (f_buf_parse) buf_parse_f32;
- case TAG_F64:
- return (f_buf_parse) buf_parse_f64;
- case TAG_FACT:
- return (f_buf_parse) buf_parse_fact;
- case TAG_FN:
- return (f_buf_parse) buf_parse_fn;
- case TAG_IDENT:
- return (f_buf_parse) buf_parse_ident;
- case TAG_INTEGER:
- return (f_buf_parse) buf_parse_integer;
- case TAG_SW:
- return (f_buf_parse) buf_parse_sw;
- case TAG_S64:
- return (f_buf_parse) buf_parse_s64;
- case TAG_S32:
- return (f_buf_parse) buf_parse_s32;
- case TAG_S16:
- return (f_buf_parse) buf_parse_s16;
- case TAG_S8:
- return (f_buf_parse) buf_parse_s8;
- case TAG_U8:
- return (f_buf_parse) buf_parse_u8;
- case TAG_U16:
- return (f_buf_parse) buf_parse_u16;
- case TAG_U32:
- return (f_buf_parse) buf_parse_u32;
- case TAG_U64:
- return (f_buf_parse) buf_parse_u64;
- case TAG_UW:
- return (f_buf_parse) buf_parse_uw;
- case TAG_LIST:
- return (f_buf_parse) buf_parse_list;
- case TAG_MAP:
- return (f_buf_parse) buf_parse_map;
- case TAG_PTAG:
- return (f_buf_parse) buf_parse_ptag;
- case TAG_PTR:
- return (f_buf_parse) buf_parse_ptr;
- case TAG_PTR_FREE:
- return (f_buf_parse) buf_parse_ptr_free;
- case TAG_QUOTE:
- return (f_buf_parse) buf_parse_quote;
- case TAG_STR:
- return (f_buf_parse) buf_parse_str;
- case TAG_STRUCT:
- return (f_buf_parse) buf_parse_struct;
- case TAG_SYM:
- return (f_buf_parse) buf_parse_sym;
- case TAG_TUPLE:
- return (f_buf_parse) buf_parse_tuple;
- case TAG_VAR:
- return (f_buf_parse) buf_parse_var;
+ case TAG_VOID: *p = (f_buf_parse) buf_parse_void; return true;
+ case TAG_ARRAY: *p = (f_buf_parse) buf_parse_array; return true;
+ case TAG_BOOL: *p = (f_buf_parse) buf_parse_bool; return true;
+ case TAG_CALL: *p = (f_buf_parse) buf_parse_call; return true;
+ case TAG_CFN: *p = (f_buf_parse) buf_parse_cfn; return true;
+ case TAG_CHARACTER: *p = (f_buf_parse) buf_parse_character; return 1;
+ case TAG_F32: *p = (f_buf_parse) buf_parse_f32; return true;
+ case TAG_F64: *p = (f_buf_parse) buf_parse_f64; return true;
+ case TAG_FACT: *p = (f_buf_parse) buf_parse_fact; return true;
+ case TAG_FN: *p = (f_buf_parse) buf_parse_fn; return true;
+ case TAG_IDENT: *p = (f_buf_parse) buf_parse_ident; return true;
+ case TAG_INTEGER: *p = (f_buf_parse) buf_parse_integer; return true;
+ case TAG_SW: *p = (f_buf_parse) buf_parse_sw; return true;
+ case TAG_S64: *p = (f_buf_parse) buf_parse_s64; return true;
+ case TAG_S32: *p = (f_buf_parse) buf_parse_s32; return true;
+ case TAG_S16: *p = (f_buf_parse) buf_parse_s16; return true;
+ case TAG_S8: *p = (f_buf_parse) buf_parse_s8; return true;
+ case TAG_U8: *p = (f_buf_parse) buf_parse_u8; return true;
+ case TAG_U16: *p = (f_buf_parse) buf_parse_u16; return true;
+ case TAG_U32: *p = (f_buf_parse) buf_parse_u32; return true;
+ case TAG_U64: *p = (f_buf_parse) buf_parse_u64; return true;
+ case TAG_UW: *p = (f_buf_parse) buf_parse_uw; return true;
+ case TAG_LIST: *p = (f_buf_parse) buf_parse_list; return true;
+ case TAG_MAP: *p = (f_buf_parse) buf_parse_map; return true;
+ case TAG_PTAG: *p = (f_buf_parse) buf_parse_ptag; return true;
+ case TAG_PTR: *p = (f_buf_parse) buf_parse_ptr; return true;
+ case TAG_PTR_FREE: *p = (f_buf_parse) buf_parse_ptr_free; return 1;
+ case TAG_QUOTE: *p = (f_buf_parse) buf_parse_quote; return true;
+ case TAG_STR: *p = (f_buf_parse) buf_parse_str; return true;
+ case TAG_STRUCT: *p = (f_buf_parse) buf_parse_struct; return true;
+ case TAG_SYM: *p = (f_buf_parse) buf_parse_sym; return true;
+ case TAG_TUPLE: *p = (f_buf_parse) buf_parse_tuple; return true;
+ case TAG_VAR: *p = (f_buf_parse) buf_parse_var; return true;
}
+ warnx("tag_type_to_buf_parse: invalid tag type: %d", type);
assert(! "tag_type_to_buf_parse: invalid tag type");
- err(1, "tag_type_to_buf_parse: invalid tag type");
- return NULL;
+ return false;
}
-f_init_cast tag_type_to_init_cast (e_tag_type type)
+bool tag_type_to_clean (e_tag_type type, f_clean *dest)
{
switch (type) {
- case TAG_VOID:
- return NULL;
- case TAG_ARRAY:
- return (f_init_cast) array_init_cast;
- case TAG_BOOL:
- return (f_init_cast) bool_init_cast;
- case TAG_CALL:
- return (f_init_cast) call_init_cast;
- case TAG_CFN:
- return (f_init_cast) cfn_init_cast;
+ case TAG_ARRAY: *dest = (f_clean) array_clean; return true;
+ case TAG_BOOL: *dest = NULL; return true;
+ case TAG_CALL: *dest = (f_clean) call_clean; return true;
+ case TAG_CFN: *dest = (f_clean) cfn_clean; return true;
case TAG_CHARACTER:
- return (f_init_cast) character_init_cast;
case TAG_F32:
- return (f_init_cast) f32_init_cast;
case TAG_F64:
- return (f_init_cast) f64_init_cast;
- case TAG_FACT:
- return (f_init_cast) fact_init_cast;
- case TAG_FN:
- return (f_init_cast) fn_init_cast;
- case TAG_IDENT:
- return (f_init_cast) ident_init_cast;
- case TAG_INTEGER:
- return (f_init_cast) integer_init_cast;
+ case TAG_FACT: *dest = NULL; return true;
+ case TAG_FN: *dest = (f_clean) fn_clean; return true;
+ case TAG_IDENT: *dest = NULL; return true;
+ case TAG_INTEGER: *dest = (f_clean) integer_clean; return true;
case TAG_SW:
- return (f_init_cast) sw_init_cast;
case TAG_S64:
- return (f_init_cast) s64_init_cast;
case TAG_S32:
- return (f_init_cast) s32_init_cast;
case TAG_S16:
- return (f_init_cast) s16_init_cast;
case TAG_S8:
- return (f_init_cast) s8_init_cast;
case TAG_U8:
- return (f_init_cast) u8_init_cast;
case TAG_U16:
- return (f_init_cast) u16_init_cast;
case TAG_U32:
- return (f_init_cast) u32_init_cast;
case TAG_U64:
- return (f_init_cast) u64_init_cast;
- case TAG_UW:
- return (f_init_cast) uw_init_cast;
- case TAG_LIST:
- return (f_init_cast) list_init_cast;
- case TAG_MAP:
- return (f_init_cast) map_init_cast;
+ case TAG_UW: *dest = NULL; return true;
+ case TAG_LIST: *dest = (f_clean) list_clean; return true;
+ case TAG_MAP: *dest = (f_clean) map_clean; return true;
case TAG_PTAG:
- return (f_init_cast) ptag_init_cast;
- case TAG_PTR:
- return (f_init_cast) ptr_init_cast;
- case TAG_PTR_FREE:
- return (f_init_cast) ptr_free_init_cast;
- case TAG_QUOTE:
- return (f_init_cast) quote_init_cast;
- case TAG_STR:
- return (f_init_cast) str_init_cast;
- case TAG_STRUCT:
- return (f_init_cast) struct_init_cast;
- case TAG_SYM:
- return (f_init_cast) sym_init_cast;
- case TAG_TUPLE:
- return (f_init_cast) tuple_init_cast;
- case TAG_VAR:
- return NULL;
- }
- warnx("tag_type_to_init_cast: invalid tag type: %d", type);
- assert(! "tag_type_to_init_cast: invalid tag type");
- return NULL;
-}
-
-f_clean tag_type_to_clean (e_tag_type type)
-{
- switch (type) {
- case TAG_ARRAY:
- return (f_clean) array_clean;
- case TAG_BOOL:
- return NULL;
- case TAG_CALL:
- return (f_clean) call_clean;
- case TAG_CFN:
- return (f_clean) cfn_clean;
- case TAG_CHARACTER:
- case TAG_F32:
- case TAG_F64:
- case TAG_FACT:
- return NULL;
- case TAG_FN:
- return (f_clean) fn_clean;
- case TAG_IDENT:
- return NULL;
- case TAG_INTEGER:
- return (f_clean) integer_clean;
- case TAG_SW:
- case TAG_S64:
- case TAG_S32:
- case TAG_S16:
- case TAG_S8:
- case TAG_U8:
- case TAG_U16:
- case TAG_U32:
- case TAG_U64:
- case TAG_UW:
- return NULL;
- case TAG_LIST:
- return (f_clean) list_clean;
- case TAG_MAP:
- return (f_clean) map_clean;
- case TAG_PTAG:
- return NULL;
- case TAG_PTR:
- return NULL;
- case TAG_PTR_FREE:
- return (f_clean) ptr_free_clean;
- case TAG_QUOTE:
- return (f_clean) quote_clean;
- case TAG_STR:
- return (f_clean) str_clean;
- case TAG_STRUCT:
- return (f_clean) struct_clean;
- case TAG_SYM:
- return NULL;
- case TAG_TUPLE:
- return (f_clean) tuple_clean;
+ case TAG_PTR: *dest = NULL; return true;
+ case TAG_PTR_FREE: *dest = (f_clean) ptr_free_clean; return true;
+ case TAG_QUOTE: *dest = (f_clean) quote_clean; return true;
+ case TAG_STR: *dest = (f_clean) str_clean; return true;
+ case TAG_STRUCT: *dest = (f_clean) struct_clean; return true;
+ case TAG_SYM: *dest = NULL; return true;
+ case TAG_TUPLE: *dest = (f_clean) tuple_clean; return true;
case TAG_VAR:
- case TAG_VOID:
- return NULL;
+ case TAG_VOID: *dest = NULL; return true;
}
+ warnx("tag_type_to_clean: invalid tag type: %d", type);
assert(! "tag_type_to_clean: invalid tag type");
- err(1, "tag_type_to_clean: invalid tag type");
- return NULL;
+ return false;
}
-f_env_eval tag_type_to_env_eval (e_tag_type type)
+bool tag_type_to_env_eval (e_tag_type type, f_env_eval *dest)
{
switch (type) {
- case TAG_VOID:
- return (f_env_eval) env_eval_void;
- case TAG_ARRAY:
- return (f_env_eval) env_eval_array_tag;
- case TAG_CALL:
- return (f_env_eval) env_eval_call;
- case TAG_IDENT:
- return (f_env_eval) env_eval_ident;
- case TAG_LIST:
- return (f_env_eval) env_eval_list;
- case TAG_MAP:
- return (f_env_eval) env_eval_map;
- case TAG_QUOTE:
- return (f_env_eval) env_eval_quote;
- case TAG_STRUCT:
- return (f_env_eval) env_eval_struct;
- case TAG_TUPLE:
- return (f_env_eval) env_eval_tuple;
+ case TAG_VOID: *dest = (f_env_eval) env_eval_void; return true;
+ case TAG_ARRAY: *dest = (f_env_eval) env_eval_array_tag; return true;
+ case TAG_CALL: *dest = (f_env_eval) env_eval_call; return true;
+ case TAG_IDENT: *dest = (f_env_eval) env_eval_ident; return true;
+ case TAG_LIST: *dest = (f_env_eval) env_eval_list; return true;
+ case TAG_MAP: *dest = (f_env_eval) env_eval_map; return true;
+ case TAG_QUOTE: *dest = (f_env_eval) env_eval_quote; return true;
+ case TAG_STRUCT: *dest = (f_env_eval) env_eval_struct; return true;
+ case TAG_TUPLE: *dest = (f_env_eval) env_eval_tuple; return true;
case TAG_BOOL:
case TAG_CFN:
case TAG_CHARACTER:
@@ -494,235 +325,183 @@ f_env_eval tag_type_to_env_eval (e_tag_type type)
case TAG_U32:
case TAG_U64:
case TAG_UW:
- case TAG_VAR:
- return NULL;
+ case TAG_VAR: *dest = NULL; return true;
}
warnx("tag_type_to_env_eval: unknown tag type: %d", type);
assert(! "tag_type_to_env_eval: unknown tag type");
- return NULL;
+ return false;
}
-ffi_type * tag_type_to_ffi_type (e_tag_type type)
+bool tag_type_to_ffi_type (e_tag_type type, ffi_type **dest)
{
switch (type) {
- case TAG_ARRAY:
- return &ffi_type_pointer;
- case TAG_BOOL:
- return &ffi_type_uint8;
- case TAG_CALL:
- return &ffi_type_pointer;
- case TAG_CFN:
- return &ffi_type_pointer;
- case TAG_CHARACTER:
- return &ffi_type_schar;
- case TAG_F32:
- return &ffi_type_float;
- case TAG_F64:
- return &ffi_type_double;
- case TAG_FACT:
- return &ffi_type_pointer;
- case TAG_FN:
- return &ffi_type_pointer;
- case TAG_IDENT:
- return &ffi_type_pointer;
- case TAG_INTEGER:
- return &ffi_type_sint;
- case TAG_LIST:
- return &ffi_type_pointer;
- case TAG_MAP:
- return &ffi_type_pointer;
- case TAG_PTAG:
- return &ffi_type_pointer;
+ case TAG_ARRAY: *dest = &ffi_type_pointer; return true;
+ case TAG_BOOL: *dest = &ffi_type_uint8; return true;
+ case TAG_CALL: *dest = &ffi_type_pointer; return true;
+ case TAG_CFN: *dest = &ffi_type_pointer; return true;
+ case TAG_CHARACTER: *dest = &ffi_type_schar; return true;
+ case TAG_F32: *dest = &ffi_type_float; return true;
+ case TAG_F64: *dest = &ffi_type_double; return true;
+ case TAG_FACT: *dest = &ffi_type_pointer; return true;
+ case TAG_FN: *dest = &ffi_type_pointer; return true;
+ case TAG_IDENT: *dest = &ffi_type_pointer; return true;
+ case TAG_INTEGER: *dest = &ffi_type_sint; return true;
+ case TAG_LIST: *dest = &ffi_type_pointer; return true;
+ case TAG_MAP: *dest = &ffi_type_pointer; return true;
+ case TAG_PTAG: *dest = &ffi_type_pointer; return true;
case TAG_PTR:
- case TAG_PTR_FREE:
- return &ffi_type_pointer;
- case TAG_QUOTE:
- return &ffi_type_pointer;
- case TAG_S8:
- return &ffi_type_sint8;
- case TAG_S16:
- return &ffi_type_sint16;
- case TAG_S32:
- return &ffi_type_sint32;
- case TAG_S64:
- return &ffi_type_sint64;
- case TAG_SW:
- return &ffi_type_slong;
- case TAG_STR:
- return &ffi_type_pointer;
- case TAG_STRUCT:
- return &ffi_type_pointer;
- case TAG_SYM:
- return &ffi_type_pointer;
- case TAG_TUPLE:
- return &ffi_type_pointer;
- case TAG_U8:
- return &ffi_type_uint8;
- case TAG_U16:
- return &ffi_type_uint16;
- case TAG_U32:
- return &ffi_type_uint32;
- case TAG_U64:
- return &ffi_type_uint64;
- case TAG_UW:
- return &ffi_type_ulong;
- case TAG_VAR:
- return &ffi_type_pointer;
- case TAG_VOID:
- return &ffi_type_void;
+ case TAG_PTR_FREE: *dest = &ffi_type_pointer; return true;
+ case TAG_QUOTE: *dest = &ffi_type_pointer; return true;
+ case TAG_S8: *dest = &ffi_type_sint8; return true;
+ case TAG_S16: *dest = &ffi_type_sint16; return true;
+ case TAG_S32: *dest = &ffi_type_sint32; return true;
+ case TAG_S64: *dest = &ffi_type_sint64; return true;
+ case TAG_SW: *dest = &ffi_type_slong; return true;
+ case TAG_STR: *dest = &ffi_type_pointer; return true;
+ case TAG_STRUCT: *dest = &ffi_type_pointer; return true;
+ case TAG_SYM: *dest = &ffi_type_pointer; return true;
+ case TAG_TUPLE: *dest = &ffi_type_pointer; return true;
+ case TAG_U8: *dest = &ffi_type_uint8; return true;
+ case TAG_U16: *dest = &ffi_type_uint16; return true;
+ case TAG_U32: *dest = &ffi_type_uint32; return true;
+ case TAG_U64: *dest = &ffi_type_uint64; return true;
+ case TAG_UW: *dest = &ffi_type_ulong; return true;
+ case TAG_VAR: *dest = &ffi_type_pointer; return true;
+ case TAG_VOID: *dest = &ffi_type_void; return true;
}
+ warnx("tag_type_to_ffi_type: unknown tag type: %d", type);
assert(! "tag_type_to_ffi_type: unknown tag type");
- errx(1, "tag_type_to_ffi_type: unknown tag type");
- return &ffi_type_void;
+ return false;
}
-f_hash_update tag_type_to_hash_update (e_tag_type type)
+bool tag_type_to_hash_update (e_tag_type type, f_hash_update *p)
{
switch (type) {
- case TAG_VOID:
- return (f_hash_update) hash_update_void;
- case TAG_ARRAY:
- case TAG_BOOL:
- return (f_hash_update) hash_update_bool;
- case TAG_CALL:
- return (f_hash_update) hash_update_call;
- case TAG_CFN:
- return (f_hash_update) hash_update_cfn;
+ case TAG_VOID: *p = (f_hash_update) hash_update_void; return true;
+ case TAG_ARRAY: *p = (f_hash_update) hash_update_array; return true;
+ case TAG_BOOL: *p = (f_hash_update) hash_update_bool; return true;
+ case TAG_CALL: *p = (f_hash_update) hash_update_call; return true;
+ case TAG_CFN: *p = (f_hash_update) hash_update_cfn; return true;
case TAG_CHARACTER:
- return (f_hash_update) hash_update_character;
- case TAG_F32:
- return (f_hash_update) hash_update_f32;
- case TAG_F64:
- return (f_hash_update) hash_update_f64;
- case TAG_FACT:
- return (f_hash_update) hash_update_fact;
- case TAG_FN:
- return (f_hash_update) hash_update_fn;
- case TAG_IDENT:
- return (f_hash_update) hash_update_ident;
+ *p = (f_hash_update) hash_update_character; return true;
+ case TAG_F32: *p = (f_hash_update) hash_update_f32; return true;
+ case TAG_F64: *p = (f_hash_update) hash_update_f64; return true;
+ case TAG_FACT: *p = (f_hash_update) hash_update_fact; return true;
+ case TAG_FN: *p = (f_hash_update) hash_update_fn; return true;
+ case TAG_IDENT: *p = (f_hash_update) hash_update_ident; return true;
case TAG_INTEGER:
- return (f_hash_update) hash_update_integer;
- case TAG_SW:
- return (f_hash_update) hash_update_sw;
- case TAG_S64:
- return (f_hash_update) hash_update_s64;
- case TAG_S32:
- return (f_hash_update) hash_update_s32;
- case TAG_S16:
- return (f_hash_update) hash_update_s16;
- case TAG_S8:
- return (f_hash_update) hash_update_s8;
- case TAG_U8:
- return (f_hash_update) hash_update_u8;
- case TAG_U16:
- return (f_hash_update) hash_update_u16;
- case TAG_U32:
- return (f_hash_update) hash_update_u32;
- case TAG_U64:
- return (f_hash_update) hash_update_u64;
- case TAG_UW:
- return (f_hash_update) hash_update_uw;
- case TAG_LIST:
- return (f_hash_update) hash_update_list;
- case TAG_MAP:
- return (f_hash_update) hash_update_map;
- case TAG_PTAG:
- return (f_hash_update) hash_update_ptag;
- case TAG_PTR:
- return (f_hash_update) hash_update_ptr;
+ *p = (f_hash_update) hash_update_integer; return true;
+ case TAG_SW: *p = (f_hash_update) hash_update_sw; return true;
+ case TAG_S64: *p = (f_hash_update) hash_update_s64; return true;
+ case TAG_S32: *p = (f_hash_update) hash_update_s32; return true;
+ case TAG_S16: *p = (f_hash_update) hash_update_s16; return true;
+ case TAG_S8: *p = (f_hash_update) hash_update_s8; return true;
+ case TAG_U8: *p = (f_hash_update) hash_update_u8; return true;
+ case TAG_U16: *p = (f_hash_update) hash_update_u16; return true;
+ case TAG_U32: *p = (f_hash_update) hash_update_u32; return true;
+ case TAG_U64: *p = (f_hash_update) hash_update_u64; return true;
+ case TAG_UW: *p = (f_hash_update) hash_update_uw; return true;
+ case TAG_LIST: *p = (f_hash_update) hash_update_list; return true;
+ case TAG_MAP: *p = (f_hash_update) hash_update_map; return true;
+ case TAG_PTAG: *p = (f_hash_update) hash_update_ptag; return true;
+ case TAG_PTR: *p = (f_hash_update) hash_update_ptr; return true;
case TAG_PTR_FREE:
- return (f_hash_update) hash_update_ptr_free;
- case TAG_QUOTE:
- return (f_hash_update) hash_update_quote;
- case TAG_STR:
- return (f_hash_update) hash_update_str;
- case TAG_STRUCT:
- return (f_hash_update) hash_update_struct;
- case TAG_SYM:
- return (f_hash_update) hash_update_sym;
- case TAG_TUPLE:
- return (f_hash_update) hash_update_tuple;
- case TAG_VAR:
- return (f_hash_update) hash_update_var;
+ *p = (f_hash_update) hash_update_ptr_free; return true;
+ case TAG_QUOTE: *p = (f_hash_update) hash_update_quote; return true;
+ case TAG_STR: *p = (f_hash_update) hash_update_str; return true;
+ case TAG_STRUCT: *p = (f_hash_update) hash_update_struct; return true;
+ case TAG_SYM: *p = (f_hash_update) hash_update_sym; return true;
+ case TAG_TUPLE: *p = (f_hash_update) hash_update_tuple; return true;
+ case TAG_VAR: *p = (f_hash_update) hash_update_var; return true;
}
+ warnx("tag_type_to_hash_update: unknown tag type: %d", type);
assert(! "tag_type_to_hash_update: unknown tag type");
- errx(1, "tag_type_to_hash_update: unknown tag type");
- return NULL;
+ return false;
}
-f_init_copy tag_type_to_init_copy (e_tag_type type)
+bool tag_type_to_init_cast (e_tag_type type, f_init_cast *p)
{
switch (type) {
- case TAG_ARRAY:
- return (f_init_copy) array_init_copy;
- case TAG_BOOL:
- return (f_init_copy) bool_init_copy;
- case TAG_CALL:
- return (f_init_copy) call_init_copy;
- case TAG_CFN:
- return (f_init_copy) cfn_init_copy;
+ case TAG_VOID: *p = NULL; return true;
+ case TAG_ARRAY: *p = (f_init_cast) array_init_cast; return true;
+ case TAG_BOOL: *p = (f_init_cast) bool_init_cast; return true;
+ case TAG_CALL: *p = (f_init_cast) call_init_cast; return true;
+ case TAG_CFN: *p = (f_init_cast) cfn_init_cast; return true;
case TAG_CHARACTER:
- return (f_init_copy) character_init_copy;
- case TAG_F32:
- return (f_init_copy) f32_init_copy;
- case TAG_F64:
- return (f_init_copy) f64_init_copy;
- case TAG_FACT:
- return (f_init_copy) fact_init_copy;
- case TAG_FN:
- return (f_init_copy) fn_init_copy;
- case TAG_IDENT:
- return (f_init_copy) ident_init_copy;
- case TAG_INTEGER:
- return (f_init_copy) integer_init_copy;
- case TAG_SW:
- return (f_init_copy) sw_init_copy;
- case TAG_S64:
- return (f_init_copy) s64_init_copy;
- case TAG_S32:
- return (f_init_copy) s32_init_copy;
- case TAG_S16:
- return (f_init_copy) s16_init_copy;
- case TAG_S8:
- return (f_init_copy) s8_init_copy;
- case TAG_U8:
- return (f_init_copy) u8_init_copy;
- case TAG_U16:
- return (f_init_copy) u16_init_copy;
- case TAG_U32:
- return (f_init_copy) u32_init_copy;
- case TAG_U64:
- return (f_init_copy) u64_init_copy;
- case TAG_UW:
- return (f_init_copy) uw_init_copy;
- case TAG_LIST:
- return (f_init_copy) list_init_copy;
- case TAG_MAP:
- return (f_init_copy) map_init_copy;
- case TAG_PTAG:
- return (f_init_copy) ptag_init_copy;
- case TAG_PTR:
- return (f_init_copy) ptr_init_copy;
- case TAG_PTR_FREE:
- return (f_init_copy) ptr_free_init_copy;
- case TAG_QUOTE:
- return (f_init_copy) quote_init_copy;
- case TAG_STR:
- return (f_init_copy) str_init_copy;
- case TAG_STRUCT:
- return (f_init_copy) struct_init_copy;
- case TAG_SYM:
- return (f_init_copy) sym_init_copy;
- case TAG_TUPLE:
- return (f_init_copy) tuple_init_copy;
- case TAG_VAR:
- return (f_init_copy) var_init_copy;
- case TAG_VOID:
- return (f_init_copy) void_init_copy;
+ *p = (f_init_cast) character_init_cast; return true;
+ case TAG_F32: *p = (f_init_cast) f32_init_cast; return true;
+ case TAG_F64: *p = (f_init_cast) f64_init_cast; return true;
+ case TAG_FACT: *p = (f_init_cast) fact_init_cast; return true;
+ case TAG_FN: *p = (f_init_cast) fn_init_cast; return true;
+ case TAG_IDENT: *p = (f_init_cast) ident_init_cast; return true;
+ case TAG_INTEGER: *p = (f_init_cast) integer_init_cast; return true;
+ case TAG_SW: *p = (f_init_cast) sw_init_cast; return true;
+ case TAG_S64: *p = (f_init_cast) s64_init_cast; return true;
+ case TAG_S32: *p = (f_init_cast) s32_init_cast; return true;
+ case TAG_S16: *p = (f_init_cast) s16_init_cast; return true;
+ case TAG_S8: *p = (f_init_cast) s8_init_cast; return true;
+ case TAG_U8: *p = (f_init_cast) u8_init_cast; return true;
+ case TAG_U16: *p = (f_init_cast) u16_init_cast; return true;
+ case TAG_U32: *p = (f_init_cast) u32_init_cast; return true;
+ case TAG_U64: *p = (f_init_cast) u64_init_cast; return true;
+ case TAG_UW: *p = (f_init_cast) uw_init_cast; return true;
+ case TAG_LIST: *p = (f_init_cast) list_init_cast; return true;
+ case TAG_MAP: *p = (f_init_cast) map_init_cast; return true;
+ case TAG_PTAG: *p = (f_init_cast) ptag_init_cast; return true;
+ case TAG_PTR: *p = (f_init_cast) ptr_init_cast; return true;
+ case TAG_PTR_FREE: *p = (f_init_cast) ptr_free_init_cast; return true;
+ case TAG_QUOTE: *p = (f_init_cast) quote_init_cast; return true;
+ case TAG_STR: *p = (f_init_cast) str_init_cast; return true;
+ case TAG_STRUCT: *p = (f_init_cast) struct_init_cast; return true;
+ case TAG_SYM: *p = (f_init_cast) sym_init_cast; return true;
+ case TAG_TUPLE: *p = (f_init_cast) tuple_init_cast; return true;
+ case TAG_VAR: *p = NULL; return true;
}
+ warnx("tag_type_to_init_cast: invalid tag type: %d", type);
+ assert(! "tag_type_to_init_cast: invalid tag type");
+ return false;
+}
+
+bool tag_type_to_init_copy (e_tag_type type, f_init_copy *p)
+{
+ switch (type) {
+ case TAG_ARRAY: *p = (f_init_copy) array_init_copy; return true;
+ case TAG_BOOL: *p = (f_init_copy) bool_init_copy; return true;
+ case TAG_CALL: *p = (f_init_copy) call_init_copy; return true;
+ case TAG_CFN: *p = (f_init_copy) cfn_init_copy; return true;
+ case TAG_CHARACTER: *p = (f_init_copy) character_init_copy; return 1;
+ case TAG_F32: *p = (f_init_copy) f32_init_copy; return true;
+ case TAG_F64: *p = (f_init_copy) f64_init_copy; return true;
+ case TAG_FACT: *p = (f_init_copy) fact_init_copy; return true;
+ case TAG_FN: *p = (f_init_copy) fn_init_copy; return true;
+ case TAG_IDENT: *p = (f_init_copy) ident_init_copy; return true;
+ case TAG_INTEGER: *p = (f_init_copy) integer_init_copy; return true;
+ case TAG_SW: *p = (f_init_copy) sw_init_copy; return true;
+ case TAG_S64: *p = (f_init_copy) s64_init_copy; return true;
+ case TAG_S32: *p = (f_init_copy) s32_init_copy; return true;
+ case TAG_S16: *p = (f_init_copy) s16_init_copy; return true;
+ case TAG_S8: *p = (f_init_copy) s8_init_copy; return true;
+ case TAG_U8: *p = (f_init_copy) u8_init_copy; return true;
+ case TAG_U16: *p = (f_init_copy) u16_init_copy; return true;
+ case TAG_U32: *p = (f_init_copy) u32_init_copy; return true;
+ case TAG_U64: *p = (f_init_copy) u64_init_copy; return true;
+ case TAG_UW: *p = (f_init_copy) uw_init_copy; return true;
+ case TAG_LIST: *p = (f_init_copy) list_init_copy; return true;
+ case TAG_MAP: *p = (f_init_copy) map_init_copy; return true;
+ case TAG_PTAG: *p = (f_init_copy) ptag_init_copy; return true;
+ case TAG_PTR: *p = (f_init_copy) ptr_init_copy; return true;
+ case TAG_PTR_FREE: *p = (f_init_copy) ptr_free_init_copy; return 1;
+ case TAG_QUOTE: *p = (f_init_copy) quote_init_copy; return true;
+ case TAG_STR: *p = (f_init_copy) str_init_copy; return true;
+ case TAG_STRUCT: *p = (f_init_copy) struct_init_copy; return true;
+ case TAG_SYM: *p = (f_init_copy) sym_init_copy; return true;
+ case TAG_TUPLE: *p = (f_init_copy) tuple_init_copy; return true;
+ case TAG_VAR: *p = NULL; return true;
+ case TAG_VOID: *p = NULL; return true;
+ }
+ warnx("tag_type_to_init_copy: invalid tag type: %d", type);
assert(! "tag_type_to_init_copy: invalid tag type");
- err(1, "tag_type_to_init_copy: invalid tag type");
- return NULL;
+ return false;
}
const s8 * tag_type_to_string (e_tag_type type)
diff --git a/libc3/tag_type.h b/libc3/tag_type.h
index f711693..2797809 100644
--- a/libc3/tag_type.h
+++ b/libc3/tag_type.h
@@ -21,16 +21,22 @@
#include "types.h"
-sw tag_type_size (e_tag_type type);
-f_buf_inspect tag_type_to_buf_inspect (e_tag_type type);
-f_buf_inspect_size tag_type_to_buf_inspect_size (e_tag_type type);
-f_buf_parse tag_type_to_buf_parse (e_tag_type type);
-f_clean tag_type_to_clean (e_tag_type type);
-f_env_eval tag_type_to_env_eval (e_tag_type type);
-f_hash_update tag_type_to_hash_update (e_tag_type type);
-f_init_cast tag_type_to_init_cast (e_tag_type type);
-f_init_copy tag_type_to_init_copy (e_tag_type type);
-const s8 * tag_type_to_string (e_tag_type type);
-const s_sym * tag_type_to_sym (e_tag_type tag_type);
+bool tag_type_to_size (e_tag_type type, uw *size);
+bool tag_type_to_buf_inspect (e_tag_type type,
+ f_buf_inspect *dest);
+bool tag_type_to_buf_inspect_size (e_tag_type type,
+ f_buf_inspect_size *dest);
+bool tag_type_to_buf_parse (e_tag_type type,
+ f_buf_parse *dest);
+bool tag_type_to_clean (e_tag_type type, f_clean *dest);
+bool tag_type_to_env_eval (e_tag_type type, f_env_eval *dest);
+bool tag_type_to_hash_update (e_tag_type type,
+ f_hash_update *dest);
+bool tag_type_to_init_cast (e_tag_type type,
+ f_init_cast *dest);
+bool tag_type_to_init_copy (e_tag_type type,
+ f_init_copy *dest);
+const s8 * tag_type_to_string (e_tag_type type);
+const s_sym * tag_type_to_sym (e_tag_type tag_type);
#endif /* LIBC3_TAG_TYPE */
diff --git a/libc3/tuple.c b/libc3/tuple.c
index ab5c959..9e53ed8 100644
--- a/libc3/tuple.c
+++ b/libc3/tuple.c
@@ -89,6 +89,21 @@ s_tuple * tuple_init_2 (s_tuple *tuple, const s_tag *a, const s_tag *b)
return tuple;
}
+s_tuple * tuple_init_cast (s_tuple *tuple, const s_tag *tag)
+{
+ switch (tag->type) {
+ case TAG_TUPLE:
+ return tuple_init_copy(tuple, &tag->data.tuple);
+ default:
+ break;
+ }
+ err_write_1("tuple_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(tag->type));
+ err_puts(" to Tuple");
+ assert(! "tuple_init_cast: cannot cast to Tuple");
+ return NULL;
+}
+
s_tuple * tuple_init_copy (s_tuple *tuple, const s_tuple *src)
{
uw i = 0;
diff --git a/libc3/u.c.in b/libc3/u.c.in
index fca8f45..406e020 100644
--- a/libc3/u.c.in
+++ b/libc3/u.c.in
@@ -19,77 +19,78 @@
#include "tag.h"
#include "u_bits$.h"
-u_bits$ * u_bits$_cast (s_tag *tag, u_bits$ *dest)
+u_bits$ * u_bits$_init_cast (u_bits$ *u, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *u = tag->data.bool ? 1 : 0;
+ return u;
case TAG_CHARACTER:
- *dest = (u_bits$) tag->data.character;
- return dest;
+ *u = (u_bits$) tag->data.character;
+ return u;
case TAG_F32:
- *dest = (u_bits$) tag->data.f32;
- return dest;
+ *u = (u_bits$) tag->data.f32;
+ return u;
case TAG_F64:
- *dest = (u_bits$) tag->data.f64;
- return dest;
+ *u = (u_bits$) tag->data.f64;
+ return u;
case TAG_INTEGER:
- *dest = integer_to_u_bits$(&tag->data.integer);
- return dest;
+ *u = integer_to_u_bits$(&tag->data.integer);
+ return u;
case TAG_SW:
- *dest = (u_bits$) tag->data.sw;
- return dest;
+ *u = (u_bits$) tag->data.sw;
+ return u;
case TAG_S64:
- *dest = (u_bits$) tag->data.s64;
- return dest;
+ *u = (u_bits$) tag->data.s64;
+ return u;
case TAG_S32:
- *dest = (u_bits$) tag->data.s32;
- return dest;
+ *u = (u_bits$) tag->data.s32;
+ return u;
case TAG_S16:
- *dest = (u_bits$) tag->data.s16;
- return dest;
+ *u = (u_bits$) tag->data.s16;
+ return u;
case TAG_S8:
- *dest = (u_bits$) tag->data.s8;
- return dest;
+ *u = (u_bits$) tag->data.s8;
+ return u;
case TAG_U8:
- *dest = (u_bits$) tag->data.u8;
- return dest;
+ *u = (u_bits$) tag->data.u8;
+ return u;
case TAG_U16:
- *dest = (u_bits$) tag->data.u16;
- return dest;
+ *u = (u_bits$) tag->data.u16;
+ return u;
case TAG_U32:
- *dest = (u_bits$) tag->data.u32;
- return dest;
+ *u = (u_bits$) tag->data.u32;
+ return u;
case TAG_U64:
- *dest = (u_bits$) tag->data.u64;
- return dest;
+ *u = (u_bits$) tag->data.u64;
+ return u;
case TAG_UW:
- *dest = (u_bits$) tag->data.uw;
- return dest;
+ *u = (u_bits$) tag->data.uw;
+ return u;
default:
break;
}
warnx("u_bits$_cast: cannot cast %s to u_bits$",
tag_type_to_string(tag->type));
- return 0;
+ assert(! "u_bits$_cast: cannot cast to u_bits$");
+ return NULL;
}
-u_bits$ * u_bits$_init_copy (u_bits$ *dest, const u_bits$ *src)
+u_bits$ * u_bits$_init_copy (u_bits$ *u, const u_bits$ *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(u);
+ *u = *src;
+ return u;
}
-u_bits$ * u_bits$_random (u_bits$ *dest)
+u_bits$ * u_bits$_random (u_bits$ *u)
{
- arc4random_buf(dest, sizeof(u_bits$));
- return dest;
+ arc4random_buf(u, sizeof(u_bits$));
+ return u;
}
-u_bits$ * u_bits$_random_uniform (u_bits$ max, u_bits$ *dest)
+u_bits$ * u_bits$_random_uniform (u_bits$ *u, u_bits$ max)
{
uw size = (uw) log2(max) / 8;
u_bits$ rest = (max - ((1 << size) - 1)) >> size;
@@ -100,6 +101,6 @@ u_bits$ * u_bits$_random_uniform (u_bits$ max, u_bits$ *dest)
tmp = arc4random_uniform(rest);
result += tmp;
}
- *dest = result;
- return dest;
+ *u = result;
+ return u;
}
diff --git a/libc3/u.h.in b/libc3/u.h.in
index 753e17d..e4d415f 100644
--- a/libc3/u.h.in
+++ b/libc3/u.h.in
@@ -18,7 +18,7 @@
u_bits$ * u_bits$_init_cast (u_bits$ *u, const s_tag *tag);
u_bits$ * u_bits$_init_copy (u_bits$ *u, const u_bits$ *src);
-u_bits$ * u_bits$_random (u_bits$ *dest);
-u_bits$ * u_bits$_random_uniform (u_bits$ max, u_bits$ *dest);
+u_bits$ * u_bits$_random (u_bits$ *u);
+u_bits$ * u_bits$_random_uniform (u_bits$ *u, u_bits$ max);
#endif /* LIBC3_U_BITS$_H */
diff --git a/libc3/u16.c b/libc3/u16.c
index b9ff319..393bff0 100644
--- a/libc3/u16.c
+++ b/libc3/u16.c
@@ -19,77 +19,78 @@
#include "tag.h"
#include "u16.h"
-u16 * u16_cast (s_tag *tag, u16 *dest)
+u16 * u16_init_cast (u16 *u, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *u = tag->data.bool ? 1 : 0;
+ return u;
case TAG_CHARACTER:
- *dest = (u16) tag->data.character;
- return dest;
+ *u = (u16) tag->data.character;
+ return u;
case TAG_F32:
- *dest = (u16) tag->data.f32;
- return dest;
+ *u = (u16) tag->data.f32;
+ return u;
case TAG_F64:
- *dest = (u16) tag->data.f64;
- return dest;
+ *u = (u16) tag->data.f64;
+ return u;
case TAG_INTEGER:
- *dest = integer_to_u16(&tag->data.integer);
- return dest;
+ *u = integer_to_u16(&tag->data.integer);
+ return u;
case TAG_SW:
- *dest = (u16) tag->data.sw;
- return dest;
+ *u = (u16) tag->data.sw;
+ return u;
case TAG_S64:
- *dest = (u16) tag->data.s64;
- return dest;
+ *u = (u16) tag->data.s64;
+ return u;
case TAG_S32:
- *dest = (u16) tag->data.s32;
- return dest;
+ *u = (u16) tag->data.s32;
+ return u;
case TAG_S16:
- *dest = (u16) tag->data.s16;
- return dest;
+ *u = (u16) tag->data.s16;
+ return u;
case TAG_S8:
- *dest = (u16) tag->data.s8;
- return dest;
+ *u = (u16) tag->data.s8;
+ return u;
case TAG_U8:
- *dest = (u16) tag->data.u8;
- return dest;
+ *u = (u16) tag->data.u8;
+ return u;
case TAG_U16:
- *dest = (u16) tag->data.u16;
- return dest;
+ *u = (u16) tag->data.u16;
+ return u;
case TAG_U32:
- *dest = (u16) tag->data.u32;
- return dest;
+ *u = (u16) tag->data.u32;
+ return u;
case TAG_U64:
- *dest = (u16) tag->data.u64;
- return dest;
+ *u = (u16) tag->data.u64;
+ return u;
case TAG_UW:
- *dest = (u16) tag->data.uw;
- return dest;
+ *u = (u16) tag->data.uw;
+ return u;
default:
break;
}
warnx("u16_cast: cannot cast %s to u16",
tag_type_to_string(tag->type));
- return 0;
+ assert(! "u16_cast: cannot cast to u16");
+ return NULL;
}
-u16 * u16_init_copy (u16 *dest, const u16 *src)
+u16 * u16_init_copy (u16 *u, const u16 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(u);
+ *u = *src;
+ return u;
}
-u16 * u16_random (u16 *dest)
+u16 * u16_random (u16 *u)
{
- arc4random_buf(dest, sizeof(u16));
- return dest;
+ arc4random_buf(u, sizeof(u16));
+ return u;
}
-u16 * u16_random_uniform (u16 max, u16 *dest)
+u16 * u16_random_uniform (u16 *u, u16 max)
{
uw size = (uw) log2(max) / 8;
u16 rest = (max - ((1 << size) - 1)) >> size;
@@ -100,6 +101,6 @@ u16 * u16_random_uniform (u16 max, u16 *dest)
tmp = arc4random_uniform(rest);
result += tmp;
}
- *dest = result;
- return dest;
+ *u = result;
+ return u;
}
diff --git a/libc3/u16.h b/libc3/u16.h
index 99b1d42..1dca4ba 100644
--- a/libc3/u16.h
+++ b/libc3/u16.h
@@ -18,7 +18,7 @@
u16 * u16_init_cast (u16 *u, const s_tag *tag);
u16 * u16_init_copy (u16 *u, const u16 *src);
-u16 * u16_random (u16 *dest);
-u16 * u16_random_uniform (u16 max, u16 *dest);
+u16 * u16_random (u16 *u);
+u16 * u16_random_uniform (u16 *u, u16 max);
#endif /* LIBC3_U16_H */
diff --git a/libc3/u32.c b/libc3/u32.c
index e015b6f..1b79bba 100644
--- a/libc3/u32.c
+++ b/libc3/u32.c
@@ -19,77 +19,78 @@
#include "tag.h"
#include "u32.h"
-u32 * u32_cast (s_tag *tag, u32 *dest)
+u32 * u32_init_cast (u32 *u, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *u = tag->data.bool ? 1 : 0;
+ return u;
case TAG_CHARACTER:
- *dest = (u32) tag->data.character;
- return dest;
+ *u = (u32) tag->data.character;
+ return u;
case TAG_F32:
- *dest = (u32) tag->data.f32;
- return dest;
+ *u = (u32) tag->data.f32;
+ return u;
case TAG_F64:
- *dest = (u32) tag->data.f64;
- return dest;
+ *u = (u32) tag->data.f64;
+ return u;
case TAG_INTEGER:
- *dest = integer_to_u32(&tag->data.integer);
- return dest;
+ *u = integer_to_u32(&tag->data.integer);
+ return u;
case TAG_SW:
- *dest = (u32) tag->data.sw;
- return dest;
+ *u = (u32) tag->data.sw;
+ return u;
case TAG_S64:
- *dest = (u32) tag->data.s64;
- return dest;
+ *u = (u32) tag->data.s64;
+ return u;
case TAG_S32:
- *dest = (u32) tag->data.s32;
- return dest;
+ *u = (u32) tag->data.s32;
+ return u;
case TAG_S16:
- *dest = (u32) tag->data.s16;
- return dest;
+ *u = (u32) tag->data.s16;
+ return u;
case TAG_S8:
- *dest = (u32) tag->data.s8;
- return dest;
+ *u = (u32) tag->data.s8;
+ return u;
case TAG_U8:
- *dest = (u32) tag->data.u8;
- return dest;
+ *u = (u32) tag->data.u8;
+ return u;
case TAG_U16:
- *dest = (u32) tag->data.u16;
- return dest;
+ *u = (u32) tag->data.u16;
+ return u;
case TAG_U32:
- *dest = (u32) tag->data.u32;
- return dest;
+ *u = (u32) tag->data.u32;
+ return u;
case TAG_U64:
- *dest = (u32) tag->data.u64;
- return dest;
+ *u = (u32) tag->data.u64;
+ return u;
case TAG_UW:
- *dest = (u32) tag->data.uw;
- return dest;
+ *u = (u32) tag->data.uw;
+ return u;
default:
break;
}
warnx("u32_cast: cannot cast %s to u32",
tag_type_to_string(tag->type));
- return 0;
+ assert(! "u32_cast: cannot cast to u32");
+ return NULL;
}
-u32 * u32_init_copy (u32 *dest, const u32 *src)
+u32 * u32_init_copy (u32 *u, const u32 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(u);
+ *u = *src;
+ return u;
}
-u32 * u32_random (u32 *dest)
+u32 * u32_random (u32 *u)
{
- arc4random_buf(dest, sizeof(u32));
- return dest;
+ arc4random_buf(u, sizeof(u32));
+ return u;
}
-u32 * u32_random_uniform (u32 max, u32 *dest)
+u32 * u32_random_uniform (u32 *u, u32 max)
{
uw size = (uw) log2(max) / 8;
u32 rest = (max - ((1 << size) - 1)) >> size;
@@ -100,6 +101,6 @@ u32 * u32_random_uniform (u32 max, u32 *dest)
tmp = arc4random_uniform(rest);
result += tmp;
}
- *dest = result;
- return dest;
+ *u = result;
+ return u;
}
diff --git a/libc3/u32.h b/libc3/u32.h
index 45398ac..9741d33 100644
--- a/libc3/u32.h
+++ b/libc3/u32.h
@@ -18,7 +18,7 @@
u32 * u32_init_cast (u32 *u, const s_tag *tag);
u32 * u32_init_copy (u32 *u, const u32 *src);
-u32 * u32_random (u32 *dest);
-u32 * u32_random_uniform (u32 max, u32 *dest);
+u32 * u32_random (u32 *u);
+u32 * u32_random_uniform (u32 *u, u32 max);
#endif /* LIBC3_U32_H */
diff --git a/libc3/u64.c b/libc3/u64.c
index bf5a47f..cbfd63d 100644
--- a/libc3/u64.c
+++ b/libc3/u64.c
@@ -19,77 +19,78 @@
#include "tag.h"
#include "u64.h"
-u64 * u64_cast (s_tag *tag, u64 *dest)
+u64 * u64_init_cast (u64 *u, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *u = tag->data.bool ? 1 : 0;
+ return u;
case TAG_CHARACTER:
- *dest = (u64) tag->data.character;
- return dest;
+ *u = (u64) tag->data.character;
+ return u;
case TAG_F32:
- *dest = (u64) tag->data.f32;
- return dest;
+ *u = (u64) tag->data.f32;
+ return u;
case TAG_F64:
- *dest = (u64) tag->data.f64;
- return dest;
+ *u = (u64) tag->data.f64;
+ return u;
case TAG_INTEGER:
- *dest = integer_to_u64(&tag->data.integer);
- return dest;
+ *u = integer_to_u64(&tag->data.integer);
+ return u;
case TAG_SW:
- *dest = (u64) tag->data.sw;
- return dest;
+ *u = (u64) tag->data.sw;
+ return u;
case TAG_S64:
- *dest = (u64) tag->data.s64;
- return dest;
+ *u = (u64) tag->data.s64;
+ return u;
case TAG_S32:
- *dest = (u64) tag->data.s32;
- return dest;
+ *u = (u64) tag->data.s32;
+ return u;
case TAG_S16:
- *dest = (u64) tag->data.s16;
- return dest;
+ *u = (u64) tag->data.s16;
+ return u;
case TAG_S8:
- *dest = (u64) tag->data.s8;
- return dest;
+ *u = (u64) tag->data.s8;
+ return u;
case TAG_U8:
- *dest = (u64) tag->data.u8;
- return dest;
+ *u = (u64) tag->data.u8;
+ return u;
case TAG_U16:
- *dest = (u64) tag->data.u16;
- return dest;
+ *u = (u64) tag->data.u16;
+ return u;
case TAG_U32:
- *dest = (u64) tag->data.u32;
- return dest;
+ *u = (u64) tag->data.u32;
+ return u;
case TAG_U64:
- *dest = (u64) tag->data.u64;
- return dest;
+ *u = (u64) tag->data.u64;
+ return u;
case TAG_UW:
- *dest = (u64) tag->data.uw;
- return dest;
+ *u = (u64) tag->data.uw;
+ return u;
default:
break;
}
warnx("u64_cast: cannot cast %s to u64",
tag_type_to_string(tag->type));
- return 0;
+ assert(! "u64_cast: cannot cast to u64");
+ return NULL;
}
-u64 * u64_init_copy (u64 *dest, const u64 *src)
+u64 * u64_init_copy (u64 *u, const u64 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(u);
+ *u = *src;
+ return u;
}
-u64 * u64_random (u64 *dest)
+u64 * u64_random (u64 *u)
{
- arc4random_buf(dest, sizeof(u64));
- return dest;
+ arc4random_buf(u, sizeof(u64));
+ return u;
}
-u64 * u64_random_uniform (u64 max, u64 *dest)
+u64 * u64_random_uniform (u64 *u, u64 max)
{
uw size = (uw) log2(max) / 8;
u64 rest = (max - ((1 << size) - 1)) >> size;
@@ -100,6 +101,6 @@ u64 * u64_random_uniform (u64 max, u64 *dest)
tmp = arc4random_uniform(rest);
result += tmp;
}
- *dest = result;
- return dest;
+ *u = result;
+ return u;
}
diff --git a/libc3/u64.h b/libc3/u64.h
index 75ffbc3..00f896f 100644
--- a/libc3/u64.h
+++ b/libc3/u64.h
@@ -18,7 +18,7 @@
u64 * u64_init_cast (u64 *u, const s_tag *tag);
u64 * u64_init_copy (u64 *u, const u64 *src);
-u64 * u64_random (u64 *dest);
-u64 * u64_random_uniform (u64 max, u64 *dest);
+u64 * u64_random (u64 *u);
+u64 * u64_random_uniform (u64 *u, u64 max);
#endif /* LIBC3_U64_H */
diff --git a/libc3/u8.c b/libc3/u8.c
index 0df8048..14ddeac 100644
--- a/libc3/u8.c
+++ b/libc3/u8.c
@@ -19,77 +19,78 @@
#include "tag.h"
#include "u8.h"
-u8 * u8_cast (s_tag *tag, u8 *dest)
+u8 * u8_init_cast (u8 *u, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *u = tag->data.bool ? 1 : 0;
+ return u;
case TAG_CHARACTER:
- *dest = (u8) tag->data.character;
- return dest;
+ *u = (u8) tag->data.character;
+ return u;
case TAG_F32:
- *dest = (u8) tag->data.f32;
- return dest;
+ *u = (u8) tag->data.f32;
+ return u;
case TAG_F64:
- *dest = (u8) tag->data.f64;
- return dest;
+ *u = (u8) tag->data.f64;
+ return u;
case TAG_INTEGER:
- *dest = integer_to_u8(&tag->data.integer);
- return dest;
+ *u = integer_to_u8(&tag->data.integer);
+ return u;
case TAG_SW:
- *dest = (u8) tag->data.sw;
- return dest;
+ *u = (u8) tag->data.sw;
+ return u;
case TAG_S64:
- *dest = (u8) tag->data.s64;
- return dest;
+ *u = (u8) tag->data.s64;
+ return u;
case TAG_S32:
- *dest = (u8) tag->data.s32;
- return dest;
+ *u = (u8) tag->data.s32;
+ return u;
case TAG_S16:
- *dest = (u8) tag->data.s16;
- return dest;
+ *u = (u8) tag->data.s16;
+ return u;
case TAG_S8:
- *dest = (u8) tag->data.s8;
- return dest;
+ *u = (u8) tag->data.s8;
+ return u;
case TAG_U8:
- *dest = (u8) tag->data.u8;
- return dest;
+ *u = (u8) tag->data.u8;
+ return u;
case TAG_U16:
- *dest = (u8) tag->data.u16;
- return dest;
+ *u = (u8) tag->data.u16;
+ return u;
case TAG_U32:
- *dest = (u8) tag->data.u32;
- return dest;
+ *u = (u8) tag->data.u32;
+ return u;
case TAG_U64:
- *dest = (u8) tag->data.u64;
- return dest;
+ *u = (u8) tag->data.u64;
+ return u;
case TAG_UW:
- *dest = (u8) tag->data.uw;
- return dest;
+ *u = (u8) tag->data.uw;
+ return u;
default:
break;
}
warnx("u8_cast: cannot cast %s to u8",
tag_type_to_string(tag->type));
- return 0;
+ assert(! "u8_cast: cannot cast to u8");
+ return NULL;
}
-u8 * u8_init_copy (u8 *dest, const u8 *src)
+u8 * u8_init_copy (u8 *u, const u8 *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(u);
+ *u = *src;
+ return u;
}
-u8 * u8_random (u8 *dest)
+u8 * u8_random (u8 *u)
{
- arc4random_buf(dest, sizeof(u8));
- return dest;
+ arc4random_buf(u, sizeof(u8));
+ return u;
}
-u8 * u8_random_uniform (u8 max, u8 *dest)
+u8 * u8_random_uniform (u8 *u, u8 max)
{
uw size = (uw) log2(max) / 8;
u8 rest = (max - ((1 << size) - 1)) >> size;
@@ -100,6 +101,6 @@ u8 * u8_random_uniform (u8 max, u8 *dest)
tmp = arc4random_uniform(rest);
result += tmp;
}
- *dest = result;
- return dest;
+ *u = result;
+ return u;
}
diff --git a/libc3/u8.h b/libc3/u8.h
index 4485d43..9fb1039 100644
--- a/libc3/u8.h
+++ b/libc3/u8.h
@@ -18,7 +18,7 @@
u8 * u8_init_cast (u8 *u, const s_tag *tag);
u8 * u8_init_copy (u8 *u, const u8 *src);
-u8 * u8_random (u8 *dest);
-u8 * u8_random_uniform (u8 max, u8 *dest);
+u8 * u8_random (u8 *u);
+u8 * u8_random_uniform (u8 *u, u8 max);
#endif /* LIBC3_U8_H */
diff --git a/libc3/uw.c b/libc3/uw.c
index c38d09c..08537ec 100644
--- a/libc3/uw.c
+++ b/libc3/uw.c
@@ -19,77 +19,78 @@
#include "tag.h"
#include "uw.h"
-uw * uw_cast (s_tag *tag, uw *dest)
+uw * uw_init_cast (uw *u, const s_tag *tag)
{
switch (tag->type) {
case TAG_BOOL:
- *dest = tag->data.bool ? 1 : 0;
- return dest;
+ *u = tag->data.bool ? 1 : 0;
+ return u;
case TAG_CHARACTER:
- *dest = (uw) tag->data.character;
- return dest;
+ *u = (uw) tag->data.character;
+ return u;
case TAG_F32:
- *dest = (uw) tag->data.f32;
- return dest;
+ *u = (uw) tag->data.f32;
+ return u;
case TAG_F64:
- *dest = (uw) tag->data.f64;
- return dest;
+ *u = (uw) tag->data.f64;
+ return u;
case TAG_INTEGER:
- *dest = integer_to_uw(&tag->data.integer);
- return dest;
+ *u = integer_to_uw(&tag->data.integer);
+ return u;
case TAG_SW:
- *dest = (uw) tag->data.sw;
- return dest;
+ *u = (uw) tag->data.sw;
+ return u;
case TAG_S64:
- *dest = (uw) tag->data.s64;
- return dest;
+ *u = (uw) tag->data.s64;
+ return u;
case TAG_S32:
- *dest = (uw) tag->data.s32;
- return dest;
+ *u = (uw) tag->data.s32;
+ return u;
case TAG_S16:
- *dest = (uw) tag->data.s16;
- return dest;
+ *u = (uw) tag->data.s16;
+ return u;
case TAG_S8:
- *dest = (uw) tag->data.s8;
- return dest;
+ *u = (uw) tag->data.s8;
+ return u;
case TAG_U8:
- *dest = (uw) tag->data.u8;
- return dest;
+ *u = (uw) tag->data.u8;
+ return u;
case TAG_U16:
- *dest = (uw) tag->data.u16;
- return dest;
+ *u = (uw) tag->data.u16;
+ return u;
case TAG_U32:
- *dest = (uw) tag->data.u32;
- return dest;
+ *u = (uw) tag->data.u32;
+ return u;
case TAG_U64:
- *dest = (uw) tag->data.u64;
- return dest;
+ *u = (uw) tag->data.u64;
+ return u;
case TAG_UW:
- *dest = (uw) tag->data.uw;
- return dest;
+ *u = (uw) tag->data.uw;
+ return u;
default:
break;
}
warnx("uw_cast: cannot cast %s to uw",
tag_type_to_string(tag->type));
- return 0;
+ assert(! "uw_cast: cannot cast to uw");
+ return NULL;
}
-uw * uw_init_copy (uw *dest, const uw *src)
+uw * uw_init_copy (uw *u, const uw *src)
{
assert(src);
- assert(dest);
- *dest = *src;
- return dest;
+ assert(u);
+ *u = *src;
+ return u;
}
-uw * uw_random (uw *dest)
+uw * uw_random (uw *u)
{
- arc4random_buf(dest, sizeof(uw));
- return dest;
+ arc4random_buf(u, sizeof(uw));
+ return u;
}
-uw * uw_random_uniform (uw max, uw *dest)
+uw * uw_random_uniform (uw *u, uw max)
{
uw size = (uw) log2(max) / 8;
uw rest = (max - ((1 << size) - 1)) >> size;
@@ -100,6 +101,6 @@ uw * uw_random_uniform (uw max, uw *dest)
tmp = arc4random_uniform(rest);
result += tmp;
}
- *dest = result;
- return dest;
+ *u = result;
+ return u;
}
diff --git a/libc3/uw.h b/libc3/uw.h
index cf4826e..b5b834c 100644
--- a/libc3/uw.h
+++ b/libc3/uw.h
@@ -18,7 +18,7 @@
uw * uw_init_cast (uw *u, const s_tag *tag);
uw * uw_init_copy (uw *u, const uw *src);
-uw * uw_random (uw *dest);
-uw * uw_random_uniform (uw max, uw *dest);
+uw * uw_random (uw *u);
+uw * uw_random_uniform (uw *u, uw max);
#endif /* LIBC3_UW_H */
diff --git a/libc3/window/sdl2/demo/earth.c b/libc3/window/sdl2/demo/earth.c
index 0465dc9..ec0c40a 100644
--- a/libc3/window/sdl2/demo/earth.c
+++ b/libc3/window/sdl2/demo/earth.c
@@ -110,9 +110,9 @@ bool earth_render (s_sequence *seq, s_window_sdl2 *window,
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl_sphere_render(sphere);
/*
- glDisable(GL_TEXTURE_2D);
- glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
- gl_sphere_render_wireframe(sphere);
+ glDisable(GL_TEXTURE_2D);
+ glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+ gl_sphere_render_wireframe(sphere);
*/
} glPopMatrix();
glDisable(GL_TEXTURE_2D);