return stmt

This commit is contained in:
Edward Chen
2021-09-16 01:30:36 -04:00
parent 12166687a9
commit 00b867445c
2 changed files with 18 additions and 11 deletions

View File

@@ -12,9 +12,9 @@ use std::fmt::{self, Display, Formatter};
pub struct FnInfo {
name: String,
args: Vec<ParameterDeclaration>,
body: Statement,
pub name: String,
pub args: Vec<ParameterDeclaration>,
pub body: Statement,
}
impl FnInfo {

View File

@@ -92,29 +92,35 @@ impl CGen {
Self { source, tu, mode }
}
fn gen_stmt(&mut self, stmt: Statement) {
// fn gen_expr(&self, ) {
// }
fn gen_stmt(&self, stmt: Statement) {
match stmt {
Statement::Compound(nodes) => {
for node in nodes {
match node.node {
BlockItem::Declaration(decl) => {
_ => panic!("Declaration not supported yet"),
}
BlockItem::Declaration(_decl) => unimplemented!("Declaration not supported yet"),
BlockItem::Statement(stmt) => {
self.gen_stmt(stmt.node);
}
BlockItem::StaticAssert(sa) => {
_ => panic!("Static Assert not supported yet"),
}
BlockItem::StaticAssert(_sa) => unimplemented!("Static Assert not supported yet"),
}
}
}
Statement::Return(ret) => {
// Return is Optional type here
println!("{:#?}", ret);
// self.gen_expr(ret);
}
Statement::Expression(expr) => {
}
_ => unimplemented!("Statement {:#?} hasn't been implemented", stmt),
}
}
fn gen(&mut self) {
fn gen(&self) {
let TranslationUnit(nodes) = &self.tu;
for n in nodes.iter() {
match n.node {
@@ -123,6 +129,7 @@ impl CGen {
}
ExternalDeclaration::FunctionDefinition(ref fn_def) => {
let fn_info = ast_utils::get_fn_info(&fn_def.node);
self.gen_stmt(fn_info.body.clone());
println!("{}", fn_info);
}
_ => panic!("Haven't implemented node: {:?}", n.node),