Commit 93a4e88d735626b9c5e7b4fd32c1835e2c416359

Thomas de Grivel 2023-03-16T15:09:32

wip cfn

diff --git a/ic3/Makefile b/ic3/Makefile
index cd7b043..d406535 100644
--- a/ic3/Makefile
+++ b/ic3/Makefile
@@ -45,7 +45,7 @@ gcovr:
 	gcovr --gcov-executable ${GCOV} --html-details ic3.html
 
 gdb_ic3: debug
-	if [ -f ic3_debug.core ]; then gdb ic3_debug ic3_debug.core; else gdb ic3_debug; fi
+	if [ -f ic3_debug.core ]; then gdb .libs/ic3_debug ic3_debug.core; else gdb .libs/ic3_debug; fi
 
 install:
 	mkdir -p ${prefix}/bin
diff --git a/libc3/call.c b/libc3/call.c
index f47c006..a67f10b 100644
--- a/libc3/call.c
+++ b/libc3/call.c
@@ -58,7 +58,7 @@ s_call * call_init_op (s_call *call)
 {
   assert(call);
   bzero(call, sizeof(s_call));
-  call->arguments = list_new(list_new(NULL));
+  call->arguments = list_new(list_new(list_new(NULL)));
   return call;
 }
 
diff --git a/libc3/cfn.c b/libc3/cfn.c
index 716ec46..2102b1d 100644
--- a/libc3/cfn.c
+++ b/libc3/cfn.c
@@ -28,37 +28,36 @@ void * cfn_tag_to_ffi_value (s_tag *tag, const s_sym *type);
 
 s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
 {
+  s_list *a;
   void **arg_values = NULL;
   s_list *cfn_arg_type;
-  sw i;
+  sw i = 0;
   sw num_args;
   void* result;
   s_tag tmp;
   assert(cfn);
   num_args = list_length(args);
-  if (cfn->arity != num_args + 1) {
+  if (cfn->arity != num_args) {
     warnx("cfn_apply: invalid number of arguments, expected %d, have %ld",
-          cfn->arity - 1, num_args);
+          cfn->arity, 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 + 1))))
+  if (cfn->arity) {
+    if (! (arg_values = malloc(sizeof(void *) * cfn->arity)))
       err(1, "cfn_apply");
     cfn_arg_type = cfn->arg_types;
-    i = 0;
-    while (args) {
+    a = args;
+    while (a) {
       assert(cfn_arg_type->tag.type.type == TAG_SYM);
-      arg_values[i] = cfn_tag_to_ffi_value(&args->tag,
+      arg_values[i] = cfn_tag_to_ffi_value(&a->tag,
                                            cfn_arg_type->tag.data.sym);
-      args = list_next(args);
+      a = list_next(a);
       cfn_arg_type = list_next(cfn_arg_type);
       i++;
     }
-    arg_values[i] = cfn_tag_to_ffi_value(&tmp,
-                                         cfn_arg_type->tag.data.sym);
   }
   if (cfn->ptr.f) {
     ffi_call(&cfn->cif, cfn->ptr.f, result, arg_values);