diff options
author | David Li <li.davidm96@gmail.com> | 2017-11-05 09:27:10 -0500 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2017-11-05 09:27:10 -0500 |
commit | b0711ef63501b7c29cb7c2014f3ceeaa399e3481 (patch) | |
tree | eb1cf61610517a7479e3f78a30b4bff37dd44708 /src/semantic/translate.rs | |
parent | 9f393b2eb7b3fb8f1924e80095bad3384049cc67 (diff) |
Add stubbed out type checker
Diffstat (limited to 'src/semantic/translate.rs')
-rw-r--r-- | src/semantic/translate.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/semantic/translate.rs b/src/semantic/translate.rs new file mode 100644 index 0000000..7bcd646 --- /dev/null +++ b/src/semantic/translate.rs @@ -0,0 +1,39 @@ +use ::ast::{self, WithLocation}; +use super::environment; +use super::types::Ty; + +#[derive(Debug)] +pub enum TypeError { + Unimplemented, +} + +type TypeEnvironment<'a> = environment::Environment<'a, String, Ty>; +pub type Result = ::std::result::Result<Ty, WithLocation<TypeError>>; + +pub fn translate(program: &ast::Program) -> Result { + trans_exp(TypeEnvironment::new(None), &*program.0) +} + +fn trans_exp<'a>(venv: TypeEnvironment<'a>, exp: &WithLocation<ast::Expression>) -> Result { + use ast::Expression::*; + + match &exp.value { + &Let(ref decls, ref body) => { + Err(WithLocation::new(TypeError::Unimplemented, exp.start, exp.end)) + }, + &UnaryOp(ref op, ref operand) => { + Err(WithLocation::new(TypeError::Unimplemented, exp.start, exp.end)) + }, + &BinOp(ref op, ref left, ref right) => { + Err(WithLocation::new(TypeError::Unimplemented, exp.start, exp.end)) + }, + &Number(_) => Ok(Ty::Int), + &String(_) => Ok(Ty::String), + &Name(ref name) => { + Err(WithLocation::new(TypeError::Unimplemented, exp.start, exp.end)) + }, + &Nil => { + Err(WithLocation::new(TypeError::Unimplemented, exp.start, exp.end)) + }, + } +} |