Skip to content

Commit

Permalink
[ racket ] Add library loading (#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysangkok authored Aug 23, 2023
1 parent 115c9e0 commit 694b165
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Scheme/Racket.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ racketTests = MkTestPool "Racket backend" [] (Just Racket)
, "conditions005"
-- , "conditions006"
-- , "conditions007"
, "ffi001"
]

nodeTests : TestPool
Expand Down
8 changes: 8 additions & 0 deletions tests/racket/ffi001/RacketLib.idr
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions tests/racket/ffi001/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 is port: False
1 is port: True
2 is port: True
1 change: 1 addition & 0 deletions tests/racket/ffi001/run
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$1 --no-banner --no-color --console-width 0 --cg racket RacketLib.idr --exec main

0 comments on commit 694b165

Please sign in to comment.