mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-09-19 04:57:24 +03:00
Implement shebang handling
Add two scripts for running idris programs with the C and node backends and adds a test. Fixes #2247
This commit is contained in:
parent
cc45cddc86
commit
fbc01c4d4c
18
scripts/runidris
Normal file
18
scripts/runidris
Normal file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is a script that runs an idris program, suitable for use
|
||||
# in a shebang line. We cache the executables by naming them after
|
||||
# the SHA hash of the idris source and looking for it before
|
||||
# compiling
|
||||
RUNIDRIS_DIR="${TEMP:-/tmp}/runidris"
|
||||
if [ ! -d $RUNIDRIS_DIR ]; then
|
||||
mkdir $RUNIDRIS_DIR
|
||||
chmod 700 $RUNIDRIS_DIR
|
||||
fi
|
||||
TEMP_NAME="runidris-`sha1sum $1 | cut -c1-40`"
|
||||
FP="$RUNIDRIS_DIR/$TEMP_NAME"
|
||||
if [ ! -e $FP ]; then
|
||||
"${IDRIS:-idris}" $1 --ibcsubdir "$RUNIDRIS_DIR" -i "." -o $FP
|
||||
fi
|
||||
shift
|
||||
"$FP" "$@"
|
18
scripts/runidris-node
Normal file
18
scripts/runidris-node
Normal file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is a script that runs an idris program, suitable for use
|
||||
# in a shebang line. We cache the executables by naming them after
|
||||
# the SHA hash of the idris source and looking for it before
|
||||
# compiling. This is the node version.
|
||||
RUNIDRIS_DIR="${TEMP:-/tmp}/runidris-node"
|
||||
if [ ! -d $RUNIDRIS_DIR ]; then
|
||||
mkdir $RUNIDRIS_DIR
|
||||
chmod 700 $RUNIDRIS_DIR
|
||||
fi
|
||||
TEMP_NAME="runidris-`sha1sum $1 | cut -c1-40`.js"
|
||||
FP="$RUNIDRIS_DIR/$TEMP_NAME"
|
||||
if [ ! -e $FP ]; then
|
||||
"${IDRIS:-idris}" --codegen node --ibcsubdir "$RUNIDRIS_DIR" -i "." $1 -o $FP
|
||||
fi
|
||||
shift
|
||||
node "$FP" "$@"
|
@ -1569,7 +1569,8 @@ parseImports fname input
|
||||
[ImportInfo],
|
||||
Maybe Delta),
|
||||
[(FC, OutputAnnotation)], IState)
|
||||
imports = do whiteSpace
|
||||
imports = do optional shebang
|
||||
whiteSpace
|
||||
(mdoc, mname, annots) <- moduleHeader
|
||||
ps_exp <- many import_
|
||||
mrk <- mark
|
||||
@ -1594,6 +1595,9 @@ parseImports fname input
|
||||
(fc, AnnNamespace ns (Just path)) : addPath annots path
|
||||
addPath (annot:annots) path = annot : addPath annots path
|
||||
|
||||
shebang :: IdrisParser ()
|
||||
shebang = string "#!" *> many (satisfy $ not . isEol) *> eol *> pure ()
|
||||
|
||||
-- | There should be a better way of doing this...
|
||||
findFC :: Doc -> (FC, String)
|
||||
findFC x = let s = show (plain x) in findFC' s
|
||||
|
5
test/interactive017/TestMod.idr
Normal file
5
test/interactive017/TestMod.idr
Normal file
@ -0,0 +1,5 @@
|
||||
module TestMod
|
||||
|
||||
export
|
||||
test : IO ()
|
||||
test = putStrLn "Hello from a module"
|
7
test/interactive017/expected
Normal file
7
test/interactive017/expected
Normal file
@ -0,0 +1,7 @@
|
||||
hello from C
|
||||
hello from C
|
||||
hello from node
|
||||
hello from node
|
||||
Hello ["aaa"]
|
||||
Hello ["bbb", "aaa"]
|
||||
Hello from a module
|
9
test/interactive017/run
Normal file
9
test/interactive017/run
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
PATH="../../scripts:$PATH"
|
||||
./shebang.idr
|
||||
./shebang.idr
|
||||
./shebang-node.idr
|
||||
./shebang-node.idr
|
||||
./shebang-args.idr aaa
|
||||
./shebang-args.idr bbb aaa
|
||||
./shebang-import.idr
|
6
test/interactive017/shebang-args.idr
Normal file
6
test/interactive017/shebang-args.idr
Normal file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env runidris
|
||||
|
||||
main : IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
putStrLn $ "Hello " ++ (show $ drop 1 args)
|
6
test/interactive017/shebang-import.idr
Normal file
6
test/interactive017/shebang-import.idr
Normal file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env runidris
|
||||
|
||||
import TestMod
|
||||
|
||||
main : IO ()
|
||||
main = TestMod.test
|
4
test/interactive017/shebang-node.idr
Normal file
4
test/interactive017/shebang-node.idr
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env runidris-node
|
||||
|
||||
main : IO ()
|
||||
main = putStrLn "hello from node"
|
4
test/interactive017/shebang.idr
Normal file
4
test/interactive017/shebang.idr
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env runidris
|
||||
|
||||
main : IO ()
|
||||
main = putStrLn "hello from C"
|
Loading…
Reference in New Issue
Block a user