refactor(tvix/eval/builtin-macros): use match block for f.block
These nested ifs are a bit confusing, a match block makes this cleaner. Change-Id: I256fd0bc921fbf2e60ad0f6e1ea51c2e0fb00317 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12628 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
ca1e628c85
commit
a833703dab
1 changed files with 34 additions and 20 deletions
|
@ -281,31 +281,45 @@ pub fn builtins(args: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let ty = &arg.ty;
|
let ty = &arg.ty;
|
||||||
let ident = &arg.name;
|
let ident = &arg.name;
|
||||||
|
|
||||||
if arg.strict {
|
f.block = Box::new(match arg {
|
||||||
if arg.catch {
|
BuiltinArgument {
|
||||||
f.block = Box::new(parse_quote_spanned! {arg.span=> {
|
strict: true,
|
||||||
let #ident: #ty = tvix_eval::generators::request_force(&co, values.pop()
|
catch: true,
|
||||||
.expect("Tvix bug: builtin called with incorrect number of arguments")).await;
|
..
|
||||||
|
} => parse_quote_spanned! {
|
||||||
|
arg.span => {
|
||||||
|
let #ident: #ty = tvix_eval::generators::request_force(
|
||||||
|
&co, values.pop().expect("Tvix bug: builtin called with incorrect number of arguments")
|
||||||
|
).await;
|
||||||
#block
|
#block
|
||||||
}});
|
}
|
||||||
} else {
|
},
|
||||||
f.block = Box::new(parse_quote_spanned! {arg.span=> {
|
BuiltinArgument {
|
||||||
let #ident: #ty = tvix_eval::generators::request_force(&co, values.pop()
|
strict: true,
|
||||||
.expect("Tvix bug: builtin called with incorrect number of arguments")).await;
|
catch: false,
|
||||||
|
..
|
||||||
|
} => parse_quote_spanned! {
|
||||||
|
arg.span => {
|
||||||
|
let #ident: #ty = tvix_eval::generators::request_force(
|
||||||
|
&co, values.pop().expect("Tvix bug: builtin called with incorrect number of arguments")
|
||||||
|
).await;
|
||||||
if #ident.is_catchable() {
|
if #ident.is_catchable() {
|
||||||
return Ok(#ident);
|
return Ok(#ident);
|
||||||
}
|
}
|
||||||
#block
|
#block
|
||||||
}});
|
}
|
||||||
}
|
},
|
||||||
} else {
|
BuiltinArgument {
|
||||||
f.block = Box::new(parse_quote_spanned! {arg.span=> {
|
strict: false,
|
||||||
let #ident: #ty = values.pop()
|
catch: _,
|
||||||
.expect("Tvix bug: builtin called with incorrect number of arguments");
|
..
|
||||||
|
} => parse_quote_spanned! {
|
||||||
#block
|
arg.span => {
|
||||||
}})
|
let #ident: #ty = values.pop().expect("Tvix bug: builtin called with incorrect number of arguments");
|
||||||
}
|
#block
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let fn_name = f.sig.ident.clone();
|
let fn_name = f.sig.ident.clone();
|
||||||
|
|
Loading…
Reference in a new issue