Commit cb1f06ee9c3b8eb0e5ccd608683eb3eafbd6b3b4

Thomas de Grivel 2023-03-15T16:44:10

wip cfn SEGV

diff --git a/c3s/configure b/c3s/configure
index f77594f..f8dd9d0 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -59,21 +59,21 @@ config_lib dl -ldl
 # Asan config
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
 LDFLAGS_ASAN="$LDFLAGS"
-LIBC3_ASAN=../libc3/libc3_asan.a
+LIBC3_ASAN=../libc3/libc3_asan.la
 LOCAL_LIBS_ASAN="$LIBC3_ASAN"
 LIBS_ASAN="$LOCAL_LIBS_ASAN $LIBS"
 
 # Coverage config
 CFLAGS_COV="$CFLAGS -ftest-coverage -fprofile-arcs"
 LDFLAGS_COV="$LDFLAGS"
-LIBC3_COV=../libc3/libc3_cov.a
+LIBC3_COV=../libc3/libc3_cov.la
 LOCAL_LIBS_COV="$LIBC3_COV"
 LIBS_COV="$LOCAL_LIBS_COV $LIBS"
 
 # Debug config
 CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -ggdb"
 LDFLAGS_DEBUG="$LDFLAGS"
-LIBC3_DEBUG=../libc3/libc3_debug.a
+LIBC3_DEBUG=../libc3/libc3_debug.la
 LOCAL_LIBS_DEBUG="$LIBC3_DEBUG"
 LIBS_DEBUG="$LOCAL_LIBS_DEBUG $LIBS"
 
@@ -82,7 +82,7 @@ if [ "x$ENV_CFLAGS" = "x" ]; then
     CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
 fi
 CFLAGS="$CFLAGS -DNDEBUG"
-LIBC3=../libc3/libc3.a
+LIBC3=../libc3/libc3.la
 LOCAL_LIBS="$LIBC3"
 LIBS="$LOCAL_LIBS $LIBS"
 
diff --git a/ic3/configure b/ic3/configure
index c7ce057..a93badf 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -59,21 +59,21 @@ config_lib dl -ldl
 # Asan config
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
 LDFLAGS_ASAN="$LDFLAGS"
-LIBC3_ASAN=../libc3/libc3_asan.a
+LIBC3_ASAN=../libc3/libc3_asan.la
 LOCAL_LIBS_ASAN="$LIBC3_ASAN"
 LIBS_ASAN="$LOCAL_LIBS_ASAN $LIBS"
 
 # Coverage config
 CFLAGS_COV="$CFLAGS -ftest-coverage -fprofile-arcs"
 LDFLAGS_COV="$LDFLAGS"
-LIBC3_COV=../libc3/libc3_cov.a
+LIBC3_COV=../libc3/libc3_cov.la
 LOCAL_LIBS_COV="$LIBC3_COV"
 LIBS_COV="$LOCAL_LIBS_COV $LIBS"
 
 # Debug config
 CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -ggdb"
 LDFLAGS_DEBUG="$LDFLAGS"
-LIBC3_DEBUG=../libc3/libc3_debug.a
+LIBC3_DEBUG=../libc3/libc3_debug.la
 LOCAL_LIBS_DEBUG="$LIBC3_DEBUG"
 LIBS_DEBUG="$LOCAL_LIBS_DEBUG $LIBS"
 
@@ -82,7 +82,7 @@ if [ "x$ENV_CFLAGS" = "x" ]; then
     CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
 fi
 CFLAGS="$CFLAGS -DNDEBUG"
-LIBC3=../libc3/libc3.a
+LIBC3=../libc3/libc3.la
 LOCAL_LIBS="$LIBC3"
 LIBS="$LOCAL_LIBS $LIBS"
 
diff --git a/lib/c3/0.1/c3.facts b/lib/c3/0.1/c3.facts
index 3231808..eb54f9c 100644
--- a/lib/c3/0.1/c3.facts
+++ b/lib/c3/0.1/c3.facts
@@ -31,4 +31,4 @@
  ({a, _b, _c}) { a }
  ({a, _b, _c, _d}) { a }
 }}
-%{hash: 0xDD25EEBBF3BE6FD3}
+%{hash: 0x6AA8D9E67CFF2BA6}
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 393682d..8e9dbae 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -35,16 +35,16 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
   s_tag tmp;
   assert(cfn);
   num_args = list_length(args);
-  if (cfn->arity != num_args) {
+  if (cfn->arity != num_args + 1) {
     warnx("cfn_apply: invalid number of arguments, expected %d, have %ld",
-          cfn->arity, num_args);
+          cfn->arity - 1, num_args);
     return NULL;
   }
   cfn_tag_init(&tmp, cfn->result_type);
   /* make result point to tmp value */
   result = cfn_tag_to_ffi_value(&tmp, cfn->result_type);
   if (args) {
-    if (! (arg_values = malloc(sizeof(void *) * num_args)))
+    if (! (arg_values = malloc(sizeof(void *) * (num_args + 1))))
       err(1, "cfn_apply");
     cfn_arg_type = cfn->arg_types;
     i = 0;
@@ -56,6 +56,8 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
       cfn_arg_type = list_next(cfn_arg_type);
       i++;
     }
