Commit acaff6665ac67255d9b3d624804fb2dd5e749726

Thomas de Grivel 2023-11-28T19:45:38

finish refactor tag_init.rb

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
diff --git a/libc3/list.c b/libc3/list.c
index e28861a..6dd33a1 100644
--- a/libc3/list.c
+++ b/libc3/list.c
@@ -167,7 +167,7 @@ s_list * list_new (s_list *next)
   return list_init(dest, next);
 }
 
-s_list * list_new_eval (const s8 *p)
+s_list * list_new_1 (const s8 *p)
 {
   s_buf buf;
   s_list *list;
diff --git a/libc3/list.h b/libc3/list.h
index 855c6d5..bb3ec64 100644
--- a/libc3/list.h
+++ b/libc3/list.h
@@ -37,7 +37,7 @@ s_list  * list_init_eval (s_list *list, const s8 *p);
 s_list * list_delete (s_list *list);
 void     list_delete_all (s_list *list);
 s_list * list_new (s_list *next);
-s_list * list_new_eval (const s8 *p);
+s_list * list_new_1 (const s8 *p);
 s_list * list_new_f64 (f64 x, s_list *next);
 s_list * list_new_copy (const s_tag *tag, s_list *next);
 s_list * list_new_list (s_list *list, s_list *next);
diff --git a/libc3/list_init.h b/libc3/list_init.h
index 61c662c..8aae05a 100644
--- a/libc3/list_init.h
+++ b/libc3/list_init.h
@@ -33,7 +33,6 @@ s_list * list_init_integer_copy (s_list *list, const s_integer *i,
                                  s_list *next);
 s_list * list_init_integer_zero (s_list *list, s_list *next);
 
-
 s_list * list_init_map (s_list *list, uw count, s_list *next);
 s_list * list_init_map_1 (s_list *list, const s8 *p, s_list *next);
 s_list * list_init_s8 (s_list *list, s8 i, s_list *next);
@@ -74,7 +73,6 @@ s_list * list_new_integer_1 (const s8 *p, s_list *next);
 s_list * list_new_integer_copy (const s_integer *i, s_list *next);
 s_list * list_new_integer_zero (s_list *next);
 
-
 s_list * list_new_map (uw count, s_list *next);
 s_list * list_new_map_1 (const s8 *p, s_list *next);
 s_list * list_new_s8 (s8 i, s_list *next);
@@ -113,7 +111,6 @@ s_list * list_integer_1 (s_list *list, const s8 *p);
 s_list * list_integer_copy (s_list *list, const s_integer *i);
 s_list * list_integer_zero (s_list *list);
 
-
 s_list * list_map (s_list *list, uw count);
 s_list * list_map_1 (s_list *list, const s8 *p);
 s_list * list_s8 (s_list *list, s8 i);
diff --git a/libc3/tag.c b/libc3/tag.c
index c601d3f..b25e390 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -59,6 +59,7 @@ bool * tag_and (const s_tag *a, const s_tag *b, bool *dest)
   return dest;
 }
 
+/*
 s_tag * tag_array (s_tag *tag, const s_sym *type, uw dimension,
                    const uw *dimensions)
 {
@@ -66,6 +67,7 @@ s_tag * tag_array (s_tag *tag, const s_sym *type, uw dimension,
   tag_clean(tag);
   return tag_init_array(tag, type, dimension, dimensions);
 }
+*/
 
 s_tag * tag_bnot (const s_tag *tag, s_tag *result)
 {
@@ -103,12 +105,14 @@ s_tag * tag_bnot (const s_tag *tag, s_tag *result)
   return NULL;
 }
 
+/*
 s_tag * tag_bool (s_tag *tag, bool b)
 {
   assert(tag);
   tag_clean(tag);
   return tag_init_bool(tag, b);
 }
+*/
 
 s_tag * tag_cast_integer_to_s8 (s_tag *tag)
 {
@@ -182,12 +186,14 @@ s_tag * tag_cast_integer_to_u64 (s_tag *tag)
   return tag_u64(tag, i);
 }
 
+/*
 s_tag * tag_character (s_tag *tag, character x)
 {
   assert(tag);
   tag_clean(tag);
   return tag_init_character(tag, x);
 }
+*/
 
 void tag_clean (s_tag *tag)
 {
@@ -339,6 +345,7 @@ s_tag * tag_equal (const s_tag *a, const s_tag *b, s_tag *dest)
   return dest;
 }
 
