-
Notifications
You must be signed in to change notification settings - Fork 5
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
Implement main expressions #168
Conversation
BinderDavid
commented
Mar 22, 2024
•
edited
Loading
edited
app/src/cli/run.rs
Outdated
match nf { | ||
Some(nf) => print_nf(&nf), | ||
None => { | ||
println!("No \"main\" expression was found in the program.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eprintln!
to print to stderr or better return Err(...)
to print to stderr and exit with status code 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, we should split pol run
into pol check
and pol run
. I can do that in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented both check
and run
in this PR, and use a miette error to report if a main expression wasn't found.
impl<P: Phase> Let<P> { | ||
/// Returns whether the declaration is the "main" expression of the module. | ||
pub fn is_main(&self) -> bool { | ||
self.name == "main" && self.params.is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably forbid parameters on let bindings called main
during lowering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasoning: otherwise it is confusing for users because they will see the error message "main not found" but they have a main
expression with a different signature.
daf2d40
to
c95d53f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I advocate for throwing a different error if main
has an unexpected signature.
impl<P: Phase> Let<P> { | ||
/// Returns whether the declaration is the "main" expression of the module. | ||
pub fn is_main(&self) -> bool { | ||
self.name == "main" && self.params.is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasoning: otherwise it is confusing for users because they will see the error message "main not found" but they have a main
expression with a different signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest throwing a different error when the main
signature is unexpected because otherwise the error message of not being able to find the main
expression will confuse users if they have a main
expression with parameters.
- `pol run` executes the main expression in a file - `pol check` only typechecks a file
c95d53f
to
ed0a218
Compare
I have added a help message to the error: david@anaxes ~/polarity/polarity (add-main-functions)$ pol run examples/example.pol
Error: × Main expression was not found
help: Main expressions must be called "main" and not take any arguments.
|