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:
1 parent
ef305e7824
commit
c319a0986d
10 files changed
+687
-1
No files matched your search
@@ -106,6 +106,15 @@ out=`$BIN tests/std.cat`
|
||||
check "std-math" "math double: 42" "`echo "$out" | sed -n 1p`"
|
||||
check "std-io" "io join: a-b-c" "`echo "$out" | sed -n 4p`"
|
||||
check "std-fs" "fs copy: true" "`echo "$out" | sed -n 6p`"
|
||||
|
||||
# ---- ffi: call native code (ctypes/CDLL-like) -----------------------
|
||||
|
||||
out=`$BIN examples/ffi.cat`
|
||||
check "ffi-pow" "pow(2,10) = 1024" "`echo "$out" | sed -n 1p`"
|
||||
check "ffi-sqrt" "sqrt(144) = 12" "`echo "$out" | sed -n 2p`"
|
||||
check "ffi-getpid" "getpid > 0: true" "`echo "$out" | sed -n 3p`"
|
||||
check "ffi-strlen" "strlen: 9" "`echo "$out" | sed -n 4p`"
|
||||
check "ffi-abs" "abs(-42) = 42" "`echo "$out" | sed -n 5p`"
|
||||
# ---- bytecode dump ---------------------------------------------------
|
||||
|
||||
out=`$BIN --dump examples/hello.cat`
|
||||
|
||||
Reference in new issue
Block a user