Add a Clojure FFI so libraries can bind native code (jolt.ffi)
A jolt library can now bind its own native dependencies and expose a Clojure API over them — no jolt built-in required. This is the foundation for moving the http-client / db / adapter functionality out of the host and into real libraries. - jolt.ffi/foreign-fn (sugar: defcfn) is a compiler special form: a compile-time -typed C signature lowers to a real Chez foreign-procedure (analyzer :ffi-fn -> backend foreign-procedure), so calls are typed and marshaled, not eval'd. - host/chez/ffi.ss provides the rest under jolt.ffi: load-library, alloc/free, read/write/sizeof, ptr<->string, null/null?. Loaded after the loader snapshot so a library's (require '[jolt.ffi]) still loads the macro side. - Types: int/uint/long/ulong/int64/uint64/size_t/ssize_t/iptr/uptr/double/float/ pointer/string/void/uint8/char. Validated end to end: a pure-Clojure file binds libc (getpid/strlen/abs) and libsqlite3 (open/prepare/step/column/finalize over out-param pointers) and runs a query. Gate test test/chez/ffi-binding-test.ss (make ffi); selfhost holds.
This commit is contained in:
parent
ccf93c896a
commit
537cb360b4
8 changed files with 282 additions and 62 deletions
|
|
@ -22,8 +22,12 @@
|
|||
(load "host/chez/png.ss") ; jolt.png — a baked namespace before the snapshot
|
||||
(load "host/chez/http-client.ss") ; jolt.http-client (libcurl)
|
||||
(load "host/chez/sqlite.ss") ; jolt.sqlite + jdbc.core (libsqlite3)
|
||||
(load "host/chez/http-server.ss") ; jolt.http.server + ring-janet.adapter (BSD sockets)
|
||||
(load "host/chez/http-server.ss") ; jolt.http.server (BSD sockets)
|
||||
(load "host/chez/loader.ss")
|
||||
;; jolt.ffi host primitives (memory / library loading) load AFTER the loader's
|
||||
;; baked-ns snapshot, so a library's (require '[jolt.ffi]) still loads jolt.ffi's
|
||||
;; Clojure side (the foreign-fn / defcfn macros, src/jolt/jolt/ffi.clj).
|
||||
(load "host/chez/ffi.ss") ; jolt.ffi (FFI: a library binds native code)
|
||||
|
||||
;; jolt.main + jolt.deps live under jolt-core; keep them (and src/jolt) on the
|
||||
;; roots so the CLI's own namespaces — and any jolt.* an app pulls in — resolve.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue