Add docs on the main function, argv and return codes#470
Add docs on the main function, argv and return codes#470JeffersGlass wants to merge 1 commit intospylang:mainfrom
Conversation
|
Hello @JeffersGlass, Thank you so much for this doc. Overall content is comprehensive. However, main() argument now supports both compiler and interpreter. So, we can compile code with main function arguments regarding #449. |
| ``` | ||
|
|
||
|
|
||
| ## Passed Arguments (Interpretter Only) |
There was a problem hiding this comment.
| ## Passed Arguments (Interpretter Only) | |
| ## Passed Arguments (Interpreter Only) |
There was a problem hiding this comment.
as @kanin-kearpimy already pointed out, the arguments works also on compiled mode now 🎉.
Maybe instead of "passed arguments" we can call this section "Accessing command line arguments"?
|
|
||
| ## Passed Arguments (Interpretter Only) | ||
|
|
||
| If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpretted |
There was a problem hiding this comment.
| If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpretted | |
| If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpreted |
Seems the sentence is not finished?
antocuni
left a comment
There was a problem hiding this comment.
Thank you @JeffersGlass!
I left some minor comments but overall looks good 💪
| print("Hello world") | ||
| ``` | ||
|
|
||
| Not every `.spy` module needs a main function, but the module invoked by, e.g. `spy execute foo.spy` must contain a main function. |
There was a problem hiding this comment.
| Not every `.spy` module needs a main function, but the module invoked by, e.g. `spy execute foo.spy` must contain a main function. | |
| Not every `.spy` module needs a main function, but the module entry point invoked by, e.g. `spy foo.spy` or `spy build foo.spy` must contain a main function. |
There was a problem hiding this comment.
I think this is a big more correct, but it become more nuanced, because e.g. spy build --target lib and spy build --target py-cffi do not require a main.
Maybe we can reword the section by starting this way:
The execution of a SPy program starts from a
mainfunction; you need amainif you try to run the interpreter (spy foo.spy) or to build an executable (spy build foo.spy). You don't need amainif you build a library (e.g.spy build --target lib foo.spy).
However, I don't fully like the wording. What do you think?
| ``` | ||
|
|
||
|
|
||
| ## Passed Arguments (Interpretter Only) |
There was a problem hiding this comment.
as @kanin-kearpimy already pointed out, the arguments works also on compiled mode now 🎉.
Maybe instead of "passed arguments" we can call this section "Accessing command line arguments"?
| 999 | ||
| ``` | ||
|
|
||
| As with CPython, args[0] is the name of the string passed to the uv runtime: |
There was a problem hiding this comment.
probably we should say that this is the equivalent of CPython's sys.argv
|
|
||
| ```py | ||
| #args.spy | ||
| def main(args: list[str]) -> None: |
There was a problem hiding this comment.
I think we should use argv as the canonical name, for consistency to CPython
Adds a documentation page for current info on the
mainfunction, and optionally providing command line arguments and return codes. Based on the work in #353 and elsewhere.