More basic types + test
This commit is contained in:
parent
0d5ccd21fe
commit
fab3fb8ec2
@ -25,7 +25,9 @@ enum TConst {
|
||||
User(Rc<String>),
|
||||
Unit,
|
||||
Nat,
|
||||
Int
|
||||
Int,
|
||||
Float,
|
||||
StringT,
|
||||
}
|
||||
|
||||
impl TConst {
|
||||
@ -80,6 +82,8 @@ impl TypeContext {
|
||||
use self::ExpressionType::*;
|
||||
match expr_type {
|
||||
NatLiteral(_) => Ok(MonoType::Const(TConst::Nat)),
|
||||
FloatLiteral(_) => Ok(MonoType::Const(TConst::Float)),
|
||||
StringLiteral(_) => Ok(MonoType::Const(TConst::StringT)),
|
||||
_ => Ok(MonoType::Const(TConst::user("unimplemented")))
|
||||
}
|
||||
}
|
||||
@ -88,6 +92,26 @@ impl TypeContext {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn parse(input: &str) -> AST {
|
||||
let tokens: Vec<::tokenizing::Token> = ::tokenizing::tokenize(input);
|
||||
let mut parser = ::parsing::Parser::new(tokens);
|
||||
parser.parse().unwrap()
|
||||
}
|
||||
|
||||
macro_rules! type_test {
|
||||
($input:expr, $correct:expr) => {
|
||||
{
|
||||
let mut tc = TypeContext::new();
|
||||
let ast = parse($input);
|
||||
tc.add_symbols(&ast);
|
||||
assert_eq!($correct, tc.type_check(&ast).unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn basic_inference() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user