summaryrefslogtreecommitdiff
path: root/Biz/Ide/repl
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-07-29 03:29:37 -0400
committerBen Sima <ben@bsima.me>2022-07-29 10:50:06 -0400
commit347c5d878d064685f4c27f36f38ef20f67996417 (patch)
tree614ca23c4431f2a87823cd2c69248b7bbb74f310 /Biz/Ide/repl
parentc39c7eb0fa82cececf286b48d5215f8f892c4d41 (diff)
Refactor repl
- added --bash in case you just really want a shell - added support for C programs
Diffstat (limited to 'Biz/Ide/repl')
-rwxr-xr-xBiz/Ide/repl48
1 files changed, 27 insertions, 21 deletions
diff --git a/Biz/Ide/repl b/Biz/Ide/repl
index 7101add..4c77e5b 100755
--- a/Biz/Ide/repl
+++ b/Biz/Ide/repl
@@ -2,12 +2,14 @@
###
### a simple complement to bild which only deals with launching repls
###
-### > repl <target..>
+### > repl [opts] <target..>
###
### Starts a repl/shell for one or more targets. (Currently, all targets must
-### have the same extension for this to work.)
+### have the same extension for this to work.) Repls started with this script
+### should bind to `localhost:$PORT`.
###
-### Repls started with this script should bind to `localhost:$PORT`.
+### Options:
+### --bash start bash instead of the target language repl
help() {
sed -rn 's/^### ?//;T;p' "$0"
}
@@ -17,44 +19,46 @@ if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then
fi
##
set -e
+ CMD=
+ if [[ "$1" == "--bash" ]]; then
+ CMD="bash"
+ shift
+ fi
targets=${@:?}
json=$(bild --json ${targets[@]})
langdeps=$(jq --raw-output '.langdeps | join(" ")' <<< $json)
sysdeps=$(jq --raw-output '.sysdeps | join(" ")' <<< $json)
exts=$(jq --raw-output '.namespace.ext' <<< $json | sort | uniq)
- flags=()
+ BILD="(import $BIZ_ROOT/Biz/Bild.nix {})"
for lib in ${sysdeps[@]}; do
- flags+=(--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.${lib}")
+ flags+=(--packages "$BILD.private.nixpkgs.${lib}")
done
case $exts in
+ C)
+ flags+=(--packages "$BILD.private.nixpkgs.gcc")
+ command="bash"
+ ;;
Hs)
if [ -z ${var+PORT} ]; then
echo "warn: repl: ghci does not support binding to a port"
fi
- nix-shell \
- "${flags[@]}" \
- --packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.ghcWith (h: with h; [$langdeps])" \
- --command "ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci ${targets[@]}"
+ flags+=(--packages "$BILD.private.ghcWith (h: with h; [$langdeps])")
+ command=${CMD:-"ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci ${targets[@]}"}
;;
Scm)
for lib in ${langdeps[@]}; do
- flags+=(--packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.guile-${lib}")
+ flags+=(--packages "$BILD.private.nixpkgs.guile-${lib}")
done
- nix-shell \
- "${flags[@]}" \
- --packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.guile_3_0" \
- --command "guile -L $BIZ_ROOT -C $BIZ_ROOT/_/int --r7rs --listen=${PORT:-37146}"
+ flags+=(--packages "$BILD.private.nixpkgs.guile_3_0")
+ command=${CMD:-"guile -L $BIZ_ROOT -C $BIZ_ROOT/_/int --r7rs --listen=${PORT:-37146}"}
;;
Lisp)
- nix-shell \
- "${flags[@]}" \
- --packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.sbclWith (p: with p; [asdf swank $langdeps])" \
- --command "sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"
+ flags+=(--packages "$BILD.private.sbclWith (p: with p; [asdf swank $langdeps])")
+ command=${CMD:-"sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"}
;;
Rs)
- nix-shell \
- "${flags[@]}" \
- --packages "(import $BIZ_ROOT/Biz/Bild.nix {}).private.nixpkgs.rustc"
+ flags+=(--packages "$BILD.private.nixpkgs.rustc")
+ command=bash
;;
*)
echo "unsupported targets: ${targets[@]}"
@@ -62,3 +66,5 @@ fi
;;
esac
##
+ nix-shell "${flags[@]}" --command "$command"
+##