From de665ce967e252fdaacc3c53b813689399a8a157 Mon Sep 17 00:00:00 2001 From: retropikzel Date: Sat, 18 May 2024 16:40:39 +0300 Subject: [PATCH] Make many implementations pass all tests, clean up repo --- Makefile | 1 + README.md | 63 +++++++++++++++++++++---- manifest.scm | 34 +++++++------ retropikzel/pffi/v0-1-0/guile.scm | 3 +- retropikzel/pffi/v0-1-0/kawa.scm | 2 +- retropikzel/pffi/v0-1-0/main.scm | 31 ------------ retropikzel/pffi/v0-1-0/main.sld | 30 ------------ retropikzel/pffi/v0-1-0/racket.rkt | 2 +- retropikzel/pffi/v0-1-0/sagittarius.scm | 2 +- 9 files changed, 81 insertions(+), 87 deletions(-) diff --git a/Makefile b/Makefile index 282a6f1..3aea63b 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ clean: rm -rf retropikzel/pffi/${VERSION}/*.o* rm -rf retropikzel/pffi/${VERSION}/*.so rm -rf retropikzel/pffi/${VERSION}/*.meta + rm -rf retropikzel/pffi/${VERSION}/retropikzel.* rm -rf retropikzel.* rm -rf test/*.c rm -rf test/*.o* diff --git a/README.md b/README.md index 08a67f2..0cc007b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ For documentation see For bugs you can use the [Bugs](https://codeberg.org/r7rs-pffi/pffi/projects/9101) -## Supports +## All tests pass - [Sagittarius](https://bitbucket.org/ktakashi/sagittarius-scheme/wiki/Home) - [Guile](https://www.gnu.org/software/guile/) @@ -14,22 +14,69 @@ For bugs you can use the - Needs atleast java 21 - Needs jvm flags - java --add-exports java.base/jdk.internal.foreign.abi=ALL-UNNAMED --add-exports java.base/jdk.internal.foreign.layout=ALL-UNNAMED --add-exports java.base/jdk.internal.foreign=ALL-UNNAMED --enable-native-access=ALL-UNNAMED --enable-preview -jar kawa.jar FILENAME.scm - -## Support is work in progress - - [Racket](https://racket-lang.org/) -- [STKlos](https://stklos.net/) -- [Cyclone](https://justinethier.github.io/cyclone/) - [Chicken](https://www.call-cc.org/) -## Support is waiting for the implementation +## Not all tests pass + +- [STKlos](https://stklos.net/) +- [Cyclone](https://justinethier.github.io/cyclone/) +- [Gambit](https://gambitscheme.org) + +## Waiting for the implementation - [LIPS](https://lips.js.org/) - Waiting for implementation to have cond-expand and library support - Will only work on nodejs +## Not supported + +- [Chibi](https://synthcode.com/scheme/chibi) + - FFI requires C code +- [MIT-Scheme](https://www.gnu.org/software/mit-scheme/) + - FF requires C code +- [tr7](https://gitlab.com/jobol/tr7) + - FFI requires C code +- [Gauche](https://practical-scheme.net/gauche/) + - FFI requires C code + ## Hacking -main.sld is the real main which is copied to other suffixes like .scm and .rkt. +main.sld is the real main which is copied to main.scm + +## Documentation + +On some implementations these are procedures, on some macros. + +### pffi-shared-object-auto-load + +Arguments: + +- object-name (symbol) + - The name of the dynamic library file you want to load without the "lib" in fron of it or .so/.dll at the end +- addition-paths (list (string)...) + - Any additional paths you want to search for the library + +Returns: + +- (object) Shared object, the type depends on the implementation + +### pffi-shared-object-load + +It is recommended to use the pffi-shared-object-auto-load instead of this +directly. + +Arguments: + + - headers (list (string) ...) Headers that need to be included + - Example (list "curl/curl.h") + - path (string) The full path to the shared object you want to load, including any "lib" infront and .so/.dll at the end + - Example "libcurl.so" + +Returns: + +- (object) Shared object, the type depends on the implementation + + diff --git a/manifest.scm b/manifest.scm index 82470ed..5582f8f 100644 --- a/manifest.scm +++ b/manifest.scm @@ -3,17 +3,23 @@ ;; that accepts a '--manifest' (or '-m') option. (specifications->manifest - (list "guile" - "racket-minimal" - "gambit-c" - "chicken" - "gerbil" - "openjdk" - "curl" - "sdl2" - "sdl2-image" - "sdl2-ttf" - "sdl2-mixer" - "ck" - "zig" - "gcc-toolchain")) + (list + ; Guile + "guile" + ; Racket + "racket-minimal" + ; Gambit + "gambit-c" + ; Chicken + "chicken" + ; Gerbil + "gerbil" + ; Cyclone + "ck" + ; Kawa + "openjdk" + ; Test libraries + "curl" + ; Compilers + "zig" + "gcc-toolchain")) diff --git a/retropikzel/pffi/v0-1-0/guile.scm b/retropikzel/pffi/v0-1-0/guile.scm index 36231b3..dace474 100644 --- a/retropikzel/pffi/v0-1-0/guile.scm +++ b/retropikzel/pffi/v0-1-0/guile.scm @@ -92,7 +92,8 @@ (define pffi-pointer-null? (lambda (pointer) - (null-pointer? pointer))) + (and (pffi-pointer? pointer) + (null-pointer? pointer)))) (define pffi-pointer-set! (lambda (pointer type offset value) diff --git a/retropikzel/pffi/v0-1-0/kawa.scm b/retropikzel/pffi/v0-1-0/kawa.scm index 99a1f0c..68462a7 100644 --- a/retropikzel/pffi/v0-1-0/kawa.scm +++ b/retropikzel/pffi/v0-1-0/kawa.scm @@ -136,7 +136,7 @@ (define pffi-pointer-free (lambda (pointer) - (invoke pointer 'unload))) + #t)) (define pffi-pointer-null? (lambda (pointer) diff --git a/retropikzel/pffi/v0-1-0/main.scm b/retropikzel/pffi/v0-1-0/main.scm index bf45eef..c67353a 100644 --- a/retropikzel/pffi/v0-1-0/main.scm +++ b/retropikzel/pffi/v0-1-0/main.scm @@ -1,6 +1,3 @@ -;> # pffi - -;> ## Procedures (define-library (retropikzel pffi v0-1-0 main) (cond-expand @@ -73,7 +70,6 @@ pffi-pointer-null pffi-string->pointer pffi-pointer->string - pffi-pointer->bytevector pffi-pointer-free pffi-pointer? pffi-pointer-null? @@ -81,13 +77,8 @@ pffi-pointer-get pffi-pointer-deref) (begin - - - (define library-version "v0-1-0") - ;> ## Procedures - (define platform-file-extension (cond-expand (racket (if (equal? (system-type 'os) 'windows) ".dll" ".so")) @@ -174,28 +165,6 @@ "/usr/lib/x86_64-linux-gnu" "/usr/local/lib")))))) - ;> ### pffi-shared-object-load - ;> - ;> Arguments: - ;> - path (string) The path to the shared object you want to load, including any "lib" infront and .so/.dll at the end - ;> - ;> Returns: - ;> - - - - - ;> ### pffi-shared-object-auto-load - ;> - ;> Arguments: - ;> - object-name (symbol) - ;> - The name of the dynamic library file you want to load without the "lib" in fron of it or .so/.dll at the end - ;> - addition-paths (list (string)...) - ;> - Any additional paths you want to search for the library - ;> - ;> Returns: - ;> - (object) Shared object, the type depends on the implementation - (define-syntax pffi-shared-object-auto-load (syntax-rules () ((pffi-shared-object-auto-load headers object-name additional-paths) diff --git a/retropikzel/pffi/v0-1-0/main.sld b/retropikzel/pffi/v0-1-0/main.sld index 2be1b6d..c67353a 100644 --- a/retropikzel/pffi/v0-1-0/main.sld +++ b/retropikzel/pffi/v0-1-0/main.sld @@ -1,6 +1,3 @@ -;> # pffi - -;> ## Procedures (define-library (retropikzel pffi v0-1-0 main) (cond-expand @@ -80,13 +77,8 @@ pffi-pointer-get pffi-pointer-deref) (begin - - - (define library-version "v0-1-0") - ;> ## Procedures - (define platform-file-extension (cond-expand (racket (if (equal? (system-type 'os) 'windows) ".dll" ".so")) @@ -173,28 +165,6 @@ "/usr/lib/x86_64-linux-gnu" "/usr/local/lib")))))) - ;> ### pffi-shared-object-load - ;> - ;> Arguments: - ;> - path (string) The path to the shared object you want to load, including any "lib" infront and .so/.dll at the end - ;> - ;> Returns: - ;> - - - - - ;> ### pffi-shared-object-auto-load - ;> - ;> Arguments: - ;> - object-name (symbol) - ;> - The name of the dynamic library file you want to load without the "lib" in fron of it or .so/.dll at the end - ;> - addition-paths (list (string)...) - ;> - Any additional paths you want to search for the library - ;> - ;> Returns: - ;> - (object) Shared object, the type depends on the implementation - (define-syntax pffi-shared-object-auto-load (syntax-rules () ((pffi-shared-object-auto-load headers object-name additional-paths) diff --git a/retropikzel/pffi/v0-1-0/racket.rkt b/retropikzel/pffi/v0-1-0/racket.rkt index 18012db..ce68c7c 100644 --- a/retropikzel/pffi/v0-1-0/racket.rkt +++ b/retropikzel/pffi/v0-1-0/racket.rkt @@ -68,7 +68,7 @@ (define pffi-pointer-allocate (lambda (size) - (malloc size))) + (malloc size 'raw))) (define pffi-pointer-null (lambda () diff --git a/retropikzel/pffi/v0-1-0/sagittarius.scm b/retropikzel/pffi/v0-1-0/sagittarius.scm index 684ca29..e20be69 100644 --- a/retropikzel/pffi/v0-1-0/sagittarius.scm +++ b/retropikzel/pffi/v0-1-0/sagittarius.scm @@ -83,7 +83,7 @@ (define pffi-pointer-allocate (lambda (size) - (allocate-pointer size))) + (c-malloc size))) (define pffi-pointer-null (lambda ()