diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index 76acad3..fb9b7ca 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -66,7 +66,7 @@ defmodule HTTPd do
end
end
- def timeout = %Time{tv_sec: (Sw) 5}
+ def timeout = %Time{tv_sec: 5}
def acceptor = fn (server_socket, events, acceptor_ev, void) do
if List.has?(events, :read) do
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 792921f..b7a48d1 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -4357,6 +4357,10 @@ sw buf_parse_time (s_buf *buf, s_time *dest)
if ((r = buf_read_1(buf, "%Time{")) <= 0)
goto clean;
result += r;
+ if (! time_allocate(&tmp))
+ goto restore;
+ tag_init_sw(tmp.tag, 0);
+ tag_init_sw(tmp.tag + 1, 0);
if ((r = buf_parse_comments(buf)) < 0)
goto restore;
result += r;
@@ -4382,9 +4386,6 @@ sw buf_parse_time (s_buf *buf, s_time *dest)
if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
- if (! tmp.tag &&
- ! time_allocate(&tmp))
- goto restore;
if ((r = buf_parse_tag(buf, tmp.tag)) <= 0)
goto restore;
if ((r = buf_parse_comments(buf)) < 0)
diff --git a/libkc3/cfn.c b/libkc3/cfn.c
index 843ebe3..b2bad89 100644
--- a/libkc3/cfn.c
+++ b/libkc3/cfn.c
@@ -38,6 +38,7 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
void *result = NULL;
s_tag tmp = {0};
s_tag tmp2 = {0};
+ s_list *trace;
assert(cfn);
assert(cfn->arity == cfn->cif.nargs);
num_args = list_length(args);
@@ -126,6 +127,12 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
}
}
if (cfn->ptr.f) {
+ if (! (trace = list_new(g_kc3_env.stacktrace)))
+ goto ko;
+ tag_init_list(&trace->tag, list_new_sym
+ (cfn->name, list_new_copy
+ (args)));
+ g_kc3_env.stacktrace = trace;
ffi_call(&cfn->cif, cfn->ptr.f, result, arg_values);
if (cfn->arg_result) {
if (result_pointer != arg_pointer_result) {
diff --git a/libkc3/env.c b/libkc3/env.c
index 338c9a7..d16e177 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -1289,11 +1289,15 @@ bool env_eval_equal_time (s_env *env, bool macro, const s_time *a,
return false;
}
if (! sw_init_cast(&tmp.tv_sec, &sym_Sw, tmp_tag)) {
+ err_puts("env_eval_equal_time: sw_init_cast (tv_sec)");
+ assert(! "env_eval_equal_time: sw_init_cast (tv_sec)");
tag_clean(tmp_tag + 1);
tag_clean(tmp_tag);
return false;
}
if (! sw_init_cast(&tmp.tv_nsec, &sym_Sw, tmp_tag + 1)) {
+ err_puts("env_eval_equal_time: sw_init_cast (tv_nsec)");
+ assert(! "env_eval_equal_time: sw_init_cast (tv_nsec)");
tag_clean(tmp_tag + 1);
tag_clean(tmp_tag);
return false;
@@ -1378,6 +1382,11 @@ bool env_eval_ident (s_env *env, const s_ident *ident, s_tag *dest)
err_inspect_ident(ident);
err_write_1("\n");
if (true) {
+ err_puts("env_eval_ident: stacktrace:");
+ err_inspect_list((const s_list * const *) &env->stacktrace);
+ err_write_1("\n");
+ }
+ if (false) {
err_write_1("frame: ");
err_inspect_frame(env->frame);
err_write_1("\n");
@@ -2008,6 +2017,7 @@ bool env_eval_tag (s_env *env, const s_tag *tag, s_tag *dest)
bool env_eval_time (s_env *env, const s_time *time, s_tag *dest)
{
+ const s_sym *sym_Sw = &g_sym_Sw;
s_tag tag[2] = {0};
s_tag tmp = {0};
tmp.type = TAG_TIME;
@@ -2018,9 +2028,7 @@ bool env_eval_time (s_env *env, const s_time *time, s_tag *dest)
tag_clean(tag);
return false;
}
- if (tag[0].type == TAG_SW)
- tmp.data.time.tv_sec = tag[0].data.sw;
- else if (tag[0].type != TAG_VOID) {
+ if (! sw_init_cast(&tmp.data.time.tv_sec, &sym_Sw, tag)) {
err_write_1("env_eval_time: tv_sec is not a Sw: ");
err_inspect_tag(tag);
err_write_1("\n");
@@ -2029,9 +2037,7 @@ bool env_eval_time (s_env *env, const s_time *time, s_tag *dest)
tag_clean(tag);
return false;
}
- if (tag[1].type == TAG_SW)
- tmp.data.time.tv_nsec = tag[1].data.sw;
- else if (tag[1].type != TAG_VOID) {
+ if (! sw_init_cast(&tmp.data.time.tv_nsec, &sym_Sw, tag + 1)) {
err_write_1("env_eval_time: tv_nsec is not a Sw: ");
err_inspect_tag(tag + 1);
err_write_1("\n");
@@ -2041,6 +2047,10 @@ bool env_eval_time (s_env *env, const s_time *time, s_tag *dest)
return false;
}
}
+ else {
+ tmp.data.time.tv_sec = time->tv_sec;
+ tmp.data.time.tv_nsec = time->tv_nsec;
+ }
*dest = tmp;
return true;
}
diff --git a/libkc3/s.c.in b/libkc3/s.c.in
index 916bb7d..7339c7f 100644
--- a/libkc3/s.c.in
+++ b/libkc3/s.c.in
@@ -101,6 +101,11 @@ s_bits$ * s_bits$_init_cast
err_inspect_sym(type);
err_puts(" aka S_bits$");
}
+ if (true) {
+ err_puts("s_bits$_cast: stacktrace:");
+ err_inspect_list((const s_list * const *) &g_kc3_env.stacktrace);
+ err_write_1("\n");
+ }
assert(! "s_bits$_cast: cannot cast to S_bits$");
return NULL;
}
diff --git a/libkc3/s16.c b/libkc3/s16.c
index f6c1f4f..341978c 100644
--- a/libkc3/s16.c
+++ b/libkc3/s16.c
@@ -101,6 +101,11 @@ s16 * s16_init_cast
err_inspect_sym(type);
err_puts(" aka S16");
}
+ if (true) {
+ err_puts("s16_cast: stacktrace:");
+ err_inspect_list((const s_list * const *) &g_kc3_env.stacktrace);
+ err_write_1("\n");
+ }
assert(! "s16_cast: cannot cast to S16");
return NULL;
}
diff --git a/libkc3/s32.c b/libkc3/s32.c
index 0c09785..4ceef97 100644
--- a/libkc3/s32.c
+++ b/libkc3/s32.c
@@ -101,6 +101,11 @@ s32 * s32_init_cast
err_inspect_sym(type);
err_puts(" aka S32");
}
+ if (true) {
+ err_puts("s32_cast: stacktrace:");
+ err_inspect_list((const s_list * const *) &g_kc3_env.stacktrace);
+ err_write_1("\n");
+ }
assert(! "s32_cast: cannot cast to S32");
return NULL;
}
diff --git a/libkc3/s64.c b/libkc3/s64.c
index 7b852c8..7203a5a 100644
--- a/libkc3/s64.c
+++ b/libkc3/s64.c
@@ -101,6 +101,11 @@ s64 * s64_init_cast
err_inspect_sym(type);
err_puts(" aka S64");
}
+ if (true) {
+ err_puts("s64_cast: stacktrace:");
+ err_inspect_list((const s_list * const *) &g_kc3_env.stacktrace);
+ err_write_1("\n");
+ }
assert(! "s64_cast: cannot cast to S64");
return NULL;
}
diff --git a/libkc3/s8.c b/libkc3/s8.c
index 4b178c0..92c9bee 100644
--- a/libkc3/s8.c
+++ b/libkc3/s8.c
@@ -101,6 +101,11 @@ s8 * s8_init_cast
err_inspect_sym(type);
err_puts(" aka S8");
}
+ if (true) {
+ err_puts("s8_cast: stacktrace:");
+ err_inspect_list((const s_list * const *) &g_kc3_env.stacktrace);
+ err_write_1("\n");
+ }
assert(! "s8_cast: cannot cast to S8");
return NULL;
}
diff --git a/libkc3/sw.c b/libkc3/sw.c
index 18da7b8..e19e439 100644
--- a/libkc3/sw.c
+++ b/libkc3/sw.c
@@ -101,6 +101,11 @@ sw * sw_init_cast
err_inspect_sym(type);
err_puts(" aka Sw");
}
+ if (true) {
+ err_puts("sw_cast: stacktrace:");
+ err_inspect_list((const s_list * const *) &g_kc3_env.stacktrace);
+ err_write_1("\n");
+ }
assert(! "sw_cast: cannot cast to Sw");
return NULL;
}
diff --git a/libkc3/time.c b/libkc3/time.c
index cade266..1909834 100644
--- a/libkc3/time.c
+++ b/libkc3/time.c
@@ -67,17 +67,21 @@ s_time * time_init_add (s_time *time, const s_time *a, const s_time *b)
s_time * time_init_copy (s_time *time, const s_time *src)
{
- const s_sym *sym_Sw = &g_sym_Sw;
s_time tmp = {0};
+ tmp.tv_sec = src->tv_sec;
+ tmp.tv_nsec = src->tv_nsec;
if (src->tag) {
- if (! sw_init_cast(&tmp.tv_sec, &sym_Sw, src->tag))
+ if (! time_allocate(&tmp))
return NULL;
- if (! sw_init_cast(&tmp.tv_nsec, &sym_Sw, src->tag + 1))
+ if (! tag_init_copy(tmp.tag, src->tag)) {
+ free(tmp.tag);
return NULL;
- }
- else {
- tmp.tv_sec = src->tv_sec;
- tmp.tv_nsec = src->tv_nsec;
+ }
+ if (! tag_init_copy(tmp.tag + 1, src->tag + 1)) {
+ tag_clean(tmp.tag);
+ free(tmp.tag);
+ return NULL;
+ }
}
*time = tmp;
return time;