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();
|
||||
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() {
|
||||
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);
|
||||
Ok(match value {
|
||||
Some(Symbol { name, spec }) => match spec {
|
||||
SymbolSpec::DataConstructor { type_name, type_args } => {
|
||||
SymbolSpec::DataConstructor { type_name, type_args, .. } => {
|
||||
if type_args.len() == 0 {
|
||||
Expr::Lit(Lit::Custom(name.clone(), vec![]))
|
||||
} else {
|
||||
|
@ -56,6 +56,7 @@ impl Schala {
|
||||
pub fn new() -> Schala {
|
||||
let prelude = r#"
|
||||
type Option<T> = Some(T) | None
|
||||
type Color = Red | Green | Blue
|
||||
"#;
|
||||
let mut s = Schala::new_blank_env();
|
||||
s.execute_pipeline(prelude, &EvalOptions::default());
|
||||
|
@ -33,6 +33,7 @@ impl fmt::Display for Symbol {
|
||||
pub enum SymbolSpec {
|
||||
Func(Vec<TypeName>),
|
||||
DataConstructor {
|
||||
index: usize,
|
||||
type_name: Rc<String>,
|
||||
type_args: Vec<Rc<String>>,
|
||||
},
|
||||
@ -43,7 +44,7 @@ impl fmt::Display for SymbolSpec {
|
||||
use self::SymbolSpec::*;
|
||||
match self {
|
||||
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 }
|
||||
);
|
||||
},
|
||||
TypeDecl { name: TypeSingletonName { name, params}, body: TypeBody(variants), mutable } => {
|
||||
for var in variants {
|
||||
TypeDecl { name: TypeSingletonName { name, params}, body: TypeBody(variants), mutable, } => {
|
||||
for (index, var) in variants.iter().enumerate() {
|
||||
match var {
|
||||
Variant::UnitStruct(variant_name) => {
|
||||
let spec = SymbolSpec::DataConstructor {
|
||||
index,
|
||||
type_name: name.clone(),
|
||||
type_args: vec![],
|
||||
};
|
||||
@ -95,6 +97,7 @@ impl SymbolTable {
|
||||
TypeName::Tuple(_) => unimplemented!(),
|
||||
}).collect();
|
||||
let spec = SymbolSpec::DataConstructor {
|
||||
index,
|
||||
type_name: name.clone(),
|
||||
type_args
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user