Commit 7b7257d47d2a5938d7b160e00b05d8b8c55f5024

Thomas de Grivel 2024-02-28T15:27:51

fix compilation

diff --git a/libc3/bool.c b/libc3/bool.c
index 42408f0..cd17bb2 100644
--- a/libc3/bool.c
+++ b/libc3/bool.c
@@ -16,6 +16,7 @@
 #include "buf_inspect.h"
 #include "integer.h"
 #include "io.h"
+#include "ratio.h"
 #include "tag_type.h"
 
 bool * bool_init_cast (bool *b, const s_tag *tag)
@@ -30,6 +31,8 @@ bool * bool_init_cast (bool *b, const s_tag *tag)
   case TAG_F128:      *b = (bool) tag->data.f128;           return b;
   case TAG_INTEGER:
     *b = ! integer_is_zero(&tag->data.integer);             return b;
+  case TAG_RATIO:
+    *b = ! ratio_is_zero(&tag->data.ratio);                 return b;
   case TAG_S8:        *b = tag->data.s8 != 0;               return b;
   case TAG_S16:       *b = tag->data.s16 != 0;              return b;
   case TAG_S32:       *b = tag->data.s32 != 0;              return b;
diff --git a/libc3/env.c b/libc3/env.c
index bd6795d..9a565fb 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -452,6 +452,7 @@ bool env_eval_equal_tag (s_env *env, bool macro, const s_tag *a,
   case TAG_F64:
   case TAG_F128:
   case TAG_INTEGER:
+  case TAG_RATIO:
   case TAG_S8:
   case TAG_S16:
   case TAG_S32:
@@ -467,6 +468,7 @@ bool env_eval_equal_tag (s_env *env, bool macro, const s_tag *a,
     case TAG_F64:
     case TAG_F128:
     case TAG_INTEGER:
+    case TAG_RATIO:
     case TAG_S8:
     case TAG_S16:
     case TAG_S32:
@@ -513,11 +515,10 @@ bool env_eval_equal_tag (s_env *env, bool macro, const s_tag *a,
     dest->type = TAG_TUPLE;
     return env_eval_equal_tuple(env, macro, &a->data.tuple,
                                 &b->data.tuple, &dest->data.tuple);
-  case TAG_CALL:
-  case TAG_QUOTE:
   case TAG_ARRAY:
   case TAG_BLOCK:
   case TAG_BOOL:
+  case TAG_CALL:
   case TAG_CFN:
   case TAG_CHARACTER:
   case TAG_FACT:
@@ -527,6 +528,7 @@ bool env_eval_equal_tag (s_env *env, bool macro, const s_tag *a,
   case TAG_PTAG:
   case TAG_PTR:
   case TAG_PTR_FREE:
+  case TAG_QUOTE:
   case TAG_STR:
   case TAG_STRUCT:
   case TAG_STRUCT_TYPE:
@@ -972,6 +974,7 @@ bool env_eval_quote_tag (s_env *env, const s_tag *tag, s_tag *dest)
   case TAG_PTAG:
   case TAG_PTR:
   case TAG_PTR_FREE:
+  case TAG_RATIO:
   case TAG_S8:
   case TAG_S16:
   case TAG_S32:
diff --git a/libc3/list_init.c b/libc3/list_init.c
index 57e7067..e0da66f 100644
--- a/libc3/list_init.c
+++ b/libc3/list_init.c
@@ -254,13 +254,12 @@ s_list * list_init_ratio_1 (s_list *list, const char *p, s_list *next)
   return list;
 }
 
-s_list * list_init_ratio (s_list *list, s_integer *numerator, 
-                          s_integer *denominator, s_list *next)
+s_list * list_init_ratio (s_list *list, s_list *next)
 {
   s_list tmp;
   assert(list);
   list_init(&tmp, next);
-  if (! tag_init_ratio(&tmp.tag, numerator, denominator))
+  if (! tag_init_ratio(&tmp.tag))
     return NULL;
   *list = tmp;
   return list;
@@ -787,14 +786,13 @@ s_list * list_new_ratio_1 (const char *p, s_list *next)
   return list;
 }
 
-s_list * list_new_ratio (s_integer *numerator, s_integer *denominator, 
-                         s_list *next)
+s_list * list_new_ratio (s_list *next)
 {
   s_list *list;
   list = list_new(next);
   if (! list)
     return NULL;
-  if (! tag_init_ratio(&list->tag, numerator, denominator)) {
+  if (! tag_init_ratio(&list->tag)) {
     free(list);
     return NULL;
   }
diff --git a/libc3/list_init.h b/libc3/list_init.h
index b33d0ce..55f6b20 100644
--- a/libc3/list_init.h
+++ b/libc3/list_init.h
@@ -44,8 +44,7 @@ s_list * list_init_ptr_free (s_list *list, void *p, s_list *next);
 s_list * list_init_quote_copy (s_list *list, const s_quote *quote, 
                                s_list *next);
 s_list * list_init_ratio_1 (s_list *list, const char *p, s_list *next);
-s_list * list_init_ratio (s_list *list, s_integer *numerator, 
-                          s_integer *denominator, s_list *next);
+s_list * list_init_ratio (s_list *list, s_list *next);
 s_list * list_init_ratio_copy (s_list *list, const s_ratio *r, 
                                s_list *next);
 s_list * list_init_ratio_zero (s_list *list, s_list *next);
@@ -105,8 +104,7 @@ s_list * list_new_ptr (void *p, s_list *next);
 s_list * list_new_ptr_free (void *p, s_list *next);
 s_list * list_new_quote_copy (const s_quote *quote, s_list *next);
 s_list * list_new_ratio_1 (const char *p, s_list *next);
-s_list * list_new_ratio (s_integer *numerator, s_integer *denominator, 
-                         s_list *next);
+s_list * list_new_ratio (s_list *next);
 s_list * list_new_ratio_copy (const s_ratio *r, s_list *next);
 s_list * list_new_ratio_zero (s_list *next);
 s_list * list_new_s8 (s8 i, s_list *next);
@@ -161,8 +159,7 @@ s_list * list_ptr (s_list *list, void *p);
 s_list * list_ptr_free (s_list *list, void *p);
 s_list * list_quote_copy (s_list *list, const s_quote *quote);
 s_list * list_ratio_1 (s_list *list, const char *p);
-s_list * list_ratio (s_list *list, s_integer *numerator, 
-                     s_integer *denominator);
+s_list * list_ratio (s_list *list);
 s_list * list_ratio_copy (s_list *list, const s_ratio *r);
 s_list * list_ratio_zero (s_list *list);
 s_list * list_s8 (s_list *list, s8 i);
diff --git a/libc3/ratio.h b/libc3/ratio.h
index 87eee7e..75f616d 100644
--- a/libc3/ratio.h
+++ b/libc3/ratio.h
@@ -17,50 +17,48 @@
 #include <stdio.h>
 #include "types.h"
 
-void ratio_clean (s_ratio *r);
-
-/* Stack allocation compatible functions */
+/* Stack-allocation compatible functions, call ratio_clean after use. */
+void      ratio_clean (s_ratio *r);
 s_ratio * ratio_init (s_ratio *dest);
-s_ratio * ratio_init_integer (s_ratio *r, s_integer *numerator, s_integer *denominator);
+s_ratio * ratio_init_integer (s_ratio *r, s_integer *numerator,
+                              s_integer *denominator);
 s_ratio * ratio_init_zero (s_ratio *r);
 s_ratio * ratio_init_1 (s_ratio *r, const char *p);
 s_ratio * ratio_init_copy (s_ratio *a, const s_ratio *x);
 s_ratio * ratio_init_f32 (s_ratio *a, f32 x);
 s_ratio * ratio_init_f64 (s_ratio *a, f64 x);
 
-s_str * ratio_inspect (const s_ratio *src, s_str *dest);
+/* Constructors, call ratio_delete after use. */
+s_ratio * ratio_new (void);
+s_ratio * ratio_new_copy (const s_ratio *a);
 
-/* Setters */
-s_ratio * ratio_set_double (s_ratio *a, double x);
+/* Observers. */
+s_str * ratio_inspect (const s_ratio *src, s_str *dest);
+bool    ratio_is_zero (const s_ratio *r);
+f32     ratio_to_f32 (const s_ratio *r);
+f64     ratio_to_f64 (const s_ratio *r);
+sw      ratio_to_sw (const s_ratio *r);
+s64     ratio_to_s64 (const s_ratio *r);
+s32     ratio_to_s32 (const s_ratio *r);
+s16     ratio_to_s16 (const s_ratio *r);
+s8      ratio_to_s8 (const s_ratio *r);
+uw      ratio_to_uw (const s_ratio *r);
+u64     ratio_to_u64 (const s_ratio *r);
+u32     ratio_to_u32 (const s_ratio *r);
+u16     ratio_to_u16 (const s_ratio *r);
+u8      ratio_to_u8 (const s_ratio *r);
 
-/* Modifiers */
+/* Operators. */
 s_ratio * ratio_add (const s_ratio *a, const s_ratio *b,
-                           s_ratio *dest);
+                     s_ratio *dest);
 s_ratio * ratio_sub (const s_ratio *a, const s_ratio *b,
-                           s_ratio *dest);
+                     s_ratio *dest);
 s_ratio * ratio_mul (const s_ratio *a, const s_ratio *b,
-                           s_ratio *dest);
+                     s_ratio *dest);
 s_ratio * ratio_div (const s_ratio *a, const s_ratio *b,
-                           s_ratio *dest);
-
-/* Constructors, call ratio_delete after use. */
-s_ratio * ratio_new (void);
-s_ratio * ratio_new_copy (const s_ratio *a);
-
-/* Observers */
-bool ratio_is_zero (const s_ratio *r);
-f32  ratio_to_f32 (const s_ratio *r);
-f64  ratio_to_f64 (const s_ratio *r);
-sw  ratio_to_sw (const s_ratio *r);
-s64 ratio_to_s64 (const s_ratio *r);
-s32 ratio_to_s32 (const s_ratio *r);
-s16 ratio_to_s16 (const s_ratio *r);
-s8 ratio_to_s8 (const s_ratio *r);
-uw ratio_to_uw (const s_ratio *r);
-u64 ratio_to_u64 (const s_ratio *r);
-u32 ratio_to_u32 (const s_ratio *r);
-u16 ratio_to_u16 (const s_ratio *r);
-u8 ratio_to_u8 (const s_ratio *r);
+                     s_ratio *dest);
 
+/* Setters. */
+s_ratio * ratio_set_double (s_ratio *a, double x);
 
-#endif /* LIBC3_RATIO_H */
\ No newline at end of file
+#endif /* LIBC3_RATIO_H */
diff --git a/libc3/tag_init.c b/libc3/tag_init.c
index 1469ce0..fd66848 100644
--- a/libc3/tag_init.c
+++ b/libc3/tag_init.c
@@ -254,13 +254,12 @@ s_tag * tag_init_ratio_1 (s_tag *tag, const char *p)
   return tag;
 }
 
