Commit 6337a493ccf9ca17cf321ed1c1c3f3de0981cc66

Thomas de Grivel 2022-12-30T17:36:32

wip compare

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
diff --git a/libc3/bool.h b/libc3/bool.h
index c82a494..db00baa 100644
--- a/libc3/bool.h
+++ b/libc3/bool.h
@@ -23,7 +23,6 @@
 #include "types.h"
 
 /* Observers */
-s8      bool_compare (e_bool a, e_bool b);
 s_str * bool_inspect (e_bool b, s_str *dest);
 
 #endif /* SYM_H */
diff --git a/libc3/character.h b/libc3/character.h
index 615653a..db9ed19 100644
--- a/libc3/character.h
+++ b/libc3/character.h
@@ -18,7 +18,6 @@
 #include "types.h"
 
 character character_1 (const s8 *p);
-s8        character_compare (character a, character b);
 void      character_hash_update (character c, t_hash *hash);
 e_bool    character_is_digit (character c);
 e_bool    character_is_lowercase (character c);
diff --git a/libc3/compare.c b/libc3/compare.c
index f697a86..ba6c23f 100644
--- a/libc3/compare.c
+++ b/libc3/compare.c
@@ -11,7 +11,10 @@
  * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
  * THIS SOFTWARE.
  */
+#include <assert.h>
+#include <err.h>
 #include "compare.h"
+#include "tag.h"
 
 #define COMPARE_DEF(type)                       \
   s8 compare_##type (type a, type b)            \
@@ -37,13 +40,167 @@ s8 compare_call (const s_call *a, const s_call *b)
   return compare_list(a->arguments, b->arguments);
 }
 
-COMPARE_DEF(f32);
-COMPARE_DEF(f64);
-COMPARE_DEF(s8);
-COMPARE_DEF(s16);
-COMPARE_DEF(s32);
-COMPARE_DEF(s64);
-COMPARE_DEF(u8);
-COMPARE_DEF(u16);
-COMPARE_DEF(u32);
-COMPARE_DEF(u64);
+
+COMPARE_DEF(f32)
+
+COMPARE_DEF(f64)
+
+s8 compare_fact (const s_fact *a, const s_fact *b)
+{
+  s8 r;
+  if (a == b)
+    return 0;
+  if (!a)
+    return -1;
+  if (!b)
+    return 1;
+  if ((r = compare_tag(a->subject, b->subject)))
+    return r;
+  if ((r = compare_tag(a->predicate, b->predicate)))
+    return r;
+  r = compare_tag(a->object, b->object);
+  return r;
+}
+
+s8 fact_compare_unbound_var_count (const s_fact *a,
+                                   const s_fact *b)
+{
+  u8 a_count;
+  u8 b_count;
+  if (a == b)
+    return 0;
+  if (!a)
+    return -1;
+  if (!b)
+    return 1;
+  a_count = 0;
+  b_count = 0;
+  if (tag_is_unbound_var(a->subject))
+    a_count++;
+  if (tag_is_unbound_var(a->predicate))
+    a_count++;
+  if (tag_is_unbound_var(a->object))
+    a_count++;
+  if (tag_is_unbound_var(b->subject))
+    b_count++;
+  if (tag_is_unbound_var(b->predicate))
+    b_count++;
+  if (tag_is_unbound_var(b->object))
+    b_count++;
+  return compare_u8(a_count, b_count);
+}
+
+s8 compare_fact_pos (const s_fact *a, const s_fact *b)
+{
+  s8 r;
+  if (a == b)
+    return 0;
+  if (!a)
+    return -1;
+  if (!b)
+    return 1;
+  if ((r = compare_tag(a->predicate, b->predicate)))
+    return r;
+  if ((r = compare_tag(a->object, b->object)))
+    return r;
+  r = compare_tag(a->subject, b->subject);
+  return r;
+}
+
+s8 compare_fact_osp (const s_fact *a, const s_fact *b)
+{
+  s8 r;
+  if (a == b)
+    return 0;
+  if (!a)
+    return -1;
+  if (!b)
+    return 1;
+  if ((r = compare_tag(a->object, b->object)))
+    return r;
+  if ((r = compare_tag(a->subject, b->subject)))
+    return r;
+  r = compare_tag(a->predicate, b->predicate);
+  return r;
+}
+
+s8 compare_ptr (const void *a, const void *b)
+{
+  if (a < b)
+    return -1;
+  if (a == b)
+    return 0;
+  return 1;
+}
+
+COMPARE_DEF(s8)
+
+COMPARE_DEF(s16)
+
+COMPARE_DEF(s32)
+
+COMPARE_DEF(s64)
+
+s8 compare_tag (const s_tag *a, const s_tag *b) {
+  if (tag_is_bound_var(a))
+    a = a->data.var;
+  if (tag_is_bound_var(b))
+    b = b->data.var;
+  if (a == b)
+    return 0;
+  if (!a ||
+      a == TAG_FIRST ||
+      b == TAG_LAST)
+    return -1;
+  if (!b ||
+      a == TAG_LAST ||
+      b == TAG_FIRST)
+    return 1;
+  if (a->type.type < b->type.type)
+    return -1;
+  if (a->type.type > b->type.type)
+    return 1;
+  switch (a->type.type) {
+  case TAG_VOID: return 0;
+  case TAG_BOOL: return compare_bool(a->data.bool, b->data.bool);
+  case TAG_CALL:
+  case TAG_CALL_FN:
+  case TAG_CALL_MACRO:
+    return compare_call(&a->data.call, &b->data.call);
+  case TAG_CHARACTER: return compare_character(a->data.character,
+                                               b->data.character);
+  case TAG_F32: return compare_f32(a->data.f32, b->data.f32);
+  case TAG_F64: return compare_f64(a->data.f64, b->data.f64);
+  case TAG_FN: return compare_ptr(a, b);
+  case TAG_IDENT: return compare_ident(&a->data.ident, &b->data.ident);
+  case TAG_INTEGER: return compare_integer(&a->data.integer,
+                                           &b->data.integer);
+  case TAG_LIST: return compare_list(a->data.list, b->data.list);
+  case TAG_PTAG: return compare_ptag(a->data.ptag, b->data.ptag);
+  case TAG_QUOTE: return compare_quote(a->data.quote, b->data.quote);
+  case TAG_S8: return compare_s8(a->data.s8, b->data.s8);
+  case TAG_S16: return compare_s16(a->data.s16, b->data.s16);
+  case TAG_S32: return compare_s32(a->data.s32, b->data.s32);
+  case TAG_S64: return compare_s64(a->data.s64, b->data.s64);
+  case TAG_STR: return compare_str(&a->data.str, &b->data.str);
+  case TAG_SYM: return compare_str(&a->data.sym->str,
+                                   &b->data.sym->str);
+  case TAG_TUPLE: return compare_tuple(&a->data.tuple, &b->data.tuple);
+  case TAG_U8: return  compare_u8(a->data.u8, b->data.u8);
+  case TAG_U16: return compare_u16(a->data.u16, b->data.u16);
+  case TAG_U32: return compare_u32(a->data.u32, b->data.u32);
+  case TAG_U64: return compare_u64(a->data.u64, b->data.u64);
+  case TAG_VAR: return compare_ptr(a->data.var, b->data.var);
+  }
+  assert(! "compare_tag: error");
+  errx(1, "compare_tag");
+  return 0;
+}
+
+COMPARE_DEF(u8)
+
+COMPARE_DEF(u16)
+
+COMPARE_DEF(u32)
+
+COMPARE_DEF(u64)
diff --git a/libc3/compare.h b/libc3/compare.h
index 1d8f6e0..233e06f 100644
--- a/libc3/compare.h
+++ b/libc3/compare.h
@@ -19,7 +19,9 @@
 #define COMPARE_PROTOTYPE(type)                     \
   s8 compare_##type (type a, type b)
 
