effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
315 stars 19 forks source link

commandLineArgs() passing doesnt work for chez backend executables #390

Closed IR0NSIGHT closed 3 months ago

IR0NSIGHT commented 7 months ago
# javascript backend (default)
max-priv@NOAH367-L:~/Dokumente/repos/fasteffekt$ effekt.sh -b ./chez-lift-runner.effekt && ./out/chez_lift_runner hello world i am args
Cons(hello, Cons(world, Cons(i, Cons(am, Cons(args, Nil())))))

# chez lift backend
max-priv@NOAH367-L:~/Dokumente/repos/fasteffekt$ effekt.sh -b ./chez-lift-runner.effekt --backend chez-lift && ./out/chez_lift_runner hello world i am args
Nil()

# chez-callcc
max-priv@NOAH367-L:~/Dokumente/repos/fasteffekt$ effekt.sh -b ./chez-lift-runner.effekt --backend chez-callcc && ./out/chez_lift_runner hello world i am args
Nil()

# chez-monadic
max-priv@NOAH367-L:~/Dokumente/repos/fasteffekt$ effekt.sh -b ./chez-lift-runner.effekt --backend chez-monadic && ./out/chez_lift_runner hello world i am args
Nil()

ran after pulling latest master:

commit d8a1fba426511663c97386eedc00b244744fa6e4 (HEAD -> master, origin/master, origin/HEAD)
Merge: ea9a6c64 20dd400a
Author: Jonathan Immanuel Brachthäuser <jonathan@b-studios.de>
Date:   Mon Feb 5 18:16:27 2024 +0100

minimal effekt implementation:

import io/args

def main(): Unit = {
    println(commandLineArgs())
}

note 1: issue can be fixed by changing the executable bash script to pass the arguments, tested only on chez-lift:

#!/bin/bash
scheme --script /home/max-priv/Dokumente/repos/fasteffekt/./out/chez_lift_runner.ss "$@"

-----------------------------------------------------------------

max-priv@NOAH367-L:~/Dokumente/repos/fasteffekt$ ./out/chez_lift_runner i am args
Cons(i, Cons(am, Cons(args, Nil())))

note: llvm and ml backends dont even compile because they cant typecheck println(commandLineArgs()) will make separate issues there.

jiribenes commented 3 months ago

Current state after stdlib changes #449:

# build for each backend, then run `./out/test hello world 42` 
$ for BACKEND in js chez-callcc chez-monadic chez-lift llvm ml; do effekt --backend $BACKEND --build test.effekt && echo -n "$BACKEND: " && ./out/test hello world 42; done

js: Cons(world, Cons(42, Nil()))
chez-callcc: Nil()
chez-monadic: Nil()
chez-lift: Nil()
llvm: Cons(hello, Cons(world, Cons(42, Nil())))
ml: Cons(hello, Cons(world, Cons(42, Nil())))

If we apply the following patch that performs the "$@" fix mentioned above:

diff --git i/effekt/jvm/src/main/scala/effekt/Runner.scala w/effekt/jvm/src/main/scala/effekt/Runner.scala
index c69f169b..d021557d 100644
--- i/effekt/jvm/src/main/scala/effekt/Runner.scala
+++ w/effekt/jvm/src/main/scala/effekt/Runner.scala
@@ -153,7 +153,7 @@ trait ChezRunner extends Runner[String] {
     val out = C.config.outputPath().getAbsolutePath
     val schemeFilePath = (out / path).unixPath
     val bashScriptPath = schemeFilePath.stripSuffix(s".$extension")
-    val bashScript = s"#!/bin/bash\nscheme --script $schemeFilePath"
+    val bashScript = s"#!/bin/bash\nscheme --script $schemeFilePath \"$$@\""
     IO.createFile(bashScriptPath, bashScript, true)
     bashScriptPath
 }

we get that chez-* now corresponds to llvm & ml:

js: Cons(world, Cons(42, Nil()))
chez-callcc: Cons(hello, Cons(world, Cons(42, Nil())))
chez-monadic: Cons(hello, Cons(world, Cons(42, Nil())))
chez-lift: Cons(hello, Cons(world, Cons(42, Nil())))
llvm: Cons(hello, Cons(world, Cons(42, Nil())))
ml: Cons(hello, Cons(world, Cons(42, Nil())))
jiribenes commented 3 months ago

https://github.com/effekt-lang/effekt/issues/318 Here is a related issue -- the same issue, but with the JS backend.

jiribenes commented 3 months ago

As of merging #487, this is the current state with the patch above:

js: Cons(world, Cons(42, Nil()))
chez-callcc: Cons(hello, Cons(world, Cons(42, Nil())))
chez-monadic: Cons(hello, Cons(world, Cons(42, Nil())))
chez-lift: Cons(hello, Cons(world, Cons(42, Nil())))
llvm: Cons(hello, Cons(world, Cons(42, Nil())))
ml: Cons(hello, Cons(world, Cons(42, Nil())))

for both:

  1. first --build and then ./run [same as above]:
    for BACKEND in js chez-callcc chez-monadic chez-lift llvm ml; do effekt --backend $BACKEND --build test.effekt && echo -n "$BACKEND: " && ./out/test hello world 42; done
  2. running immediately (effekt test.effekt -- hello world 42)
    for BACKEND in js chez-callcc chez-monadic chez-lift llvm ml; do echo -n "$BACKEND: " && effekt --backend $BACKEND test.effekt -- hello world 42; done

So if these two are the only ways of building & running, then we can just update: https://github.com/effekt-lang/effekt/blob/cd741e8a4576c62ab318efd48fc0831958ba7e8d/libraries/common/args.effekt#L12 and that should be enough.

b-studios commented 3 months ago

My first reaction was: "but what if I run the compiled effekt program from node directly?". But then, why should I do this?

There is two kinds of software:

  1. applications with a main (and arguably, it should be good enough to run them like you do)
  2. libraries (that will be linked with other "native" -- that is js -- libaries)

Right now we do not support case 2 very well anyways, so...