Starting basic type stuff
This commit is contained in:
parent
a50d8d9e3f
commit
76575e9ba3
11
TODO.md
11
TODO.md
@ -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
|
||||
|
||||
* another idea, allow:
|
||||
type enum {
|
||||
type enum MySubVariant {
|
||||
SubVariant1, SubVariant2, etc.
|
||||
}
|
||||
Variant1(MySubVariant),
|
||||
Variant2(...),
|
||||
}
|
||||
|
||||
|
||||
|
||||
* idea for Schala: both currying *and* default arguments!
|
||||
ex. fn a(b: Int, c:Int, d:Int = 1) -> Int
|
||||
a(1,2) : Int
|
||||
|
@ -4,9 +4,14 @@ use schala_lang::parsing;
|
||||
|
||||
pub struct TypeContext { }
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum Type {
|
||||
Unit,
|
||||
Int,
|
||||
Float,
|
||||
StringT,
|
||||
Bool,
|
||||
Custom(Rc<String>),
|
||||
Void
|
||||
}
|
||||
|
||||
@ -25,9 +30,11 @@ impl TypeContext {
|
||||
Ok(ret_type)
|
||||
}
|
||||
fn type_check_statement(&mut self, statement: &parsing::Statement) -> TypeResult<Type> {
|
||||
println!("statement should be: {:?}", statement);
|
||||
|
||||
use self::parsing::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),
|
||||
}
|
||||
}
|
||||
@ -35,9 +42,24 @@ impl TypeContext {
|
||||
use self::Type::*;
|
||||
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::*;
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user