-s_tag * tag_init_ratio (s_tag *tag, s_integer *numerator, 
-                        s_integer *denominator)
+s_tag * tag_init_ratio (s_tag *tag)
 {
   s_tag tmp = {0};
   assert(tag);
   tmp.type = TAG_RATIO;
-  if (! ratio_init(&tmp.data.ratio, numerator, denominator))
+  if (! ratio_init(&tmp.data.ratio))
     return NULL;
   *tag = tmp;
   return tag;
@@ -797,7 +796,7 @@ s_tag * tag_new_ratio_1 (const char *p)
   return tag;
 }
 
-s_tag * tag_new_ratio (s_integer *numerator, s_integer *denominator)
+s_tag * tag_new_ratio (void)
 {
   s_tag *tag;
   if (! (tag = calloc(1, sizeof(s_tag)))) {
@@ -805,7 +804,7 @@ s_tag * tag_new_ratio (s_integer *numerator, s_integer *denominator)
     return NULL;
   }
   tag->type = TAG_RATIO;
-  if (! ratio_init(&tag->data.ratio, numerator, denominator)) {
+  if (! ratio_init(&tag->data.ratio)) {
     free(tag);
     return NULL;
   }
@@ -1367,14 +1366,13 @@ s_tag * tag_ratio_1 (s_tag *tag, const char *p)
   return tag;
 }
 
-s_tag * tag_ratio (s_tag *tag, s_integer *numerator, 
-                   s_integer *denominator)
+s_tag * tag_ratio (s_tag *tag)
 {
   s_tag tmp = {0};
   assert(tag);
   tag_clean(tag);
   tmp.type = TAG_RATIO;
-  if (! ratio_init(&tmp.data.ratio, numerator, denominator))
+  if (! ratio_init(&tmp.data.ratio))
     return NULL;
   *tag = tmp;
   return tag;
diff --git a/libc3/tag_init.h b/libc3/tag_init.h
index 4fdc50d..78b84a0 100644
--- a/libc3/tag_init.h
+++ b/libc3/tag_init.h
@@ -38,8 +38,7 @@ s_tag * tag_init_ptr (s_tag *tag, void *p);
 s_tag * tag_init_ptr_free (s_tag *tag, void *p);
 s_tag * tag_init_quote_copy (s_tag *tag, const s_quote *quote);
 s_tag * tag_init_ratio_1 (s_tag *tag, const char *p);
-s_tag * tag_init_ratio (s_tag *tag, s_integer *numerator, 
-                        s_integer *denominator);
+s_tag * tag_init_ratio (s_tag *tag);
 s_tag * tag_init_ratio_copy (s_tag *tag, const s_ratio *r);
 s_tag * tag_init_ratio_zero (s_tag *tag);
 s_tag * tag_init_s8 (s_tag *tag, s8 i);
@@ -90,7 +89,7 @@ s_tag * tag_new_ptr (void *p);
 s_tag * tag_new_ptr_free (void *p);
 s_tag * tag_new_quote_copy (const s_quote *quote);
 s_tag * tag_new_ratio_1 (const char *p);
-s_tag * tag_new_ratio (s_integer *numerator, s_integer *denominator);
+s_tag * tag_new_ratio (void);
 s_tag * tag_new_ratio_copy (const s_ratio *r);
 s_tag * tag_new_ratio_zero (void);
 s_tag * tag_new_s8 (s8 i);
@@ -141,8 +140,7 @@ s_tag * tag_ptr (s_tag *tag, void *p);
 s_tag * tag_ptr_free (s_tag *tag, void *p);
 s_tag * tag_quote_copy (s_tag *tag, const s_quote *quote);
 s_tag * tag_ratio_1 (s_tag *tag, const char *p);
-s_tag * tag_ratio (s_tag *tag, s_integer *numerator, 
-                   s_integer *denominator);
+s_tag * tag_ratio (s_tag *tag);
 s_tag * tag_ratio_copy (s_tag *tag, const s_ratio *r);
 s_tag * tag_ratio_zero (s_tag *tag);
 s_tag * tag_s8 (s_tag *tag, s8 i);
diff --git a/libc3/tag_init.rb b/libc3/tag_init.rb
index 3df6956..6cefaff 100644
--- a/libc3/tag_init.rb
+++ b/libc3/tag_init.rb
@@ -344,12 +344,11 @@ class TagInitList
                    [Arg.new("const s_quote *", "quote")]),
        TagInit1.new("ratio", "1", "TAG_RATIO", :init_mode_init),
        TagInit.new("ratio", "TAG_RATIO", :init_mode_init,
-                      [Arg.new("s_integer *", "numerator"),
-                      Arg.new("s_integer *", "denominator")]),
+                   []),
        TagInit.new("ratio", "copy", "TAG_RATIO", :init_mode_init,
-                      [Arg.new("const s_ratio *", "r")]),
+                   [Arg.new("const s_ratio *", "r")]),
        TagInit.new("ratio", "zero", "TAG_RATIO", :init_mode_init,
-                       []),
+                   []),
        TagInit.new("s8", "TAG_S8", :init_mode_direct,
                    [Arg.new("s8", "i")]),
        TagInit.new("s16", "TAG_S16", :init_mode_direct,