Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chez shebang: use "scheme-script" instead of "scheme --script" #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Compiler/Scheme/Chez.idr
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ firstExists : List String -> IO (Maybe String)
firstExists [] = pure Nothing
firstExists (x :: xs) = if !(exists x) then pure (Just x) else firstExists xs

findChez : IO String
findChez
findBin : String -> List String -> IO String
findBin name altNames
= do e <- firstExists [p ++ x | p <- ["/usr/bin/", "/usr/local/bin/"],
x <- ["scheme", "chez", "chezscheme9.5"]]
maybe (pure "/usr/bin/env scheme") pure e
x <- (name :: altNames)]
maybe (pure ("/usr/bin/env " ++ name)) pure e

findChez : IO String
findChez = findBin "scheme" ["chez", "chezscheme9.5"]

findChezScript : IO String
findChezScript = findBin "scheme-script" []

findLibs : List String -> List String
findLibs = mapMaybe (isLib . trim)
Expand All @@ -46,8 +52,8 @@ escapeQuotes s = pack $ foldr escape [] $ unpack s
escape c cs = c :: cs

schHeader : String -> List String -> String
schHeader chez libs
= "#!" ++ chez ++ " --script\n\n" ++
schHeader chezScript libs
= "#!" ++ chezScript ++ "\n\n" ++
"(import (chezscheme))\n" ++
"(case (machine-type)\n" ++
" [(i3le ti3le a6le ta6le) (load-shared-object \"libc.so.6\")]\n" ++
Expand Down Expand Up @@ -107,7 +113,7 @@ compileToSS c tm outfile
compdefs <- traverse (getScheme chezExtPrim defs) ns
let code = concat compdefs
main <- schExp chezExtPrim 0 [] !(compileExp tags tm)
chez <- coreLift findChez
chez <- coreLift findChezScript
support <- readDataFile "chez/support.ss"
let scm = schHeader chez libs ++ support ++ code ++ main ++ schFooter
Right () <- coreLift $ writeFile outfile scm
Expand Down
9 changes: 4 additions & 5 deletions tests/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import System
%default covering

ttimpTests : List String
ttimpTests
ttimpTests
= ["test001", "test002", "test003", "test004", "test005",
"test006", "test007", "test008", "test009",
"case001",
Expand All @@ -21,7 +21,7 @@ blodwenTests
"test021", "test022", "test023", "test024", "test025",
"test026", "test027", "test028", "test029", "test030",
"chez001", "chez002", "chez003", "chez004", "chez005",
"chez006",
"chez006", "chez007",
"chicken001", "chicken002",
"error001", "error002", "error003", "error004", "error005",
"error006",
Expand All @@ -47,12 +47,12 @@ blodwenTests
"with001"]

chdir : String -> IO Bool
chdir dir
chdir dir
= do ok <- foreign FFI_C "chdir" (String -> IO Int) dir
pure (ok == 0)

fail : String -> IO ()
fail err
fail err
= do putStrLn err
exitWith (ExitFailure 1)

Expand Down Expand Up @@ -82,4 +82,3 @@ main
if (any not (ttimps ++ blods))
then exitWith (ExitFailure 1)
else exitWith ExitSuccess

6 changes: 6 additions & 0 deletions tests/blodwen/chez007/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hello blodwen devs
1/1: Building hello (hello.blod)
Welcome to Blodwen. Good luck.
Main> Main> hello written
Main> Bye for now!
hello blodwen devs
2 changes: 2 additions & 0 deletions tests/blodwen/chez007/hello.blod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main : IO ()
main = putStrLn "hello blodwen devs"
3 changes: 3 additions & 0 deletions tests/blodwen/chez007/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:exec main
:c hello main
:q
4 changes: 4 additions & 0 deletions tests/blodwen/chez007/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$1 hello.blod < input
./hello.ss
rm -rf build hello.ss