Skip to content

Commit

Permalink
feat: fix function
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Jan 18, 2024
1 parent e02b01a commit 3a531f8
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions fmt/src/gen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::BorrowMut;

use dprint_core::formatting::PrintItems;
use whistle_ast::{IdentType, IdentTyped, ProgramStmt, Stmt};
use whistle_ast::*;

use crate::{config::Configuration, ParsedSource};

Expand All @@ -22,9 +22,9 @@ pub fn generate(parsed_source: &ParsedSource, _config: &Configuration) -> PrintI
items.borrow_mut(),
export,
inline,
ident,
params,
ret_type,
ident.clone(),
params.to_vec(),
&mut ret_type.clone(),
stmt,
),
_ => panic!("Unimplemented"),
Expand All @@ -34,12 +34,52 @@ pub fn generate(parsed_source: &ParsedSource, _config: &Configuration) -> PrintI
}

pub fn gen_fn(
_items: &mut PrintItems,
_export: &bool,
items: &mut PrintItems,
export: &bool,
_inline: &bool,
_ident: &str,
_params: &Vec<IdentTyped>,
_ret_type: &IdentType,
_stmts: &Vec<Stmt>,
ident: String,
params: Vec<IdentTyped>,
ret_type: &mut IdentType,
stmts: &Vec<Stmt>,
) {
if *export {
items.push_str("export ");
}
items.push_str("fn ");
items.push_string(ident);
items.push_str("(");
for (i, param) in params.iter().enumerate() {
if i > 0 {
items.push_str(", ");
}
items.push_string(param.ident.clone());
items.push_str(": ");
match param.type_ident.to_type() {
Type::Ident(ident) => {
items.push_string(ident);
}
_ => panic!("Unimplemented"),
}
}
items.push_str(")");
items.push_str(": ");
match ret_type.borrow_mut().to_type() {
Type::Ident(ident) => {
items.push_string(ident);
}
_ => panic!("Unimplemented"),
}
// items.push_str(&ret_type.to_type().type_id());

items.push_str(" {\n");
for stmt in stmts {
gen_stmt(items, stmt);
}
items.push_str("}\n");
}

pub fn gen_stmt(_items: &mut PrintItems, stmt: &Stmt) {
match stmt {
_ => panic!("Unimplemented"),
}
}

0 comments on commit 3a531f8

Please sign in to comment.