+s8 compare_bool (e_bool a, e_bool b);
 s8 compare_call (const s_call *a, const s_call *b);
+s8 compare_character (character a, character b);
 COMPARE_PROTOTYPE(f32);
 COMPARE_PROTOTYPE(f64);
 s8 compare_fact (const s_fact *a, const s_fact *b);
@@ -31,12 +33,15 @@ s8 compare_ident (const s_ident *a, const s_ident *b);
 s8 compare_integer (const s_integer *a, const s_integer *b);
 s8 compare_integer_s64 (const s_integer *a, s64 b);
 s8 compare_integer_u64 (const s_integer *a, u64 b);
+s8 compare_list (const s_list *a, const s_list *b);
 s8 compare_ptag (const p_tag a, const p_tag b);
 s8 compare_quote (const p_quote a, const p_quote b);
 COMPARE_PROTOTYPE(s8);
 COMPARE_PROTOTYPE(s16);
 COMPARE_PROTOTYPE(s32);
 COMPARE_PROTOTYPE(s64);
+s8 compare_str (const s_str *a, const s_str *b);
+s8 compare_tag (const s_tag *a, const s_tag *b);
 s8 compare_tuple (const s_tuple *a, const s_tuple *b);
 COMPARE_PROTOTYPE(u8);
 COMPARE_PROTOTYPE(u16);
diff --git a/libc3/fact.c b/libc3/fact.c
index 7c4b594..ede4bd4 100644
--- a/libc3/fact.c
+++ b/libc3/fact.c
@@ -19,85 +19,6 @@
 #include "fact.h"
 #include "tag.h"
 