+/*
 s_tag * tag_f32 (s_tag *tag, f32 x)
 {
   assert(tag);
@@ -352,6 +359,7 @@ s_tag * tag_f64 (s_tag *tag, f64 x)
   tag_clean(tag);
   return tag_init_f64(tag, x);
 }
+*/
 
 bool * tag_gt (const s_tag *a, const s_tag *b, bool *dest)
 {
@@ -434,6 +442,7 @@ s_tag * tag_init_1 (s_tag *tag, const s8 *p)
   return tag;
 }
 
+/*
 s_tag * tag_init_array (s_tag *tag, const s_sym *type,
                         uw dimension, const uw *dimensions)
 {
@@ -452,7 +461,6 @@ s_tag * tag_init_bool (s_tag *tag, bool b)
   return tag;
 }
 
-/*
 s_tag * tag_init_character (s_tag *tag, character c)
 {
   assert(tag);
@@ -545,6 +553,7 @@ s_tag * tag_init_integer_u64 (s_tag *tag, u64 u)
   return tag;
 }
 
+/*
 s_tag * tag_init_integer_zero (s_tag *tag)
 {
   assert(tag);
@@ -563,7 +572,6 @@ s_tag * tag_init_list (s_tag *tag, s_list *list)
   return tag;
 }
 
-/*
 s_tag * tag_init_list_1 (s_tag *tag, const s8 *p)
 {
   s_buf buf;
@@ -690,6 +698,7 @@ s_tag * tag_init_time (s_tag *tag)
   return time_to_tag(&time, tag);
 }
 
+/*
 s_tag * tag_init_tuple (s_tag *tag, uw count)
 {
   assert(tag);
@@ -709,7 +718,6 @@ s_tag * tag_init_tuple_2 (s_tag *tag, const s_tag *a, const s_tag *b)
   return tag;
 }
 
-/*
 s_tag * tag_init_u8 (s_tag *tag, u8 i)
 {
   assert(tag);
@@ -792,6 +800,7 @@ s_str * tag_inspect (const s_tag *tag, s_str *dest)
   return buf_to_str(&buf, dest);
 }
 
+/*
 s_tag * tag_integer_1 (s_tag *tag, const s8 *p)
 {
   assert(tag);
@@ -805,6 +814,7 @@ s_tag * tag_integer_copy (s_tag *tag, const s_integer *x)
   tag_clean(tag);
   return tag_init_integer_copy(tag, x);
 }
+*/
 
 s_tag * tag_integer_reduce (s_tag *tag)
 {
@@ -870,21 +880,25 @@ bool tag_is_unbound_var (const s_tag *tag)
   return (tag && tag->type == TAG_VAR);
 }
 
+/*
 s_tag * tag_list (s_tag *tag, s_list *x)
 {
   assert(tag);
   tag_clean(tag);
   return tag_init_list(tag, x);
 }
+*/
 
-/*
 s_tag * tag_list_1 (s_tag *tag, const s8 *p)
 {
+  s_tag tmp = {0};
   assert(tag);
   tag_clean(tag);
-  return tag_init_list_1(tag, p);
+  tmp.type = TAG_LIST;
+  tmp.data.list = list_new_1(p);
+  *tag = tmp;
+  return tag;
 }
-*/
 
 bool * tag_lt (const s_tag *a, const s_tag *b, bool *dest)
 {
@@ -903,6 +917,8 @@ bool * tag_lte (const s_tag *a, const s_tag *b, bool *dest)
   *dest = compare_tag(a, b) <= 0 ? 1 : 0;
   return dest;
 }
+
+/*
 s_tag * tag_map (s_tag *tag, uw count)
 {
   assert(tag);
@@ -910,7 +926,6 @@ s_tag * tag_map (s_tag *tag, uw count)
   return tag_init_map(tag, count);
 }
 
-/*
 s_tag * tag_map_1 (s_tag *tag, const s8 *p)
 {
   assert(tag);
@@ -1020,12 +1035,14 @@ s_tag * tag_new_copy (const s_tag *src)
   return tag_init_copy(dest, src);
 }
 
+/*
 s_tag * tag_new_var (void)
 {
   s_tag *tag;
   tag = calloc(1, sizeof(s_tag));
   return tag_init_var(tag);
 }
+*/
 
 bool * tag_not (const s_tag *tag, bool *dest)
 {
@@ -1113,7 +1130,7 @@ s_tag * tag_str_1 (s_tag *tag, s8 *free, const s8 *p)
   tag_clean(tag);
   return tag_init_str_1(tag, free, p);
 }
