diff --git a/libc3/array.c b/libc3/array.c
index 1d8a362..62173d0 100644
--- a/libc3/array.c
+++ b/libc3/array.c
@@ -241,7 +241,8 @@ s_array * array_init_1 (s_array *array, const char *p)
return array;
}
-s_array * array_init_cast (s_array *array, const s_sym *type, const s_tag *tag)
+s_array * array_init_cast (s_array *array, const s_sym * const *type,
+ const s_tag *tag)
{
assert(array);
assert(type);
@@ -257,7 +258,13 @@ s_array * array_init_cast (s_array *array, const s_sym *type, const s_tag *tag)
}
err_write_1("array_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to Array");
+ if (*type == &g_sym_Array)
+ err_puts(" to Array");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka Array");
+ }
assert(! "array_init_cast: cannot cast to Array");
return NULL;
}
diff --git a/libc3/array.h b/libc3/array.h
index 2f53517..07d06f8 100644
--- a/libc3/array.h
+++ b/libc3/array.h
@@ -20,7 +20,7 @@ void array_clean (s_array *a);
s_array * array_init (s_array *a, const s_sym *array_type,
uw dimension, const uw *dimensions);
s_array * array_init_1 (s_array *a, const char *p);
-s_array * array_init_cast (s_array *a, const s_sym *type,
+s_array * array_init_cast (s_array *a, const s_sym * const *type,
const s_tag *tag);
s_array * array_init_copy (s_array *a, const s_array *src);
s_array * array_init_copy_shallow (s_array *a, const s_array *src);
diff --git a/libc3/bool.c b/libc3/bool.c
index f2bb8a6..3b5834e 100644
--- a/libc3/bool.c
+++ b/libc3/bool.c
@@ -21,7 +21,8 @@
#include "sym.h"
#include "tag_type.h"
-bool * bool_init_cast (bool *b, const s_sym *type, const s_tag *tag)
+bool * bool_init_cast (bool *b, const s_sym * const *type,
+ const s_tag *tag)
{
assert(b);
assert(type);
@@ -74,11 +75,11 @@ bool * bool_init_cast (bool *b, const s_sym *type, const s_tag *tag)
}
err_write_1("bool_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Bool)
+ if (*type == &g_sym_Bool)
err_puts(" to Bool");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Bool");
}
assert(! "bool_cast: cannot cast to Bool");
diff --git a/libc3/bool.h b/libc3/bool.h
index 0c36b85..7670326 100644
--- a/libc3/bool.h
+++ b/libc3/bool.h
@@ -22,7 +22,8 @@
#include "types.h"
/* Stack-allocation compatible functions */
-bool * bool_init_cast (bool *b, const s_sym *type, const s_tag *tag);
+bool * bool_init_cast (bool *b, const s_sym * const *type,
+ const s_tag *tag);
bool * bool_init_copy (bool *b, const bool *src);
/* Observers */
diff --git a/libc3/c3.c b/libc3/c3.c
index 8f74f72..e02d00f 100644
--- a/libc3/c3.c
+++ b/libc3/c3.c
@@ -110,9 +110,11 @@ s_tag * c3_if_then_else (const s_tag *cond, const s_tag *then,
{
bool b;
s_tag tmp;
+ const s_sym *type;
if (! env_eval_tag(&g_c3_env, cond, &tmp))
return NULL;
- if (! bool_init_cast(&b, &g_sym_Bool, &tmp)) {
+ type = &g_sym_Bool;
+ if (! bool_init_cast(&b, &type, &tmp)) {
tag_clean(&tmp);
return NULL;
}
diff --git a/libc3/c3.h b/libc3/c3.h
index c4f6eab..5542da2 100644
--- a/libc3/c3.h
+++ b/libc3/c3.h
@@ -49,6 +49,7 @@
#include "cfn.h"
#include "character.h"
#include "compare.h"
+#include "data.h"
#include "env.h"
#include "error.h"
#include "eval.h"
diff --git a/libc3/call.c b/libc3/call.c
index 9b25dfc..0a733d0 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -104,70 +104,6 @@ bool call_get (s_call *call, s_facts *facts)
return true;
}
-bool call_op_get (s_call *call, s_facts *facts)
-{
- s_facts_cursor cursor;
- s_tag tag_ident;
- s_tag tag_is_a;
- s_tag tag_macro;
- s_tag tag_module_name;
- s_tag tag_special_operator;
- s_tag tag_sym;
- s_tag tag_symbol;
- s_tag tag_symbol_value;
- s_tag tag_var;
- tag_init_ident(&tag_ident, &call->ident);
- tag_init_sym( &tag_is_a, &g_sym_is_a);
- tag_init_sym( &tag_macro, &g_sym_macro);
- tag_init_sym( &tag_module_name, call->ident.module);
- tag_init_sym( &tag_special_operator, &g_sym_special_operator);
- tag_init_sym( &tag_sym, call->ident.sym);
- tag_init_sym( &tag_symbol, &g_sym_symbol);
- tag_init_sym( &tag_symbol, &g_sym_symbol_value);
- tag_init_var( &tag_var);
- if (! facts_find_fact_by_tags(facts, &tag_module_name,
- &tag_symbol, &tag_ident)) {
- err_write_1("call_op_get: symbol ");
- err_write_1(call->ident.sym->str.ptr.pchar);
- err_write_1(" not found in module ");
- err_write_1(call->ident.module->str.ptr.pchar);
- err_write_1("\n");
- return false;
- }
- if (! facts_with_tags(facts, &cursor, &tag_ident, &tag_symbol_value,
- &tag_var))
- return false;
- if (facts_cursor_next(&cursor)) {
- if (tag_var.type == TAG_CFN)
- call->cfn = cfn_new_copy(&tag_var.data.cfn);
- else if (tag_var.type == TAG_FN)
- call->fn = fn_new_copy(&tag_var.data.fn);
- else {
- err_write_1("call_op_get: ");
- err_inspect_ident(&call->ident);
- err_puts(" is not a function");
- facts_cursor_clean(&cursor);
- return false;
- }
- }
- facts_cursor_clean(&cursor);
- if (facts_find_fact_by_tags(facts, &tag_ident, &tag_is_a,
- &tag_macro)) {
- if (call->fn)
- call->fn->macro = true;
- if (call->cfn)
- call->cfn->macro = true;
- }
- if (facts_find_fact_by_tags(facts, &tag_ident, &tag_is_a,
- &tag_special_operator)) {
- if (call->fn)
- call->fn->special_operator = true;
- if (call->cfn)
- call->cfn->special_operator = true;
- }
- return true;
-}
-
s_call * call_init (s_call *call)
{
assert(call);
@@ -216,7 +152,7 @@ s_call * call_init_call_cast (s_call *call, const s_sym *type)
return call;
}
-s_call * call_init_cast (s_call *call, const s_sym *type,
+s_call * call_init_cast (s_call *call, const s_sym * const *type,
const s_tag *tag)
{
assert(call);
@@ -230,11 +166,11 @@ s_call * call_init_cast (s_call *call, const s_sym *type,
}
err_write_1("call_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Call)
+ if (*type == &g_sym_Call)
err_puts(" to Call");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Call");
}
assert(! "call_init_cast: cannot cast to Call");
@@ -289,3 +225,67 @@ s_str * call_inspect (const s_call *call, s_str *dest)
assert(tmp.wpos == tmp.size);
return buf_to_str(&tmp, dest);
}
+
+bool call_op_get (s_call *call, s_facts *facts)
+{
+ s_facts_cursor cursor;
+ s_tag tag_ident;
+ s_tag tag_is_a;
+ s_tag tag_macro;
+ s_tag tag_module_name;
+ s_tag tag_special_operator;
+ s_tag tag_sym;
+ s_tag tag_symbol;
+ s_tag tag_symbol_value;
+ s_tag tag_var;
+ tag_init_ident(&tag_ident, &call->ident);
+ tag_init_sym( &tag_is_a, &g_sym_is_a);
+ tag_init_sym( &tag_macro, &g_sym_macro);
+ tag_init_sym( &tag_module_name, call->ident.module);
+ tag_init_sym( &tag_special_operator, &g_sym_special_operator);
+ tag_init_sym( &tag_sym, call->ident.sym);
+ tag_init_sym( &tag_symbol, &g_sym_symbol);
+ tag_init_sym( &tag_symbol, &g_sym_symbol_value);
+ tag_init_var( &tag_var);
+ if (! facts_find_fact_by_tags(facts, &tag_module_name,
+ &tag_symbol, &tag_ident)) {
+ err_write_1("call_op_get: symbol ");
+ err_write_1(call->ident.sym->str.ptr.pchar);
+ err_write_1(" not found in module ");
+ err_write_1(call->ident.module->str.ptr.pchar);
+ err_write_1("\n");
+ return false;
+ }
+ if (! facts_with_tags(facts, &cursor, &tag_ident, &tag_symbol_value,
+ &tag_var))
+ return false;
+ if (facts_cursor_next(&cursor)) {
+ if (tag_var.type == TAG_CFN)
+ call->cfn = cfn_new_copy(&tag_var.data.cfn);
+ else if (tag_var.type == TAG_FN)
+ call->fn = fn_new_copy(&tag_var.data.fn);
+ else {
+ err_write_1("call_op_get: ");
+ err_inspect_ident(&call->ident);
+ err_puts(" is not a function");
+ facts_cursor_clean(&cursor);
+ return false;
+ }
+ }
+ facts_cursor_clean(&cursor);
+ if (facts_find_fact_by_tags(facts, &tag_ident, &tag_is_a,
+ &tag_macro)) {
+ if (call->fn)
+ call->fn->macro = true;
+ if (call->cfn)
+ call->cfn->macro = true;
+ }
+ if (facts_find_fact_by_tags(facts, &tag_ident, &tag_is_a,
+ &tag_special_operator)) {
+ if (call->fn)
+ call->fn->special_operator = true;
+ if (call->cfn)
+ call->cfn->special_operator = true;
+ }
+ return true;
+}
diff --git a/libc3/call.h b/libc3/call.h
index c6f1a39..2ac99ed 100644
--- a/libc3/call.h
+++ b/libc3/call.h
@@ -20,7 +20,7 @@ void call_clean (s_call *call);
s_call * call_init (s_call *call);
s_call * call_init_1 (s_call *call, const char *p);
s_call * call_init_call_cast (s_call *call, const s_sym *type);
-s_call * call_init_cast (s_call *call, const s_sym *type,
+s_call * call_init_cast (s_call *call, const s_sym * const *type,
const s_tag *tag);
s_call * call_init_copy (s_call *call, const s_call *src);
s_call * call_init_op (s_call *call);
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 066cc00..cd5a8bd 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -180,7 +180,8 @@ 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_sym *type, const s_tag *tag)
+s_cfn * cfn_init_cast (s_cfn *cfn, const s_sym * const *type,
+ const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -191,7 +192,13 @@ s_cfn * cfn_init_cast (s_cfn *cfn, const s_sym *type, const s_tag *tag)
}
err_write_1("cfn_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to Cfn");
+ if (*type == &g_sym_Cfn)
+ err_puts(" to Cfn");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka Cfn");
+ }
assert(! "cfn_init_cast: cannot cast to Cfn");
return NULL;
}
diff --git a/libc3/cfn.h b/libc3/cfn.h
index 8b81fb0..ac6ecf2 100644
--- a/libc3/cfn.h
+++ b/libc3/cfn.h
@@ -19,7 +19,8 @@
void cfn_clean (s_cfn *cfn);
s_cfn * cfn_init (s_cfn *cfn, const s_sym *name, s_list *arg_types,
const s_sym *result_type);
-s_cfn * cfn_init_cast (s_cfn *cfn, const s_sym *type, const s_tag *tag);
+s_cfn * cfn_init_cast (s_cfn *cfn, const s_sym * const *type,
+ const s_tag *tag);
s_cfn * cfn_init_copy (s_cfn *cfn, const s_cfn *src);
/* Heap-allocation functions, call cfn_delete after use. */
diff --git a/libc3/character.c b/libc3/character.c
index 73e1641..2b17a11 100644
--- a/libc3/character.c
+++ b/libc3/character.c
@@ -28,7 +28,7 @@ character character_1 (const char *p)
return c;
}
-character * character_init_cast (character *c, const s_sym *type,
+character * character_init_cast (character *c, const s_sym * const *type,
const s_tag *tag)
{
assert(c);
@@ -53,11 +53,11 @@ character * character_init_cast (character *c, const s_sym *type,
}
err_write_1("character_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Character)
+ if (*type == &g_sym_Character)
err_puts(" to Character");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Character");
}
assert(! "character_cast: cannot cast to Character");
diff --git a/libc3/character.h b/libc3/character.h
index d244579..9e6f8a0 100644
--- a/libc3/character.h
+++ b/libc3/character.h
@@ -18,7 +18,7 @@
character character_1 (const char *p);
void character_hash_update (character c, t_hash *hash);
-character * character_init_cast (character *c, const s_sym *type,
+character * character_init_cast (character *c, const s_sym * const *type,
const s_tag *tag);
character * character_init_copy (character *c, const character *src);
bool character_is_digit (character c);
diff --git a/libc3/complex.c b/libc3/complex.c
index 7db55d2..90808a0 100644
--- a/libc3/complex.c
+++ b/libc3/complex.c
@@ -115,7 +115,8 @@ s_complex * complex_init (s_complex *c)
return c;
}
-s_complex * complex_init_cast (s_complex *c, const s_tag *src)
+s_complex * complex_init_cast (s_complex *c, const s_sym * const *type,
+ const s_tag *src)
{
assert(c);
assert(src);
@@ -155,6 +156,16 @@ s_complex * complex_init_cast (s_complex *c, const s_tag *src)
default:
break;
}
+ err_write_1("complex_init_cast: cannot cast ");
+ err_write_1(tag_type_to_string(src->type));
+ if (*type == &g_sym_F64)
+ err_puts(" to F64");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka F64");
+ }
+ assert(! "f64_init_cast: cannot cast to F64");
err_puts("complex_init_cast: invalid tag type");
assert(! "complex_init_cast: invalid tag type");
return NULL;
@@ -237,11 +248,13 @@ s_complex * complex_new_add (const s_complex *a, const s_complex *b)
s_complex * complex_new_cast (const s_tag *src)
{
s_complex *c;
+ const s_sym *type;
assert(src);
c = alloc(sizeof(s_complex));
if (! c)
return NULL;
- if (! complex_init_cast(c, src)) {
+ type = &g_sym_Complex;
+ if (! complex_init_cast(c, &type, src)) {
free(c);
return NULL;
}
@@ -337,29 +350,35 @@ bool complex_is_zero(const s_complex *c)
f32 complex_to_f32 (const s_complex *c)
{
s_tag norm;
+ const s_sym *type;
f32 x;
assert(c);
complex_norm(c, &norm);
- f32_init_cast(&x, &g_sym_F32, &norm);
+ type = &g_sym_F32;
+ f32_init_cast(&x, &type, &norm);
return x;
}
f64 complex_to_f64 (const s_complex *c)
{
s_tag norm;
+ const s_sym *type;
f64 x;
assert(c);
complex_norm(c, &norm);
- f64_init_cast(&x, &g_sym_F64, &norm);
+ type = &g_sym_F64;
+ f64_init_cast(&x, &type, &norm);
return x;
}
f128 complex_to_f128 (const s_complex *c)
{
s_tag norm;
+ const s_sym *type;
f128 x;
assert(c);
complex_norm(c, &norm);
- f128_init_cast(&x, &g_sym_F128, &norm);
+ type = &g_sym_F128;
+ f128_init_cast(&x, &type, &norm);
return x;
}
diff --git a/libc3/complex.h b/libc3/complex.h
index 6ca25e2..0c9ce3a 100644
--- a/libc3/complex.h
+++ b/libc3/complex.h
@@ -20,7 +20,8 @@
void complex_clean (s_complex *c);
s_complex * complex_init (s_complex *c);
s_complex * complex_init_1 (s_complex *c, const s8 *p);
-s_complex * complex_init_cast (s_complex *c, const s_tag *src);
+s_complex * complex_init_cast (s_complex *c, const s_sym * const *type,
+ const s_tag *src);
s_complex * complex_init_copy (s_complex *c, const s_complex *src);
s_complex * complex_init_f32 (s_complex *c, f32 src);
s_complex * complex_init_f64 (s_complex *c, f64 src);
diff --git a/libc3/data.c b/libc3/data.c
index 392f9a5..d658eae 100644
--- a/libc3/data.c
+++ b/libc3/data.c
@@ -475,78 +475,81 @@ bool data_hash_update (const s_sym *type, t_hash *hash, const void *data)
return false;
}
-void * data_init_cast (void *data, const s_sym *type, const s_tag *tag)
+void * data_init_cast (void *data, const s_sym * const *type,
+ const s_tag *tag)
{
+ const s_sym *t;
const s_struct_type *st;
- if (type == &g_sym_Array ||
- sym_is_array_type(type))
+ t = *type;
+ if (t == &g_sym_Array ||
+ sym_is_array_type(*type))
return array_init_cast(data, type, tag);
- if (type == &g_sym_Bool)
+ if (t == &g_sym_Bool)
return bool_init_cast(data, type, tag);
- if (type == &g_sym_Call)
+ if (t == &g_sym_Call)
return call_init_cast(data, type, tag);
- if (type == &g_sym_Cfn)
+ if (t == &g_sym_Cfn)
return cfn_init_cast(data, type, tag);
- if (type == &g_sym_Character)
+ if (t == &g_sym_Character)
return character_init_cast(data, type, tag);
- if (type == &g_sym_F32)
+ if (t == &g_sym_F32)
return f32_init_cast(data, type, tag);
- if (type == &g_sym_F64)
+ if (t == &g_sym_F64)
return f64_init_cast(data, type, tag);
- if (type == &g_sym_Fact)
+ if (t == &g_sym_Fact)
return fact_init_cast(data, type, tag);
- if (type == &g_sym_Fn)
+ if (t == &g_sym_Fn)
return fn_init_cast(data, type, tag);
- if (type == &g_sym_Ident)
+ if (t == &g_sym_Ident)
return ident_init_cast(data, type, tag);
- if (type == &g_sym_Integer)
+ if (t == &g_sym_Integer)
return integer_init_cast(data, type, tag);
- if (type == &g_sym_List)
+ if (t == &g_sym_List)
return list_init_cast(data, type, tag);
- if (type == &g_sym_Ptag)
+ if (t == &g_sym_Ptag)
return ptag_init_cast(data, type, tag);
- if (type == &g_sym_Ptr)
+ if (t == &g_sym_Ptr)
return ptr_init_cast(data, type, tag);
- if (type == &g_sym_PtrFree)
+ if (t == &g_sym_PtrFree)
return ptr_free_init_cast(data, type, tag);
- if (type == &g_sym_Quote)
+ if (t == &g_sym_Quote)
return quote_init_cast(data, type, tag);
- if (type == &g_sym_S8)
+ if (t == &g_sym_S8)
return s8_init_cast(data, type, tag);
- if (type == &g_sym_S16)
+ if (t == &g_sym_S16)
return s16_init_cast(data, type, tag);
- if (type == &g_sym_S32)
+ if (t == &g_sym_S32)
return s32_init_cast(data, type, tag);
- if (type == &g_sym_S64)
+ if (t == &g_sym_S64)
return s64_init_cast(data, type, tag);
- if (type == &g_sym_Str)
+ if (t == &g_sym_Str)
return str_init_cast(data, type, tag);
- if (type == &g_sym_Sw)
+ if (t == &g_sym_Sw)
return sw_init_cast(data, type, tag);
- if (type == &g_sym_Sym)
+ if (t == &g_sym_Sym)
return sym_init_cast(data, type, tag);
- if (type == &g_sym_Tag)
+ if (t == &g_sym_Tag)
return tag_init_copy(data, tag);
- if (type == &g_sym_Tuple)
+ if (t == &g_sym_Tuple)
return tuple_init_cast(data, type, tag);
- if (type == &g_sym_U8)
+ if (t == &g_sym_U8)
return u8_init_cast(data, type, tag);
- if (type == &g_sym_U16)
+ if (t == &g_sym_U16)
return u16_init_cast(data, type, tag);
- if (type == &g_sym_U32)
+ if (t == &g_sym_U32)
return u32_init_cast(data, type, tag);
- if (type == &g_sym_U64)
+ if (t == &g_sym_U64)
return u64_init_cast(data, type, tag);
- if (type == &g_sym_Uw)
+ if (t == &g_sym_Uw)
return uw_init_cast(data, type, tag);
- if (type == &g_sym_Var)
+ if (t == &g_sym_Var)
return var_init_cast(data, type, tag);
- if (type == &g_sym_Void)
+ if (t == &g_sym_Void)
return data;
/*
- if (sym_is_array_type(type)) {
+ if (sym_is_array_type(t)) {
*/
- st = struct_type_find(type);
+ st = struct_type_find(t);
if (st) {
s_struct s = {0};
s.type = st;
@@ -554,7 +557,7 @@ void * data_init_cast (void *data, const s_sym *type, const s_tag *tag)
return struct_init_cast(&s, type, tag);
}
err_write_1("data_init_cast: unknown type: ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_write_1("\n");
assert(! "data_init_cast: unknown type");
return NULL;
diff --git a/libc3/data.h b/libc3/data.h
index dbc3177..524d3b0 100644
--- a/libc3/data.h
+++ b/libc3/data.h
@@ -27,7 +27,7 @@ bool data_clean (const s_sym *type, void *v);
bool data_compare (const s_sym *type, const void *a, const void *b);
bool data_hash_update (const s_sym *type, t_hash *hash,
const void *s);
-void * data_init_cast (void *v, const s_sym *type, const s_tag *src);
+void * data_init_cast (void *v, const s_sym * const *type, const s_tag *src);
void * data_init_copy (const s_sym *type, void *v, const void *src);
#endif /* LIBC3_DATA_H */
diff --git a/libc3/env.c b/libc3/env.c
index d61d807..3dfef2f 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -298,7 +298,7 @@ bool env_eval_array (s_env *env, const s_array *array, s_array *dest)
while (i < tmp.count) {
if (! env_eval_tag(env, tag, &tag_eval))
goto ko;
- if (! data_init_cast(data, tmp.element_type, &tag_eval)) {
+ if (! data_init_cast(data, &tmp.element_type, &tag_eval)) {
err_write_1("env_eval_array: cannot cast ");
err_inspect_tag(&tag_eval);
err_write_1(" to ");
@@ -1685,7 +1685,7 @@ bool env_eval_struct (s_env *env, const s_struct *s, s_tag *dest)
if (! env_eval_tag(env, s->tag + i, &tag))
goto ko;
if (! data_init_cast((s8 *) t->data + t->type->offset[i],
- type, &tag)) {
+ &type, &tag)) {
err_write_1("env_eval_struct: invalid type ");
err_write_1(tag_type_to_string(tag.type));
err_write_1(" for key ");
diff --git a/libc3/f128.c b/libc3/f128.c
index 5bce202..5988417 100644
--- a/libc3/f128.c
+++ b/libc3/f128.c
@@ -20,7 +20,8 @@
#include "tag_type.h"
#include "u64.h"
-f128 * f128_init_cast (f128 *x, const s_sym *type, const s_tag *tag)
+f128 * f128_init_cast (f128 *x, const s_sym * const *type,
+ const s_tag *tag)
{
assert(x);
assert(type);
@@ -82,11 +83,11 @@ f128 * f128_init_cast (f128 *x, const s_sym *type, const s_tag *tag)
}
err_write_1("f128_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_F128)
+ if (*type == &g_sym_F128)
err_puts(" to F128");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka F128");
}
assert(! "f128_init_cast: cannot cast to F128");
diff --git a/libc3/f128.h b/libc3/f128.h
index 261744d..5d78548 100644
--- a/libc3/f128.h
+++ b/libc3/f128.h
@@ -15,7 +15,8 @@
#include "types.h"
-f128 * f128_init_cast (f128 *x, const s_sym *type, const s_tag *tag);
+f128 * f128_init_cast (f128 *x, const s_sym * const *type,
+ const s_tag *tag);
f128 * f128_init_copy (f128 *x, const f128 *src);
f128 * f128_random (f128 *x);
diff --git a/libc3/f32.c b/libc3/f32.c
index 3dc20aa..cb4272d 100644
--- a/libc3/f32.c
+++ b/libc3/f32.c
@@ -20,7 +20,8 @@
#include "tag_type.h"
#include "u32.h"
-f32 * f32_init_cast (f32 *x, const s_sym *type, const s_tag *tag)
+f32 * f32_init_cast (f32 *x, const s_sym * const *type,
+ const s_tag *tag)
{
assert(x);
assert(type);
@@ -79,11 +80,11 @@ f32 * f32_init_cast (f32 *x, const s_sym *type, const s_tag *tag)
}
err_write_1("f32_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_F32)
+ if (*type == &g_sym_F32)
err_puts(" to F32");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka F32");
}
assert(! "f32_init_cast: cannot cast to F32");
diff --git a/libc3/f32.h b/libc3/f32.h
index db5345a..971a2b7 100644
--- a/libc3/f32.h
+++ b/libc3/f32.h
@@ -15,7 +15,8 @@
#include "types.h"
-f32 * f32_init_cast (f32 *x, const s_sym *type, const s_tag *tag);
+f32 * f32_init_cast (f32 *x, const s_sym * const *type,
+ const s_tag *tag);
f32 * f32_init_copy (f32 *x, const f32 *src);
f32 * f32_random (f32 *x);
diff --git a/libc3/f64.c b/libc3/f64.c
index 4457968..31bca3b 100644
--- a/libc3/f64.c
+++ b/libc3/f64.c
@@ -20,7 +20,7 @@
#include "tag_type.h"
#include "u64.h"
-f64 * f64_init_cast (f64 *x, const s_sym *type, const s_tag *tag)
+f64 * f64_init_cast (f64 *x, const s_sym * const *type, const s_tag *tag)
{
assert(x);
assert(type);
@@ -76,11 +76,11 @@ f64 * f64_init_cast (f64 *x, const s_sym *type, const s_tag *tag)
}
err_write_1("f64_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_F64)
+ if (*type == &g_sym_F64)
err_puts(" to F64");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka F64");
}
assert(! "f64_init_cast: cannot cast to F64");
diff --git a/libc3/f64.h b/libc3/f64.h
index c233ce0..4e1ea84 100644
--- a/libc3/f64.h
+++ b/libc3/f64.h
@@ -15,7 +15,8 @@
#include "types.h"
-f64 * f64_init_cast (f64 *x, const s_sym *type, const s_tag *tag);
+f64 * f64_init_cast (f64 *x, const s_sym * const *type,
+ const s_tag *tag);
f64 * f64_init_copy (f64 *x, const f64 *src);
f64 * f64_random (f64 *x);
diff --git a/libc3/fact.c b/libc3/fact.c
index caf09aa..11cd450 100644
--- a/libc3/fact.c
+++ b/libc3/fact.c
@@ -40,7 +40,7 @@ s_fact * fact_init (s_fact *fact, const s_tag *subject,
return fact;
}
-s_fact * fact_init_cast (s_fact *fact, const s_sym *type,
+s_fact * fact_init_cast (s_fact *fact, const s_sym * const *type,
const s_tag *tag)
{
assert(fact);
@@ -54,11 +54,11 @@ s_fact * fact_init_cast (s_fact *fact, const s_sym *type,
}
err_write_1("fact_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Fact)
+ if (*type == &g_sym_Fact)
err_puts(" to Fact");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Fact");
}
assert(! "fact_init_cast: cannot cast to Fact");
diff --git a/libc3/fact.h b/libc3/fact.h
index 9123387..9c1d43c 100644
--- a/libc3/fact.h
+++ b/libc3/fact.h
@@ -19,7 +19,7 @@
#define fact_clean(fact) do {} while(0)
s_fact * fact_init (s_fact *fact, const s_tag *subject,
const s_tag *predicate, const s_tag *object);
-s_fact * fact_init_cast (s_fact *fact, const s_sym *type,
+s_fact * fact_init_cast (s_fact *fact, const s_sym * const *type,
const s_tag *tag);
s_fact * fact_init_copy (s_fact *fact, const s_fact *src);
diff --git a/libc3/fn.c b/libc3/fn.c
index 0cf110c..284436e 100644
--- a/libc3/fn.c
+++ b/libc3/fn.c
@@ -82,7 +82,7 @@ s_fn * fn_init_1 (s_fn *fn, char *p)
return fn;
}
-s_fn * fn_init_cast (s_fn *fn, const s_sym *type, const s_tag *tag)
+s_fn * fn_init_cast (s_fn *fn, const s_sym * const *type, const s_tag *tag)
{
assert(fn);
assert(type);
@@ -95,11 +95,11 @@ s_fn * fn_init_cast (s_fn *fn, const s_sym *type, const s_tag *tag)
}
err_write_1("fn_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Fn)
+ if (*type == &g_sym_Fn)
err_puts(" to Fn");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Fn");
}
assert(! "fn_init_cast: cannot cast to Fn");
diff --git a/libc3/fn.h b/libc3/fn.h
index deda5e5..b6a299a 100644
--- a/libc3/fn.h
+++ b/libc3/fn.h
@@ -25,7 +25,8 @@
void fn_clean (s_fn *fn);
s_fn * fn_init (s_fn *fn, const s_sym *module);
s_fn * fn_init_1 (s_fn *fn, char *p);
-s_fn * fn_init_cast (s_fn *fn, const s_sym *type, const s_tag *tag);
+s_fn * fn_init_cast (s_fn *fn, const s_sym * const *type,
+ const s_tag *tag);
s_fn * fn_init_copy (s_fn *fn, const s_fn *src);
/* Heap-allocation functions, call fn_delete after use. */
diff --git a/libc3/ident.c b/libc3/ident.c
index 7bec178..f8d58b8 100644
--- a/libc3/ident.c
+++ b/libc3/ident.c
@@ -159,7 +159,8 @@ s_ident * ident_init_1 (s_ident *ident, const char *p)
return ident;
}
-s_ident * ident_init_cast (s_ident *ident, const s_tag *tag)
+s_ident * ident_init_cast (s_ident *ident, const s_sym * const *type,
+ const s_tag *tag)
{
switch (tag->type) {
case TAG_IDENT:
@@ -170,7 +171,13 @@ s_ident * ident_init_cast (s_ident *ident, const s_tag *tag)
}
err_write_1("ident_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to Ident");
+ if (*type == &g_sym_Ident)
+ err_puts(" to Ident");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka Ident");
+ }
assert(! "ident_init_cast: cannot cast to Ident");
return NULL;
}
diff --git a/libc3/ident.h b/libc3/ident.h
index cd1d38f..7a1621e 100644
--- a/libc3/ident.h
+++ b/libc3/ident.h
@@ -23,7 +23,7 @@
s_ident * ident_init (s_ident *ident, const s_sym *module,
const s_sym *sym);
s_ident * ident_init_1 (s_ident *ident, const char *p);
-s_ident * ident_init_cast (s_ident *ident, const s_sym *type,
+s_ident * ident_init_cast (s_ident *ident, const s_sym * const *type,
const s_tag *tag);
s_ident * ident_init_copy (s_ident *ident, const s_ident *src);
diff --git a/libc3/integer.c b/libc3/integer.c
index ad9bdd9..1406929 100644
--- a/libc3/integer.c
+++ b/libc3/integer.c
@@ -16,6 +16,7 @@
#include "buf_parse.h"
#include "compare.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
@@ -134,7 +135,7 @@ uw integer_bytes (const s_integer *i)
return (integer_bits(i) + 7) / 8;
}
-s_integer * integer_init_cast (s_integer *a, const s_sym *type,
+s_integer * integer_init_cast (s_integer *a, const s_sym * const *type,
const s_tag *tag)
{
(void) type;
@@ -178,8 +179,14 @@ s_integer * integer_init_cast (s_integer *a, const s_sym *type,
}
err_write_1("integer_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to integer");
- assert(! "integer_cast: cannot cast");
+ if (*type == &g_sym_Integer)
+ err_puts(" to Integer");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka Integer");
+ }
+ assert(! "integer_cast: cannot cast to Integer");
return NULL;
}
diff --git a/libc3/integer.h b/libc3/integer.h
index ab2bcd9..46d24e8 100644
--- a/libc3/integer.h
+++ b/libc3/integer.h
@@ -26,7 +26,7 @@
/* Stack allocation compatible functions */
s_integer * integer_init (s_integer *i);
s_integer * integer_init_1 (s_integer *i, const char *p);
-s_integer * integer_init_cast (s_integer *a, const s_sym *type,
+s_integer * integer_init_cast (s_integer *a, const s_sym * const *type,
const s_tag *tag);
s_integer * integer_init_copy (s_integer *a, const s_integer *src);
s_integer * integer_init_f32 (s_integer *a, f32 x);
diff --git a/libc3/list.c b/libc3/list.c
index 2e5256d..0522a31 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -74,7 +74,7 @@ s_list * list_init_1 (s_list *list, const char *p, s_list *next)
return list;
}
-s_list ** list_init_cast (s_list **list, const s_sym *type,
+s_list ** list_init_cast (s_list **list, const s_sym * const *type,
const s_tag *tag)
{
assert(list);
@@ -89,11 +89,11 @@ s_list ** list_init_cast (s_list **list, const s_sym *type,
}
err_write_1("list_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_List)
+ if (*type == &g_sym_List)
err_puts(" to List");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka List");
}
assert(! "list_init_cast: cannot cast to List");
diff --git a/libc3/list.h b/libc3/list.h
index 229383e..d36e057 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -28,7 +28,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 char *p, s_list *next);
-s_list ** list_init_cast (s_list **list, const s_sym *type,
+s_list ** list_init_cast (s_list **list, const s_sym * const *type,
const s_tag *tag);
s_list ** list_init_copy (s_list **list, const s_list * const *src);
s_list * list_init_eval (s_list *list, const char *p);
diff --git a/libc3/ptag.c b/libc3/ptag.c
index a2cef3e..b0eab43 100644
--- a/libc3/ptag.c
+++ b/libc3/ptag.c
@@ -15,7 +15,7 @@
#include "sym.h"
#include "tag_type.h"
-p_tag * ptag_init_cast (p_tag *ptag, const s_sym *type,
+p_tag * ptag_init_cast (p_tag *ptag, const s_sym * const *type,
const s_tag *tag)
{
assert(ptag);
@@ -29,11 +29,11 @@ p_tag * ptag_init_cast (p_tag *ptag, const s_sym *type,
}
err_write_1("ptag_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Ptag)
+ if (*type == &g_sym_Ptag)
err_puts(" to Ptag");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Ptag");
}
assert(! "ptag_init_cast: cannot cast to Ptag");
diff --git a/libc3/ptag.h b/libc3/ptag.h
index b35cb74..f332f24 100644
--- a/libc3/ptag.h
+++ b/libc3/ptag.h
@@ -15,7 +15,7 @@
#include "types.h"
-p_tag * ptag_init_cast (p_tag *dest, const s_sym *type,
+p_tag * ptag_init_cast (p_tag *dest, const s_sym * const *type,
const s_tag *tag);
p_tag * ptag_init_copy (p_tag *dest, const p_tag *src);
diff --git a/libc3/ptr.c b/libc3/ptr.c
index 9bccfdb..8f28ea8 100644
--- a/libc3/ptr.c
+++ b/libc3/ptr.c
@@ -32,7 +32,8 @@ 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_sym *type,
+u_ptr_w * ptr_init_cast (u_ptr_w *p,
+ const s_sym * const *type,
const s_tag *tag)
{
assert(p);
@@ -60,11 +61,11 @@ u_ptr_w * ptr_init_cast (u_ptr_w *p, const s_sym *type,
}
err_write_1("ptr_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Ptr)
+ if (*type == &g_sym_Ptr)
err_puts(" to Ptr");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Ptr");
}
assert(! "ptr_cast: cannot cast to Ptr");
diff --git a/libc3/ptr.h b/libc3/ptr.h
index 26ff8e0..c3827dd 100644
--- a/libc3/ptr.h
+++ b/libc3/ptr.h
@@ -17,7 +17,8 @@
/* Stack-allocation compatible functions. */
u_ptr_w * ptr_init (u_ptr_w *ptr, void *p);
-u_ptr_w * ptr_init_cast (u_ptr_w *ptr, const s_sym *type,
+u_ptr_w * ptr_init_cast (u_ptr_w *ptr,
+ const s_sym * const *type,
const s_tag *tag);
u_ptr_w * ptr_init_copy (u_ptr_w *ptr, const u_ptr_w *src);
diff --git a/libc3/ptr_free.c b/libc3/ptr_free.c
index 19fdabd..e900dd8 100644
--- a/libc3/ptr_free.c
+++ b/libc3/ptr_free.c
@@ -39,7 +39,8 @@ u_ptr_w * ptr_free_init (u_ptr_w *ptr_free, void *p)
return ptr_free;
}
-u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_sym *type,
+u_ptr_w * ptr_free_init_cast (u_ptr_w *p,
+ const s_sym * const *type,
const s_tag *tag)
{
assert(p);
@@ -66,11 +67,11 @@ u_ptr_w * ptr_free_init_cast (u_ptr_w *p, const s_sym *type,
}
err_write_1("ptr_free_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_PtrFree)
+ if (*type == &g_sym_PtrFree)
err_puts(" to PtrFree");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka PtrFree");
}
assert(! "ptr_free_init_cast: cannot cast to PtrFree");
diff --git a/libc3/ptr_free.h b/libc3/ptr_free.h
index 4123e25..43bcebb 100644
--- a/libc3/ptr_free.h
+++ b/libc3/ptr_free.h
@@ -19,7 +19,8 @@
after use. */
void ptr_free_clean (u_ptr_w *ptr_free);
u_ptr_w * ptr_free_init (u_ptr_w *ptr_free, void *p);
-u_ptr_w * ptr_free_init_cast (u_ptr_w *ptr_free, const s_sym *type,
+u_ptr_w * ptr_free_init_cast (u_ptr_w *ptr_free,
+ const s_sym * const *type,
const s_tag *tag);
u_ptr_w * ptr_free_init_copy (u_ptr_w *ptr_free, const u_ptr_w *src);
diff --git a/libc3/quote.c b/libc3/quote.c
index 053dc43..ef9723d 100644
--- a/libc3/quote.c
+++ b/libc3/quote.c
@@ -27,7 +27,7 @@ s_quote * quote_init (s_quote *quote, const s_tag *tag)
return quote;
}
-s_quote * quote_init_cast (s_quote *quote, const s_sym *type,
+s_quote * quote_init_cast (s_quote *quote, const s_sym * const *type,
const s_tag *tag)
{
assert(quote);
@@ -41,11 +41,11 @@ s_quote * quote_init_cast (s_quote *quote, const s_sym *type,
}
err_write_1("quote_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Quote)
+ if (*type == &g_sym_Quote)
err_puts(" to Quote");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Quote");
}
assert(! "quote_init_cast: cannot cast to Quote");
diff --git a/libc3/quote.h b/libc3/quote.h
index 14806fd..3ee1d18 100644
--- a/libc3/quote.h
+++ b/libc3/quote.h
@@ -19,7 +19,7 @@
void quote_clean (s_quote *quote);
s_quote * quote_init (s_quote *quote, const s_tag *tag);
s_quote * quote_init_1 (s_quote *quote, const s8 *p);
-s_quote * quote_init_cast (s_quote *quote, const s_sym *type,
+s_quote * quote_init_cast (s_quote *quote, const s_sym * const *type,
const s_tag *src);
s_quote * quote_init_copy (s_quote *quote, const s_quote *src);
diff --git a/libc3/s.c.in b/libc3/s.c.in
index 050c589..3ef208a 100644
--- a/libc3/s.c.in
+++ b/libc3/s.c.in
@@ -16,13 +16,14 @@
#include "assert.h"
#include "complex.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
#include "s_bits$.h"
s_bits$ * s_bits$_init_cast
-(s_bits$ *s, const s_sym *type, const s_tag *tag)
+(s_bits$ *s, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -79,8 +80,14 @@ s_bits$ * s_bits$_init_cast
}
err_write_1("s_bits$_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to s_bits$");
- assert(! "s_bits$_cast: cannot cast to s_bits$");
+ if (*type == &g_sym_S_bits$)
+ err_puts(" to S_bits$");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka S_bits$");
+ }
+ assert(! "s_bits$_cast: cannot cast to S_bits$");
return NULL;
}
diff --git a/libc3/s.h.in b/libc3/s.h.in
index 3eddf8d..2994671 100644
--- a/libc3/s.h.in
+++ b/libc3/s.h.in
@@ -17,7 +17,7 @@
#include "types.h"
s_bits$ * s_bits$_init_cast
-(s_bits$ *s, const s_sym *type, const s_tag *tag);
+(s_bits$ *s, const s_sym * const *type, 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);
u_bits$ * s_bits$_random_uniform (s_bits$ *s, s_bits$ min, s_bits$ max);
diff --git a/libc3/s16.c b/libc3/s16.c
index 5f7a099..d36264d 100644
--- a/libc3/s16.c
+++ b/libc3/s16.c
@@ -16,13 +16,14 @@
#include "assert.h"
#include "complex.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
#include "s16.h"
s16 * s16_init_cast
-(s16 *s, const s_sym *type, const s_tag *tag)
+(s16 *s, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -79,8 +80,14 @@ s16 * s16_init_cast
}
err_write_1("s16_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to s16");
- assert(! "s16_cast: cannot cast to s16");
+ if (*type == &g_sym_S16)
+ err_puts(" to S16");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka S16");
+ }
+ assert(! "s16_cast: cannot cast to S16");
return NULL;
}
diff --git a/libc3/s16.h b/libc3/s16.h
index b5174bd..7f6bb64 100644
--- a/libc3/s16.h
+++ b/libc3/s16.h
@@ -17,7 +17,7 @@
#include "types.h"
s16 * s16_init_cast
-(s16 *s, const s_sym *type, const s_tag *tag);
+(s16 *s, const s_sym * const *type, const s_tag *tag);
s16 * s16_init_copy (s16 *s, const s16 *src);
s16 * s16_random (s16 *s);
u16 * s16_random_uniform (s16 *s, s16 min, s16 max);
diff --git a/libc3/s32.c b/libc3/s32.c
index 213633a..0973173 100644
--- a/libc3/s32.c
+++ b/libc3/s32.c
@@ -16,13 +16,14 @@
#include "assert.h"
#include "complex.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
#include "s32.h"
s32 * s32_init_cast
-(s32 *s, const s_sym *type, const s_tag *tag)
+(s32 *s, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -79,8 +80,14 @@ s32 * s32_init_cast
}
err_write_1("s32_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to s32");
- assert(! "s32_cast: cannot cast to s32");
+ if (*type == &g_sym_S32)
+ err_puts(" to S32");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka S32");
+ }
+ assert(! "s32_cast: cannot cast to S32");
return NULL;
}
diff --git a/libc3/s32.h b/libc3/s32.h
index b9b119f..f737e53 100644
--- a/libc3/s32.h
+++ b/libc3/s32.h
@@ -17,7 +17,7 @@
#include "types.h"
s32 * s32_init_cast
-(s32 *s, const s_sym *type, const s_tag *tag);
+(s32 *s, const s_sym * const *type, const s_tag *tag);
s32 * s32_init_copy (s32 *s, const s32 *src);
s32 * s32_random (s32 *s);
u32 * s32_random_uniform (s32 *s, s32 min, s32 max);
diff --git a/libc3/s64.c b/libc3/s64.c
index 644a445..ae6a423 100644
--- a/libc3/s64.c
+++ b/libc3/s64.c
@@ -16,13 +16,14 @@
#include "assert.h"
#include "complex.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
#include "s64.h"
s64 * s64_init_cast
-(s64 *s, const s_sym *type, const s_tag *tag)
+(s64 *s, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -79,8 +80,14 @@ s64 * s64_init_cast
}
err_write_1("s64_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to s64");
- assert(! "s64_cast: cannot cast to s64");
+ if (*type == &g_sym_S64)
+ err_puts(" to S64");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka S64");
+ }
+ assert(! "s64_cast: cannot cast to S64");
return NULL;
}
diff --git a/libc3/s64.h b/libc3/s64.h
index cb4c0f2..8a09ffa 100644
--- a/libc3/s64.h
+++ b/libc3/s64.h
@@ -17,7 +17,7 @@
#include "types.h"
s64 * s64_init_cast
-(s64 *s, const s_sym *type, const s_tag *tag);
+(s64 *s, const s_sym * const *type, const s_tag *tag);
s64 * s64_init_copy (s64 *s, const s64 *src);
s64 * s64_random (s64 *s);
u64 * s64_random_uniform (s64 *s, s64 min, s64 max);
diff --git a/libc3/s8.c b/libc3/s8.c
index 9fb04c3..2d35404 100644
--- a/libc3/s8.c
+++ b/libc3/s8.c
@@ -16,13 +16,14 @@
#include "assert.h"
#include "complex.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
#include "s8.h"
s8 * s8_init_cast
-(s8 *s, const s_sym *type, const s_tag *tag)
+(s8 *s, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -79,8 +80,14 @@ s8 * s8_init_cast
}
err_write_1("s8_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to s8");
- assert(! "s8_cast: cannot cast to s8");
+ if (*type == &g_sym_S8)
+ err_puts(" to S8");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka S8");
+ }
+ assert(! "s8_cast: cannot cast to S8");
return NULL;
}
diff --git a/libc3/s8.h b/libc3/s8.h
index 9f7301e..7ca5fd9 100644
--- a/libc3/s8.h
+++ b/libc3/s8.h
@@ -17,7 +17,7 @@
#include "types.h"
s8 * s8_init_cast
-(s8 *s, const s_sym *type, const s_tag *tag);
+(s8 *s, const s_sym * const *type, const s_tag *tag);
s8 * s8_init_copy (s8 *s, const s8 *src);
s8 * s8_random (s8 *s);
u8 * s8_random_uniform (s8 *s, s8 min, s8 max);
diff --git a/libc3/str.c b/libc3/str.c
index 17b8e5c..9376c6f 100644
--- a/libc3/str.c
+++ b/libc3/str.c
@@ -148,7 +148,8 @@ s_str * str_init_alloc (s_str *str, uw size, const char *p)
return str;
}
-s_str * str_init_cast (s_str *str, const s_sym *type, const s_tag *tag)
+s_str * str_init_cast (s_str *str, const s_sym * const *type,
+ const s_tag *tag)
{
assert(str);
assert(type);
@@ -183,11 +184,11 @@ s_str * str_init_cast (s_str *str, const s_sym *type, const s_tag *tag)
}
err_write_1("str_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Str)
+ if (*type == &g_sym_Str)
err_puts(" to Str");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Str");
}
assert(! "str_init_cast: cannot cast to Str");
diff --git a/libc3/str.h b/libc3/str.h
index e77866e..1a8355e 100644
--- a/libc3/str.h
+++ b/libc3/str.h
@@ -34,7 +34,7 @@ void str_clean (s_str *str);
s_str * str_init (s_str *str, char *free, uw size, const char *p);
s_str * str_init_1 (s_str *str, char *free, const char *p);
s_str * str_init_alloc (s_str *str, uw size, const char *p);
-s_str * str_init_cast (s_str *str, const s_sym *type,
+s_str * str_init_cast (s_str *str, const s_sym * const *type,
const s_tag *tag);
s_str * str_init_cat (s_str *str, const s_str *a, const s_str *b);
s_str * str_init_copy (s_str *str, const s_str *src);
diff --git a/libc3/struct.c b/libc3/struct.c
index 702cf72..6912c8e 100644
--- a/libc3/struct.c
+++ b/libc3/struct.c
@@ -143,22 +143,23 @@ s_struct * struct_init_1 (s_struct *s, const s8 *p)
return s;
}
-s_struct * struct_init_cast (s_struct *s, const s_sym *type, const s_tag *tag)
+s_struct * struct_init_cast (s_struct *s, const s_sym * const *type,
+ const s_tag *tag)
{
assert(s);
assert(tag);
switch (tag->type) {
case TAG_STRUCT:
- if (type == tag->data.struct_.type->module)
+ if (*type == tag->data.struct_.type->module)
return struct_init_copy(s, &tag->data.struct_);
default:
break;
}
err_write_1("struct_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_write_1(" to ");
- err_inspect_sym(&type);
- err_write_1("\n");
+ err_write_1(" to %");
+ err_inspect_sym(type);
+ err_write_1("{}\n");
assert(! "struct_init_cast: cannot cast to Struct");
return NULL;
}
diff --git a/libc3/struct.h b/libc3/struct.h
index e921d5a..7250a43 100644
--- a/libc3/struct.h
+++ b/libc3/struct.h
@@ -24,7 +24,7 @@
void struct_clean (s_struct *s);
s_struct * struct_init (s_struct *s, const s_sym *module);
s_struct * struct_init_1 (s_struct *s, const s8 *p);
-s_struct * struct_init_cast (s_struct *s, const s_sym *type,
+s_struct * struct_init_cast (s_struct *s, const s_sym * const *type,
const s_tag *tag);
s_struct * struct_init_copy (s_struct *s, const s_struct *src);
s_struct * struct_init_from_lists (s_struct *s, const s_sym *module,
diff --git a/libc3/sw.c b/libc3/sw.c
index e79de95..fdbbd3c 100644
--- a/libc3/sw.c
+++ b/libc3/sw.c
@@ -16,13 +16,14 @@
#include "assert.h"
#include "complex.h"
#include "integer.h"
+#include "sym.h"
#include "tag.h"
#include "tag_type.h"
#include "ratio.h"
#include "sw.h"
sw * sw_init_cast
-(sw *s, const s_sym *type, const s_tag *tag)
+(sw *s, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -79,8 +80,14 @@ sw * sw_init_cast
}
err_write_1("sw_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to sw");
- assert(! "sw_cast: cannot cast to sw");
+ if (*type == &g_sym_Sw)
+ err_puts(" to Sw");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka Sw");
+ }
+ assert(! "sw_cast: cannot cast to Sw");
return NULL;
}
diff --git a/libc3/sw.h b/libc3/sw.h
index 38cc5a2..6a5a643 100644
--- a/libc3/sw.h
+++ b/libc3/sw.h
@@ -17,7 +17,7 @@
#include "types.h"
sw * sw_init_cast
-(sw *s, const s_sym *type, const s_tag *tag);
+(sw *s, const s_sym * const *type, const s_tag *tag);
sw * sw_init_copy (sw *s, const sw *src);
sw * sw_random (sw *s);
uw * sw_random_uniform (sw *s, sw min, sw max);
diff --git a/libc3/sym.c b/libc3/sym.c
index 6ea4513..e48e7d7 100644
--- a/libc3/sym.c
+++ b/libc3/sym.c
@@ -254,7 +254,8 @@ const s_sym ** sym_init_1 (const s_sym **sym, const char *p)
return sym;
}
-const s_sym ** sym_init_cast (const s_sym **sym, const s_sym *type,
+const s_sym ** sym_init_cast (const s_sym **sym,
+ const s_sym * const *type,
const s_tag *tag)
{
assert(sym);
@@ -270,11 +271,11 @@ const s_sym ** sym_init_cast (const s_sym **sym, const s_sym *type,
}
err_write_1("sym_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Sym)
+ if (*type == &g_sym_Sym)
err_puts(" to Sym");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Sym");
}
assert(! "sym_init_cast: cannot cast to Sym");
diff --git a/libc3/sym.h b/libc3/sym.h
index 18918b1..fbc8613 100644
--- a/libc3/sym.h
+++ b/libc3/sym.h
@@ -111,7 +111,8 @@ extern const s_sym g_sym_x;
const s_sym * sym_1 (const char *p);
const s_sym ** sym_init_1 (const s_sym **sym, const char *p);
-const s_sym ** sym_init_cast (const s_sym **sym, const s_sym *type,
+const s_sym ** sym_init_cast (const s_sym **sym,
+ const s_sym * const *type,
const s_tag *tag);
const s_sym ** sym_init_copy (const s_sym **sym,
const s_sym * const *src);
diff --git a/libc3/tag_addi.c b/libc3/tag_addi.c
index 85f92d2..3a4a4da 100644
--- a/libc3/tag_addi.c
+++ b/libc3/tag_addi.c
@@ -13,6 +13,7 @@
#include "alloc.h"
#include "assert.h"
#include "complex.h"
+#include "sym.h"
#include "tag.h"
s_tag * tag_addi (const s_tag *a, const s_tag *b, s_tag *dest)
@@ -20,17 +21,19 @@ s_tag * tag_addi (const s_tag *a, const s_tag *b, s_tag *dest)
s_complex *c;
s_complex ca = {0};
s_complex cb = {0};
+ const s_sym *type;
assert(a);
assert(b);
assert(dest);
c = alloc(sizeof(s_complex));
if (! c)
return NULL;
- if (! complex_init_cast(&ca, a)) {
+ type = &g_sym_Complex;
+ if (! complex_init_cast(&ca, &type, a)) {
free(c);
return NULL;
}
- if (! complex_init_cast(&cb, b)) {
+ if (! complex_init_cast(&cb, &type, b)) {
complex_clean(&ca);
free(c);
return NULL;
diff --git a/libc3/tuple.c b/libc3/tuple.c
index 0f30abe..b4183a9 100644
--- a/libc3/tuple.c
+++ b/libc3/tuple.c
@@ -87,7 +87,7 @@ 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_sym *type,
+s_tuple * tuple_init_cast (s_tuple *tuple, const s_sym * const *type,
const s_tag *tag)
{
switch (tag->type) {
@@ -98,11 +98,11 @@ s_tuple * tuple_init_cast (s_tuple *tuple, const s_sym *type,
}
err_write_1("tuple_init_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- if (type == &g_sym_Tuple)
+ if (*type == &g_sym_Tuple)
err_puts(" to Tuple");
else {
err_write_1(" to ");
- err_inspect_sym(&type);
+ err_inspect_sym(type);
err_puts(" aka Tuple");
}
assert(! "tuple_init_cast: cannot cast to Tuple");
diff --git a/libc3/tuple.h b/libc3/tuple.h
index 3ca22ab..4d75aab 100644
--- a/libc3/tuple.h
+++ b/libc3/tuple.h
@@ -26,7 +26,7 @@
s_tuple * tuple_init (s_tuple *tuple, uw count);
s_tuple * tuple_init_1 (s_tuple *tuple, const char *p);
s_tuple * tuple_init_2 (s_tuple *tuple, const s_tag *a, const s_tag *b);
-s_tuple * tuple_init_cast (s_tuple *tuple, const s_sym *type,
+s_tuple * tuple_init_cast (s_tuple *tuple, const s_sym * const *type,
const s_tag *tag);
s_tuple * tuple_init_copy (s_tuple *tuple, const s_tuple *src);
void tuple_clean (s_tuple *tuple);
diff --git a/libc3/u.c.in b/libc3/u.c.in
index 52cfba1..9a71469 100644
--- a/libc3/u.c.in
+++ b/libc3/u.c.in
@@ -17,11 +17,12 @@
#include "f128.h"
#include "integer.h"
#include "ratio.h"
+#include "sym.h"
#include "tag.h"
#include "u_bits$.h"
u_bits$ * u_bits$_init_cast
-(u_bits$ *u, const s_sym *type, const s_tag *tag)
+(u_bits$ *u, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -78,8 +79,14 @@ u_bits$ * u_bits$_init_cast
}
err_write_1("u_bits$_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to u_bits$");
- assert(! "u_bits$_cast: cannot cast to u_bits$");
+ if (*type == &g_sym_U_bits$)
+ err_puts(" to U_bits$");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka U_bits$");
+ }
+ assert(! "u_bits$_cast: cannot cast to U_bits$");
return NULL;
}
diff --git a/libc3/u.h.in b/libc3/u.h.in
index 1eca73b..990236e 100644
--- a/libc3/u.h.in
+++ b/libc3/u.h.in
@@ -17,7 +17,7 @@
#include "types.h"
u_bits$ * u_bits$_init_cast
-(u_bits$ *u, const s_sym *type, const s_tag *tag);
+(u_bits$ *u, const s_sym * const *type, const s_tag *tag);
u_bits$ * u_bits$_init_copy (u_bits$ *u, const u_bits$ *src);
u_bits$ * u_bits$_random (u_bits$ *u);
diff --git a/libc3/u16.c b/libc3/u16.c
index 66afa49..cfa1c7d 100644
--- a/libc3/u16.c
+++ b/libc3/u16.c
@@ -17,11 +17,12 @@
#include "f128.h"
#include "integer.h"
#include "ratio.h"
+#include "sym.h"
#include "tag.h"
#include "u16.h"
u16 * u16_init_cast
-(u16 *u, const s_sym *type, const s_tag *tag)
+(u16 *u, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -78,8 +79,14 @@ u16 * u16_init_cast
}
err_write_1("u16_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to u16");
- assert(! "u16_cast: cannot cast to u16");
+ if (*type == &g_sym_U16)
+ err_puts(" to U16");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka U16");
+ }
+ assert(! "u16_cast: cannot cast to U16");
return NULL;
}
diff --git a/libc3/u16.h b/libc3/u16.h
index a53a97a..c31130f 100644
--- a/libc3/u16.h
+++ b/libc3/u16.h
@@ -17,7 +17,7 @@
#include "types.h"
u16 * u16_init_cast
-(u16 *u, const s_sym *type, const s_tag *tag);
+(u16 *u, const s_sym * const *type, const s_tag *tag);
u16 * u16_init_copy (u16 *u, const u16 *src);
u16 * u16_random (u16 *u);
diff --git a/libc3/u32.c b/libc3/u32.c
index 9c01855..b2bbdd0 100644
--- a/libc3/u32.c
+++ b/libc3/u32.c
@@ -17,11 +17,12 @@
#include "f128.h"
#include "integer.h"
#include "ratio.h"
+#include "sym.h"
#include "tag.h"
#include "u32.h"
u32 * u32_init_cast
-(u32 *u, const s_sym *type, const s_tag *tag)
+(u32 *u, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -78,8 +79,14 @@ u32 * u32_init_cast
}
err_write_1("u32_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to u32");
- assert(! "u32_cast: cannot cast to u32");
+ if (*type == &g_sym_U32)
+ err_puts(" to U32");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka U32");
+ }
+ assert(! "u32_cast: cannot cast to U32");
return NULL;
}
diff --git a/libc3/u32.h b/libc3/u32.h
index ece4abe..7ddac82 100644
--- a/libc3/u32.h
+++ b/libc3/u32.h
@@ -17,7 +17,7 @@
#include "types.h"
u32 * u32_init_cast
-(u32 *u, const s_sym *type, const s_tag *tag);
+(u32 *u, const s_sym * const *type, const s_tag *tag);
u32 * u32_init_copy (u32 *u, const u32 *src);
u32 * u32_random (u32 *u);
diff --git a/libc3/u64.c b/libc3/u64.c
index 87c64e8..d4ee40c 100644
--- a/libc3/u64.c
+++ b/libc3/u64.c
@@ -17,11 +17,12 @@
#include "f128.h"
#include "integer.h"
#include "ratio.h"
+#include "sym.h"
#include "tag.h"
#include "u64.h"
u64 * u64_init_cast
-(u64 *u, const s_sym *type, const s_tag *tag)
+(u64 *u, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -78,8 +79,14 @@ u64 * u64_init_cast
}
err_write_1("u64_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to u64");
- assert(! "u64_cast: cannot cast to u64");
+ if (*type == &g_sym_U64)
+ err_puts(" to U64");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka U64");
+ }
+ assert(! "u64_cast: cannot cast to U64");
return NULL;
}
diff --git a/libc3/u64.h b/libc3/u64.h
index 05802cb..3b54018 100644
--- a/libc3/u64.h
+++ b/libc3/u64.h
@@ -17,7 +17,7 @@
#include "types.h"
u64 * u64_init_cast
-(u64 *u, const s_sym *type, const s_tag *tag);
+(u64 *u, const s_sym * const *type, const s_tag *tag);
u64 * u64_init_copy (u64 *u, const u64 *src);
u64 * u64_random (u64 *u);
diff --git a/libc3/u8.c b/libc3/u8.c
index 090aa92..6d8c3ba 100644
--- a/libc3/u8.c
+++ b/libc3/u8.c
@@ -17,11 +17,12 @@
#include "f128.h"
#include "integer.h"
#include "ratio.h"
+#include "sym.h"
#include "tag.h"
#include "u8.h"
u8 * u8_init_cast
-(u8 *u, const s_sym *type, const s_tag *tag)
+(u8 *u, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -78,8 +79,14 @@ u8 * u8_init_cast
}
err_write_1("u8_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to u8");
- assert(! "u8_cast: cannot cast to u8");
+ if (*type == &g_sym_U8)
+ err_puts(" to U8");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka U8");
+ }
+ assert(! "u8_cast: cannot cast to U8");
return NULL;
}
diff --git a/libc3/u8.h b/libc3/u8.h
index 0d6622e..bb6b914 100644
--- a/libc3/u8.h
+++ b/libc3/u8.h
@@ -17,7 +17,7 @@
#include "types.h"
u8 * u8_init_cast
-(u8 *u, const s_sym *type, const s_tag *tag);
+(u8 *u, const s_sym * const *type, const s_tag *tag);
u8 * u8_init_copy (u8 *u, const u8 *src);
u8 * u8_random (u8 *u);
diff --git a/libc3/uw.c b/libc3/uw.c
index dfc0974..1f4feb5 100644
--- a/libc3/uw.c
+++ b/libc3/uw.c
@@ -17,11 +17,12 @@
#include "f128.h"
#include "integer.h"
#include "ratio.h"
+#include "sym.h"
#include "tag.h"
#include "uw.h"
uw * uw_init_cast
-(uw *u, const s_sym *type, const s_tag *tag)
+(uw *u, const s_sym * const *type, const s_tag *tag)
{
(void) type;
switch (tag->type) {
@@ -78,8 +79,14 @@ uw * uw_init_cast
}
err_write_1("uw_cast: cannot cast ");
err_write_1(tag_type_to_string(tag->type));
- err_puts(" to uw");
- assert(! "uw_cast: cannot cast to uw");
+ if (*type == &g_sym_Uw)
+ err_puts(" to Uw");
+ else {
+ err_write_1(" to ");
+ err_inspect_sym(type);
+ err_puts(" aka Uw");
+ }
+ assert(! "uw_cast: cannot cast to Uw");
return NULL;
}
diff --git a/libc3/uw.h b/libc3/uw.h
index 06b1fb9..a639296 100644
--- a/libc3/uw.h
+++ b/libc3/uw.h
@@ -17,7 +17,7 @@
#include "types.h"
uw * uw_init_cast
-(uw *u, const s_sym *type, const s_tag *tag);
+(uw *u, const s_sym * const *type, const s_tag *tag);
uw * uw_init_copy (uw *u, const uw *src);
uw * uw_random (uw *u);
diff --git a/libc3/var.c b/libc3/var.c
index e294fa0..103f605 100644
--- a/libc3/var.c
+++ b/libc3/var.c
@@ -16,22 +16,22 @@
#include "tag.h"
#include "var.h"
-s_tag * var_init_cast (s_tag *tag, const s_sym *type, const s_tag *src)
+s_tag * var_init_cast (s_tag *tag, const s_sym * const *type,
+ const s_tag *src)
{
void *data;
s_tag tmp;
assert(tag);
assert(type);
- assert(type != &g_sym_Var);
assert(src);
- if (type == &g_sym_Var) {
+ if (*type == &g_sym_Var) {
err_puts("var_init_cast: cannot cast to Var");
assert(! "var_init_cast: cannot cast to Var");
return NULL;
}
- if (! sym_to_tag_type(type, &tmp.type))
+ if (! sym_to_tag_type(*type, &tmp.type))
return NULL;
- if (! tag_to_pointer(&tmp, type, &data))
+ if (! tag_to_pointer(&tmp, *type, &data))
return NULL;
if (! data_init_cast(data, type, src))
return NULL;
diff --git a/libc3/var.h b/libc3/var.h
index 2933f37..31a4018 100644
--- a/libc3/var.h
+++ b/libc3/var.h
@@ -15,7 +15,8 @@
#include "types.h"
-s_tag * var_init_cast (s_tag *tag, const s_sym *type, const s_tag *src);
+s_tag * var_init_cast (s_tag *tag, const s_sym * const *type,
+ const s_tag *src);
s_tag * var_init_copy (s_tag *tag, const s_tag *src);
#endif /* LIBC3_VAR_H */