New Constructor
This commit is contained in:
parent
c637a922a9
commit
32acf89814
@ -77,7 +77,9 @@ impl Expr {
|
|||||||
UserDefined { name: None, .. } => format!("<function>"),
|
UserDefined { name: None, .. } => format!("<function>"),
|
||||||
UserDefined { name: Some(name), .. } => format!("<function {}>", name),
|
UserDefined { name: Some(name), .. } => format!("<function {}>", name),
|
||||||
},
|
},
|
||||||
Expr::Constructor { name } => format!("<constructor {}>", name),
|
Expr::NewConstructor {
|
||||||
|
type_name, tag, arity,
|
||||||
|
} => unimplemented!(),
|
||||||
Expr::Tuple(exprs) => paren_wrapped_vec(exprs),
|
Expr::Tuple(exprs) => paren_wrapped_vec(exprs),
|
||||||
_ => format!("{:?}", self),
|
_ => format!("{:?}", self),
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ pub enum Expr {
|
|||||||
NewConstructor {
|
NewConstructor {
|
||||||
type_name: Rc<String>,
|
type_name: Rc<String>,
|
||||||
tag: usize,
|
tag: usize,
|
||||||
arg: Box<Expression>,
|
arity: usize,
|
||||||
},
|
},
|
||||||
Constructor {
|
Constructor {
|
||||||
name: Rc<String>,
|
name: Rc<String>,
|
||||||
@ -117,8 +117,10 @@ impl Expression {
|
|||||||
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
||||||
Value(name) => {
|
Value(name) => {
|
||||||
match symbol_table.values.get(name) {
|
match symbol_table.values.get(name) {
|
||||||
Some(Symbol { spec: SymbolSpec::DataConstructor { type_args, .. }, .. }) => {
|
Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::NewConstructor {
|
||||||
Expr::Constructor { name: name.clone() }
|
type_name: type_name.clone(),
|
||||||
|
tag: index.clone(),
|
||||||
|
arity: type_args.len(),
|
||||||
},
|
},
|
||||||
_ => Expr::Val(name.clone()),
|
_ => Expr::Val(name.clone()),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user