Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for command-line arguments #12

Closed
TobiasWrigstad opened this issue Jul 19, 2014 · 8 comments
Closed

Add support for command-line arguments #12

TobiasWrigstad opened this issue Jul 19, 2014 · 8 comments

Comments

@TobiasWrigstad
Copy link
Contributor

Currently, the PONY_MAIN case in each actor's dispatch is set up to allocate its heap and then to call MSG_Main_main. However, in this process, all command-line arguments are lost. One obstacle on the way to supporting this is our current lack of array support. As an intermediate step, I therefore suggest that we support the following scheme:

  1. PONY_MAIN passes on arity number of arguments to MSG_Main_main where arity is the the arity of MSG_Main_main from its declaration. If argc in PONY_MAIN is less than arity, the "missing arguments" will be null, 0 or false depending on type.
  2. An alternative design is to fail unless arity equals argc.
@TobiasWrigstad
Copy link
Contributor Author

As soon as we have limited support for arrays, then MSG_Main_main will of course take a single array argument.

@TobiasWrigstad
Copy link
Contributor Author

(Right now, I have to recompile if I want to change test sizes. It is making me crazy. And I don't want to use temp files and sed…)

@EliasC
Copy link
Contributor

EliasC commented Jul 19, 2014

Couldn't we just pass on argv and argc from PONY_MAIN to Main_main in the C-layer and let them be accessible through embeds?

class Main
  def main() : void
    let argc = embed int argc end in
    let first = embed string argv[0] end in
      ...

(and then of course add them as proper arguments when we have array support in encore)

@TobiasWrigstad
Copy link
Contributor Author

What do you mean "pass on"? As in we add those parameters to the Main_main function, and then you have to use C to extract them?

I guess this would solve the problem but it is way more hacky than anything I suggested. What is the rationale for doing it this way? To be able to solve it in <5 minutes?

@EliasC
Copy link
Contributor

EliasC commented Jul 19, 2014

The rationale is that doing it this way first, we will only add features that we will use when we have array support as well (the arguments have to make their way into the main functions anyway). It would also require the lowest total amount of work, since we don't need to redo or throw away any intermediate work.

Since parameter passing is something we are going to want in the language anyway, I would rather have a simple "hacky" version before implementing it properly (when we have the proper machinery).

@TobiasWrigstad
Copy link
Contributor Author

OK. I thought of my first one as very hacky too, just way less hacky. :) As long as I don't have to go crazy, I am fine.

@EliasC
Copy link
Contributor

EliasC commented Jul 30, 2014

Fixed, as of 8432b64 (although commit messages are messed up). argv and argc are available in embed statements. As soon as we have a story for arrays, the transition should be relatively painless.

@EliasC EliasC closed this as completed Jul 30, 2014
@EliasC
Copy link
Contributor

EliasC commented Jul 31, 2014

Here is a program that shows how one can go about to get the command line arguments. Note the (now common) trick to define an empty passive class to be able to type an embedded value.

passive class Array

class Main
  def main() : void
    let 
      nth = \(arr : Array, n : int) -> (embed string ((char**)arr)[n]; end)
    in
      let argc = embed int argc; end in
      let argv = embed Array argv; end in
      let i = 0 in
        while i < argc{
          printf "argv[{}] = {}\n", i, nth(argv, i);
          i = i + 1;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants