diff --git a/.ikc3_history b/.ikc3_history
index bc800e4..e64971d 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,17 +1,3 @@
-a = ?
-a <- 1
-a
-(Ptr) a
-a <- 1
-a <- 2
-type(a)
-a = ?
-a <- 1
-a
-a = ?
-a <- 1
-a
-a = ?
a <- 1
a = ?
a <- 1
@@ -97,3 +83,17 @@ a <- 1
a
(Ptr) 0x1801350e830
(Tag) (Ptr) 0x1801350e830
+Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { puts(fact.object); 1 })
+Facts.with(Facts.env_facts(), [[KC3, :operator, ?]], fn (fact) { puts(fact.object); 1 })
+(Ptr) 0xf24fc9ce000
+(Tag) (Ptr) 0xf24fc9ce000
+?
+Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { puts(fact.object); 1 })
+Facts.with(Facts.env_facts(), [[KC3, :operator, ?]], fn (fact) { puts(fact.object); 1 })
+Facts.with(Facts.env_facts(), quote [[KC3, :operator, op]], fn (fact) { puts(fact.object); 1 })
+op
+op = ?
+Facts.with(Facts.env_facts(), quote [[KC3, :operator, op]], fn (fact) { puts(fact.object); 1 })
+op
+Facts.with(Facts.env_facts(), quote [[KC3, :operator, op]], fn (fact) { puts(fact.object); 1 })
+Facts.with(Facts.env_facts(), quote [[KC3, :operator, op = (Ident) ?]], fn (fact) { puts(fact.object); 1 })
diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index a36cb3d..97edddb 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -3746,21 +3746,26 @@ sw buf_inspect_var (s_buf *buf, const s_tag *tag)
assert(tag->type == TAG_VAR);
assert(tag->data.var.type);
if (tag->data.var.type == &g_sym_Tag) {
- if ((r = buf_write_1(buf, "?0x")) < 0)
+ if ((r = buf_write_1(buf, "?")) < 0)
return r;
}
else {
if ((r = buf_inspect_paren_sym(buf, tag->data.var.type)) < 0)
return r;
result += r;
- if ((r = buf_write_1(buf, " ?0x")) < 0)
+ if ((r = buf_write_1(buf, " ?")) < 0)
+ return r;
+ result += r;
+ }
+ if (tag->data.var.ptr) {
+ if ((r = buf_write_1(buf, "0x")) < 0)
+ return r;
+ result += r;
+ if ((r = buf_inspect_uw_hexadecimal
+ (buf, (uw *) &tag->data.var.ptr)) < 0)
return r;
result += r;
}
- if ((r = buf_inspect_uw_hexadecimal
- (buf, (uw *) &tag->data.var.ptr)) < 0)
- return r;
- result += r;
return result;
}
@@ -3785,10 +3790,15 @@ sw buf_inspect_var_size (s_pretty *pretty, const s_tag *tag)
return r;
result += r;
}
- if ((r = buf_inspect_uw_hexadecimal_size
- (pretty, (uw *) &tag->data.var.ptr)) < 0)
- return r;
- result += r;
+ if (tag->data.var.ptr) {
+ if ((r = buf_write_1_size(pretty, "0x")) < 0)
+ return r;
+ result += r;
+ if ((r = buf_inspect_uw_hexadecimal_size
+ (pretty, (uw *) &tag->data.var.ptr)) < 0)
+ return r;
+ result += r;
+ }
return result;
}
diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 9119676..330a017 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -20,6 +20,7 @@
#include "buf.h"
#include "buf_inspect.h"
#include "buf_parse.h"
+#include "buf_parse_uw.h"
#include "buf_save.h"
#include "call.h"
#include "cfn.h"
@@ -4517,6 +4518,7 @@ sw buf_parse_unquote (s_buf *buf, s_unquote *dest)
sw buf_parse_var (s_buf *buf, s_var *dest)
{
character c;
+ uw i;
sw r;
sw result = 0;
s_buf_save save;
@@ -4536,11 +4538,18 @@ sw buf_parse_var (s_buf *buf, s_var *dest)
if ((r = buf_read_1(buf, "?")) <= 0)
goto restore;
result += r;
+ if ((r = buf_read_1(buf, "0x")) < 0)
+ goto ok;
+ if (r > 0) {
+ if ((r = buf_parse_uw_hexadecimal(buf, &i)) < 0)
+ goto restore;
+ }
if (buf_peek_character_utf8(buf, &c) > 0 &&
! ident_character_is_reserved(c)) {
r = 0;
goto restore;
}
+ ok:
*dest = tmp;
r = result;
goto clean;
diff --git a/libkc3/buf_parse_u.c.in b/libkc3/buf_parse_u.c.in
index edacd21..9be4d27 100644
--- a/libkc3/buf_parse_u.c.in
+++ b/libkc3/buf_parse_u.c.in
@@ -155,6 +155,11 @@ sw buf_parse_u_bits$_base (s_buf *buf, const s_str *base,
return r;
}
+sw buf_parse_u_bits$_hexadecimal (s_buf *buf, u_bits$ *dest)
+{
+ return buf_parse_u_bits$_base(buf, &g_kc3_base_hexadecimal, dest);
+}
+
s_tag * buf_parse_tag_u_bits$ (s_buf *buf, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/buf_parse_u.h.in b/libkc3/buf_parse_u.h.in
index fee8d12..ae3877d 100644
--- a/libkc3/buf_parse_u.h.in
+++ b/libkc3/buf_parse_u.h.in
@@ -19,6 +19,7 @@
sw buf_parse_u_bits$ (s_buf *buf, u_bits$ *dest);
sw buf_parse_u_bits$_base (s_buf *buf, const s_str *base,
u_bits$ *dest);
+sw buf_parse_u_bits$_hexadecimal (s_buf *buf, u_bits$ *dest);
s_tag * buf_parse_tag_u_bits$ (s_buf *buf, s_tag *dest);
s_tag * buf_parse_tag_u_bits$_base (s_buf *buf, const s_str *base,
s_tag *dest);
diff --git a/libkc3/buf_parse_u16.c b/libkc3/buf_parse_u16.c
index fce9b62..a5b2291 100644
--- a/libkc3/buf_parse_u16.c
+++ b/libkc3/buf_parse_u16.c
@@ -155,6 +155,11 @@ sw buf_parse_u16_base (s_buf *buf, const s_str *base,
return r;
}
+sw buf_parse_u16_hexadecimal (s_buf *buf, u16 *dest)
+{
+ return buf_parse_u16_base(buf, &g_kc3_base_hexadecimal, dest);
+}
+
s_tag * buf_parse_tag_u16 (s_buf *buf, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/buf_parse_u16.h b/libkc3/buf_parse_u16.h
index 4ab68da..3a11e19 100644
--- a/libkc3/buf_parse_u16.h
+++ b/libkc3/buf_parse_u16.h
@@ -19,6 +19,7 @@
sw buf_parse_u16 (s_buf *buf, u16 *dest);
sw buf_parse_u16_base (s_buf *buf, const s_str *base,
u16 *dest);
+sw buf_parse_u16_hexadecimal (s_buf *buf, u16 *dest);
s_tag * buf_parse_tag_u16 (s_buf *buf, s_tag *dest);
s_tag * buf_parse_tag_u16_base (s_buf *buf, const s_str *base,
s_tag *dest);
diff --git a/libkc3/buf_parse_u32.c b/libkc3/buf_parse_u32.c
index d3e771b..111135c 100644
--- a/libkc3/buf_parse_u32.c
+++ b/libkc3/buf_parse_u32.c
@@ -155,6 +155,11 @@ sw buf_parse_u32_base (s_buf *buf, const s_str *base,
return r;
}
+sw buf_parse_u32_hexadecimal (s_buf *buf, u32 *dest)
+{
+ return buf_parse_u32_base(buf, &g_kc3_base_hexadecimal, dest);
+}
+
s_tag * buf_parse_tag_u32 (s_buf *buf, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/buf_parse_u32.h b/libkc3/buf_parse_u32.h
index 8fbc6c8..e798007 100644
--- a/libkc3/buf_parse_u32.h
+++ b/libkc3/buf_parse_u32.h
@@ -19,6 +19,7 @@
sw buf_parse_u32 (s_buf *buf, u32 *dest);
sw buf_parse_u32_base (s_buf *buf, const s_str *base,
u32 *dest);
+sw buf_parse_u32_hexadecimal (s_buf *buf, u32 *dest);
s_tag * buf_parse_tag_u32 (s_buf *buf, s_tag *dest);
s_tag * buf_parse_tag_u32_base (s_buf *buf, const s_str *base,
s_tag *dest);
diff --git a/libkc3/buf_parse_u64.c b/libkc3/buf_parse_u64.c
index c27df5d..a852a87 100644
--- a/libkc3/buf_parse_u64.c
+++ b/libkc3/buf_parse_u64.c
@@ -155,6 +155,11 @@ sw buf_parse_u64_base (s_buf *buf, const s_str *base,
return r;
}
+sw buf_parse_u64_hexadecimal (s_buf *buf, u64 *dest)
+{
+ return buf_parse_u64_base(buf, &g_kc3_base_hexadecimal, dest);
+}
+
s_tag * buf_parse_tag_u64 (s_buf *buf, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/buf_parse_u64.h b/libkc3/buf_parse_u64.h
index 3c5468e..7e71d1c 100644
--- a/libkc3/buf_parse_u64.h
+++ b/libkc3/buf_parse_u64.h
@@ -19,6 +19,7 @@
sw buf_parse_u64 (s_buf *buf, u64 *dest);
sw buf_parse_u64_base (s_buf *buf, const s_str *base,
u64 *dest);
+sw buf_parse_u64_hexadecimal (s_buf *buf, u64 *dest);
s_tag * buf_parse_tag_u64 (s_buf *buf, s_tag *dest);
s_tag * buf_parse_tag_u64_base (s_buf *buf, const s_str *base,
s_tag *dest);
diff --git a/libkc3/buf_parse_u8.c b/libkc3/buf_parse_u8.c
index c339e05..316e0c1 100644
--- a/libkc3/buf_parse_u8.c
+++ b/libkc3/buf_parse_u8.c
@@ -155,6 +155,11 @@ sw buf_parse_u8_base (s_buf *buf, const s_str *base,
return r;
}
+sw buf_parse_u8_hexadecimal (s_buf *buf, u8 *dest)
+{
+ return buf_parse_u8_base(buf, &g_kc3_base_hexadecimal, dest);
+}
+
s_tag * buf_parse_tag_u8 (s_buf *buf, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/buf_parse_u8.h b/libkc3/buf_parse_u8.h
index fd23a59..882081e 100644
--- a/libkc3/buf_parse_u8.h
+++ b/libkc3/buf_parse_u8.h
@@ -19,6 +19,7 @@
sw buf_parse_u8 (s_buf *buf, u8 *dest);
sw buf_parse_u8_base (s_buf *buf, const s_str *base,
u8 *dest);
+sw buf_parse_u8_hexadecimal (s_buf *buf, u8 *dest);
s_tag * buf_parse_tag_u8 (s_buf *buf, s_tag *dest);
s_tag * buf_parse_tag_u8_base (s_buf *buf, const s_str *base,
s_tag *dest);
diff --git a/libkc3/buf_parse_uw.c b/libkc3/buf_parse_uw.c
index 43d9b9a..c123fa7 100644
--- a/libkc3/buf_parse_uw.c
+++ b/libkc3/buf_parse_uw.c
@@ -155,6 +155,11 @@ sw buf_parse_uw_base (s_buf *buf, const s_str *base,
return r;
}
+sw buf_parse_uw_hexadecimal (s_buf *buf, uw *dest)
+{
+ return buf_parse_uw_base(buf, &g_kc3_base_hexadecimal, dest);
+}
+
s_tag * buf_parse_tag_uw (s_buf *buf, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/buf_parse_uw.h b/libkc3/buf_parse_uw.h
index c1c0b7c..c298fa5 100644
--- a/libkc3/buf_parse_uw.h
+++ b/libkc3/buf_parse_uw.h
@@ -19,6 +19,7 @@
sw buf_parse_uw (s_buf *buf, uw *dest);
sw buf_parse_uw_base (s_buf *buf, const s_str *base,
uw *dest);
+sw buf_parse_uw_hexadecimal (s_buf *buf, uw *dest);
s_tag * buf_parse_tag_uw (s_buf *buf, s_tag *dest);
s_tag * buf_parse_tag_uw_base (s_buf *buf, const s_str *base,
s_tag *dest);
diff --git a/libkc3/env.c b/libkc3/env.c
index 78d2e84..ddfb65e 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -2058,6 +2058,7 @@ s_tag * env_facts_with (s_env *env, s_facts *facts, s_list **spec,
if (! facts_with_cursor_next(&cursor, &fact))
goto clean;
if (! fact) {
+ err_puts("env_facts_with: ok");
goto ok;
}
tag_clean(&tmp);
@@ -2124,7 +2125,7 @@ s_facts_with_cursor * env_facts_with_list (s_env *env, s_facts *facts,
tmp_tail = &(*tmp_tail)->next.data.list;
spec_i = list_next(spec_i);
}
- if (true) {
+ if (false) {
err_write_1("env_facts_with_list: spec = ");
err_inspect_list((const s_list * const *) &tmp);
err_write_1("\n");
@@ -2134,7 +2135,7 @@ s_facts_with_cursor * env_facts_with_list (s_env *env, s_facts *facts,
assert(! "env_facts_with_list: facts_spec_new_list");
goto ko;
}
- if (true) {
+ if (false) {
err_write_1("env_facts_with_list: spec = ");
err_inspect_facts_spec(facts_spec);
err_write_1("\n");
diff --git a/libkc3/facts_with.c b/libkc3/facts_with.c
index 2b54df8..76a48a7 100644
--- a/libkc3/facts_with.c
+++ b/libkc3/facts_with.c
@@ -27,37 +27,34 @@ s_facts_with_cursor * facts_with (s_facts *facts,
p_facts_spec spec)
{
uw facts_count;
+ s_facts_with_cursor tmp = {0};
assert(facts);
assert(cursor);
assert(spec);
facts_count = facts_spec_count_facts(spec);
- cursor->facts = facts;
- cursor->facts_count = facts_count;
+ tmp.facts = facts;
+ tmp.facts_count = facts_count;
if (facts_count > 0) {
- cursor->levels = alloc(facts_count *
- sizeof(s_facts_with_cursor_level));
- if (! cursor->levels)
+ tmp.levels = alloc(facts_count *
+ sizeof(s_facts_with_cursor_level));
+ if (! tmp.levels)
return NULL;
- cursor->spec = facts_spec_new_expand(spec);
- /*
- buf_inspect_facts_spec(&g_c3_env.err, spec);
- buf_write_1(&g_c3_env.err, "\n");
- buf_inspect_facts_spec(&g_c3_env.err, cursor->spec);
- buf_write_1(&g_c3_env.err, "\n");
- buf_flush(&g_c3_env.err);
- */
- /* facts_spec_sort(cursor->spec); */
+ tmp.spec = facts_spec_new_expand(spec);
+ if (false) {
+ err_write_1("facts_with: spec = ");
+ err_inspect_facts_spec(spec);
+ err_write_1("\nfacts_with: tmp.spec = ");
+ err_inspect_facts_spec(tmp.spec);
+ err_write_1("\n");
+ }
+ /* facts_spec_sort(tmp.spec); */
}
- else {
- cursor->levels = NULL;
- cursor->spec = NULL;
- }
- cursor->level = 0;
- if (pthread_mutex_init(&cursor->mutex, NULL)) {
+ if (pthread_mutex_init(&tmp.mutex, NULL)) {
err_puts("facts_with: pthread_mutex_init");
assert(! "facts_with: pthread_mutex_init");
return NULL;
}
+ *cursor = tmp;
return cursor;
}
diff --git a/test/ikc3/facts_with_tags.kc3 b/test/ikc3/facts_with_tags.kc3
index 9ebc9cd..082c42f 100644
--- a/test/ikc3/facts_with_tags.kc3
+++ b/test/ikc3/facts_with_tags.kc3
@@ -1,8 +1,38 @@
quote Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) {
puts(fact.object)
- void
+ 1
})
Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) {
puts(fact.object)
- void
+ 1
+})
+quote Facts.with_tags(Facts.env_facts(), KC3, :operator, op = ?, fn (fact) {
+ puts(op)
+ 2
+})
+Facts.with_tags(Facts.env_facts(), KC3, :operator, op = ?, fn (fact) {
+ puts(op)
+ 2
+})
+quote op = ?
+op = ?
+quote Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) {
+ puts(op)
+ 3
+})
+Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) {
+ puts(op)
+ 3
+})
+quote type(op)
+type(op)
+quote op = quote KC3.operator_eq
+op = quote KC3.operator_eq
+quote Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) {
+ puts(op)
+ 4
+})
+Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) {
+ puts(op)
+ 4
})
diff --git a/test/ikc3/facts_with_tags.out.expected b/test/ikc3/facts_with_tags.out.expected
index 269d066..644156a 100644
--- a/test/ikc3/facts_with_tags.out.expected
+++ b/test/ikc3/facts_with_tags.out.expected
@@ -1,4 +1,4 @@
-Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { puts(fact.object); void })
+Facts.with_tags(Facts.env_facts(), KC3, :operator, ?, fn (fact) { puts(fact.object); 1 })
operator_eq
operator_gt
operator_lt
@@ -21,10 +21,82 @@ operator_bnot
operator_bxor
operator_equal
operator_paren
+operator_assign
operator_not_eq
operator_require
operator_brackets
operator_defstruct
operator_shift_left
operator_shift_right
-void
+1
+Facts.with_tags(Facts.env_facts(), KC3, :operator, op = ?, fn (fact) { puts(op); 2 })
+operator_eq
+operator_gt
+operator_lt
+operator_or
+operator_add
+operator_and
+operator_bor
+operator_div
+operator_gte
+operator_lte
+operator_mod
+operator_mul
+operator_neg
+operator_not
+operator_pin
+operator_sub
+operator_addi
+operator_band
+operator_bnot
+operator_bxor
+operator_equal
+operator_paren
+operator_assign
+operator_not_eq
+operator_require
+operator_brackets
+operator_defstruct
+operator_shift_left
+operator_shift_right
+2
+op = ?
+?0x
+Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) { puts(op); 3 })
+operator_eq
+operator_gt
+operator_lt
+operator_or
+operator_add
+operator_and
+operator_bor
+operator_div
+operator_gte
+operator_lte
+operator_mod
+operator_mul
+operator_neg
+operator_not
+operator_pin
+operator_sub
+operator_addi
+operator_band
+operator_bnot
+operator_bxor
+operator_equal
+operator_paren
+operator_assign
+operator_not_eq
+operator_require
+operator_brackets
+operator_defstruct
+operator_shift_left
+operator_shift_right
+3
+type(op)
+Var
+op = quote operator_eq
+operator_eq
+Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) { puts(op); 4 })
+operator_eq
+4