c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Ability to pass to $exec over stdin

Open DrSloth opened this issue 1 year ago • 12 comments

Currently all parameters to $exec are passed as command line args. Command line arguments have a lot of trickiness around shell escaping etc. The ability to also pass values over stdin to $exec would simplify this and would allow to pass binary data. The data passed over stdin and as args can also be used for different things e.g. type information over stdin and the names of resulting types as args.

DrSloth avatar Aug 07 '24 12:08 DrSloth

would love to work on this issue, and as I'm new to this repo, would love to know if their are any in-depth docs, might take little time to walkthrough projectt

Himasnhu-AT avatar Aug 07 '24 15:08 Himasnhu-AT

Nothing in-depth. Style guide and then roughly the code is: sema*.c - semantic checking llvm_codegen*.c - codegen parse*.c parsing

$exec happens during semantic checking.

Things happen in order, so roughly main -> compiler.c -> parsing -> semantic checking -> codegen -> compiler.c -> end

If one wants to look at this, then it's really only the semantic check and parsing, as it is completely folded in the semantic stage.

lerno avatar Aug 08 '24 10:08 lerno

@Himasnhu-AT are you looking at this, otherwise I'll probably fix it.

lerno avatar Aug 11 '24 17:08 lerno

If you wish you can go ahead. As I'll take some more time to got through repo

Himasnhu-AT avatar Aug 11 '24 17:08 Himasnhu-AT

There is one unsolved question though, and that is how to fit this nicely into the current syntax. So currently, $exec is $exec(<script name>, <arg1>, <arg2>, ...). There is no clear way define what is going to go into stdin.

While we can imagine $exec("foo.c3", 23, "hello", .stdin = "okfeokfekf"), it violates the behaviour of other compile time functions, as they never use named parameters.

However, we have the option to parse $exec in a completely unique way, so for example $exec("foo.c3", "arg1" : "to_stdin"); is possible or even something like $exec("foo.c3", "arg1", < "to_stdin"); or $exec("foo.c3", "arg1") < "to_stdin"; although it's a bit gross.

We can also consider attributes: $exec("foo.c3", "arg1") @stdin("to_stdin") or $exec("foo.c3", "arg1", "to_stdin" @stdin)

None of these alternatives are super attractive though, so I am open to suggestions.

lerno avatar Aug 12 '24 21:08 lerno

There is now $exec("foo", { "arg1", "arg2" }, "stdin data"), try it out and if it works well – close this.

lerno avatar Aug 15 '24 07:08 lerno

Okay ill do it. Currently went through project. Will see if their a better way we can implement this functionality

Himasnhu-AT avatar Aug 16 '24 05:08 Himasnhu-AT

I wanted to avoid fork, which would be the "correct" way to setting up two-way pipes. Putting it in a file could use a temp file instead though.

lerno avatar Aug 16 '24 06:08 lerno

We can do it these ways:

  • Using special delimiter: $exec("foo.c3", "arg1", "arg2" | "to_stdin")
  • Named Parameter convention: $exec("foo.c3", "arg1", "arg2", .stdin = "to_stdin")
  • Using attributes: $exec("foo.c3", "arg1", "arg2") @stdin("to_stdin")
  • Different function: $exec_with_stdin("foo.c3", "arg1", "arg2", "to_stdin")
  • inline stdin specification: $exec("foo.c3", "arg1", "arg2" < "to_stdin")

Himasnhu-AT avatar Aug 20 '24 19:08 Himasnhu-AT

I've implemented it with $exec("foo.c3", { "arg1", "arg2" }, "to_stdin") already, it seems good enough.

lerno avatar Aug 20 '24 19:08 lerno

okay

Himasnhu-AT avatar Aug 20 '24 20:08 Himasnhu-AT

@DrSloth is the feature completed as expected?

lerno avatar Aug 21 '24 20:08 lerno

I'm going to close this because I think it was finished.

lerno avatar Sep 14 '24 14:09 lerno