diff --git a/c3s/c3s.c b/c3s/c3s.c
index 5fcb8ca..4b3608a 100644
--- a/c3s/c3s.c
+++ b/c3s/c3s.c
@@ -70,7 +70,7 @@ int main (int argc, char **argv)
sw r;
s_tag result;
libc3_init();
- facts_init(&facts, NULL);
+ facts_init(&facts);
c3_init(&c3, &facts);
if (argc < 1)
return usage(argv[0]);
diff --git a/ic3/ic3.c b/ic3/ic3.c
index 3b49663..5565789 100644
--- a/ic3/ic3.c
+++ b/ic3/ic3.c
@@ -70,7 +70,7 @@ int main (int argc, char **argv)
sw r;
s_tag result;
libc3_init();
- facts_init(&facts, NULL);
+ facts_init(&facts);
c3_init(&c3, &facts);
if (argc < 1)
return usage(argv[0]);
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 23f8641..6505381 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -442,7 +442,7 @@ sw buf_inspect_quote (s_buf *buf, p_quote quote)
{
sw r;
sw result = 0;
- if ((r = buf_write_1(buf, "'")) < 0)
+ if ((r = buf_write_1(buf, "quote ")) < 0)
return r;
result += r;
if ((r = buf_inspect_tag(buf, quote)) < 0)
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 0fab5c4..bbc258d 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -948,6 +948,31 @@ sw buf_parse_new_tag (s_buf *buf, s_tag **dest)
return r;
}
+/* call tag_delete after */
+sw buf_parse_quote (s_buf *buf, p_quote *dest)
+{
+ p_quote quote;
+ sw r;
+ sw result = 0;
+ s_buf_save save;
+ buf_save_init(buf, &save);
+ if ((r = buf_read_1(buf, "quote ")) <= 0)
+ goto clean;
+ result += r;
+ quote = tag_new();
+ if ((r = buf_parse_tag(buf, quote)) <= 0)
+ goto restore;
+ result += r;
+ *dest = quote;
+ r = result;
+ goto clean;
+ restore:
+ buf_save_restore_rpos(buf, &save);
+ clean:
+ buf_save_clean(buf, &save);
+ return r;
+}
+
sw buf_parse_str (s_buf *buf, s_str *dest)
{
u8 b;
@@ -1238,6 +1263,7 @@ sw buf_parse_tag (s_buf *buf, s_tag *dest)
if ((r = buf_parse_tag_list(buf, dest)) != 0 ||
(r = buf_parse_tag_str(buf, dest)) != 0 ||
(r = buf_parse_tag_tuple(buf, dest)) != 0 ||
+ (r = buf_parse_tag_quote(buf, dest)) != 0 ||
(r = buf_parse_tag_call(buf, dest)) != 0 ||
(r = buf_parse_tag_ident(buf, dest)) != 0 ||
(r = buf_parse_tag_sym(buf, dest)) != 0)
@@ -1308,6 +1334,14 @@ sw buf_parse_tag_list (s_buf *buf, s_tag *dest)
return r;
}
+sw buf_parse_tag_quote (s_buf *buf, s_tag *dest)
+{
+ sw r;
+ if ((r = buf_parse_quote(buf, &dest->data.quote)) > 0)
+ dest->type.type = TAG_QUOTE;
+ return r;
+}
+
sw buf_parse_tag_str (s_buf *buf, s_tag *dest)
{
sw r;
diff --git a/libc3/buf_parse.h b/libc3/buf_parse.h
index baaf11f..376f16b 100644
--- a/libc3/buf_parse.h
+++ b/libc3/buf_parse.h
@@ -68,6 +68,7 @@ sw buf_parse_tag_character (s_buf *buf, s_tag *dest);
sw buf_parse_tag_ident (s_buf *buf, s_tag *dest);
sw buf_parse_tag_integer (s_buf *buf, s_tag *dest);
sw buf_parse_tag_list (s_buf *buf, s_tag *dest);
+sw buf_parse_tag_quote (s_buf *buf, s_tag *dest);
sw buf_parse_tag_str (s_buf *buf, s_tag *dest);
sw buf_parse_tag_str_character (s_buf *buf, s_tag *dest);
sw buf_parse_tag_str_u8 (s_buf *buf, s_tag *dest);
diff --git a/libc3/facts.c b/libc3/facts.c
index 193b797..bef6d35 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -172,7 +172,7 @@ s_tag * facts_find_tag (const s_facts *facts, const s_tag *tag)
return NULL;
}
-s_facts * facts_init (s_facts *facts, s_buf *log)
+s_facts * facts_init (s_facts *facts)
{
const u8 max_height = 10;
const double spacing = 2.7;
@@ -188,7 +188,7 @@ s_facts * facts_init (s_facts *facts, s_buf *log)
facts->index_osp = skiplist_new__fact(max_height, spacing);
assert(facts->index_osp);
facts->index_osp->compare = compare_fact_osp;
- facts->log = log;
+ facts->log = NULL;
return facts;
}
@@ -274,12 +274,12 @@ sw facts_log_remove (s_buf *log, const s_fact *fact)
return result;
}
-s_facts * facts_new (s_buf *log)
+s_facts * facts_new ()
{
s_facts *n;
if (! (n = malloc(sizeof(s_facts))))
errx(1, "facts_new: out of memory");
- return facts_init(n, log);
+ return facts_init(n);
}
sw facts_open_buf (s_facts *facts, s_buf *buf)
diff --git a/libc3/facts.h b/libc3/facts.h
index 000d317..2a238f3 100644
--- a/libc3/facts.h
+++ b/libc3/facts.h
@@ -16,14 +16,14 @@
#include "types.h"
-#define facts_count(facts) (facts->facts.count)
+#define facts_count(f) ((f)->facts.count)
/* Stack allocation compatible functions */
void facts_clean (s_facts *facts);
-s_facts * facts_init (s_facts *facts, s_buf *log);
+s_facts * facts_init (s_facts *facts);
/* Constructors */
-s_facts * facts_new (s_buf *log);
+s_facts * facts_new ();
/* Destructor */
void facts_delete (s_facts *facts);
diff --git a/test/facts_cursor_test.c b/test/facts_cursor_test.c
index 4660e98..cbf1607 100644
--- a/test/facts_cursor_test.c
+++ b/test/facts_cursor_test.c
@@ -59,7 +59,7 @@ void facts_cursor_test_init ()
};
s_fact fact[24];
s_facts facts;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -129,7 +129,7 @@ void facts_cursor_test_next ()
};
s_fact fact[24];
s_facts facts;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
diff --git a/test/facts_test.c b/test/facts_test.c
index 546c228..051016b 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -76,7 +76,7 @@ void facts_test_add ()
s_fact *pf;
s_fact fact[24];
s_facts facts;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
TEST_ASSERT((pf = facts_add_fact(&facts, fact + i)));
@@ -128,7 +128,7 @@ void facts_test_dump_file ()
};
s_fact fact[24];
s_facts facts;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -179,7 +179,7 @@ void facts_test_find ()
s_fact fact[24];
s_facts facts;
s_fact *pf;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
TEST_EQ(facts_find_fact(&facts, fact + i), NULL);
@@ -203,24 +203,28 @@ void facts_test_find ()
void facts_test_init_clean ()
{
s_facts facts;
- s_buf buf;
- TEST_EQ(facts_init(&facts, NULL), &facts);
+ TEST_EQ(facts_init(&facts), &facts);
TEST_EQ(facts.tags.count, 0);
TEST_EQ(facts.facts.count, 0);
TEST_EQ(facts.log, NULL);
facts_clean(&facts);
test_ok();
- BUF_INIT_ALLOCA(&buf, 1024);
- TEST_EQ(facts_init(&facts, &buf), &facts);
+ TEST_EQ(facts_init(&facts), &facts);
TEST_EQ(facts.tags.count, 0);
TEST_EQ(facts.facts.count, 0);
- TEST_EQ(facts.log, &buf);
+ TEST_EQ(facts.log, NULL);
facts_clean(&facts);
test_ok();
}
void facts_test_load ()
{
+ s_facts facts;
+ facts_init(&facts);
+ TEST_EQ(facts_load_file(&facts,
+ "facts_test_dump_file.facts.expected"),
+ 0);
+ TEST_EQ(facts_count(&facts), 23);
}
void facts_test_log_add ()
@@ -259,7 +263,8 @@ void facts_test_log_add ()
BUF_INIT_ALLOCA(&log, 1024);
fp = fopen("facts_test_log_add.facts", "w");
buf_file_open_w(&log, fp);
- facts_init(&facts, &log);
+ facts_init(&facts);
+ facts.log = &log;
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -310,7 +315,8 @@ void facts_test_log_remove ()
BUF_INIT_ALLOCA(&log, 1024);
fp = fopen("facts_test_log_remove.facts", "w");
buf_file_open_w(&log, fp);
- facts_init(&facts, &log);
+ facts_init(&facts);
+ facts.log = &log;
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -345,12 +351,11 @@ void facts_test_new_delete ()
facts_delete(facts);
test_ok();
}
- BUF_INIT_ALLOCA(&buf, 1024);
TEST_ASSERT((facts = facts_new(&buf)));
if (g_test_last_ok) {
TEST_EQ(facts->tags.count, 0);
TEST_EQ(facts->facts.count, 0);
- TEST_EQ(facts->log, &buf);
+ TEST_EQ(facts->log, NULL);
facts_delete(facts);
test_ok();
}
@@ -387,7 +392,7 @@ void facts_test_remove ()
};
s_fact fact[24];
s_facts facts;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
@@ -436,7 +441,7 @@ void facts_test_save ()
};
s_fact fact[24];
s_facts facts;
- facts_init(&facts, NULL);
+ facts_init(&facts);
while (p[i]) {
fact_test_init_1(fact + i, p[i]);
facts_add_fact(&facts, fact + i);
diff --git a/test/facts_with_test.c b/test/facts_with_test.c
index 8db3ab9..61708b6 100644
--- a/test/facts_with_test.c
+++ b/test/facts_with_test.c
@@ -44,7 +44,7 @@ void facts_with_test_ ()
tag_init_1(tag + i, p[i]);
i++;
}
- facts_init(&facts, NULL);
+ facts_init(&facts);
facts_add_tags(&facts, tag, tag + 1, tag + 2);
facts_add_tags(&facts, tag, tag + 1, tag + 3);
facts_add_tags(&facts, tag, tag + 4, tag + 3);
@@ -194,7 +194,7 @@ void facts_with_test_tags ()
tag_init_1(tag + i, p[i]);
i++;
}
- facts_init(&facts, NULL);
+ facts_init(&facts);
facts_add_tags(&facts, tag, tag + 1, tag + 2);
facts_add_tags(&facts, tag, tag + 1, tag + 3);
facts_add_tags(&facts, tag, tag + 4, tag + 3);
diff --git a/test/ic3/call.in b/test/ic3/call.in
index 75715fc..609b214 100644
--- a/test/ic3/call.in
+++ b/test/ic3/call.in
@@ -1,13 +1,8 @@
-defmodule(Test) do
-
- def(test) do
- test()
- test(1)
- test(1, 2)
- test(1, 2, 3)
- Test.test()
- Test.test(1)
- Test.test(1, 2)
- Test.test(1, 2, 3)
- end
-end
+quote test()
+quote test(1)
+quote test(1, 2)
+quote test(1, 2, 3)
+quote Test.test()
+quote Test.test(1)
+quote Test.test(1, 2)
+quote Test.test(1, 2, 3)
diff --git a/test/ic3/call.out.expected b/test/ic3/call.out.expected
index 95738c8..8d68690 100644
--- a/test/ic3/call.out.expected
+++ b/test/ic3/call.out.expected
@@ -1,4 +1,16 @@
-Module.ident(arg, arg, arg)
+quote test()
-a(b)
+quote test(1)
+
+quote test(1, 2)
+
+quote test(1, 2, 3)
+
+quote Test.test()
+
+quote Test.test(1)
+
+quote Test.test(1, 2)
+
+quote Test.test(1, 2, 3)
diff --git a/test/ic3/ident.in b/test/ic3/ident.in
index 6598121..3d5cd7f 100644
--- a/test/ic3/ident.in
+++ b/test/ic3/ident.in
@@ -1,28 +1,28 @@
-_" "
-_"
+quote _" "
+quote _"
"
-_"\0"
-_"\n"
-_"\r"
-_"\s"
-_"\t"
-_"\v"
-_0
-_9
-_A
-_Z
-a
-z
-_À
-_É
-_Ÿ
-à
-é
-ÿ
-_Π
-꒴
-𐅀
-🎳
-😄
-🟣
-🤩
+quote _"\0"
+quote _"\n"
+quote _"\r"
+quote _"\s"
+quote _"\t"
+quote _"\v"
+quote _0
+quote _9
+quote _A
+quote _Z
+quote a
+quote z
+quote _À
+quote _É
+quote _Ÿ
+quote à
+quote é
+quote ÿ
+quote _Π
+quote ꒴
+quote 𐅀
+quote 🎳
+quote 😄
+quote 🟣
+quote 🤩
diff --git a/test/ic3/ident.out.expected b/test/ic3/ident.out.expected
index 5e9fd82..5221f31 100644
--- a/test/ic3/ident.out.expected
+++ b/test/ic3/ident.out.expected
@@ -1,54 +1,54 @@
-_" "
+quote _" "
-_"\n"
+quote _"\n"
-_"\0"
+quote _"\0"
-_"\n"
+quote _"\n"
-_"\r"
+quote _"\r"
-_" "
+quote _" "
-_"\t"
+quote _"\t"
-_"\v"
+quote _"\v"
-_0
+quote _0
-_9
+quote _9
-_A
+quote _A
-_Z
+quote _Z
-a
+quote a
-z
+quote z
-_À
+quote _À
-_É
+quote _É
-_Ÿ
+quote _Ÿ
-à
+quote à
-é
+quote é
-ÿ
+quote ÿ
-_Π
+quote _Π
-꒴
+quote ꒴
-𐅀
+quote 𐅀
-🎳
+quote 🎳
-😄
+quote 😄
-🟣
+quote 🟣
-🤩
+quote 🤩