diff --git a/ic3/ic3.c b/ic3/ic3.c
index 5bcc60c..2e36744 100644
--- a/ic3/ic3.c
+++ b/ic3/ic3.c
@@ -62,11 +62,13 @@ sw buf_xfer_spaces (s_buf *out, s_buf *in)
int main (int argc, char **argv)
{
s_module c3;
+ s_env env;
s_facts facts;
s_buf in;
+ s_tag input;
s_buf out;
sw r;
- s_tag tag;
+ s_tag result;
libc3_init();
facts_init(&facts, NULL);
c3_init(&c3, &facts);
@@ -77,13 +79,20 @@ int main (int argc, char **argv)
in.line = 0;
BUF_INIT_ALLOCA(&out, BUFSZ);
buf_file_open_w(&out, stdout);
+ env_init(&env);
while ((r = buf_xfer_spaces(&out, &in)) >= 0) {
- if ((r = buf_parse_tag(&in, &tag)) > 0) {
- if (buf_inspect_tag(&out, &tag) < 0) {
- tag_clean(&tag);
+ if ((r = buf_parse_tag(&in, &input)) > 0) {
+ if (! eval_tag(&env, &result, &input)) {
+ tag_clean(&input);
+ continue;
+ }
+ if (buf_inspect_tag(&out, &result) < 0) {
+ tag_clean(&input);
+ tag_clean(&result);
break;
}
- tag_clean(&tag);
+ tag_clean(&input);
+ tag_clean(&result);
buf_write_u8(&out, '\n');
if ((r = buf_flush(&out)) < 0)
break;
@@ -95,6 +104,7 @@ int main (int argc, char **argv)
if ((r = buf_refill_compact(&in)) < 0)
break;
}
+ env_clean(&env);
buf_readline_close(&in);
buf_file_close(&out);
c3_clean(&c3);
diff --git a/libc3/c3.h b/libc3/c3.h
index 4354459..bc8abc3 100644
--- a/libc3/c3.h
+++ b/libc3/c3.h
@@ -21,6 +21,8 @@
#include "buf_parse.h"
#include "call.h"
#include "character.h"
+#include "env.h"
+#include "eval.h"
#include "f32.h"
#include "f64.h"
#include "fact.h"
diff --git a/libc3/list.c b/libc3/list.c
index 3b2b3a5..662d2d2 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -62,6 +62,7 @@ s8 list_compare (const s_list *a, const s_list *b)
s_list * list_copy (const s_list *src, s_list **dest)
{
+ s_list *next;
s_list *result = NULL;
*dest = NULL;
while (src) {
@@ -69,8 +70,14 @@ s_list * list_copy (const s_list *src, s_list **dest)
if (! result)
result = *dest;
tag_copy(&src->tag, &(*dest)->tag);
- dest = &(*dest)->next.data.list;
- src = list_next(src);
+ if ((next = list_next(src))) {
+ src = next;
+ dest = &(*dest)->next.data.list;
+ }
+ else {
+ tag_copy(&src->next, &(*dest)->next);
+ break;
+ }
}
return result;
}