+    arg_values[i] = cfn_tag_to_ffi_value(&tmp,
+                                         cfn_arg_type->tag.data.sym);
   }
   ffi_call(&cfn->cif, cfn->ptr.f, result, arg_values);
   free(arg_values);
diff --git a/libc3/env.c b/libc3/env.c
index 4533c74..1e3f4b1 100644
--- a/libc3/env.c
+++ b/libc3/env.c
@@ -170,29 +170,23 @@ bool env_eval_call_cfn (s_env *env, const s_call *call, s_tag *dest)
 {
   s_list *args = NULL;
   s_cfn *cfn;
-  s_frame frame;
   s_tag tag;
   assert(env);
   assert(call);
   assert(dest);
   cfn = call->cfn;
   assert(cfn);
-  frame_init(&frame, env->frame);
-  env->frame = &frame;
   if (call->arguments) {
     if (! env_eval_call_arguments(env, call->arguments, &args)) {
-      env->frame = frame_clean(&frame);
       return false;
     }
   }
   if (! cfn_apply(cfn, args, &tag)) {
     list_delete_all(args);
-    env->frame = frame_clean(&frame);
     return false;
   }
   *dest = tag;
   list_delete_all(args);
-  env->frame = frame_clean(&frame);
   return true;
 }
 
diff --git a/libc3/tag.c b/libc3/tag.c
index f6c7085..60250a7 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -476,6 +476,14 @@ void tag_delete (s_tag *tag)
   free(tag);
 }
 
+s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest)
+{
+  (void) a;
+  (void) b;
+  (void) dest;
+  return NULL;
+}
+
 s_tag * tag_f32 (s_tag *tag, f32 x)
 {
   assert(tag);
@@ -908,6 +916,14 @@ s_tag * tag_list_1 (s_tag *tag, const s8 *p)
   return tag_init_list_1(tag, p);
 }
 
+s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest)
+{
+  (void) a;
+  (void) b;
+  (void) dest;
+  return NULL;
+}
+
 s_tag * tag_new ()
 {
   s_tag *tag;
@@ -972,6 +988,14 @@ s_tag * tag_str_1 (s_tag *tag, s8 *free, const s8 *p)
   return tag_init_str_1(tag, free, p);
 }
 
+s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest)
+{
+  (void) a;
+  (void) b;
+  (void) dest;
+  return NULL;
+}
+
 s_tag * tag_sym (s_tag *tag, const s_sym *x)
 {
   assert(tag);
diff --git a/libc3/tag.h b/libc3/tag.h
index e9502b1..c66b624 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -139,5 +139,8 @@ ffi_type tag_to_ffi_type(const s_tag *tag);
 
 /* operators */
 s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest);
+s_tag * tag_sub (const s_tag *a, const s_tag *b, s_tag *dest);
+s_tag * tag_mul (const s_tag *a, const s_tag *b, s_tag *dest);
+s_tag * tag_div (const s_tag *a, const s_tag *b, s_tag *dest);
 
 #endif /* STR_H */
diff --git a/test/configure b/test/configure
index cd58259..2db741e 100755
--- a/test/configure
+++ b/test/configure
@@ -59,19 +59,19 @@ config_lib dl -ldl
 # Asan config
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
 LDFLAGS_ASAN="$LDFLAGS"
-LIBC3_ASAN=../libc3/libc3_asan.a
+LIBC3_ASAN=../libc3/libc3_asan.la
 LIBS_ASAN="$LIBC3_ASAN $LIBS"
 
 # Coverage config
 CFLAGS_COV="$CFLAGS -ftest-coverage -fprofile-arcs"
 LDFLAGS_COV="$LDFLAGS"
-LIBC3_COV=../libc3/libc3_cov.a
+LIBC3_COV=../libc3/libc3_cov.la
 LIBS_COV="$LIBC3_COV $LIBS"
 
 # Debug config
 CFLAGS_DEBUG="$CFLAGS -DDEBUG -O0 -ggdb"
 LDFLAGS_DEBUG="$LDFLAGS"
-LIBC3_DEBUG=../libc3/libc3_debug.a
+LIBC3_DEBUG=../libc3/libc3_debug.la
 LIBS_DEBUG="$LIBC3_DEBUG $LIBS"
 
 # Main config
@@ -79,7 +79,7 @@ if [ "x$ENV_CFLAGS" = "x" ]; then
     CFLAGS="$CFLAGS $DEFAULT_CFLAGS"
 fi
 CFLAGS="$CFLAGS -DNDEBUG"
-LIBC3=../libc3/libc3.a
+LIBC3=../libc3/libc3.la
 LIBS="$LIBC3 $LIBS"
 
 echo "HAVE_ASAN = $HAVE_ASAN" >> ${CONFIG_MK}