Commit 7f69abab00179edf7f888d0aa15e1f34621d7308

Thomas de Grivel 2024-08-27T12:27:38

wip tests

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
diff --git a/README.md b/README.md
index 82b0f51..6c2f447 100644
--- a/README.md
+++ b/README.md
@@ -525,6 +525,10 @@ serving files for display or download (Web 1.0).
      - [DONE] error_404_page
      - [DONE] directory_page
    - dynamic pages
+     - dynamic router
+     - views
+     - templates
+     - MVC
  - lib
    - [DONE] File.exists?
    - [DONE] File.list
diff --git a/lib/kc3/0.1/kc3/operator.kc3 b/lib/kc3/0.1/kc3/operator.kc3
index 0aa800f..524e5ae 100644
--- a/lib/kc3/0.1/kc3/operator.kc3
+++ b/lib/kc3/0.1/kc3/operator.kc3
@@ -2,7 +2,7 @@ defmodule KC3.Operator do
 
   defstruct [sym: :+,
 	     symbol_value: ?,
-             operator_precedence: (Sw) 0,
+             operator_precedence: 0,
              operator_associativity: :left]
 
   def find_by_sym = cfn Tag "kc3_operator_find_by_sym" (Sym, Result)
diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index 7e16383..c0accef 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -23,6 +23,7 @@
 #include "buf_inspect_s64_decimal.h"
 #include "buf_save.h"
 #include "character.h"
+#include "compare.h"
 #include "cow.h"
 #include "data.h"
 #include "ident.h"
@@ -3097,7 +3098,9 @@ sw buf_inspect_str_size (s_pretty *pretty, const s_str *str)
 
 sw buf_inspect_struct (s_buf *buf, const s_struct *s)
 {
-  uw i = 0;
+  bool display;
+  uw   display_last = 0;
+  uw i;
   s_tag *k;
   s_pretty_save pretty_save;
   sw r;
@@ -3123,52 +3126,66 @@ sw buf_inspect_struct (s_buf *buf, const s_struct *s)
   pretty_save_init(&pretty_save, &buf->pretty);
   pretty_indent_from_column(&buf->pretty, 0);
   if (s->data || s->tag) {
+    i = 0;
     while (i < s->type->map.count) {
-      k = s->type->map.key + i;
-      if (k->type != TAG_SYM) {
-        err_write_1("buf_inspect_struct: key type is not a symbol: ");
-        err_inspect_tag(k);
-        err_write_1(" (");
-        err_write_1(tag_type_to_string(k->type));
-        err_puts(")");
-        assert(k->type == TAG_SYM);
-        r = -1;
-        goto clean;
-      }
-      if (sym_has_reserved_characters(k->data.sym)) {
-        if ((r = buf_inspect_str(buf, &k->data.sym->str)) < 0)
-          goto clean;
-      }
-      else
-        if ((r = buf_write_str_without_indent(buf,
-                                              &k->data.sym->str)) < 0)
-          goto clean;
-      result += r;
-      if ((r = buf_write_1(buf, ": ")) < 0)
-        goto clean;
-      result += r;
-      if (s->data) {
-        if (s->type->map.value[i].type == TAG_VAR)
-          type = s->type->map.value[i].data.var.type;
-        else if (! tag_type(s->type->map.value + i, &type))
-          goto clean;
-        assert(s->type->offset[i] < s->type->size);
-        if ((r = data_buf_inspect(buf, type, (char *) s->data +
-                                  s->type->offset[i])) < 0)
+      if (s->data ||
+          compare_tag(s->tag + i, s->type->map.value + i))
+        display_last = i;
+      i++;
+    }
+    i = 0;
+    while (i < s->type->map.count) {
+      display = s->data ||
+        compare_tag(s->tag + i, s->type->map.value + i);
+      if (display) {
+        k = s->type->map.key + i;
+        if (k->type != TAG_SYM) {
+          err_write_1("buf_inspect_struct: key type is not a symbol: ");
+          err_inspect_tag(k);
+          err_write_1(" (");
+          err_write_1(tag_type_to_string(k->type));
+          err_puts(")");
+          assert(k->type == TAG_SYM);
+          r = -1;
           goto clean;
+        }
+        if (sym_has_reserved_characters(k->data.sym)) {
+          if ((r = buf_inspect_str(buf, &k->data.sym->str)) < 0)
+            goto clean;
+        }
+        else
+          if ((r = buf_write_str_without_indent(buf,
+                                                &k->data.sym->str)) < 0)
+            goto clean;
         result += r;
-      }
-      else if (s->tag) {
-        if ((r = buf_inspect_tag(buf, s->tag + i)) < 0)
+        if ((r = buf_write_1(buf, ": ")) < 0)
           goto clean;
         result += r;
+        if (s->data) {
+          if (s->type->map.value[i].type == TAG_VAR)
+            type = s->type->map.value[i].data.var.type;
+          else if (! tag_type(s->type->map.value + i, &type))
+            goto clean;
+          assert(s->type->offset[i] < s->type->size);
+          if ((r = data_buf_inspect(buf, type, (char *) s->data +
+                                    s->type->offset[i])) < 0)
+            goto clean;
+          result += r;
+        }
+        else if (s->tag) {
+          if ((r = buf_inspect_tag(buf, s->tag + i)) < 0)
+            goto clean;
+          result += r;
+        }
       }
-      i++;
-      if (i < s->type->map.count) {
+      if (display &&
+          i < display_last &&
+          i < s->type->map.count - 1) {
         if ((r = buf_write_1(buf, ",\n")) < 0)
           goto clean;
         result += r;
       }
+      i++;
     }
   }
   pretty_save_clean(&pretty_save, &buf->pretty);
@@ -3183,7 +3200,9 @@ sw buf_inspect_struct (s_buf *buf, const s_struct *s)
 
 sw buf_inspect_struct_size (s_pretty *pretty, const s_struct *s)
 {
-  uw i = 0;
+  bool display;
+  uw   display_last = 0;
+  uw i;
   s_tag *k;
   s_pretty_save pretty_save;
   sw r;
@@ -3210,52 +3229,67 @@ sw buf_inspect_struct_size (s_pretty *pretty, const s_struct *s)
   pretty_save_init(&pretty_save, pretty);
   pretty_indent_from_column(pretty, 0);
   if (s->data || s->tag) {
+    i = 0;
     while (i < s->type->map.count) {
-      k = s->type->map.key + i;
-      if (k->type != TAG_SYM) {
-        err_write_1("buf_inspect_struct: key type is not a symbol: ");
-        err_inspect_tag(k);
-        err_write_1(" (");
-        err_write_1(tag_type_to_string(k->type));
-        err_puts(")");
-        assert(k->type == TAG_SYM);
-        r = -1;
-        goto clean;
-      }
-      if (sym_has_reserved_characters(k->data.sym)) {
-        if ((r = buf_inspect_str_size(pretty, &k->data.sym->str)) < 0)
-          goto clean;
-      }
-      else
-        if ((r = buf_write_str_without_indent_size(pretty,
-                                              &k->data.sym->str)) < 0)
-          goto clean;
-      result += r;
-      if ((r = buf_write_1_size(pretty, ": ")) < 0)
-        goto clean;
-      result += r;
-      if (s->data) {
-        if (s->type->map.value[i].type == TAG_VAR)
-          type = s->type->map.value[i].data.var.type;
-        else if (! tag_type(s->type->map.value + i, &type))
-          goto clean;
-        assert(s->type->offset[i] < s->type->size);
-        if ((r = data_buf_inspect_size(pretty, type, (char *) s->data +
-                                  s->type->offset[i])) < 0)
+      if (s->data ||
+          compare_tag(s->tag + i, s->type->map.value + i))
+        display_last = i;
+      i++;
+    }
+    i = 0;
+    while (i < s->type->map.count) {
+      display = s->data ||
+        compare_tag(s->tag + i, s->type->map.value + i);
+      if (display) {
+        k = s->type->map.key + i;
+        if (k->type != TAG_SYM) {
+          err_write_1("buf_inspect_struct: key type is not a symbol: ");
+          err_inspect_tag(k);
+          err_write_1(" (");
+          err_write_1(tag_type_to_string(k->type));
+          err_puts(")");
+          assert(k->type == TAG_SYM);
+          r = -1;
           goto clean;
+        }
+        if (sym_has_reserved_characters(k->data.sym)) {
+          if ((r = buf_inspect_str_size(pretty, &k->data.sym->str)) < 0)
+            goto clean;
+        }
+        else
+          if ((r = buf_write_str_without_indent_size
+               (pretty, &k->data.sym->str)) < 0)
+            goto clean;
         result += r;
-      }
-      else if (s->tag) {
-        if ((r = buf_inspect_tag_size(pretty, s->tag + i)) < 0)
+        if ((r = buf_write_1_size(pretty, ": ")) < 0)
           goto clean;
         result += r;
+        if (s->data) {
+          if (s->type->map.value[i].type == TAG_VAR)
+            type = s->type->map.value[i].data.var.type;
+          else if (! tag_type(s->type->map.value + i, &type))
+            goto clean;
+          assert(s->type->offset[i] < s->type->size);
+          if ((r = data_buf_inspect_size(pretty, type,
+                                         (char *) s->data +
+                                         s->type->offset[i])) < 0)
+            goto clean;
+          result += r;
+        }
+        else if (s->tag) {
+          if ((r = buf_inspect_tag_size(pretty, s->tag + i)) < 0)
+            goto clean;
+          result += r;
+        }
       }
-      i++;
-      if (i < s->type->map.count) {
+      if (display &&
+          i <= display_last &&
+          i < s->type->map.count - 1) {
         if ((r = buf_write_1_size(pretty, ",\n")) < 0)
           goto clean;
         result += r;
       }
+      i++;
     }
   }
   pretty_save_clean(&pretty_save, pretty);
@@ -3782,8 +3816,7 @@ sw buf_inspect_var_size (s_pretty *pretty, const s_var *var)
       return r;
   }
   else {
-    if ((r = buf_inspect_paren_sym_size(pretty,
-                                        var->type)) < 0)
+    if ((r = buf_inspect_paren_sym_size(pretty, var->type)) < 0)
       return r;
     result += r;
     if ((r = buf_write_1_size(pretty, " ?")) < 0)
@@ -3794,8 +3827,8 @@ sw buf_inspect_var_size (s_pretty *pretty, const s_var *var)
     if ((r = buf_write_1_size(pretty, "0x")) < 0)
       return r;
     result += r;
-    if ((r = buf_inspect_uw_hexadecimal_size
-         (pretty, (uw *) &var->ptr)) < 0)
+    if ((r = buf_inspect_uw_hexadecimal
+         _size(pretty, (uw *) &var->ptr)) < 0)
       return r;
     result += r;
   }
diff --git a/libkc3/env.c b/libkc3/env.c
index 28a1e84..fb90c6a 100644
--- a/libkc3/env.c
+++ b/libkc3/env.c
@@ -1855,7 +1855,8 @@ bool env_eval_tag (s_env *env, const s_tag *tag, s_tag *dest)
   assert(dest);
   switch (tag->type) {
   case TAG_VOID:
-    return env_eval_void(env, NULL, dest);
+    tag_init_void(dest);
+    return true;
   case TAG_ARRAY:
     return env_eval_array_tag(env, &tag->data.array, dest);
   case TAG_BLOCK:
@@ -1992,16 +1993,6 @@ bool env_eval_var (s_env *env, const s_var *var, s_tag *dest)
   return true;
 }
 
-bool env_eval_void (s_env *env, const void *_, s_tag *dest)
-{
-  assert(env);
-  assert(dest);
-  (void) env;
-  (void) _;
-  tag_init_void(dest);
-  return true;
-}
-
 s_fact_w * env_fact_w_eval (s_env *env, const s_fact_w *fact,
 			    s_fact_w *dest)
 {
diff --git a/libkc3/env.h b/libkc3/env.h
index 9fb1ce3..c0ac251 100644
--- a/libkc3/env.h
+++ b/libkc3/env.h
@@ -240,7 +240,6 @@ bool env_eval_time (s_env *env, const s_time *time,
 bool env_eval_tuple (s_env *env, const s_tuple *tuple,
                      s_tag *dest);
 bool env_eval_var (s_env *env, const s_var *var, s_tag *dest);
-bool env_eval_void (s_env *env, const void *_, s_tag *dest);
 
 /* Modifiers. */
 bool env_call_get (s_env *env, s_call *call);
diff --git a/libkc3/struct.c b/libkc3/struct.c
index 6b20b2d..3550c21 100644
--- a/libkc3/struct.c
+++ b/libkc3/struct.c
@@ -238,7 +238,7 @@ s_struct * struct_init_1 (s_struct *s, const char *p)
       struct_clean(&tmp);
     return NULL;
   }
-  if (true) {
+  if (false) {
     err_write_1("\nstruct_init_1: tmp = ");
     err_inspect_struct(&tmp);
     err_write_1("\n");
diff --git a/test/ikc3/block.out.expected b/test/ikc3/block.out.expected
index 7de59cd..92564f2 100644
--- a/test/ikc3/block.out.expected
+++ b/test/ikc3/block.out.expected
@@ -18,14 +18,11 @@ do
 end
 1
 do
-  1
-  2
+  1 ; 2
 end
 2
 do
-  1
-  2
-  3
+  1 ; 2 ; 3
 end
 3
 do
diff --git a/test/ikc3/defoperator.out.expected b/test/ikc3/defoperator.out.expected
index 03bbca4..4ba44a8 100644
--- a/test/ikc3/defoperator.out.expected
+++ b/test/ikc3/defoperator.out.expected
@@ -1,12 +1,11 @@
-%KC3.Operator{}
+%KC3.Operator{symbol_value: void}
 %KC3.Operator{sym: :+,
-              symbol_value: ?,
+              symbol_value: void,
               operator_precedence: 0,
               operator_associativity: :left}
 def operator_muul = %KC3.Operator{sym: :****,
                                   symbol_value: cfn Tag "tag_mul" (Tag, Tag, Result),
-                                  operator_precedence: 11,
-                                  operator_associativity: :left}
+                                  operator_precedence: 11}
 operator_muul
 4 **** 4
 16
@@ -14,3 +13,4 @@ operator_muul
 64
 4 **** 4 + 4
 20
+to_lisp(quote 4 **** 4 + 4)
diff --git a/test/ikc3/facts_with_tags.out.expected b/test/ikc3/facts_with_tags.out.expected
index 644156a..6805aa5 100644
--- a/test/ikc3/facts_with_tags.out.expected
+++ b/test/ikc3/facts_with_tags.out.expected
@@ -26,6 +26,7 @@ operator_not_eq
 operator_require
 operator_brackets
 operator_defstruct
+operator_semicolumn
 operator_shift_left
 operator_shift_right
 1
@@ -57,11 +58,12 @@ operator_not_eq
 operator_require
 operator_brackets
 operator_defstruct
+operator_semicolumn
 operator_shift_left
 operator_shift_right
 2
-op = ?
-?0x
+op = ? ; void
+void
 Facts.with_tags(Facts.env_facts(), KC3, :operator, op, fn (fact) { puts(op); 3 })
 operator_eq
 operator_gt
@@ -90,6 +92,7 @@ operator_not_eq
 operator_require
 operator_brackets
 operator_defstruct
+operator_semicolumn
 operator_shift_left
 operator_shift_right
 3
diff --git a/test/ikc3/facts_with_tuple.out.expected b/test/ikc3/facts_with_tuple.out.expected
index 03807f0..cee9922 100644
--- a/test/ikc3/facts_with_tuple.out.expected
+++ b/test/ikc3/facts_with_tuple.out.expected
@@ -21,10 +21,12 @@ operator_bnot
 operator_bxor
 operator_equal
 operator_paren
+operator_assign
 operator_not_eq
 operator_require
 operator_brackets
 operator_defstruct
+operator_semicolumn
 operator_shift_left
 operator_shift_right
 void
diff --git a/test/ikc3/let.kc3 b/test/ikc3/let.kc3
index 8542214..d5dac07 100644
--- a/test/ikc3/let.kc3
+++ b/test/ikc3/let.kc3
@@ -1,4 +1,4 @@
-quote let %{a: 1} do a; end
-let %{a: 1} do a; end
-quote let %{a: 1, b: 2} do a + b; end
-let %{a: 1, b: 2} do a + b; end
+quote let %{a: 1} do a end
+let %{a: 1} do a end
+quote let %{a: 1, b: 2} do a + b end
+let %{a: 1, b: 2} do a + b end
diff --git a/test/inspect_test.c b/test/inspect_test.c
index fb292e4..5733b05 100644
--- a/test/inspect_test.c
+++ b/test/inspect_test.c
@@ -430,17 +430,17 @@ TEST_CASE(inspect_struct)
   INSPECT_TEST_STRUCT("%KC3.Operator{symbol_value: 1}",
                       "%KC3.Operator{sym: :+,\n"
                       "              symbol_value: 1,\n"
-                      "              operator_precedence: (Sw) 0,\n"
+                      "              operator_precedence: 0,\n"
                       "              operator_associativity: :left}");
   INSPECT_TEST_STRUCT("%KC3.Operator{symbol_value: void}",
                       "%KC3.Operator{sym: :+,\n"
                       "              symbol_value: void,\n"
-                      "              operator_precedence: (Sw) 0,\n"
+                      "              operator_precedence: 0,\n"
                       "              operator_associativity: :left}");
   INSPECT_TEST_STRUCT("%KC3.Operator{sym: :-, symbol_value: void}",
                       "%KC3.Operator{sym: :-,\n"
                       "              symbol_value: void,\n"
-                      "              operator_precedence: (Sw) 0,\n"
+                      "              operator_precedence: 0,\n"
                       "              operator_associativity: :left}");
 }
 TEST_CASE_END(inspect_struct)