Skip to content

Commit

Permalink
WIP sketch of insert_casts pass
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Oct 1, 2023
1 parent cdbeb79 commit 62c47ce
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
36 changes: 1 addition & 35 deletions ncc/src/casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl Stmt
{
fn insert_casts(&mut self) -> Result<(), ParseError>
{
/*
match self {
Stmt::Expr(expr) => {
expr.insert_casts()?;
Expand Down Expand Up @@ -62,58 +61,29 @@ impl Stmt
}

Stmt::For { init_stmt, test_expr, incr_expr, body_stmt } => {
env.push_scope();
if init_stmt.is_some() {
init_stmt.as_mut().unwrap().insert_casts()?;
}

test_expr.insert_casts()?;
incr_expr.insert_casts()?;
body_stmt.insert_casts()?;
env.pop_scope();
}

// Local variable declaration
Stmt::VarDecl { var_type, var_name, init_expr } => {
resolve_types(var_type, env, None)?;
env.define_local(var_name, var_type.clone());
let decl = env.lookup(var_name).unwrap();
let ref_expr = Expr::Ref(decl);
// If there is an initiaization expression
if let Some(init_expr) = init_expr {
init_expr.insert_casts()?;
let assign_expr = Expr::Binary {
op: BinOp::Assign,
lhs: Box::new(ref_expr),
rhs: Box::new(init_expr.clone()),
};
*self = Stmt::Expr(assign_expr);
}
else
{
*self = Stmt::Expr(Expr::Int(0));
}
}

Stmt::Block(stmts) => {
env.push_scope();
for stmt in stmts {
stmt.insert_casts()?;
}
env.pop_scope();
}
}
*/

Ok(())
}
Expand All @@ -128,11 +98,7 @@ impl Expr
Expr::Int(_) => {}
Expr::Float32(_) => {}
Expr::String(str_const) => {
// Get a global symbol for the string constant
let decl = env.get_string(str_const);
*self = Expr::Ref(decl);
}
Expr::String(str_const) => {}
Expr::Array(exprs) => {
for expr in exprs {
Expand Down
2 changes: 1 addition & 1 deletion ncc/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl Stmt
let decl = env.lookup(var_name).unwrap();
let ref_expr = Expr::Ref(decl);

// If there is an initiaization expression
// If there is an initialization expression
if let Some(init_expr) = init_expr {
init_expr.resolve_syms(env)?;

Expand Down

0 comments on commit 62c47ce

Please sign in to comment.