Starting basic type stuff

This commit is contained in:
greg 2018-02-21 03:39:40 -08:00
parent c674148772
commit 4c8b4c8c71
2 changed files with 37 additions and 4 deletions

11
TODO.md
View File

@ -5,6 +5,17 @@
* idea for Schala - scoped types - be able to define a quick enum type scoped to a function ro something, that only is meant to be used as a quick bespoke interface between two other things * idea for Schala - scoped types - be able to define a quick enum type scoped to a function ro something, that only is meant to be used as a quick bespoke interface between two other things
* another idea, allow:
type enum {
type enum MySubVariant {
SubVariant1, SubVariant2, etc.
}
Variant1(MySubVariant),
Variant2(...),
}
* idea for Schala: both currying *and* default arguments! * idea for Schala: both currying *and* default arguments!
ex. fn a(b: Int, c:Int, d:Int = 1) -> Int ex. fn a(b: Int, c:Int, d:Int = 1) -> Int
a(1,2) : Int a(1,2) : Int

View File

@ -4,9 +4,14 @@ use schala_lang::parsing;
pub struct TypeContext { } pub struct TypeContext { }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Clone)]
pub enum Type { pub enum Type {
Unit, Unit,
Int,
Float,
StringT,
Bool,
Custom(Rc<String>),
Void Void
} }
@ -25,9 +30,11 @@ impl TypeContext {
Ok(ret_type) Ok(ret_type)
} }
fn type_check_statement(&mut self, statement: &parsing::Statement) -> TypeResult<Type> { fn type_check_statement(&mut self, statement: &parsing::Statement) -> TypeResult<Type> {
println!("statement should be: {:?}", statement);
use self::parsing::Statement::*; use self::parsing::Statement::*;
match statement { match statement {
&ExpressionStatement(ref expr) => self.type_check_expression(expr), &ExpressionStatement(ref expr) => self.type_infer(expr),
&Declaration(ref decl) => self.type_check_declaration(decl), &Declaration(ref decl) => self.type_check_declaration(decl),
} }
} }
@ -35,9 +42,24 @@ impl TypeContext {
use self::Type::*; use self::Type::*;
Ok(Unit) Ok(Unit)
} }
fn type_check_expression(&mut self, expr: &parsing::Expression) -> TypeResult<Type> { fn type_infer(&mut self, expr: &parsing::Expression) -> TypeResult<Type> {
use self::parsing::Expression;
use self::parsing::ExpressionType::*;
use self::Type::*; use self::Type::*;
Ok(Void) match expr {
&Expression(ref e, Some(ref ty)) => Err(format!("Anno not implemented")),
&Expression(ref e, None) => match e {
&IntLiteral(_) => Ok(Int),
&FloatLiteral(_) => Ok(Float),
&StringLiteral(_) => Ok(StringT),
&BoolLiteral(_) => Ok(Bool),
_ => Err(format!("Type not yet implemented"))
}
}
}
fn unify(&mut self, t1: Type, t2: Type) -> TypeResult<Type> {
use self::Type::*;
Ok(Unit)
} }
} }