-s8 fact_compare (const s_fact *a, const s_fact *b)
-{
-  s8 r;
-  if (a == b)
-    return 0;
-  if (!a)
-    return -1;
-  if (!b)
-    return 1;
-  if ((r = tag_compare(a->subject, b->subject)))
-    return r;
-  if ((r = tag_compare(a->predicate, b->predicate)))
-    return r;
-  r = tag_compare(a->object, b->object);
-  return r;
-}
-
-s8 fact_compare_unbound_var_count (const s_fact *a,
-                                   const s_fact *b)
-{
-  u8 ca;
-  u8 cb;
-  if (a == b)
-    return 0;
-  if (!a)
-    return -1;
-  if (!b)
-    return 1;
-  ca = 0;
-  cb = 0;
-  if (tag_is_unbound_var(a->subject))
-    ca++;
-  if (tag_is_unbound_var(a->predicate))
-    ca++;
-  if (tag_is_unbound_var(a->object))
-    ca++;
-  if (tag_is_unbound_var(b->subject))
-    cb++;
-  if (tag_is_unbound_var(b->predicate))
-    cb++;
-  if (tag_is_unbound_var(b->object))
-    cb++;
-  return u8_compare(ca, cb);
-}
-
-s8 fact_compare_pos (const s_fact *a, const s_fact *b)
-{
-  s8 r;
-  if (a == b)
-    return 0;
-  if (!a)
-    return -1;
-  if (!b)
-    return 1;
-  if ((r = tag_compare(a->predicate, b->predicate)))
-    return r;
-  if ((r = tag_compare(a->object, b->object)))
-    return r;
-  r = tag_compare(a->subject, b->subject);
-  return r;
-}
-
-s8 fact_compare_osp (const s_fact *a, const s_fact *b)
-{
-  s8 r;
-  if (a == b)
-    return 0;
-  if (!a)
-    return -1;
-  if (!b)
-    return 1;
-  if ((r = tag_compare(a->object, b->object)))
-    return r;
-  if ((r = tag_compare(a->subject, b->subject)))
-    return r;
-  r = tag_compare(a->predicate, b->predicate);
-  return r;
-}
-
 s_fact * fact_copy (const s_fact *src, s_fact *dest)
 {
   assert(src);
@@ -111,7 +32,7 @@ uw fact_hash_uw (const s_fact *fact)
   t_hash hash;
   assert(fact);
   hash_init(&hash);
-  fact_hash_update(&hash, fact);
+  hash_update_fact(&hash, fact);
   return hash_to_uw(&hash);
 }
 
diff --git a/libc3/facts.c b/libc3/facts.c
index 1f083fb..559ee73 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -19,6 +19,7 @@
 #include "buf_file.h"
 #include "buf_inspect.h"
 #include "buf_parse.h"
+#include "compare.h"
 #include "fact.h"
 #include "facts.h"
 #include "facts_cursor.h"
@@ -100,12 +101,6 @@ sw facts_dump (const s_facts *facts, s_buf *buf)
   if ((r = buf_inspect_u64_hex(buf, facts_count(facts))) < 0)
     return r;
   result += r;
-  if ((r = buf_write_1(buf, ",\n  digest: 0x")) < 0)
-    return r;
-  result += r;
-  if ((r = buf_inspect_u64_hex(buf, digest)) < 0)
-    return r;
-  result += r;
   if ((r = buf_write_1(buf, "}\n")) < 0)
     return r;
   result += r;
@@ -115,6 +110,17 @@ sw facts_dump (const s_facts *facts, s_buf *buf)
       return r;
     result += r;
   }
+  /*
+  if ((r = buf_write_1(buf, "\n%{hash: 0x")) < 0)
+    return r;
+  result += r;
+  if ((r = buf_inspect_u64_hex(buf, hash_u64)) < 0)
+    return r;
+  result += r;
+  if ((r = buf_write_1(buf, "}\n")) < 0)
+    return r;
+  result += r;
+  */
   return result;
 }
 
@@ -170,25 +176,38 @@ s_facts * facts_init (s_facts *facts, s_buf *log)
   set_init__fact(&facts->facts, 1024);
   facts->index_spo = skiplist_new__fact(max_height, spacing);
   assert(facts->index_spo);
-  facts->index_spo->compare = fact_compare;
+  facts->index_spo->compare = compare_fact;
   facts->index_pos = skiplist_new__fact(max_height, spacing);
   assert(facts->index_pos);
-  facts->index_pos->compare = fact_compare_pos;
+  facts->index_pos->compare = compare_fact_pos;
   facts->index_osp = skiplist_new__fact(max_height, spacing);
   assert(facts->index_osp);
