ffi: call native code (ctypes/CDLL-like) via libffi

- new ffi library: ffi.load(path) dlopen()s a shared object
- lib:func(name, sig) dlsym()s a symbol and prepares a libffi call
- signature grammar RET(ARG,...): void/bool/char/int*/uint*/long/
  float/double/string/pointers; ABI-correct call via ffi_prep_cif
- selector type scaffolding for () [] . {} dispatch (runtime wired)
- examples/ffi.cat (pow, sqrt, getpid, strlen, abs); 53/53 tests
- Makefile: -lffi -ldl
This commit is contained in:
Minus committed 2026-11-16 03:42:43 +00:00
1 parent ef305e7824
commit c319a0986d
10 files changed
+687 -1

No files matched your search

+3
View File
@@ -20,6 +20,7 @@
#include "cat/types/table.h"
#include "cat/types/native.h"
#include "cat/types/file.h"
#include "cat/types/ffi.h"
#include <stdio.h>
#include <stdlib.h>
@@ -433,5 +434,7 @@ int cat_stdlib_stdlib_install(CAT_VM_State *vm)
cat_types_native_new("StringIO", lf_stringio));
cat_vm_set_global(vm, "BytesIO",
cat_types_native_new("BytesIO", lf_bytesio));
/* the `ffi` library: call native code (ctypes/CDLL-like) */
cat_vm_set_global(vm, "ffi", cat_types_ffi_module());
return 0;
}