[ racket ] Add library loading (#3049)

This commit is contained in:
Janus Troelsen 2023-08-23 05:04:01 -05:00 committed by GitHub
parent 115c9e0889
commit 694b1650c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 0 deletions

View File

@ -40,6 +40,12 @@
* Non-recursive top-level constants are compiled to eagerly evaluated
constants in Chez Scheme.
#### Racket
* FFI declarations can now specify which `require` to perform, i.e. which
library to load before executing the FFI.
The syntax is `scheme,racket:my-function,my-library`.
#### Node.js/Browser
* Generated JavaScript files now include a shebang when using the Node.js backend

View File

@ -280,6 +280,9 @@ useCC appdir fc ccs args ret
Just ("scheme,racket", [sfn]) =>
do let body = schemeCall fc sfn (map fst args) ret
pure ("", body)
Just ("scheme,racket", [sfn, racketlib]) =>
do let body = schemeCall fc sfn (map fst args) ret
pure (fromString $ "(require " ++ racketlib ++ ")", body)
Just ("scheme", [sfn]) =>
do let body = schemeCall fc sfn (map fst args) ret
pure ("", body)

View File

@ -339,6 +339,7 @@ racketTests = MkTestPool "Racket backend" [] (Just Racket)
, "conditions005"
-- , "conditions006"
-- , "conditions007"
, "ffi001"
]
nodeTests : TestPool

View File

@ -0,0 +1,8 @@
%foreign "scheme,racket:(lambda (x) (if (port-number? x) 1 0)),racket/tcp"
isPortNumber : Int -> Bool
main : IO ()
main = do
putStrLn $ "0 is port: " ++ show (isPortNumber 0)
putStrLn $ "1 is port: " ++ show (isPortNumber 1)
putStrLn $ "2 is port: " ++ show (isPortNumber 2)

View File

@ -0,0 +1,3 @@
0 is port: False
1 is port: True
2 is port: True

1
tests/racket/ffi001/run Normal file
View File

@ -0,0 +1 @@
$1 --no-banner --no-color --console-width 0 --cg racket RacketLib.idr --exec main