2
3
Fork
You've already forked foreign-c
1
(foreign c) is a C foreign function interface (FFI) library for R6RS and R7RS Schemes. It is portable in the sense that it supports multiple implementations.
  • Scheme 50.2%
  • C 43.3%
  • Tree-sitter Query 5.8%
  • Makefile 0.7%
2026年07月07日 06:59:27 +03:00
foreign Test sagittarius on latest 2026年07月04日 15:40:46 +03:00
tests Add bit more tests 2026年07月03日 16:04:04 +03:00
.gitignore feat: add kons manifest file 2026年06月20日 22:13:39 +07:00
COPYING Add license 2025年07月20日 06:33:58 +03:00
Dockerfile.jenkins Fixing Jenkins tests 2026年07月04日 10:57:02 +03:00
Jenkinsfile Improve Jenkins test 2026年07月04日 17:22:18 +03:00
kons.scm Gauche improvements 2026年07月02日 15:23:06 +03:00
LICENSE Fix tests, add pffi-os-name 2024年07月31日 21:14:38 +03:00
Makefile Move most docker tests onto latest tag 2026年07月04日 15:48:00 +03:00
README.md Add Jenkins link to readme 2026年07月07日 06:59:27 +03:00
REFERENCE.md Gauche improvements 2026年07月02日 14:16:15 +03:00

(foreign c) is a C foreign function interface (FFI) library for R6RS and R7RS Schemes

Documentation

See REFERENCE.md

Tests

Jenkins

Supported implementations

R6RS is supported trough akku and akku-r7rs.

  • Chez => 10.0.0
    • R6RS
  • Chibi > 0.11
    • R7RS
  • Chicken >= 6.0.0
    • R7RS
  • Ikarus >= 0.0.4-rc1+
    • R6RS
  • Ironscheme
    • R6RS
  • Kawa >= 3.11 and Java >= 24
    • R7RS
    • Needs arguments to enable FFI
      • -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED
      • -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED
      • -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED
      • -J--enable-native-access=ALL-UNNAMED
    • All needed arguments on one line for copy pasting
      • -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED -J--enable-native-access=ALL-UNNAMED
    • So that snow-chibi installed library is found
      • -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld
  • Mosh
    • R7RS
  • Racket >= 8.16 [cs]
    • R7RS
  • Sagittarius >= 0.9.13
    • R6RS
    • R7RS
  • STklos >= 26.0
    • R7RS
  • Ypsilon >= 2.08
    • R7RS

Work in progress

  • Capyscheme
    • R6RS
    • R7RS
  • Cyclone
    • R7RS
  • Gambit
    • R7RS
  • Gauche
    • R7RS
  • Gerbil
    • R7RS
  • Guile
    • R6RS
    • R7RS
  • Mit-Scheme
    • R7RS
  • Mosh
    • R6RS
  • Racket
    • R6RS
      • Unable to run tests as it cant find SRFI-64
  • Larceny
    • R6RS
    • R7RS
  • Ypsilon
    • R6RS
      • Problems with akku-r7rs

Native dependencies

  • Chibi
    • libffi

Installation

R6RS - Akku

In your project directory run:

akku install "(foreign c)"

R6RS - Manual

Download the latest release or clone from git and copy directory named
"foreign" into your project, then run:
 akku install

R7RS - Snow-fort

https://snow-fort.org/

snow-chibi --impls=IMPLEMENTATION install "(foreign c)"

R7RS installing manually

Manual system wide installation requires snow-chibi.

Either download the latest release from https://git.sr.ht/~retropikzel/foreign-c/refs or git clone, tag, and copy the foreign directory to your library directory.

Example for how to install for Gauche:

apt-get install libffi-dev
git clone https://git.sr.ht/~retropikzel/foreign-c
cd foreign-c
make SCHEME=gauche
make SCHEME=gauche install

Adding support for new implementation

  • Make the library files foreign/c/YOURSCHEME-primitives.scm
  • Include it in cond expand in foreign/c.sld

Implementation specific code

SCHEME-primitives.scm must implement:

  • shared-object-load
  • define-c-procedure
  • c-u8-ref
  • c-u8-set!
  • c-pointer-ref
  • c-pointer-set!
  • c-null
  • c-null?

YOURSCHEME-primitives.scm optionally can implement:

  • define-c-callback

If there is no support for callbacks then this stub must be there:

(define-syntax define-c-callback
 (syntax-rules ()
 ((_ scheme-name return-type argument-types procedure)
 (define scheme-name
 (error "define-c-callback not yet supported on YOURSCHEME")))))

Run tests with:

make SCHEME=YOURSCHEME test-r6rs

or

make SCHEME=YOURSCHEME test-r6rs