summaryrefslogtreecommitdiff
path: root/ocaml/lib/cue_ffi.c
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-06 10:30:19 +0700
committerpolwex <polwex@sortug.com>2025-10-06 10:30:19 +0700
commit4be1d7f999ffb3eb1c12c54e863b141af21b3fbf (patch)
tree6e33b141cd98985799e02a253dddcf201fec6b74 /ocaml/lib/cue_ffi.c
parentc3545b7ba9e8448226417fab6edaa2d039c9babe (diff)
some progress but man
Diffstat (limited to 'ocaml/lib/cue_ffi.c')
-rw-r--r--ocaml/lib/cue_ffi.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/ocaml/lib/cue_ffi.c b/ocaml/lib/cue_ffi.c
new file mode 100644
index 0000000..9b70547
--- /dev/null
+++ b/ocaml/lib/cue_ffi.c
@@ -0,0 +1,57 @@
+/* C bindings for fast cue using C Vere's implementation
+ *
+ * This provides OCaml with access to C Vere's optimized cue
+ */
+
+#include <caml/mlvalues.h>
+#include <caml/memory.h>
+#include <caml/alloc.h>
+#include <caml/custom.h>
+#include <caml/fail.h>
+
+#include "../../vere/pkg/noun/noun.h"
+#include "../../vere/pkg/ur/ur.h"
+
+/* Convert C Vere noun to OCaml noun
+ * This is a placeholder - actual implementation would need
+ * to traverse the C noun tree and build OCaml representation
+ */
+static value c_noun_to_ocaml(u3_noun noun) {
+ // TODO: Implement proper conversion
+ // For now, return unit
+ return Val_unit;
+}
+
+/* OCaml entry point: cue_bytes : bytes -> noun */
+CAMLprim value
+caml_cue_bytes(value bytes_v)
+{
+ CAMLparam1(bytes_v);
+ CAMLlocal1(result);
+
+ /* Get bytes data */
+ c3_d len_d = caml_string_length(bytes_v);
+ c3_y* byt_y = (c3_y*)Bytes_val(bytes_v);
+
+ /* Initialize if needed */
+ static int initialized = 0;
+ if (!initialized) {
+ u3C.wag_w |= u3o_hashless;
+ u3m_boot_lite(1 << 26); // 64 MB loom
+ initialized = 1;
+ }
+
+ /* Cue the bytes */
+ u3_cue_xeno* sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28);
+ u3_weak pil = u3s_cue_xeno_with(sil_u, len_d, byt_y);
+ u3s_cue_xeno_done(sil_u);
+
+ if (u3_none == pil) {
+ caml_failwith("cue failed");
+ }
+
+ /* Convert C noun to OCaml noun */
+ result = c_noun_to_ocaml(pil);
+
+ CAMLreturn(result);
+}