-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from HigherOrderCO/feature/sc-483/add-an-opti…
…on-to-pass-arguments-to-hvm-lang [sc-483] Add an option to pass arguments to hvm-lang programs
- Loading branch information
Showing
10 changed files
with
138 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::fmt::Display; | ||
|
||
use crate::{ | ||
diagnostics::Info, | ||
term::{Ctx, Pattern, Term}, | ||
}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum ArgError { | ||
PatternArgError, | ||
ArityArgError { expected: usize, got: usize }, | ||
} | ||
|
||
impl Display for ArgError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
ArgError::PatternArgError => write!(f, ""), | ||
ArgError::ArityArgError { expected, got } => write!(f, "Expected {expected} arguments, got {got}."), | ||
} | ||
} | ||
} | ||
|
||
impl Ctx<'_> { | ||
pub fn apply_args(&mut self, args: Option<Vec<Term>>) -> Result<(), Info> { | ||
self.info.start_pass(); | ||
|
||
if let Some(entrypoint) = &self.book.entrypoint { | ||
let main_def = &mut self.book.defs[entrypoint]; | ||
|
||
if !main_def.rules[0].pats.iter().all(|pat| matches!(pat, Pattern::Var(Some(..)))) { | ||
self.info.def_error(entrypoint.clone(), ArgError::PatternArgError); | ||
} | ||
|
||
if let Some(args) = args { | ||
let expected = main_def.rules[0].pats.len(); | ||
let got = args.len(); | ||
if expected != got { | ||
self.info.error(ArgError::ArityArgError { expected, got }); | ||
} | ||
|
||
main_def.convert_match_def_to_term(); | ||
let main_body = &mut self.book.defs[entrypoint].rule_mut().body; | ||
|
||
*main_body = Term::call(main_body.clone(), args); | ||
} | ||
} | ||
|
||
self.info.fatal(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod apply_args; | ||
pub mod definition_merge; | ||
pub mod definition_pruning; | ||
pub mod desugar_implicit_match_binds; | ||
|
Oops, something went wrong.