Commit 69671c6df26379fcd238a0af11163e878f677378

Thomas de Grivel 2024-07-25T17:19:03

wip http request and Buf

diff --git a/lib/kc3/0.1/buf.kc3 b/lib/kc3/0.1/buf.kc3
index 0f6dc02..f83d453 100644
--- a/lib/kc3/0.1/buf.kc3
+++ b/lib/kc3/0.1/buf.kc3
@@ -13,4 +13,10 @@ defmodule Buf do
              user_ptr: (Ptr) 0,
              wpos: (Uw) 0]
 
+  def init_alloc = cfn Buf "buf_init_alloc" (Result, Uw)
+
+  def inspect = cfn Sw "buf_inspect_tag" (Buf, Tag)
+
+  def parse_tag = cfn Tag "kc3_buf_parse_tag" (Buf, Result)
+
 end
diff --git a/lib/kc3/0.1/http/request.kc3 b/lib/kc3/0.1/http/request.kc3
new file mode 100644
index 0000000..c3afe1c
--- /dev/null
+++ b/lib/kc3/0.1/http/request.kc3
@@ -0,0 +1,8 @@
+defmodule HTTP.Request do
+
+  defstruct [action: :get,
+             url: "/",
+             protocol: "HTTP/1.1",
+             headers: []]
+
+end
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 7fd41dd..a8beb90 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -16,6 +16,7 @@
 #include <stdlib.h>
 #include "bool.h"
 #include "buf.h"
+#include "buf_parse.h"
 #include "kc3_main.h"
 #include "env.h"
 #include "map.h"
@@ -63,6 +64,15 @@ void kc3_break (void)
   abort();
 }
 
+s_tag * kc3_buf_parse_tag (s_buf *buf, s_tag *dest)
+{
+  sw r;
+  r = buf_parse_tag(buf, dest);
+  if (r <= 0)
+    return NULL;
+  return dest;
+}
+
 void kc3_clean (s_env *env)
 {
   if (! env)
diff --git a/libkc3/kc3_main.h b/libkc3/kc3_main.h
index c6f8a32..d770d2a 100644
--- a/libkc3/kc3_main.h
+++ b/libkc3/kc3_main.h
@@ -39,6 +39,7 @@ sw             kc3_puts (const s_tag *tag);
 /* Operators. */
 s_tag * kc3_access (const s_tag *tag, const s_sym * const *sym,
                     s_tag *dest);
+s_tag * kc3_buf_parse_tag (s_buf *buf, s_tag *dest);
 s_tag * kc3_def (const s_call *call, s_tag *dest);
 s_tag * kc3_defmodule (const s_sym **name, const s_block *block,
                        s_tag *dest);
diff --git a/libkc3/tag.c b/libkc3/tag.c
index 33416cd..ce9025f 100644
--- a/libkc3/tag.c
+++ b/libkc3/tag.c
@@ -923,12 +923,6 @@ bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest)
     return true;
   }
   switch (tag->type) {
-  case TAG_VOID:
-    if (type == &g_sym_Void) {
-      *dest = NULL;
-      return true;
-    }
-    goto invalid_cast;
   case TAG_ARRAY:
     if (type == &g_sym_Array) {
       *dest = tag->data.array.data;
@@ -1182,6 +1176,12 @@ bool tag_to_ffi_pointer (s_tag *tag, const s_sym *type, void **dest)
       return true;
     }
     goto invalid_cast;
+  case TAG_VOID:
+    if (type == &g_sym_Void) {
+      *dest = NULL;
+      return true;
+    }
+    goto invalid_cast;
   }
   err_puts("tag_to_ffi_pointer: invalid tag type");
   assert(! "tag_to_ffi_pointer: invalid tag type");