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 -1
View File
@@ -17,7 +17,7 @@ CC ?= cc
CFLAGS ?= -std=c11 -Wall -Wextra -O2 -Wno-unused-parameter -D_DEFAULT_SOURCE
CPPFLAGS += -Iinclude
LDFLAGS ?=
LDLIBS ?= -lm
LDLIBS ?= -lm -lffi -ldl
BUILD := build/catscript
BIN := $(BUILD)/catscript
@@ -46,6 +46,8 @@ SRCS := \
src/cat/types/native.c \
src/cat/types/file.c \
src/cat/types/generator.c \
src/cat/types/selector.c \
src/cat/types/ffi.c \
src/cat/stdlib/stdlib.c \
src/cat/stdlib/toml.c \
src/cat/stdlib/build.c