-*/
+
 s_tag * tag_sym (s_tag *tag, const s_sym *x)
 {
   assert(tag);
@@ -1127,6 +1144,7 @@ s_tag * tag_sym_1 (s_tag *tag, const s8 *p)
   tag_clean(tag);
   return tag_init_sym_1(tag, p);
 }
+*/
 
 void * tag_to_ffi_pointer (s_tag *tag, const s_sym *type)
 {
diff --git a/libc3/tag.h b/libc3/tag.h
index ac9321f..9ab8bdf 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -64,6 +64,7 @@ s_tag * tag_integer_cast_to_u32 (const s_tag *tag, s_tag *dest);
 s_tag * tag_integer_cast_to_u64 (const s_tag *tag, s_tag *dest);
 s_tag * tag_integer_cast_to_u8 (const s_tag *tag, s_tag *dest);
 s_tag * tag_integer_reduce (s_tag *tag);
+s_tag * tag_list_1 (s_tag *tag, const s8 *p);
 void  * tag_to_ffi_pointer (s_tag *tag, const s_sym *type);
 void  * tag_to_pointer (s_tag *tag, const s_sym *type);
 
diff --git a/libc3/tag_init.c b/libc3/tag_init.c
index 9d9e7df..b897837 100644
--- a/libc3/tag_init.c
+++ b/libc3/tag_init.c
@@ -141,23 +141,23 @@ s_tag * tag_init_integer_copy (s_tag *tag, const s_integer *i)
   return tag;
 }
 
-s_tag * tag_init_list (s_tag *tag, s_list *list)
+s_tag * tag_init_integer_zero (s_tag *tag)
 {
   s_tag tmp = {0};
   assert(tag);
-  tmp.type = TAG_LIST;
-  tmp.data.list = list;
+  tmp.type = TAG_INTEGER;
+  if (! integer_init_zero(&tmp.data.integer))
+    return NULL;
   *tag = tmp;
   return tag;
 }
 
-s_tag * tag_init_list_1 (s_tag *tag, const s8 *p, s_list *next)
+s_tag * tag_init_list (s_tag *tag, s_list *list)
 {
   s_tag tmp = {0};
   assert(tag);
   tmp.type = TAG_LIST;
-  if (! list_init_1(tmp.data.list, p, next))
-    return NULL;
+  tmp.data.list = list;
   *tag = tmp;
   return tag;
 }
@@ -503,30 +503,30 @@ s_tag * tag_new_integer_copy (const s_integer *i)
   return tag;
 }
 
-s_tag * tag_new_list (s_list *list)
+s_tag * tag_new_integer_zero (void)
 {
   s_tag *tag;
   if (! (tag = calloc(1, sizeof(s_tag)))) {
-    warn("tag_new_list: calloc");
+    warn("tag_new_integer_zero: calloc");
+    return NULL;
+  }
+  tag->type = TAG_INTEGER;
+  if (! integer_init_zero(&tag->data.integer)) {
+    free(tag);
     return NULL;
   }
-  tag->type = TAG_LIST;
-  tag->data.list = list;
   return tag;
 }
 
-s_tag * tag_new_list_1 (const s8 *p, s_list *next)
+s_tag * tag_new_list (s_list *list)
 {
   s_tag *tag;
   if (! (tag = calloc(1, sizeof(s_tag)))) {
-    warn("tag_new_list_1: calloc");
+    warn("tag_new_list: calloc");
     return NULL;
   }
   tag->type = TAG_LIST;
-  if (! list_init_1(tag->data.list, p, next)) {
-    free(tag);
-    return NULL;
-  }
+  tag->data.list = list;
   return tag;
 }
 
@@ -905,25 +905,25 @@ s_tag * tag_integer_copy (s_tag *tag, const s_integer *i)
   return tag;
 }
 
