Skip to content
Snippets Groups Projects
Commit 7109f237 authored by Per Lindgren's avatar Per Lindgren
Browse files

move to new syntax, wip8

parent dc365160
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ fn main() {
let mut a = 5;
a = 5;
a = { 7 };
a = if true { 7 } else { 5 }
a = if true { 7 } else { 5 };
}
fn b(x: i32) -> i32 {
......
......@@ -190,7 +190,7 @@ fn expr_type(
Block(b) => check_stmts(b, fn_env, type_env, var_env),
Stmt(s) => panic!(),
Stmt(s) => check_stmt(s, fn_env, type_env, var_env),
}
}
......@@ -246,17 +246,13 @@ fn is_known(t: &Type) -> bool {
}
}
pub fn check_stmts(
stmts: &Stmts,
pub fn check_stmt(
s: &Stmt,
fn_env: &FnEnv,
type_env: &TypeEnv,
var_env: &mut VarEnv,
) -> Result<Type, Error> {
use Stmt::*;
var_env.push_empty_scope();
let t = stmts.stmts.iter().try_fold(Type::Unit, |_, s| {
trace!("stmt: {}", s);
match s {
Stmt::Block(b) => check_stmts(b, fn_env, type_env, var_env),
......@@ -367,7 +363,22 @@ pub fn check_stmts(
},
Semi => panic!("ICE"),
}
})?;
}
pub fn check_stmts(
stmts: &Stmts,
fn_env: &FnEnv,
type_env: &TypeEnv,
var_env: &mut VarEnv,
) -> Result<Type, Error> {
use Stmt::*;
var_env.push_empty_scope();
let t = stmts
.stmts
.iter()
.try_fold(Type::Unit, |_, s| check_stmt(s, fn_env, type_env, var_env))?;
var_env.pop_scope();
if !stmts.ret {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment