diff --git a/c3s/configure b/c3s/configure
index 88dc913..0aa1f9e 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -42,8 +42,8 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe -fPIC"
-#LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
-LDFLAGS="${LDFLAGS:=}"
+LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
+#LDFLAGS="${LDFLAGS:=}"
LIBS="${LIBS:=-lm}"
# Common config for all targets
diff --git a/ic3/configure b/ic3/configure
index 1044319..d224494 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -42,8 +42,8 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe -fPIC"
-#LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:-}"
-LDFLAGS="${LDFLAGS:-}"
+LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:-}"
+#LDFLAGS="${LDFLAGS:-}"
LIBS="${LIBS:=-lm}"
# Common config for all targets
diff --git a/libc3/array.c b/libc3/array.c
index 54ab541..783d86d 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -16,6 +16,7 @@
#include <err.h>
#include "array.h"
#include "tag.h"
+#include "type.h"
void array_clean (s_array *a)
{
@@ -26,10 +27,12 @@ void array_clean (s_array *a)
s_array * array_copy (const s_array *src, s_array *dest)
{
+ uw i = 0;
assert(dest);
assert(src);
assert(src->dimension);
assert(src->dimensions);
+ (void) i;
if (! src->dimension) {
assert(! "array_copy: zero dimension");
errx(1, "array_copy: zero dimension");
diff --git a/libc3/array.h b/libc3/array.h
index 6bcbda2..bb6c3e1 100644
--- a/libc3/array.h
+++ b/libc3/array.h
@@ -18,7 +18,7 @@
void array_clean (s_array *a);
s_array * array_copy (const s_array *src, s_array *dest);
s_array * array_init (s_array *a, e_tag_type type, uw dimension,
- const uw *sizes);
+ const uw *dimensions);
void * array_data (const s_array *a, const uw *address);
#endif /* ARRAY_H */
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index d7b204c..3d8691f 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -334,7 +334,7 @@ sw buf_inspect_call_op (s_buf *buf, const s_call *call, s8 op_precedence)
s_tag *right;
left = &call->arguments->tag;
right = &list_next(call->arguments)->tag;
- if (left->type.type == TAG_CALL &&
+ if (left->type == TAG_CALL &&
(precedence = operator_precedence(&left->data.call.ident))
< op_precedence) {
paren = true;
@@ -361,7 +361,7 @@ sw buf_inspect_call_op (s_buf *buf, const s_call *call, s8 op_precedence)
if ((r = buf_write_1(buf, " ")) < 0)
return r;
result += r;
- if (right->type.type == TAG_CALL &&
+ if (right->type == TAG_CALL &&
(precedence = operator_precedence(&right->data.call.ident))
< op_precedence) {
paren = true;
@@ -793,7 +793,6 @@ sw buf_inspect_fn_pattern_size (const s_list *pattern)
{
sw r;
sw result = 0;
- assert(buf);
r = strlen("(");
result += r;
while (pattern) {
@@ -979,7 +978,7 @@ sw buf_inspect_list (s_buf *buf, const s_list *x)
if ((r = buf_inspect_tag(buf, &i->tag)) < 0)
return r;
result += r;
- switch (i->next.type.type) {
+ switch (i->next.type) {
case TAG_LIST:
if (i->next.data.list) {
if ((r = buf_write_1(buf, ", ")) < 0)
@@ -1015,7 +1014,7 @@ sw buf_inspect_list_size (const s_list *list)
if ((r = buf_inspect_tag_size(&i->tag)) < 0)
return r;
result += r;
- switch (i->next.type.type) {
+ switch (i->next.type) {
case TAG_LIST:
if (i->next.data.list)
result += strlen(", ");
@@ -1400,7 +1399,7 @@ sw buf_inspect_tag (s_buf *buf, const s_tag *tag)
{
if (! tag)
return buf_write_1(buf, "NULL");
- switch(tag->type.type) {
+ switch(tag->type) {
case TAG_VOID: return buf_inspect_void(buf, &tag);
case TAG_ARRAY: return buf_inspect_array(buf, &tag->data.array);
case TAG_BOOL: return buf_inspect_bool(buf, &tag->data.bool);
@@ -1440,7 +1439,7 @@ sw buf_inspect_tag (s_buf *buf, const s_tag *tag)
sw buf_inspect_tag_size (const s_tag *tag)
{
assert(tag);
- switch(tag->type.type) {
+ switch(tag->type) {
case TAG_VOID: return buf_inspect_void_size(tag);
case TAG_ARRAY: return buf_inspect_array_size(&tag->data.array);
case TAG_BOOL: return buf_inspect_bool_size(&tag->data.bool);
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 5538981..2f33332 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -301,6 +301,41 @@
sw buf_parse_cfn_arg_types (s_buf *buf, s_list **dest);
+sw buf_parse_array_type (s_buf *buf, e_tag_type *dest)
+{
+ sw r;
+ sw result = 0;
+ s_buf_save save;
+ e_tag_type tmp;
+ s_ident type_ident;
+ buf_save_init(buf, &save);
+ if ((r = buf_read_1(buf, "(")) <= 0)
+ goto clean;
+ result += r;
+ if ((r = buf_ignore_spaces(buf)) < 0)
+ goto restore;
+ result += r;
+ if ((r = buf_parse_ident(buf, &type_ident)) <= 0)
+ goto restore;
+ result += r;
+ if (! ident_to_tag_type(&type_ident, &tmp))
+ goto restore;
+ if ((r = buf_ignore_spaces(buf)) < 0)
+ goto clean;
+ result += r;
+ if ((r = buf_read_1(buf, ")")) <= 0)
+ goto clean;
+ result += r;
+ *dest = tmp;
+ r = result;
+ goto clean;
+ restore:
+ buf_save_restore_rpos(buf, &save);
+ clean:
+ buf_save_clean(buf, &save);
+ return r;
+}
+
sw buf_parse_array (s_buf *buf, s_array *dest)
{
uw *address;
@@ -314,32 +349,18 @@ sw buf_parse_array (s_buf *buf, s_array *dest)
s_buf_save save_data;
s_tag tag;
s_array tmp;
- const s_sym *type;
+ e_tag_type type;
assert(buf);
assert(dest);
buf_save_init(buf, &save);
- if ((r = buf_read_1(buf, "(")) <= 0)
+ if ((r = buf_parse_array_type(buf, &type)) < 0)
goto clean;
result += r;
if ((r = buf_ignore_spaces(buf)) < 0)
- goto clean;
- result += r;
- if ((r = buf_parse_sym(buf, &type)) <= 0)
goto restore;
result += r;
- if (! sym_to_tag_type(type, &tmp.type))
- goto restore;
- item_size = tag_type_size(tmp.type);
+ item_size = tag_type_size(type);
item = tag_to_pointer(&tag, type);
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto clean;
- result += r;
- if ((r = buf_read_1(buf, ")")) <= 0)
- goto clean;
- result += r;
- if ((r = buf_ignore_spaces(buf)) < 0)
- goto clean;
- result += r;
tmp.dimension = 0;
buf_save_init(buf, &save_data);
while ((r = buf_read_1(buf, "[")) > 0) {
@@ -721,7 +742,7 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, u8 min_precedence)
call_init_op(&tmp2);
tmp2.arguments->tag = *right;
if ((r = buf_parse_call_op_rec(buf, &tmp2, (next_op_precedence > op_precedence) ? op_precedence + 1 : op_precedence)) <= 0) {
- tmp2.arguments->tag.type.type = TAG_VOID;
+ tmp2.arguments->tag.type = TAG_VOID;
call_clean(&tmp2);
break;
}
@@ -2102,7 +2123,7 @@ sw buf_parse_tag_array (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_array(buf, &dest->data.array)) > 0)
- dest->type.type = TAG_ARRAY;
+ dest->type = TAG_ARRAY;
return r;
}
@@ -2112,7 +2133,7 @@ sw buf_parse_tag_bool (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_bool(buf, &dest->data.bool)) > 0)
- dest->type.type = TAG_BOOL;
+ dest->type = TAG_BOOL;
return r;
}
@@ -2122,7 +2143,7 @@ sw buf_parse_tag_call (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_call(buf, &dest->data.call)) > 0)
- dest->type.type = TAG_CALL;
+ dest->type = TAG_CALL;
return r;
}
@@ -2132,7 +2153,7 @@ sw buf_parse_tag_call_op (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_call_op(buf, &dest->data.call)) > 0)
- dest->type.type = TAG_CALL;
+ dest->type = TAG_CALL;
return r;
}
@@ -2142,7 +2163,7 @@ sw buf_parse_tag_cfn (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_cfn(buf, &dest->data.cfn)) > 0)
- dest->type.type = TAG_CFN;
+ dest->type = TAG_CFN;
return r;
}
@@ -2152,7 +2173,7 @@ sw buf_parse_tag_character (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_character(buf, &dest->data.character)) > 0)
- dest->type.type = TAG_CHARACTER;
+ dest->type = TAG_CHARACTER;
return r;
}
@@ -2162,7 +2183,7 @@ sw buf_parse_tag_fn (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_fn(buf, &dest->data.fn)) > 0)
- dest->type.type = TAG_FN;
+ dest->type = TAG_FN;
return r;
}
@@ -2172,7 +2193,7 @@ sw buf_parse_tag_ident (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_ident(buf, &dest->data.ident)) > 0)
- dest->type.type = TAG_IDENT;
+ dest->type = TAG_IDENT;
return r;
}
@@ -2182,7 +2203,7 @@ sw buf_parse_tag_integer (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_integer(buf, &dest->data.integer)) > 0)
- dest->type.type = TAG_INTEGER;
+ dest->type = TAG_INTEGER;
return r;
}
@@ -2192,7 +2213,7 @@ sw buf_parse_tag_list (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_list(buf, &dest->data.list)) > 0)
- dest->type.type = TAG_LIST;
+ dest->type = TAG_LIST;
return r;
}
@@ -2254,7 +2275,7 @@ sw buf_parse_tag_quote (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_quote(buf, &dest->data.quote)) > 0)
- dest->type.type = TAG_QUOTE;
+ dest->type = TAG_QUOTE;
return r;
}
@@ -2264,7 +2285,7 @@ sw buf_parse_tag_str (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_str(buf, &dest->data.str)) > 0)
- dest->type.type = TAG_STR;
+ dest->type = TAG_STR;
return r;
}
@@ -2274,7 +2295,7 @@ sw buf_parse_tag_sym (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_sym(buf, &dest->data.sym)) > 0)
- dest->type.type = TAG_SYM;
+ dest->type = TAG_SYM;
return r;
}
@@ -2284,7 +2305,7 @@ sw buf_parse_tag_tuple (s_buf *buf, s_tag *dest)
assert(buf);
assert(dest);
if ((r = buf_parse_tuple(buf, &dest->data.tuple)) > 0)
- dest->type.type = TAG_TUPLE;
+ dest->type = TAG_TUPLE;
return r;
}
diff --git a/libc3/buf_parse.h b/libc3/buf_parse.h
index e85540b..0f302f9 100644
--- a/libc3/buf_parse.h
+++ b/libc3/buf_parse.h
@@ -41,6 +41,7 @@
u ## bits *dest)
sw buf_parse_array (s_buf *buf, s_array *dest);
+sw buf_parse_array_type (s_buf *buf, e_tag_type *type);
sw buf_parse_bool (s_buf *buf, bool *dest);
sw buf_parse_call (s_buf *buf, s_call *dest);
sw buf_parse_call_args_paren (s_buf *buf, s_call *dest);
diff --git a/libc3/c3.h b/libc3/c3.h
index 0aecb13..70ddf8d 100644
--- a/libc3/c3.h
+++ b/libc3/c3.h
@@ -46,6 +46,7 @@
#include "str.h"
#include "tag.h"
#include "tuple.h"
+#include "type.h"
#include "ucd.h"
#define C3_EXT ".c3"
diff --git a/libc3/cfn.c b/libc3/cfn.c
index f431568..4a11cfb 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -48,7 +48,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
if (cfn->arg_result)
cfn_tag_init(&tmp2, cfn->result_type);
/* make result point to tmp value */
- result = tag_to_pointer(&tmp, cfn->result_type);
+ result = tag_to_ffi_pointer(&tmp, cfn->result_type);
if (cfn->arity) {
if (! (arg_pointers = calloc(sizeof(void *), cfn->arity + 1)))
err(1, "cfn_apply");
@@ -57,23 +57,23 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
cfn_arg_types = cfn->arg_types;
a = args;
while (cfn_arg_types) {
- assert(cfn_arg_types->tag.type.type == TAG_SYM);
+ assert(cfn_arg_types->tag.type == TAG_SYM);
if (cfn_arg_types->tag.data.sym == sym_1("&result"))
if (cfn->cif.rtype == &ffi_type_pointer) {
- arg_pointers[i] = tag_to_pointer(&tmp2, cfn->result_type);
+ arg_pointers[i] = tag_to_ffi_pointer(&tmp2, cfn->result_type);
arg_values[i] = &arg_pointers[i];
}
else
- arg_values[i] = tag_to_pointer(&tmp2, cfn->result_type);
+ arg_values[i] = tag_to_ffi_pointer(&tmp2, cfn->result_type);
else {
if (cfn->cif.arg_types[i] == &ffi_type_pointer) {
- arg_pointers[i] = tag_to_pointer(&a->tag,
- cfn_arg_types->tag.data.sym);
+ arg_pointers[i] =
+ tag_to_ffi_pointer(&a->tag, cfn_arg_types->tag.data.sym);
arg_values[i] = &arg_pointers[i];
}
else
- arg_values[i] = tag_to_pointer(&a->tag,
- cfn_arg_types->tag.data.sym);
+ arg_values[i] =
+ tag_to_ffi_pointer(&a->tag, cfn_arg_types->tag.data.sym);
a = list_next(a);
}
cfn_arg_types = list_next(cfn_arg_types);
@@ -176,7 +176,7 @@ s_cfn * cfn_prep_cif (s_cfn *cfn)
a = cfn->arg_types;
while (a) {
assert(i < cfn->arity);
- if (a->tag.type.type != TAG_SYM) {
+ if (a->tag.type != TAG_SYM) {
assert(! "cfn_prep_cif: invalid type");
errx(1, "cfn_prep_cif: invalid type");
}
@@ -211,7 +211,7 @@ s_tag * cfn_tag_init (s_tag *tag, const s_sym *type)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- if (! sym_to_tag_type(type, &tag->type.type)) {
+ if (! sym_to_tag_type(type, &tag->type)) {
assert(! "cfn_tag_init: invalid type");
errx(1, "cfn_tag_init: invalid type: %s", type->str.ptr.ps8);
return NULL;
diff --git a/libc3/compare.c b/libc3/compare.c
index 03b4dfc..f183e95 100644
--- a/libc3/compare.c
+++ b/libc3/compare.c
@@ -366,11 +366,11 @@ s8 compare_tag (const s_tag *a, const s_tag *b) {
a == TAG_LAST ||
b == TAG_FIRST)
return 1;
- if (a->type.type < b->type.type)
+ if (a->type < b->type)
return -1;
- if (a->type.type > b->type.type)
+ if (a->type > b->type)
return 1;
- switch (a->type.type) {
+ switch (a->type) {
case TAG_VOID: return 0;
case TAG_ARRAY: return compare_array(&a->data.array, &b->data.array);
case TAG_BOOL: return compare_bool(a->data.bool, b->data.bool);
@@ -413,9 +413,9 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
{
assert(a);
assert(b);
- switch (a->type.type) {
+ switch (a->type) {
case TAG_INTEGER:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return compare_integer(&a->data.integer, &b->data.integer);
case TAG_S8:
@@ -438,7 +438,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_S8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_s64(&b->data.integer, a->data.s8);
case TAG_S8:
@@ -461,7 +461,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_S16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_s64(&b->data.integer, a->data.s16);
case TAG_S8:
@@ -484,7 +484,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_S32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_s64(&b->data.integer, a->data.s32);
case TAG_S8:
@@ -507,7 +507,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_S64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_s64(&b->data.integer, a->data.s64);
case TAG_S8:
@@ -530,7 +530,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_U8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_u64(&b->data.integer, a->data.u8);
case TAG_S8:
@@ -553,7 +553,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_U16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_u64(&b->data.integer, a->data.u16);
case TAG_S8:
@@ -576,7 +576,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_U32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_u64(&b->data.integer, a->data.u32);
case TAG_S8:
@@ -599,7 +599,7 @@ s8 compare_tag_number (const s_tag *a, const s_tag *b)
}
break;
case TAG_U64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_INTEGER:
return -compare_integer_u64(&b->data.integer, a->data.u64);
case TAG_S8:
diff --git a/libc3/env.c b/libc3/env.c
index d88e352..a89d95e 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -44,7 +44,7 @@ void env_error_f (s_env *env, const char *fmt, ...)
assert(env);
assert(fmt);
va_start(ap, fmt);
- tag.type.type = TAG_STR;
+ tag.type = TAG_STR;
str_init_vf(&tag.data.str, fmt, ap);
va_end(ap);
env_error_tag(env, &tag);
@@ -115,7 +115,7 @@ bool env_eval_call (s_env *env, const s_call *call, s_tag *dest)
&tag_ident, &tag_fn, &tag_var,
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
- if (tag_var.type.type != TAG_FN)
+ if (tag_var.type != TAG_FN)
errx(1, "%s.%s is not a function",
c.ident.module_name->str.ptr.ps8,
c.ident.sym->str.ptr.ps8);
@@ -126,7 +126,7 @@ bool env_eval_call (s_env *env, const s_call *call, s_tag *dest)
&tag_ident, &tag_cfn, &tag_var,
NULL, NULL });
if (facts_with_cursor_next(&cursor)) {
- if (tag_var.type.type != TAG_CFN)
+ if (tag_var.type != TAG_CFN)
errx(1, "%s.%s is not a C function",
c.ident.module_name->str.ptr.ps8,
c.ident.sym->str.ptr.ps8);
@@ -293,23 +293,23 @@ bool env_eval_equal_tag (s_env *env, const s_tag *a, const s_tag *b,
assert(a);
assert(b);
assert(dest);
- if (a->type.type == TAG_IDENT) {
- if (b->type.type == TAG_IDENT)
+ if (a->type == TAG_IDENT) {
+ if (b->type == TAG_IDENT)
warnx("TAG_IDENT = TAG_IDENT");
tag_copy(b, dest);
frame_binding_new(env->frame, a->data.ident.sym, b);
return true;
}
- if (b->type.type == TAG_IDENT) {
+ if (b->type == TAG_IDENT) {
tag_copy(a, dest);
frame_binding_new(env->frame, b->data.ident.sym, a);
return true;
}
- if (a->type.type != b->type.type) {
+ if (a->type != b->type) {
warnx("env_eval_equal_tag: type mismatch");
return false;
}
- switch (a->type.type) {
+ switch (a->type) {
case TAG_VOID:
tag_init_void(dest);
return true;
@@ -320,7 +320,7 @@ bool env_eval_equal_tag (s_env *env, const s_tag *a, const s_tag *b,
return env_eval_equal_list(env, a->data.list, b->data.list,
&dest->data.list);
case TAG_TUPLE:
- dest->type.type = TAG_TUPLE;
+ dest->type = TAG_TUPLE;
return env_eval_equal_tuple(env, &a->data.tuple, &b->data.tuple,
&dest->data.tuple);
case TAG_ARRAY:
@@ -417,7 +417,7 @@ bool env_eval_progn (s_env *env, const s_list *program, s_tag *dest)
bool env_eval_tag (s_env *env, const s_tag *tag, s_tag *dest)
{
- switch (tag->type.type) {
+ switch (tag->type) {
case TAG_VOID:
tag_init_void(dest);
return true;
@@ -577,7 +577,7 @@ s8 env_operator_precedence (s_env *env, const s_ident *op)
NULL, NULL });
if (! facts_with_cursor_next(&cursor))
goto ko;
- if (tag_var.type.type != TAG_U8) {
+ if (tag_var.type != TAG_U8) {
warnx("%s.%s: invalid operator_precedence type",
tmp.module_name->str.ptr.ps8,
tmp.sym->str.ptr.ps8);
diff --git a/libc3/hash.c b/libc3/hash.c
index 767fe74..816464e 100644
--- a/libc3/hash.c
+++ b/libc3/hash.c
@@ -244,8 +244,8 @@ void hash_update_tag (t_hash *hash, const s_tag *tag)
{
assert(hash);
assert(tag);
- hash_update_u64(hash, tag->type.type);
- switch (tag->type.type) {
+ hash_update_u64(hash, tag->type);
+ switch (tag->type) {
case TAG_VOID: break;
case TAG_ARRAY: hash_update_array(hash, &tag->data.array); break;
case TAG_BOOL: hash_update_bool(hash, tag->data.bool); break;
diff --git a/libc3/ident.h b/libc3/ident.h
index bde714f..02d42db 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -42,4 +42,6 @@ s_ident * ident_init (s_ident *ident, const s_sym *sym);
s_str * ident_inspect (const s_ident *ident, s_str *dest);
+bool ident_to_tag_type (const s_ident *ident, e_tag_type *dest);
+
#endif
diff --git a/libc3/list.c b/libc3/list.c
index 7cd6129..a1f9882 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -37,7 +37,7 @@ void list_clean (s_list *list)
{
if (list) {
tag_clean(&list->tag);
- if (list->next.type.type != TAG_LIST)
+ if (list->next.type != TAG_LIST)
tag_clean(&list->next);
}
}
@@ -124,7 +124,7 @@ sw list_length (const s_list *list)
s_list * list_next (const s_list *list)
{
assert(list);
- switch (list->next.type.type) {
+ switch (list->next.type) {
case TAG_LIST: return list->next.data.list;
default: return NULL;
}
diff --git a/libc3/tag.c b/libc3/tag.c
index a897eb7..bf4f32f 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -31,9 +31,9 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
assert(a);
assert(b);
assert(dest);
- switch (a->type.type) {
+ switch (a->type) {
case TAG_F32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.f32 + b->data.f32);
case TAG_F64:
@@ -58,7 +58,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_F64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f64(dest, a->data.f64 + b->data.f32);
case TAG_F64:
@@ -83,7 +83,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s8 + b->data.f32);
case TAG_F64:
@@ -108,7 +108,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s16 + b->data.f32);
case TAG_F64:
@@ -133,7 +133,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s32 + b->data.f32);
case TAG_F64:
@@ -158,7 +158,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s64 + b->data.f32);
case TAG_F64:
@@ -183,7 +183,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u8 + b->data.f32);
case TAG_F64:
@@ -208,7 +208,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u16 + b->data.f32);
case TAG_F64:
@@ -233,7 +233,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u32 + b->data.f32);
case TAG_F64:
@@ -258,7 +258,7 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u64 + b->data.f32);
case TAG_F64:
@@ -287,8 +287,8 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
}
ko:
errx(1, "cannot add %s to %s",
- tag_type_to_string(a->type.type),
- tag_type_to_string(b->type.type));
+ tag_type_to_string(a->type),
+ tag_type_to_string(b->type));
}
s_tag * tag_array (s_tag *tag, const s_array *a)
@@ -310,7 +310,7 @@ s_tag * tag_cast_integer_to_s8 (s_tag *tag)
{
s8 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_s8(&tag->data.integer);
return tag_s8(tag, i);
}
@@ -319,7 +319,7 @@ s_tag * tag_cast_integer_to_s16 (s_tag *tag)
{
s16 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_s16(&tag->data.integer);
return tag_s16(tag, i);
}
@@ -328,7 +328,7 @@ s_tag * tag_cast_integer_to_s32 (s_tag *tag)
{
s32 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_s32(&tag->data.integer);
return tag_s32(tag, i);
}
@@ -337,7 +337,7 @@ s_tag * tag_cast_integer_to_s64 (s_tag *tag)
{
s64 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_s64(&tag->data.integer);
return tag_s64(tag, i);
}
@@ -346,7 +346,7 @@ s_tag * tag_cast_integer_to_u8 (s_tag *tag)
{
u8 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_u8(&tag->data.integer);
return tag_u8(tag, i);
}
@@ -355,7 +355,7 @@ s_tag * tag_cast_integer_to_u16 (s_tag *tag)
{
u16 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_u16(&tag->data.integer);
return tag_u16(tag, i);
}
@@ -364,7 +364,7 @@ s_tag * tag_cast_integer_to_u32 (s_tag *tag)
{
u32 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_u32(&tag->data.integer);
return tag_u32(tag, i);
}
@@ -373,7 +373,7 @@ s_tag * tag_cast_integer_to_u64 (s_tag *tag)
{
u64 i;
assert(tag);
- assert(tag->type.type == TAG_INTEGER);
+ assert(tag->type == TAG_INTEGER);
i = integer_to_u64(&tag->data.integer);
return tag_u64(tag, i);
}
@@ -388,7 +388,7 @@ s_tag * tag_character (s_tag *tag, character x)
void tag_clean (s_tag *tag)
{
assert(tag);
- switch (tag->type.type) {
+ switch (tag->type) {
case TAG_ARRAY: array_clean(&tag->data.array); break;
case TAG_CALL:
case TAG_CALL_FN:
@@ -425,7 +425,7 @@ s_tag * tag_copy (const s_tag *src, s_tag *dest)
{
assert(src);
assert(dest);
- switch (src->type.type) {
+ switch (src->type) {
case TAG_VAR:
tag_init_var(dest);
break;
@@ -478,7 +478,7 @@ s_tag * tag_copy (const s_tag *src, s_tag *dest)
case TAG_U64:
dest->data = src->data;
}
- dest->type.type = src->type.type;
+ dest->type = src->type;
return dest;
}
@@ -493,9 +493,9 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
assert(a);
assert(b);
assert(dest);
- switch (a->type.type) {
+ switch (a->type) {
case TAG_F32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.f32 / b->data.f32);
case TAG_F64:
@@ -520,7 +520,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_F64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f64(dest, a->data.f64 / b->data.f32);
case TAG_F64:
@@ -545,7 +545,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s8 / b->data.f32);
case TAG_F64:
@@ -570,7 +570,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s16 / b->data.f32);
case TAG_F64:
@@ -595,7 +595,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s32 / b->data.f32);
case TAG_F64:
@@ -620,7 +620,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s64 / b->data.f32);
case TAG_F64:
@@ -645,7 +645,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u8 / b->data.f32);
case TAG_F64:
@@ -670,7 +670,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u16 / b->data.f32);
case TAG_F64:
@@ -695,7 +695,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u32 / b->data.f32);
case TAG_F64:
@@ -720,7 +720,7 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u64 / b->data.f32);
case TAG_F64:
@@ -749,8 +749,8 @@ s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
}
ko:
errx(1, "cannot divide %s by %s",
- tag_type_to_string(a->type.type),
- tag_type_to_string(b->type.type));
+ tag_type_to_string(a->type),
+ tag_type_to_string(b->type));
}
s_tag * tag_f32 (s_tag *tag, f32 x)
@@ -827,7 +827,7 @@ s_tag * tag_init_array (s_tag *tag, const s_array *a)
{
assert(tag);
assert(a);
- tag->type.type = TAG_ARRAY;
+ tag->type = TAG_ARRAY;
array_copy(a, &tag->data.array);
return tag;
}
@@ -836,7 +836,7 @@ s_tag * tag_init_bool (s_tag *tag, bool b)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_BOOL;
+ tag->type = TAG_BOOL;
tag->data.bool = b;
return tag;
}
@@ -846,7 +846,7 @@ s_tag * tag_init_call (s_tag *tag, const s_call *call)
assert(tag);
assert(call);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_CALL;
+ tag->type = TAG_CALL;
tag->data.call = *call;
return tag;
}
@@ -855,7 +855,7 @@ s_tag * tag_init_character (s_tag *tag, character c)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_CHARACTER;
+ tag->type = TAG_CHARACTER;
tag->data.character = c;
return tag;
}
@@ -864,7 +864,7 @@ s_tag * tag_init_f32 (s_tag *tag, f32 x)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_F32;
+ tag->type = TAG_F32;
tag->data.f32 = x;
return tag;
}
@@ -873,7 +873,7 @@ s_tag * tag_init_f64 (s_tag *tag, f64 x)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_F64;
+ tag->type = TAG_F64;
tag->data.f64 = x;
return tag;
}
@@ -882,7 +882,7 @@ s_tag * tag_init_ident (s_tag *tag, const s_ident *x)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_IDENT;
+ tag->type = TAG_IDENT;
tag->data.ident = *x;
return tag;
}
@@ -891,7 +891,7 @@ s_tag * tag_init_ident_1 (s_tag *tag, const s8 *p)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_IDENT;
+ tag->type = TAG_IDENT;
ident_init_1(&tag->data.ident, p);
return tag;
}
@@ -900,7 +900,7 @@ s_tag * tag_init_integer (s_tag *tag, const s_integer *i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_INTEGER;
+ tag->type = TAG_INTEGER;
integer_init(&tag->data.integer);
integer_copy(i, &tag->data.integer);
return tag;
@@ -911,7 +911,7 @@ s_tag * tag_init_integer_1 (s_tag *tag, const s8 *p)
s_buf buf;
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_INTEGER;
+ tag->type = TAG_INTEGER;
buf_init_1(&buf, p);
if (buf_parse_integer(&buf, &tag->data.integer) != (sw) strlen(p)) {
assert(! "tag_init_integer_1: invalid integer");
@@ -927,7 +927,7 @@ s_tag * tag_init_list (s_tag *tag, s_list *list)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_LIST;
+ tag->type = TAG_LIST;
tag->data.list = list;
return tag;
}
@@ -937,7 +937,7 @@ s_tag * tag_init_list_1 (s_tag *tag, const s8 *p)
s_buf buf;
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_LIST;
+ tag->type = TAG_LIST;
buf_init_1(&buf, p);
if (buf_parse_list(&buf, &tag->data.list) != (sw) strlen(p)) {
assert(! "tag_init_list_1: invalid list");
@@ -953,7 +953,7 @@ s_tag * tag_init_s8 (s_tag *tag, s8 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_S8;
+ tag->type = TAG_S8;
tag->data.s8 = i;
return tag;
}
@@ -962,7 +962,7 @@ s_tag * tag_init_s16 (s_tag *tag, s16 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_S16;
+ tag->type = TAG_S16;
tag->data.s16 = i;
return tag;
}
@@ -971,7 +971,7 @@ s_tag * tag_init_s32 (s_tag *tag, s32 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_S32;
+ tag->type = TAG_S32;
tag->data.s32 = i;
return tag;
}
@@ -980,7 +980,7 @@ s_tag * tag_init_s64 (s_tag *tag, s64 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_S64;
+ tag->type = TAG_S64;
tag->data.s64 = i;
return tag;
}
@@ -989,7 +989,7 @@ s_tag * tag_init_str (s_tag *tag, s8 *free, uw size, const s8 *p)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_STR;
+ tag->type = TAG_STR;
str_init(&tag->data.str, free, size, p);
return tag;
}
@@ -998,7 +998,7 @@ s_tag * tag_init_str_1 (s_tag *tag, s8 *free, const s8 *p)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_STR;
+ tag->type = TAG_STR;
str_init_1(&tag->data.str, free, p);
return tag;
}
@@ -1008,7 +1008,7 @@ s_tag * tag_init_sym (s_tag *tag, const s_sym *p)
assert(tag);
assert(p);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_SYM;
+ tag->type = TAG_SYM;
tag->data.sym = p;
return tag;
}
@@ -1019,7 +1019,7 @@ s_tag * tag_init_sym_1 (s_tag *tag, const s8 *p)
assert(tag);
assert(p);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_SYM;
+ tag->type = TAG_SYM;
buf_init_1(&buf, p);
if (buf_parse_sym(&buf, &tag->data.sym) != (sw) strlen(p)) {
assert(! "tag_init_sym_1: invalid symbol");
@@ -1035,7 +1035,7 @@ s_tag * tag_init_u8 (s_tag *tag, u8 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_U8;
+ tag->type = TAG_U8;
tag->data.u8 = i;
return tag;
}
@@ -1044,7 +1044,7 @@ s_tag * tag_init_u16 (s_tag *tag, u16 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_U16;
+ tag->type = TAG_U16;
tag->data.u16 = i;
return tag;
}
@@ -1053,7 +1053,7 @@ s_tag * tag_init_u32 (s_tag *tag, u32 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_U32;
+ tag->type = TAG_U32;
tag->data.u32 = i;
return tag;
}
@@ -1062,7 +1062,7 @@ s_tag * tag_init_u64 (s_tag *tag, u64 i)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_U64;
+ tag->type = TAG_U64;
tag->data.u64 = i;
return tag;
}
@@ -1071,7 +1071,7 @@ s_tag * tag_init_var (s_tag *tag)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_VAR;
+ tag->type = TAG_VAR;
return tag;
}
@@ -1079,7 +1079,7 @@ s_tag * tag_init_void (s_tag *tag)
{
assert(tag);
bzero(tag, sizeof(s_tag));
- tag->type.type = TAG_VOID;
+ tag->type = TAG_VOID;
return tag;
}
@@ -1120,7 +1120,7 @@ s_tag * tag_integer_reduce (s_tag *tag)
uw bytes;
e_bool negative;
assert(tag);
- switch (tag->type.type) {
+ switch (tag->type) {
case TAG_INTEGER:
bytes = integer_bytes(&tag->data.integer);
if (bytes > 8)
@@ -1152,13 +1152,13 @@ s_tag * tag_integer_reduce (s_tag *tag)
e_bool tag_is_bound_var (const s_tag *tag)
{
return (tag &&
- tag->type.type != TAG_VAR);
+ tag->type != TAG_VAR);
}
e_bool tag_is_number (const s_tag *tag)
{
assert(tag);
- switch (tag->type.type) {
+ switch (tag->type) {
case TAG_INTEGER:
case TAG_S8:
case TAG_S16:
@@ -1177,7 +1177,7 @@ e_bool tag_is_number (const s_tag *tag)
e_bool tag_is_unbound_var (const s_tag *tag)
{
return (tag &&
- tag->type.type == TAG_VAR);
+ tag->type == TAG_VAR);
}
s_tag * tag_list (s_tag *tag, s_list *x)
@@ -1199,9 +1199,9 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
assert(a);
assert(b);
assert(dest);
- switch (a->type.type) {
+ switch (a->type) {
case TAG_F32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.f32 * b->data.f32);
case TAG_F64:
@@ -1226,7 +1226,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_F64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f64(dest, a->data.f64 * b->data.f32);
case TAG_F64:
@@ -1251,7 +1251,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s8 * b->data.f32);
case TAG_F64:
@@ -1276,7 +1276,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s16 * b->data.f32);
case TAG_F64:
@@ -1301,7 +1301,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s32 * b->data.f32);
case TAG_F64:
@@ -1326,7 +1326,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s64 * b->data.f32);
case TAG_F64:
@@ -1351,7 +1351,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u8 * b->data.f32);
case TAG_F64:
@@ -1376,7 +1376,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u16 * b->data.f32);
case TAG_F64:
@@ -1401,7 +1401,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u32 * b->data.f32);
case TAG_F64:
@@ -1426,7 +1426,7 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u64 * b->data.f32);
case TAG_F64:
@@ -1455,8 +1455,8 @@ s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
}
ko:
errx(1, "cannot multiply %s by %s",
- tag_type_to_string(a->type.type),
- tag_type_to_string(b->type.type));
+ tag_type_to_string(a->type),
+ tag_type_to_string(b->type));
}
s_tag * tag_new ()
@@ -1537,9 +1537,9 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
assert(a);
assert(b);
assert(dest);
- switch (a->type.type) {
+ switch (a->type) {
case TAG_F32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.f32 - b->data.f32);
case TAG_F64:
@@ -1564,7 +1564,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_F64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f64(dest, a->data.f64 - b->data.f32);
case TAG_F64:
@@ -1589,7 +1589,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s8 - b->data.f32);
case TAG_F64:
@@ -1614,7 +1614,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s16 - b->data.f32);
case TAG_F64:
@@ -1639,7 +1639,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s32 - b->data.f32);
case TAG_F64:
@@ -1664,7 +1664,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_S64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.s64 - b->data.f32);
case TAG_F64:
@@ -1689,7 +1689,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U8:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u8 - b->data.f32);
case TAG_F64:
@@ -1714,7 +1714,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U16:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u16 - b->data.f32);
case TAG_F64:
@@ -1739,7 +1739,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U32:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u32 - b->data.f32);
case TAG_F64:
@@ -1764,7 +1764,7 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
goto ko;
}
case TAG_U64:
- switch (b->type.type) {
+ switch (b->type) {
case TAG_F32:
return tag_init_f32(dest, a->data.u64 - b->data.f32);
case TAG_F64:
@@ -1793,8 +1793,8 @@ s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
}
ko:
errx(1, "cannot subtract %s by %s",
- tag_type_to_string(a->type.type),
- tag_type_to_string(b->type.type));
+ tag_type_to_string(a->type),
+ tag_type_to_string(b->type));
}
s_tag * tag_sym (s_tag *tag, const s_sym *x)
@@ -1811,11 +1811,11 @@ s_tag * tag_sym_1 (s_tag *tag, const s8 *p)
return tag_init_sym_1(tag, p);
}
-void * tag_to_pointer (s_tag *tag, const s_sym *type)
+void * tag_to_ffi_pointer (s_tag *tag, const s_sym *type)
{
if (type == sym_1("tag"))
return tag;
- switch (tag->type.type) {
+ switch (tag->type) {
case TAG_VOID:
if (type == sym_1("void"))
return NULL;
@@ -1938,7 +1938,7 @@ void * tag_to_pointer (s_tag *tag, const s_sym *type)
return NULL;
invalid_type:
warnx("tag_to_pointer: cannot cast %s to %s",
- tag_type_to_sym(tag->type.type)->str.ptr.ps8,
+ tag_type_to_sym(tag->type)->str.ptr.ps8,
type->str.ptr.ps8);
return NULL;
}
diff --git a/libc3/tag.h b/libc3/tag.h
index b9ab1a7..28644d5 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -99,7 +99,9 @@ s8 tag_number_compare (const s_tag *a, const s_tag *b);
sw tag_size (const s_tag *tag);
sw tag_type_size (e_tag_type type);
f_buf_parse tag_type_to_buf_parse (e_tag_type type);
-void * tag_to_pointer (s_tag *tag, const s_sym *type);
+void * tag_to_ffi_pointer (s_tag *tag, const s_sym *type);
+ffi_type tag_to_ffi_type(const s_tag *tag);
+void * tag_to_pointer (s_tag *tag, e_tag_type type);
s8 * tag_type_to_string (e_tag_type type);
const s_sym * tag_type_to_sym (e_tag_type tag_type);
@@ -140,8 +142,6 @@ s_tag * tag_u64 (s_tag *tag, u64 i);
s_tag * tag_u8 (s_tag *tag, u8 i);
s_tag * tag_var (s_tag *tag);
s_tag * tag_void (s_tag *tag);
-void * tag_to_pointer (s_tag *tag, const s_sym *type);
-ffi_type tag_to_ffi_type(const s_tag *tag);
/* operators */
s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest);
diff --git a/libc3/type.c b/libc3/type.c
new file mode 100644
index 0000000..c0cfb48
--- /dev/null
+++ b/libc3/type.c
@@ -0,0 +1,19 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#include "type.h"
+
+void type_clean (s_type *t);
+s_type * type_copy (const s_type *t, s_type *dest);
+s_type * type_init (s_type *t, const s_ident *ident);
+sw type_size (const s_type *t);
+bool type_to_tag_type (const s_type *t, e_tag_type *tag_type);
diff --git a/libc3/type.h b/libc3/type.h
new file mode 100644
index 0000000..dce133d
--- /dev/null
+++ b/libc3/type.h
@@ -0,0 +1,33 @@
+/* c3
+ * Copyright 2022,2023 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+/**
+ * @file type.h
+ * @brief C3 types.
+ *
+ * Structure to manipulate C3 type.
+ */
+#ifndef TYPE_H
+#define TYPE_H
+
+#include "types.h"
+
+/* Stack allocation compatible functions, call type_clean after use. */
+void type_clean (s_type *t);
+s_type * type_init (s_type *t, const s_ident *ident);
+
+/* Observers */
+s_type * type_copy (const s_type *t, s_type *dest);
+sw type_size (const s_type *t);
+bool type_to_tag_type (const s_type *t, e_tag_type *tag_type);
+
+#endif /* TYPE_H */
diff --git a/libc3/types.h b/libc3/types.h
index d3655a5..1d4a133 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -223,7 +223,7 @@ struct struct_ {
void *data;
uw count;
s_module *module;
- s_ident *type;
+ e_tag_type type;
};
struct sym_list {
@@ -332,7 +332,7 @@ struct type {
/* 4 */
struct array {
uw dimension;
- s_type type;
+ e_tag_type type;
s_array_dimension *dimensions;
uw size;
void *data;
diff --git a/libtommath b/libtommath
index dcbb148..b8ce37d 160000
--- a/libtommath
+++ b/libtommath
@@ -1 +1 @@
-Subproject commit dcbb148d00d82455f0dc69bd6a98f5391af4fc15
+Subproject commit b8ce37d2566a02604815f1b6cd9e5d2fa41354a7
diff --git a/test/cfn_test.c b/test/cfn_test.c
index 9598714..5aaf7df 100644
--- a/test/cfn_test.c
+++ b/test/cfn_test.c
@@ -57,7 +57,7 @@ TEST_CASE(cfn_apply)
args = list_new(NULL, NULL);
tag_init_bool(&args->tag, false);
TEST_EQ(cfn_apply(&a, args, &result), &result);
- TEST_EQ(result.type.type, TAG_BOOL);
+ TEST_EQ(result.type, TAG_BOOL);
TEST_EQ(result.data.bool, true);
list_delete_all(args);
cfn_clean(&a);
@@ -82,8 +82,8 @@ TEST_CASE(cfn_copy)
a_arg_types = a.arg_types;
b_arg_types = b.arg_types;
while (a_arg_types && b_arg_types) {
- TEST_EQ(a_arg_types->tag.type.type, TAG_SYM);
- TEST_EQ(a_arg_types->tag.type.type, b_arg_types->tag.type.type);
+ TEST_EQ(a_arg_types->tag.type, TAG_SYM);
+ TEST_EQ(a_arg_types->tag.type, b_arg_types->tag.type);
TEST_EQ(a_arg_types->tag.data.sym, b_arg_types->tag.data.sym);
a_arg_types = list_next(a_arg_types);
b_arg_types = list_next(b_arg_types);
@@ -112,9 +112,9 @@ TEST_CASE(cfn_init_clean)
TEST_EQ(a.arity, 1);
TEST_EQ(a.result_type, sym_1("bool"));
TEST_EQ(a.arg_result, false);
- TEST_EQ(a.arg_types->tag.type.type, TAG_SYM);
+ TEST_EQ(a.arg_types->tag.type, TAG_SYM);
TEST_EQ(a.arg_types->tag.data.sym, sym_1("bool"));
- TEST_EQ(a.arg_types->next.type.type, TAG_LIST);
+ TEST_EQ(a.arg_types->next.type, TAG_LIST);
TEST_EQ(a.arg_types->next.data.list, NULL);
TEST_EQ(a.cif.abi, 0);
TEST_EQ(a.cif.nargs, 0);
diff --git a/test/configure b/test/configure
index 82aba7e..413e534 100755
--- a/test/configure
+++ b/test/configure
@@ -42,8 +42,8 @@ echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
CPPFLAGS="${CPPFLAGS:=}"
ENV_CFLAGS="${CFLAGS:=}"
DEFAULT_CFLAGS="-O2 -pipe"
-#LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
-LDFLAGS="${LDFLAGS:=}"
+LDFLAGS="-Wl,--allow-shlib-undefined ${LDFLAGS:=}"
+#LDFLAGS="${LDFLAGS:=}"
LIBS="${LIBS:=} -lm"
# Common config for all targets