TypeSingletonName broken out
This commit is contained in:
parent
1f2a4c706f
commit
ef4620e90a
@ -396,15 +396,15 @@ pub enum Statement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ParamName = Rc<String>;
|
type ParamName = Rc<String>;
|
||||||
type TraitName = Rc<String>;
|
type TraitName = Rc<String>; //should be a singleton I think??
|
||||||
type FormalParam = (ParamName, Option<TypeName>);
|
type FormalParam = (ParamName, Option<TypeName>);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Declaration {
|
pub enum Declaration {
|
||||||
FuncSig(Signature),
|
FuncSig(Signature),
|
||||||
FuncDecl(Signature, Vec<Statement>),
|
FuncDecl(Signature, Vec<Statement>),
|
||||||
TypeDecl(Rc<String>, TypeBody),
|
TypeDecl(Rc<String>, TypeBody), //should have TypeSingletonName in it
|
||||||
TypeAlias(Rc<String>, Rc<String>),
|
TypeAlias(Rc<String>, Rc<String>), //should have TypeSingletonName in it, or maybe just String, not sure
|
||||||
Binding {
|
Binding {
|
||||||
name: Rc<String>,
|
name: Rc<String>,
|
||||||
constant: bool,
|
constant: bool,
|
||||||
@ -440,10 +440,13 @@ pub struct Expression(pub ExpressionType, pub Option<TypeName>);
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum TypeName {
|
pub enum TypeName {
|
||||||
Tuple(Vec<TypeName>),
|
Tuple(Vec<TypeName>),
|
||||||
Singleton {
|
Singleton(TypeSingletonName)
|
||||||
name: Rc<String>,
|
}
|
||||||
params: Vec<TypeName>,
|
|
||||||
}
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
pub struct TypeSingletonName {
|
||||||
|
pub name: Rc<String>,
|
||||||
|
pub params: Vec<TypeName>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -710,7 +713,7 @@ impl Parser {
|
|||||||
let result = match (first, second) {
|
let result = match (first, second) {
|
||||||
(first, Some(second)) => {
|
(first, Some(second)) => {
|
||||||
match first {
|
match first {
|
||||||
TypeName::Singleton { ref name, ref params } if params.len() == 0 =>
|
TypeName::Singleton(TypeSingletonName { ref name, ref params }) if params.len() == 0 =>
|
||||||
Declaration::Impl { type_name: second, trait_name: Some(name.clone()), block },
|
Declaration::Impl { type_name: second, trait_name: Some(name.clone()), block },
|
||||||
_ => return ParseError::new(&format!("Invalid name for a trait")),
|
_ => return ParseError::new(&format!("Invalid name for a trait")),
|
||||||
}
|
}
|
||||||
@ -746,13 +749,13 @@ impl Parser {
|
|||||||
use self::TypeName::*;
|
use self::TypeName::*;
|
||||||
Ok(match self.peek() {
|
Ok(match self.peek() {
|
||||||
LParen => Tuple(delimited!(self, LParen, '(', type_name, Comma, RParen, ')')),
|
LParen => Tuple(delimited!(self, LParen, '(', type_name, Comma, RParen, ')')),
|
||||||
_ => Singleton {
|
_ => Singleton(TypeSingletonName {
|
||||||
name: self.identifier()?,
|
name: self.identifier()?,
|
||||||
params: match self.peek() {
|
params: match self.peek() {
|
||||||
LAngleBracket => delimited!(self, LAngleBracket, '<', type_name, Comma, RAngleBracket, '>'),
|
LAngleBracket => delimited!(self, LAngleBracket, '<', type_name, Comma, RAngleBracket, '>'),
|
||||||
_ => vec![],
|
_ => vec![],
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
||||||
use schala_lang::parsing::{AST, Statement, Declaration, Signature, Expression, ExpressionType, Operation, Variant, TypeName};
|
use schala_lang::parsing::{AST, Statement, Declaration, Signature, Expression, ExpressionType, Operation, Variant, TypeName, TypeSingletonName};
|
||||||
|
|
||||||
// from Niko's talk
|
// from Niko's talk
|
||||||
/* fn type_check(expression, expected_ty) -> Ty {
|
/* fn type_check(expression, expected_ty) -> Ty {
|
||||||
@ -234,7 +234,7 @@ impl TypeContext {
|
|||||||
use self::TypeConst::*;
|
use self::TypeConst::*;
|
||||||
|
|
||||||
match anno {
|
match anno {
|
||||||
&TypeName::Singleton { ref name, .. } => {
|
&TypeName::Singleton(TypeSingletonName { ref name, .. }) => {
|
||||||
match name.as_ref().as_ref() {
|
match name.as_ref().as_ref() {
|
||||||
"Int" => TConst(Integer),
|
"Int" => TConst(Integer),
|
||||||
"Float" => TConst(Float),
|
"Float" => TConst(Float),
|
||||||
|
Loading…
Reference in New Issue
Block a user