Commit 27db40621a4535e40a8f3c80f8931791c558215d

Thomas de Grivel 2022-12-31T01:43:49

tests ok

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
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 🤩