Skip to content
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

distinguish function calls that appear on the same line #169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/modules/function/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct FunctionInvocation {
variant_id: usize,
id: usize,
line: usize,
col: usize,
failed: Failed,
modifier: CommandModifier,
is_failable: bool
Expand All @@ -43,6 +44,7 @@ impl SyntaxModule<ParserMetadata> for FunctionInvocation {
variant_id: 0,
id: 0,
line: 0,
col: 0,
failed: Failed::new(),
modifier: CommandModifier::new().parse_expr(),
is_failable: false
Expand All @@ -56,6 +58,7 @@ impl SyntaxModule<ParserMetadata> for FunctionInvocation {
let tok = meta.get_current_token();
if let Some(ref tok) = tok {
self.line = tok.pos.0;
self.col = tok.pos.1;
}
self.name = variable(meta, variable_name_extensions())?;
// Get the arguments
Expand Down Expand Up @@ -135,15 +138,15 @@ impl TranslateModule for FunctionInvocation {
}).collect::<Vec<String>>().join(" ");
meta.stmt_queue.push_back(format!("{name} {args}{silent}"));
let invocation_return = &format!("__AF_{}{}_v{}", self.name, self.id, self.variant_id);
let invocation_instance = &format!("__AF_{}{}_v{}__{}", self.name, self.id, self.variant_id, self.line);
let invocation_instance = &format!("__AF_{}{}_v{}__{}_{}", self.name, self.id, self.variant_id, self.line, self.col);
let parsed_invocation_return = self.get_variable(meta, invocation_return, true);
swap(&mut is_silent, &mut meta.silenced);
if self.is_failable {
let failed = self.failed.translate(meta);
meta.stmt_queue.push_back(failed);
}
meta.stmt_queue.push_back(
format!("__AF_{}{}_v{}__{}={}", self.name, self.id, self.variant_id, self.line, if matches!(self.kind, Type::Array(_)) {
format!("__AF_{}{}_v{}__{}_{}={}", self.name, self.id, self.variant_id, self.line, self.col, if matches!(self.kind, Type::Array(_)) {
// If the function returns an array we have to store the intermediate result in a variable that is of type array
format!("({})", parsed_invocation_return)
} else {
Expand Down
13 changes: 13 additions & 0 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,19 @@ fn variable_ref_function_invocation() {
test_amber!(code, "\"sram\"");
}

#[test]
fn function_calls_on_the_same_line() {
let code = "
fun f(arg: Num): Num {
return arg
}

let a = f(1) + f(2)
echo a
";
test_amber!(code, "3");
}

#[test]
fn main_args() {
let code = "
Expand Down