-  facts->index_osp->compare = fact_compare_osp;
+  facts->index_osp->compare = compare_fact_osp;
   facts->log = log;
   return facts;
 }
 
 sw facts_load (s_facts *facts, s_buf *buf)
 {
+  u64 count;
   s_fact fact;
+  u64 i;
   sw r;
   sw result = 0;
   assert(facts);
   assert(buf);
-  while (1) {
+  if ((r = buf_read_1(buf,
+                      "%{module: C3.Facts,\n"
+                      "  version: 0x0000000000000001,\n"
+                      "  count: 0x")) < 0)
+    return r;
+  result += r;
+  if ((r = buf_parse_u64_hex(buf, &count)) < 0)
+    return r;
+  if ((r = buf_write_1(buf, "}\n")) < 0)
+    return r;
+  result += r;
+  for (i = 0; i < count; i++) {
     if ((r = buf_read_1(buf, "add ")) < 0)
       break;
     result += r;
@@ -276,29 +295,9 @@ sw facts_open_buf (s_facts *facts, s_buf *buf)
   u64 log_pos;
   sw r;
   if ((r = buf_read_1(buf,
-                      "%{module: C3.Facts,\n"
-                      "  version: 0x0000000000000001,\n"
-                      "  count: 0x")) < 0)
-    return r;
-  if ((r = buf_parse_u64_hex(buf, &count)) < 0)
-    return r;
-  if ((r = buf_read_1(buf, ",\n  digest: 0x")) < 0)
-    return r;
-  if ((r = buf_parse_u64_hex(buf, &digest)) < 0)
-    return r;
-  if ((r = buf_read_1(buf, ",\n  dump: 0x")) < 0)
-    return r;
-  if ((r = buf_parse_u64_hex(buf, &dump_pos)) < 0)
-    return r;
-  if ((r = buf_read_1(buf, ",\n  log: 0x")) < 0)
-    return r;
-  if ((r = buf_parse_u64_hex(buf, &log_pos)) < 0)
-    return r;
-  if ((r = buf_read_1(buf, "}\n")) < 0)
-    return r;
-  if ((r = buf_seek(buf, dump_pos, SEEK_SET)) < 0)
-    return r;
-  if ((r = facts_open_buf_read_dump(facts, buf, count, digest)) < 0)
+                      "%{module: C3.Facts.Open,\n"
+                      "  version: 0x0000000000000001}"
+  if ((r = facts_load(facts, buf)) < 0)
     return r;
   if ((r = buf_seek(buf, log_pos, SEEK_SET)) < 0)
     return r;
diff --git a/libc3/hash.h b/libc3/hash.h
index 412f551..c2e16dd 100644
--- a/libc3/hash.h
+++ b/libc3/hash.h
@@ -37,6 +37,7 @@ HASH_UPDATE_PROTOTYPE(s8);
 HASH_UPDATE_PROTOTYPE(s16);
 HASH_UPDATE_PROTOTYPE(s32);
 HASH_UPDATE_PROTOTYPE(s64);
+void hash_update_str (t_hash *hash, const s_str *src);
 void hash_update_tag (t_hash *hash, const s_tag *tag);
 void hash_update_tuple (t_hash *hash, const s_tuple *tuple);
 HASH_UPDATE_PROTOTYPE(u8);
diff --git a/libc3/list.h b/libc3/list.h
index cca17be..097b650 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -38,7 +38,6 @@ s_list * list_delete (s_list *list);
 void     list_delete_all (s_list *list);
 
 /* Observers */
-s8        list_compare (const s_list *a, const s_list *b);
 s_list *  list_copy (const s_list *src, s_list **dest);
 sw        list_length (const s_list *list);
 s_list *  list_next (const s_list *list);
diff --git a/libc3/str.h b/libc3/str.h
index b5f4b34..27133a3 100644
--- a/libc3/str.h
+++ b/libc3/str.h
@@ -54,10 +54,8 @@ void str_delete (s_str *str);
 /* Observers */
 character     str_character_escape (character c);
 e_bool        str_character_is_reserved (character c);
-sw            str_compare (const s_str *a, const s_str *b);
 s_str *       str_copy (const s_str *src, s_str *dest);
 e_bool        str_has_reserved_characters (const s_str *str);
-void          str_hash_update (const s_str *src, t_hash *hash);
 s_str *       str_inspect (const s_str *x, s_str *dest);
 sw            str_peek_bool (const s_str *src, bool *p);
 sw            str_peek_character (const s_str *src, character *p);
diff --git a/libc3/tag.c b/libc3/tag.c
index ed08a51..3579ccb 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -128,62 +128,6 @@ void tag_clean (s_tag *tag)
   }
 }
 
-s8 tag_compare (const s_tag *a, const s_tag *b) {
-  if (tag_is_bound_var(a))
-    a = a->data.var;
-  if (tag_is_bound_var(b))
-    b = b->data.var;
-  if (a == b)
-    return 0;
-  if (!a ||
-      a == TAG_FIRST ||
-      b == TAG_LAST)
-    return -1;
-  if (!b ||
-      a == TAG_LAST ||
-      b == TAG_FIRST)
-    return 1;
-  if (a->type.type < b->type.type)
-    return -1;
-  if (a->type.type > b->type.type)
-    return 1;
-  switch (a->type.type) {
-  case TAG_VOID: return 0;
-  case TAG_BOOL: return bool_compare(a->data.bool, b->data.bool);
-  case TAG_CALL:
-  case TAG_CALL_FN:
-  case TAG_CALL_MACRO:
-    return call_compare(&a->data.call, &b->data.call);
-  case TAG_CHARACTER: return character_compare(a->data.character,
-                                               b->data.character);
-  case TAG_F32: return f32_compare(a->data.f32, b->data.f32);
-  case TAG_F64: return f64_compare(a->data.f64, b->data.f64);
-  case TAG_FN: return ptr_compare(a, b);
-  case TAG_IDENT: return ident_compare(&a->data.ident, &b->data.ident);
-  case TAG_INTEGER: return integer_compare(&a->data.integer,
-                                           &b->data.integer);
-  case TAG_LIST: return list_compare(a->data.list, b->data.list);
-  case TAG_PTAG: return ptag_compare(a->data.ptag, b->data.ptag);
-  case TAG_QUOTE: return quote_compare(a->data.quote, b->data.quote);
-  case TAG_S8: return s8_compare(a->data.s8, b->data.s8);
-  case TAG_S16: return s16_compare(a->data.s16, b->data.s16);
-  case TAG_S32: return s32_compare(a->data.s32, b->data.s32);
-  case TAG_S64: return s64_compare(a->data.s64, b->data.s64);
-  case TAG_STR: return str_compare(&a->data.str, &b->data.str);
-  case TAG_SYM: return str_compare(&a->data.sym->str,
-                                   &b->data.sym->str);
-  case TAG_TUPLE: return tuple_compare(&a->data.tuple, &b->data.tuple);
-  case TAG_U8: return u8_compare(a->data.u8, b->data.u8);
-  case TAG_U16: return u16_compare(a->data.u16, b->data.u16);
-  case TAG_U32: return u32_compare(a->data.u32, b->data.u32);
-  case TAG_U64: return u64_compare(a->data.u64, b->data.u64);
-  case TAG_VAR: return ptr_compare(a->data.var, b->data.var);
-  }
-  assert(! "tag_compare: error");
-  errx(1, "tag_compare");
-  return 0;
-}
-
 s_tag * tag_copy (const s_tag *src, s_tag *dest)
 {
   assert(src);
diff --git a/libc3/tag.h b/libc3/tag.h
index 5ef2733..facef48 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -87,7 +87,6 @@ s_tag * tag_new_var ();
 void tag_delete (s_tag *tag);
 
 /* Observers */
-s8      tag_compare (const s_tag *a, const s_tag *b);
 u64     tag_hash_u64 (const s_tag *tag);
 uw      tag_hash_uw (const s_tag *tag);
 s_str * tag_inspect (const s_tag *tag, s_str *dest);
diff --git a/test/compare_test.c b/test/compare_test.c
new file mode 100644
index 0000000..d550d44
--- /dev/null
+++ b/test/compare_test.c
@@ -0,0 +1,272 @@
+/* c3
+ * Copyright 2022 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software excepted
+ * on Apple computers granted the above copyright notice and
+ * this permission paragraph are included in all copies and
+ * substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#include "test.h"
+#include "../libc3/compare.h"
+#include "../libc3/tag.h"
+
+#define COMPARE_TEST_TAG(a, b, expected)                               \
+  do {                                                                 \
+    TEST_EQ(compare_tag((a), (b)), (expected));                        \
+  } while (0)
+
+void compare_test_f32 ();
+void compare_test_f64 ();
+
+void compare_test ()
+{
+  compare_test_f32();
+  compare_test_f64();
+}
+
+void compare_test_f32 ()
+{
+  TEST_EQ(compare_f32('0', '0'), 0);
+  TEST_EQ(compare_f32('0', '1'), -1);
+  TEST_EQ(compare_f32('1', '0'), 1);
+  TEST_EQ(compare_f32(1.0, 1.0), 0);
+  TEST_EQ(compare_f32(1.0, 2.0), -1);
+  TEST_EQ(compare_f32(1.0, 0.0), 1);
+  TEST_EQ(compare_f32(10000000000000000000000.0,
+                      10000000000000000000000.0),
+          0);
+  TEST_EQ(compare_f32(3.40282346638528859811704183484516925440e+38,
+                      3.40282346638528859811704183484516925440e+38),
+          0);
+  TEST_EQ(compare_f32(1.797693134862315708145274237317043567981e+38,
+                      1.797693134862315708145274237317043567981e+38),
+          0);
+  TEST_EQ(compare_f32(1.797693134862315708145274237317043567981e+38,
+                      1.797693134862315708145274237317043567981e+38),
+          0);
+  TEST_EQ(compare_f32(1.597693134862315708145274237317043567981e+38,
+                      1.797693134862315708145274237317043567980e+38),
+          -1);
+  TEST_EQ(compare_f32(1.797693134862315708145274237317043567980e+38,
+                      1.597693134862315708145274237317043567981e+38),
+          1);
+}
+
+void compare_test_f64 ()
+{
+  TEST_EQ(compare_f64(0.0, 0.0), 0);
+  TEST_EQ(compare_f64(0.0, 1.0), -1);
+  TEST_EQ(compare_f64(1.0, 0.0), 1);
+  TEST_EQ(compare_f64(1.0, 1.0), 0);
+  TEST_EQ(compare_f64(10000000000000000000000.0,
+                      10000000000000000000000.0),
+          0);
+  TEST_EQ(compare_f64(3.40282346638528859811704183484516925440e+38,
+                      3.40282346638528859811704183484516925440e+38),
+          0);
+  TEST_EQ(compare_f64(1.797693134862315708145274237317043567981e+308,
+                      1.797693134862315708145274237317043567981e+308),
+          0);
+  TEST_EQ(compare_f64(1.597693134862315708145274237317043567981e+308,
+                      1.797693134862315708145274237317043567980e+308),
+          -1);
+  TEST_EQ(compare_f64(1.797693134862315708145274237317043567980e+308,
+                      1.597693134862315708145274237317043567981e+308),
+          1);
+}
+
+void compare_test_tag ()
+{
+  s_tag a;
+  s_tag b;
+  /* tuple */
+  COMPARE_TEST_TAG(tag_init_1(&a, "{a, b}"), &a, 0);
+  COMPARE_TEST_TAG(tag_1(&a, "{a, b}"), tag_init_1(&b, "{a, b}"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "{{a, b}, {c, d}}"),
+               tag_1(&b, "{{a, b}, {c, d}}"), 0);
+  /* integer <> s8 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+                   tag_1(&b, "-0x7F"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7F"),
+                   tag_1(&b, "-0x10000000000000000"), 1);
+  /* integer <> s16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+                   tag_1(&b, "-0x7FFF"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7FFF"),
+                   tag_1(&b, "-0x10000000000000000"), 1);
+  /* integer <> s32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+                   tag_1(&b, "-0x7FFFFFFF"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7FFFFFFF"),
+                   tag_1(&b, "-0x10000000000000000"), 1);
+  /* integer <> s64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000000000000000"),
+                   tag_1(&b, "-0x7FFFFFFFFFFFFFFF"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7FFFFFFFFFFFFFFF"),
+                   tag_1(&b, "-0x10000000000000000"), 1);
+  /* integer <> u8 */
+  COMPARE_TEST_TAG(tag_1(&a, "0xFF"),
+                   tag_1(&b, "0x10000000000000000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+                   tag_1(&b, "0xFF"), -1);
+  /* integer <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "0xFFFF"),
+                   tag_1(&b, "0x10000000000000000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+                   tag_1(&b, "0xFFFF"), -1);
+  /* integer <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "0xFFFFFFFF"),
+                   tag_1(&b, "0x10000000000000000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+                   tag_1(&b, "0xFFFFFFFF"), -1);
+  /* integer <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "0xFFFFFFFFFFFFFFFF"),
+                   tag_1(&b, "0x10000000000000000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000000000000000"),
+                   tag_1(&b, "0xFFFFFFFFFFFFFFFF"), -1);
+  /* s8 <> s8 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x7F"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-1"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "-0x7F"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "-1"), 0);
+  /* s8 <> s16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x7F"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100"), 1);
+  /* s8 <> s32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x7F"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x10000"), 1);
+  /* s8 <> s64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x7F"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100000000"), 1);
+  /* s8 <> u8 */
+  COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-1"), 1);
+  /* s8 <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-1"), 1);
+  /* s8 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "-1"), 1);
+  /* s8 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-1"), tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "-1"), 1);
+  /* s16 <> s16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x100"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x200"), tag_1(&b, "-0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x200"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x200"), tag_1(&b, "-0x200"), 0);
+  /* s16 <> s32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x10000"), 1);
+  /* s16 <> s64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "-0x100000000"), 1);
+  /* s16 <> u8 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-0x100"), 1);
+  /* s16 <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-0x100"), 1);
+  /* s16 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "-0x100"), 1);
+  /* s16 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100"), tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "-0x100"), 1);
+  /* s32 <> s32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x10000"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x20000"), tag_1(&b, "-0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x20000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x20000"), tag_1(&b, "-0x20000"), 0);
+  /* s32 <> s64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100000000"), 1);
+  /* s32 <> u8 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "0"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-0x10000"), 1);
+  /* s32 <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-0x10000"), 1);
+  /* s32 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"), tag_1(&b, "0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "-0x10000"), 1);
+  /* s32 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x10000"),
+                   tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+                   tag_1(&b, "-0x10000"), 1);
+  /* s64 <> s64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+                   tag_1(&b, "-0x100000000"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x200000000"),
+                   tag_1(&b, "-0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+                   tag_1(&b, "-0x200000000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "-0x200000000"),
+                   tag_1(&b, "-0x200000000"), 0);
+  /* s64 <> u8 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "0"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "-0x100000000"), 1);
+  /* s64 <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"), tag_1(&b, "0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "-0x100000000"), 1);
+  /* s64 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+                   tag_1(&b, "0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"),
+                   tag_1(&b, "-0x100000000"), 1);
+  /* s64 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "-0x100000000"),
+                   tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+                   tag_1(&b, "-0x100000000"), 1);
+  /* u8 <> u8 */
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "1"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "1"), tag_1(&b, "0"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "1"), tag_1(&b, "1"), 0);
+  /* u8 <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0x100"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0"), 1);
+  /* u8 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0"), 1);
+  /* u8 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "0"), tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "0"), 1);
+  /* u16 <> u16 */
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x100"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x200"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x200"), tag_1(&b, "0x100"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x200"), tag_1(&b, "0x200"), 0);
+  /* u16 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x10000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x100"), 1);
+  /* u16 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "0x100"), tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "0x100"), 1);
+  /* u32 <> u32 */
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x10000"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x20000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x20000"), tag_1(&b, "0x10000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x20000"), tag_1(&b, "0x20000"), 0);
+  /* u32 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "0x10000"), tag_1(&b, "0x100000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"), tag_1(&b, "0x10000"), 1);
+  /* u64 <> u64 */
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+                   tag_1(&b, "0x100000000"), 0);
+  COMPARE_TEST_TAG(tag_1(&a, "0x100000000"),
+                   tag_1(&b, "0x200000000"), -1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x200000000"),
+                   tag_1(&b, "0x100000000"), 1);
+  COMPARE_TEST_TAG(tag_1(&a, "0x200000000"),
+                   tag_1(&b, "0x200000000"), 0);
+  tag_clean(&a);
+  tag_clean(&b);
+}
diff --git a/test/f32_test.c b/test/f32_test.c
deleted file mode 100644
index 040400a..0000000
--- a/test/f32_test.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include <float.h>
-#include <math.h>
-#include <string.h>
-#include "test.h"
-#include "../libc3/f32.h"
-
-void f32_test_compare ();
-
-void f32_test ()
-{
-    f32_test_compare();
-}
-
-void f32_test_compare ()
-{
-  TEST_EQ(f32_compare('0', '0'), 0);
-  TEST_EQ(f32_compare('0', '1'), -1);
-  TEST_EQ(f32_compare('1', '0'), 1);
-  TEST_EQ(f32_compare(1.0, 1.0), 0);
-  TEST_EQ(f32_compare(1.0, 2.0), -1);
-  TEST_EQ(f32_compare(1.0, 0.0), 1);
-  TEST_EQ(f32_compare(10000000000000000000000.0,
-                      10000000000000000000000.0), 0);
-  TEST_EQ(f32_compare(3.40282346638528859811704183484516925440e+38,
-                      3.40282346638528859811704183484516925440e+38), 0);
-  TEST_EQ(f32_compare(1.797693134862315708145274237317043567981e+38,
-                      1.797693134862315708145274237317043567981e+38), 0);
-  TEST_EQ(f32_compare(1.797693134862315708145274237317043567981e+38,
-                      1.797693134862315708145274237317043567981e+38), 0);
-  TEST_EQ(f32_compare(1.597693134862315708145274237317043567981e+38,
-                      1.797693134862315708145274237317043567980e+38), -1);
-  TEST_EQ(f32_compare(1.797693134862315708145274237317043567980e+38,
-                      1.597693134862315708145274237317043567981e+38), 1);
-}
diff --git a/test/f64_test.c b/test/f64_test.c
deleted file mode 100644
index 39739f2..0000000
--- a/test/f64_test.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* c3
- * Copyright 2022 kmx.io <contact@kmx.io>
- *
- * Permission is hereby granted to use this software excepted
- * on Apple computers granted the above copyright notice and
- * this permission paragraph are included in all copies and
- * substantial portions of this software.
- *
- * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
- * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
- * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
- * THIS SOFTWARE.
- */
-#include "../libc3/f64.h"
-#include "test.h"
-
-void f64_test_compare ();
-
-void f64_test()
-{
-  f64_test_compare();
-}
-
-void f64_test_compare ()
-{
-  TEST_EQ(f64_compare(0.0, 0.0), 0);
-  TEST_EQ(f64_compare(0.0, 1.0), -1);
-  TEST_EQ(f64_compare(1.0, 0.0), 1);
-  TEST_EQ(f64_compare(1.0, 1.0), 0);
-  TEST_EQ(f64_compare(10000000000000000000000.0,
-                      10000000000000000000000.0), 0);
-  TEST_EQ(f64_compare(3.40282346638528859811704183484516925440e+38,
-                      3.40282346638528859811704183484516925440e+38), 0);
-  TEST_EQ(f64_compare(1.797693134862315708145274237317043567981e+308,
-                      1.797693134862315708145274237317043567981e+308), 0);
-  TEST_EQ(f64_compare(1.597693134862315708145274237317043567981e+308,
-                      1.797693134862315708145274237317043567980e+308), -1);
-  TEST_EQ(f64_compare(1.797693134862315708145274237317043567980e+308,
-                      1.597693134862315708145274237317043567981e+308), 1);
-
- }
-
diff --git a/test/hash_test.c b/test/hash_test.c
new file mode 100644
index 0000000..8bb6d59
--- /dev/null
+++ b/test/hash_test.c
@@ -0,0 +1,15 @@
+/* c3
+ * Copyright 2022 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software excepted
+ * on Apple computers granted the above copyright notice and
+ * this permission paragraph are included in all copies and
+ * substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#include <string.h>
+#include "test.h"
diff --git a/test/sources.mk b/test/sources.mk
index 52143f5..a84910e 100644
--- a/test/sources.mk
+++ b/test/sources.mk
@@ -1,2 +1,2 @@
 # sources.mk generated by update_sources
-SOURCES = bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c f32_test.c f64_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c 
+SOURCES = bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c compare_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c hash_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c 
diff --git a/test/sources.sh b/test/sources.sh
index 6c531df..565d8be 100644
--- a/test/sources.sh
+++ b/test/sources.sh
@@ -1,2 +1,2 @@
 # sources.sh generated by update_sources
-SOURCES='bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c f32_test.c f64_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c '
+SOURCES='bool_test.c buf_file_test.c buf_inspect_test.c buf_parse_test.c buf_test.c call_test.c character_test.c compare_test.c fact_test.c facts_cursor_test.c facts_test.c facts_with_test.c hash_test.c ident_test.c libc3_test.c list_test.c set__fact_test.c set__tag_test.c skiplist__fact_test.c str_test.c sym_test.c tag_test.c test.c tuple_test.c types_test.c '
diff --git a/test/tag_test.c b/test/tag_test.c
index 421f89b..9b2ee1c 100644
--- a/test/tag_test.c
+++ b/test/tag_test.c
@@ -14,222 +14,23 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
-#include "../libc3/u64.h"
 #include "../libc3/tag.h"
 #include "test.h"
 
-#define TAG_TEST_COMPARE(a, b, expected)                                   \
+#define TAG_TEST_HASH_U64_COMPARE(a, b, expected)                      \
   do {                                                                 \
-    TEST_EQ(tag_compare((a), (b)), (expected));                            \
-  } while (0)
-
-#define TAG_TEST_HASH_COMPARE(a, b, expected)                              \
-  do {                                                                 \
-    TEST_EQ(u64_compare(tag_hash(a), tag_hash(b)), (expected));            \
+    TEST_EQ(compare_u64(tag_hash_u64(a), tag_hash_u64(b)),             \
+            (expected));                                               \
   } while (0)
 
 void tag_test ();
-void tag_test_compare ();
 void tag_test_hash ();
-void tag_to_ffi_type_test ();
 
 void tag_test ()
 {
-  tag_test_compare();
   tag_test_hash();
 }
 
-void tag_test_compare ()
-{
-  s_tag a;
-  s_tag b;
-  /* tuple */
-  TAG_TEST_COMPARE(tag_init_1(&a, "{a, b}"), &a, 0);
-  TAG_TEST_COMPARE(tag_1(&a, "{a, b}"), tag_init_1(&b, "{a, b}"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "{{a, b}, {c, d}}"),
-               tag_1(&b, "{{a, b}, {c, d}}"), 0);
-  /* integer <> s8 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
-                   tag_1(&b, "-0x7F"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7F"),
-                   tag_1(&b, "-0x10000000000000000"), 1);
-  /* integer <> s16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
-                   tag_1(&b, "-0x7FFF"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7FFF"),
-                   tag_1(&b, "-0x10000000000000000"), 1);
-  /* integer <> s32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
-                   tag_1(&b, "-0x7FFFFFFF"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7FFFFFFF"),
-                   tag_1(&b, "-0x10000000000000000"), 1);
-  /* integer <> s64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000000000000000"),
-                   tag_1(&b, "-0x7FFFFFFFFFFFFFFF"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7FFFFFFFFFFFFFFF"),
-                   tag_1(&b, "-0x10000000000000000"), 1);
-  /* integer <> u8 */
-  TAG_TEST_COMPARE(tag_1(&a, "0xFF"),
-                   tag_1(&b, "0x10000000000000000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
-                   tag_1(&b, "0xFF"), -1);
-  /* integer <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "0xFFFF"),
-                   tag_1(&b, "0x10000000000000000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
-                   tag_1(&b, "0xFFFF"), -1);
-  /* integer <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "0xFFFFFFFF"),
-                   tag_1(&b, "0x10000000000000000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
-                   tag_1(&b, "0xFFFFFFFF"), -1);
-  /* integer <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "0xFFFFFFFFFFFFFFFF"),
-                   tag_1(&b, "0x10000000000000000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000000000000000"),
-                   tag_1(&b, "0xFFFFFFFFFFFFFFFF"), -1);
-  /* s8 <> s8 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x7F"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-1"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "-0x7F"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "-1"), 0);
-  /* s8 <> s16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x7F"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100"), 1);
-  /* s8 <> s32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x7F"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x10000"), 1);
-  /* s8 <> s64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x7F"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x7F"), tag_1(&b, "-0x100000000"), 1);
-  /* s8 <> u8 */
-  TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-1"), 1);
-  /* s8 <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-1"), 1);
-  /* s8 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "-1"), 1);
-  /* s8 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-1"), tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "-1"), 1);
-  /* s16 <> s16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x100"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x200"), tag_1(&b, "-0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x200"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x200"), tag_1(&b, "-0x200"), 0);
-  /* s16 <> s32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x10000"), 1);
-  /* s16 <> s64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "-0x100000000"), 1);
-  /* s16 <> u8 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-0x100"), 1);
-  /* s16 <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-0x100"), 1);
-  /* s16 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "-0x100"), 1);
-  /* s16 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100"), tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "-0x100"), 1);
-  /* s32 <> s32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x10000"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x20000"), tag_1(&b, "-0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x20000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x20000"), tag_1(&b, "-0x20000"), 0);
-  /* s32 <> s64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "-0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "-0x100000000"), 1);
-  /* s32 <> u8 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "0"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-0x10000"), 1);
-  /* s32 <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-0x10000"), 1);
-  /* s32 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"), tag_1(&b, "0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "-0x10000"), 1);
-  /* s32 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x10000"),
-                   tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
-                   tag_1(&b, "-0x10000"), 1);
-  /* s64 <> s64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
-                   tag_1(&b, "-0x100000000"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x200000000"),
-                   tag_1(&b, "-0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
-                   tag_1(&b, "-0x200000000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "-0x200000000"),
-                   tag_1(&b, "-0x200000000"), 0);
-  /* s64 <> u8 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "0"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "-0x100000000"), 1);
-  /* s64 <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"), tag_1(&b, "0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "-0x100000000"), 1);
-  /* s64 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
-                   tag_1(&b, "0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"),
-                   tag_1(&b, "-0x100000000"), 1);
-  /* s64 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "-0x100000000"),
-                   tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
-                   tag_1(&b, "-0x100000000"), 1);
-  /* u8 <> u8 */
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "1"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "1"), tag_1(&b, "0"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "1"), tag_1(&b, "1"), 0);
-  /* u8 <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0x100"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0"), 1);
-  /* u8 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0"), 1);
-  /* u8 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "0"), tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "0"), 1);
-  /* u16 <> u16 */
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x100"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x200"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x200"), tag_1(&b, "0x100"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x200"), tag_1(&b, "0x200"), 0);
-  /* u16 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x10000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x100"), 1);
-  /* u16 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "0x100"), tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "0x100"), 1);
-  /* u32 <> u32 */
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x10000"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x20000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x20000"), tag_1(&b, "0x10000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x20000"), tag_1(&b, "0x20000"), 0);
-  /* u32 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "0x10000"), tag_1(&b, "0x100000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"), tag_1(&b, "0x10000"), 1);
-  /* u64 <> u64 */
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
-                   tag_1(&b, "0x100000000"), 0);
-  TAG_TEST_COMPARE(tag_1(&a, "0x100000000"),
-                   tag_1(&b, "0x200000000"), -1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x200000000"),
-                   tag_1(&b, "0x100000000"), 1);
-  TAG_TEST_COMPARE(tag_1(&a, "0x200000000"),
-                   tag_1(&b, "0x200000000"), 0);
-  tag_clean(&a);
-  tag_clean(&b);
-}
-
 void tag_test_hash ()
 {
   s_tag a;