diff --git a/README.md b/README.md index d258deb..7c30e73 100644 --- a/README.md +++ b/README.md @@ -71,12 +71,13 @@ Options are optionally set in `options`, which is a semicolon-delimited list of For JavaScript: - `harmony` enables harmony features (`--harmony` on node) +- `e` prints the result of evaluating the code For Python: - `2` runs Python 2 instead of Python 3 For Haskell: -- None +- `e` evaluates a single expression instead of a module For Pascal: - None diff --git a/docker/haskell/run.sh b/docker/haskell/run.sh index 09cec34..911cf4e 100644 --- a/docker/haskell/run.sh +++ b/docker/haskell/run.sh @@ -1,2 +1,6 @@ -echo "$1" > program.hs -ghc -O0 -j +RTS -A128m -n2m -RTS program.hs >/dev/null && ./program +if [ "$EVAL_EXPR" = "true" ]; then + ghc -e "$1" +else + echo "$1" > program.hs + ghc -O0 -j +RTS -A128m -n2m -RTS program.hs >/dev/null && ./program +fi diff --git a/docker/javascript/run.sh b/docker/javascript/run.sh index f1f0a24..ff35f13 100644 --- a/docker/javascript/run.sh +++ b/docker/javascript/run.sh @@ -1,5 +1,11 @@ -if [ "$EVAL_HARMONY" = "true" ]; then - node --harmony -e "$1" +if [ "$EVAL_EXPR" = "true" ]; then + flag="-p" else - node -e "$1" + flag="-e" +fi + +if [ "$EVAL_HARMONY" = "true" ]; then + node --harmony "$flag" "$1" +else + node "$flag" "$1" fi diff --git a/src/languages/haskell.js b/src/languages/haskell.js index 033a37d..d886fdb 100644 --- a/src/languages/haskell.js +++ b/src/languages/haskell.js @@ -4,9 +4,20 @@ class Haskell extends Language { constructor() { super('haskell', { highlight: 'hs', - aliases: ['haskell', 'hs'] + aliases: ['haskell', 'hs'], + options: { + e: () => '' + } }); } + + runWith(options) { + if (options.has('e')) { + return { id: this.id, env: { EVAL_EXPR: 'true' } }; + } + + return super.runWith(options); + } } module.exports = Haskell; diff --git a/src/languages/javascript.js b/src/languages/javascript.js index 8444cdf..7fbb032 100644 --- a/src/languages/javascript.js +++ b/src/languages/javascript.js @@ -6,17 +6,23 @@ class JavaScript extends Language { highlight: 'js', aliases: ['javascript', 'js'], options: { - harmony: () => '' + harmony: () => '', + e: () => '' } }); } runWith(options) { + const ret = { id: this.id, env: {} }; if (options.has('harmony')) { - return { id: this.id, env: { EVAL_HARMONY: 'true' } }; + ret.env.EVAL_HARMONY = 'true'; } - return { id: this.id, env: {} }; + if (options.has('e')) { + ret.env.EVAL_EXPR = 'true'; + } + + return ret; } }