Lower top-level fn calls in home module with params

This commit is contained in:
Agus Zubiaga 2024-08-17 13:44:19 -03:00
parent 07ec24502e
commit bcd8e7e28a
No known key found for this signature in database
4 changed files with 26 additions and 4 deletions

View file

@ -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,

View file

@ -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"

View file

@ -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)
"""

View file

@ -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,