-s_tag * tag_list (s_tag *tag, s_list *list)
+s_tag * tag_integer_zero (s_tag *tag)
 {
   s_tag tmp = {0};
   assert(tag);
   tag_clean(tag);
-  tmp.type = TAG_LIST;
-  tmp.data.list = list;
+  tmp.type = TAG_INTEGER;
+  if (! integer_init_zero(&tmp.data.integer))
+    return NULL;
   *tag = tmp;
   return tag;
 }
 
-s_tag * tag_list_1 (s_tag *tag, const s8 *p, s_list *next)
+s_tag * tag_list (s_tag *tag, s_list *list)
 {
   s_tag tmp = {0};
   assert(tag);
   tag_clean(tag);
   tmp.type = TAG_LIST;
-  if (! list_init_1(tmp.data.list, p, next))
-    return NULL;
+  tmp.data.list = list;
   *tag = tmp;
   return tag;
 }
diff --git a/libc3/tag_init.h b/libc3/tag_init.h
index 4b825eb..4cc6ec1 100644
--- a/libc3/tag_init.h
+++ b/libc3/tag_init.h
@@ -30,7 +30,6 @@ s_tag * tag_init_integer_1 (s_tag *tag, const s8 *p);
 s_tag * tag_init_integer_copy (s_tag *tag, const s_integer *i);
 s_tag * tag_init_integer_zero (s_tag *tag);
 s_tag * tag_init_list (s_tag *tag, s_list *list);
-s_tag * tag_init_list_1 (s_tag *tag, const s8 *p, s_list *next);
 s_tag * tag_init_map (s_tag *tag, uw count);
 s_tag * tag_init_map_1 (s_tag *tag, const s8 *p);
 s_tag * tag_init_s8 (s_tag *tag, s8 i);
@@ -68,7 +67,6 @@ s_tag * tag_new_integer_1 (const s8 *p);
 s_tag * tag_new_integer_copy (const s_integer *i);
 s_tag * tag_new_integer_zero (void);
 s_tag * tag_new_list (s_list *list);
-s_tag * tag_new_list_1 (const s8 *p, s_list *next);
 s_tag * tag_new_map (uw count);
 s_tag * tag_new_map_1 (const s8 *p);
 s_tag * tag_new_s8 (s8 i);
@@ -106,7 +104,6 @@ s_tag * tag_integer_1 (s_tag *tag, const s8 *p);
 s_tag * tag_integer_copy (s_tag *tag, const s_integer *i);
 s_tag * tag_integer_zero (s_tag *tag);
 s_tag * tag_list (s_tag *tag, s_list *list);
-s_tag * tag_list_1 (s_tag *tag, const s8 *p, s_list *next);
 s_tag * tag_map (s_tag *tag, uw count);
 s_tag * tag_map_1 (s_tag *tag, const s8 *p);
 s_tag * tag_s8 (s_tag *tag, s8 i);
diff --git a/libc3/tag_init.h.rb b/libc3/tag_init.h.rb
index 6271d44..cfdc8b4 100644
--- a/libc3/tag_init.h.rb
+++ b/libc3/tag_init.h.rb
@@ -291,13 +291,13 @@ class TagInitList
        TagInit1.new("integer", "1", "TAG_INTEGER", :init_mode_init),
        TagInit.new("integer", "copy", "TAG_INTEGER", :init_mode_init,
                    [Arg.new("const s_integer *", "i")]),
-       TagInitProto.new("integer_zero", "TAG_INTEGER", :init_mode_init,
-                        []),
+       TagInit.new("integer", "zero", "TAG_INTEGER", :init_mode_init,
+                   []),
        TagInit.new("list", "TAG_LIST", :init_mode_direct,
                    [Arg.new("s_list *", "list")]),
-       TagInit1.new("list", "1", "TAG_LIST", :init_mode_init,
-                    [Arg.new("const s8 *", "p"),
-                     Arg.new("s_list *", "next")]),
+#       TagInit1.new("list", "1", "TAG_LIST", :init_mode_init,
+#                    [Arg.new("const s8 *", "p"),
+#                     Arg.new("s_list *", "next")]),
        TagInit.new("map", "TAG_MAP", :init_mode_init,
                    [Arg.new("uw", "count")]),
        TagInit1.new("map", "1", "TAG_MAP", :init_mode_init),