Add index of variants to symbol table
Also new prelude type, just for testing
This commit is contained in:
parent
7548bdbb78
commit
42d0aba21c
@ -181,7 +181,7 @@ impl<'a> State<'a> {
|
|||||||
{
|
{
|
||||||
let symbol_table = self.symbol_table_handle.borrow();
|
let symbol_table = self.symbol_table_handle.borrow();
|
||||||
match symbol_table.values.get(&name) {
|
match symbol_table.values.get(&name) {
|
||||||
Some(Symbol { spec: SymbolSpec::DataConstructor { type_name, type_args }, name }) => {
|
Some(Symbol { spec: SymbolSpec::DataConstructor { type_name, type_args, .. }, name }) => {
|
||||||
if args.len() != type_args.len() {
|
if args.len() != type_args.len() {
|
||||||
return Err(format!("Data constructor {} requires {} args", name, type_args.len()));
|
return Err(format!("Data constructor {} requires {} args", name, type_args.len()));
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ impl<'a> State<'a> {
|
|||||||
let value = symbol_table.values.get(&name);
|
let value = symbol_table.values.get(&name);
|
||||||
Ok(match value {
|
Ok(match value {
|
||||||
Some(Symbol { name, spec }) => match spec {
|
Some(Symbol { name, spec }) => match spec {
|
||||||
SymbolSpec::DataConstructor { type_name, type_args } => {
|
SymbolSpec::DataConstructor { type_name, type_args, .. } => {
|
||||||
if type_args.len() == 0 {
|
if type_args.len() == 0 {
|
||||||
Expr::Lit(Lit::Custom(name.clone(), vec![]))
|
Expr::Lit(Lit::Custom(name.clone(), vec![]))
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,6 +56,7 @@ impl Schala {
|
|||||||
pub fn new() -> Schala {
|
pub fn new() -> Schala {
|
||||||
let prelude = r#"
|
let prelude = r#"
|
||||||
type Option<T> = Some(T) | None
|
type Option<T> = Some(T) | None
|
||||||
|
type Color = Red | Green | Blue
|
||||||
"#;
|
"#;
|
||||||
let mut s = Schala::new_blank_env();
|
let mut s = Schala::new_blank_env();
|
||||||
s.execute_pipeline(prelude, &EvalOptions::default());
|
s.execute_pipeline(prelude, &EvalOptions::default());
|
||||||
|
@ -33,6 +33,7 @@ impl fmt::Display for Symbol {
|
|||||||
pub enum SymbolSpec {
|
pub enum SymbolSpec {
|
||||||
Func(Vec<TypeName>),
|
Func(Vec<TypeName>),
|
||||||
DataConstructor {
|
DataConstructor {
|
||||||
|
index: usize,
|
||||||
type_name: Rc<String>,
|
type_name: Rc<String>,
|
||||||
type_args: Vec<Rc<String>>,
|
type_args: Vec<Rc<String>>,
|
||||||
},
|
},
|
||||||
@ -43,7 +44,7 @@ impl fmt::Display for SymbolSpec {
|
|||||||
use self::SymbolSpec::*;
|
use self::SymbolSpec::*;
|
||||||
match self {
|
match self {
|
||||||
Func(type_names) => write!(f, "Func({:?})", type_names),
|
Func(type_names) => write!(f, "Func({:?})", type_names),
|
||||||
DataConstructor { type_name, type_args } => write!(f, "DataConstructor({:?} -> {})", type_args, type_name),
|
DataConstructor { index, type_name, type_args } => write!(f, "DataConstructor({})({:?} -> {})", index, type_args, type_name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,11 +80,12 @@ impl SymbolTable {
|
|||||||
Symbol { name: signature.name.clone(), spec }
|
Symbol { name: signature.name.clone(), spec }
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
TypeDecl { name: TypeSingletonName { name, params}, body: TypeBody(variants), mutable } => {
|
TypeDecl { name: TypeSingletonName { name, params}, body: TypeBody(variants), mutable, } => {
|
||||||
for var in variants {
|
for (index, var) in variants.iter().enumerate() {
|
||||||
match var {
|
match var {
|
||||||
Variant::UnitStruct(variant_name) => {
|
Variant::UnitStruct(variant_name) => {
|
||||||
let spec = SymbolSpec::DataConstructor {
|
let spec = SymbolSpec::DataConstructor {
|
||||||
|
index,
|
||||||
type_name: name.clone(),
|
type_name: name.clone(),
|
||||||
type_args: vec![],
|
type_args: vec![],
|
||||||
};
|
};
|
||||||
@ -94,7 +96,8 @@ impl SymbolTable {
|
|||||||
TypeName::Singleton(TypeSingletonName { name, ..}) => name.clone(),
|
TypeName::Singleton(TypeSingletonName { name, ..}) => name.clone(),
|
||||||
TypeName::Tuple(_) => unimplemented!(),
|
TypeName::Tuple(_) => unimplemented!(),
|
||||||
}).collect();
|
}).collect();
|
||||||
let spec = SymbolSpec::DataConstructor {
|
let spec = SymbolSpec::DataConstructor {
|
||||||
|
index,
|
||||||
type_name: name.clone(),
|
type_name: name.clone(),
|
||||||
type_args
|
type_args
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user