Codegen function call parameters

master
Araozu 2024-01-11 19:36:11 -05:00
parent a6bff95d24
commit a605d182b4
4 changed files with 12 additions and 8 deletions

View File

@ -20,7 +20,7 @@
## v0.0.10 ## v0.0.10
- [x] Parse function call parameters - [x] Parse function call parameters
- [ ] Codegen function call parameters - [x] Codegen function call parameters
- [ ] Parse function declaration arguments - [ ] Parse function declaration arguments
- [ ] Begin work on semantic analysis - [ ] Begin work on semantic analysis
- [ ] Symbol table - [ ] Symbol table

View File

@ -4,6 +4,8 @@ use super::Transpilable;
impl Transpilable for FunctionCall { impl Transpilable for FunctionCall {
fn transpile(&self) -> String { fn transpile(&self) -> String {
format!("{}()", self.function.transpile()) let parameters = &self.arguments.arguments.iter().map(|expr| expr.transpile()).collect::<Vec<_>>().join(", ");
format!("{}({})", self.function.transpile(), parameters)
} }
} }

View File

@ -3,6 +3,7 @@ use super::Expression;
#[derive(Debug)] #[derive(Debug)]
pub struct FunctionCall { pub struct FunctionCall {
pub function: Box<Expression>, pub function: Box<Expression>,
pub arguments: Box<ArgumentsList>,
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,7 +1,10 @@
use crate::{ use crate::{
lexic::token::Token, lexic::token::Token,
syntax::{ syntax::{
ast::{functions::FunctionCall, Expression}, ast::{
functions::{ArgumentsList, FunctionCall},
Expression,
},
functions::arguments_list, functions::arguments_list,
ParseResult, ParseResult,
}, },
@ -20,7 +23,7 @@ pub fn try_parse(tokens: &Vec<Token>, pos: usize) -> ParseResult<Expression, ()>
}; };
// Parse arguments list // Parse arguments list
let (_args_list, next_pos) = match arguments_list::try_parse(tokens, next_pos) { let (arguments, next_pos) = match arguments_list::try_parse(tokens, next_pos) {
ParseResult::Ok(args, next) => (args, next), ParseResult::Ok(args, next) => (args, next),
ParseResult::Err(err) => return ParseResult::Err(err), ParseResult::Err(err) => return ParseResult::Err(err),
_ => { _ => {
@ -30,13 +33,11 @@ pub fn try_parse(tokens: &Vec<Token>, pos: usize) -> ParseResult<Expression, ()>
let fun_call = FunctionCall { let fun_call = FunctionCall {
function: Box::new(primary_expr), function: Box::new(primary_expr),
arguments: Box::new(arguments),
}; };
ParseResult::Ok(Expression::FunctionCall(fun_call), next_pos) ParseResult::Ok(Expression::FunctionCall(fun_call), next_pos)
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {}
}