mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
Lower top-level fn calls in home module with params
This commit is contained in:
parent
07ec24502e
commit
bcd8e7e28a
4 changed files with 26 additions and 4 deletions
|
@ -739,6 +739,8 @@ mod cli_run {
|
|||
App2.getUser 2: http://api.example.com/two/users/2
|
||||
App1.getPost 1: https://api.example.com/one/posts/1
|
||||
App2.getPost 2: http://api.example.com/two/posts/2
|
||||
App1.getPostComments 1: https://api.example.com/one/posts/1/comments
|
||||
App2.getPostComments 2: http://api.example.com/two/posts/2/comments
|
||||
"#
|
||||
),
|
||||
UseValgrind::No,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module { appId, protocol } -> [baseUrl, getUser, getPost]
|
||||
module { appId, protocol } -> [baseUrl, getUser, getPost, getPostComments]
|
||||
|
||||
baseUrl : Str
|
||||
baseUrl =
|
||||
|
@ -13,3 +13,8 @@ getUser = \userId ->
|
|||
getPost : U32 -> Str
|
||||
getPost = \postId ->
|
||||
"$(baseUrl)/posts/$(Num.toStr postId)"
|
||||
|
||||
|
||||
getPostComments : U32 -> Str
|
||||
getPostComments = \postId ->
|
||||
"$(getPost postId)/comments"
|
||||
|
|
|
@ -16,4 +16,6 @@ main =
|
|||
App2.getUser 2: $(App2.getUser 2)
|
||||
App1.getPost 1: $(App1.getPost 1)
|
||||
App2.getPost 2: $(App2.getPost 2)
|
||||
App1.getPostComments 1: $(App1.getPostComments 1)
|
||||
App2.getPostComments 2: $(App2.getPostComments 2)
|
||||
"""
|
||||
|
|
|
@ -104,9 +104,7 @@ impl<'a> LowerParams<'a> {
|
|||
*expr = self.call_params_var(*symbol, *var, *params_symbol, *params_var);
|
||||
}
|
||||
Var(symbol, var) => {
|
||||
if symbol.module_id() == self.home_id
|
||||
&& self.home_top_level_idents.contains(&symbol.ident_id())
|
||||
{
|
||||
if self.is_params_extended_home_symbol(symbol) {
|
||||
// A reference to a top-level value def in the home module with params
|
||||
let params = self.home_params.as_ref().unwrap();
|
||||
*expr =
|
||||
|
@ -130,6 +128,16 @@ impl<'a> LowerParams<'a> {
|
|||
args.push((params_var, Loc::at_zero(Var(params_symbol, params_var))));
|
||||
fun.1.value = Var(symbol, var);
|
||||
}
|
||||
Var(symbol, _var) => {
|
||||
if self.is_params_extended_home_symbol(&symbol) {
|
||||
// A call to a top-level function in the home module with params
|
||||
let params = self.home_params.as_ref().unwrap();
|
||||
args.push((
|
||||
params.whole_var,
|
||||
Loc::at_zero(Var(params.whole_symbol, params.whole_var)),
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => self.lower_expr(&mut fun.1.value),
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +159,11 @@ impl<'a> LowerParams<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_params_extended_home_symbol(&self, symbol: &Symbol) -> bool {
|
||||
symbol.module_id() == self.home_id
|
||||
&& self.home_top_level_idents.contains(&symbol.ident_id())
|
||||
}
|
||||
|
||||
fn call_params_var(
|
||||
&mut self,
|
||||
symbol: Symbol,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue