Compare commits
3 Commits
851fd9885f
...
264fc2ae58
Author | SHA1 | Date | |
---|---|---|---|
|
264fc2ae58 | ||
|
e4592ddfb2 | ||
|
8896b1a7a7 |
@ -136,7 +136,28 @@ impl<'a> Reducer<'a> {
|
||||
body: self.function_internal_block(body),
|
||||
})
|
||||
},
|
||||
NamedStruct { .. } => Expression::ReductionError("NamedStruct not implemented".to_string()), //self.reduce_named_struct(name, fields),
|
||||
NamedStruct { name, fields } => {
|
||||
let symbol = self.symbol_table.lookup_symbol(&name.id).unwrap();
|
||||
let constructor = match symbol.spec() {
|
||||
SymbolSpec::RecordConstructor { index, members: _, type_id } => Expression::Callable(Callable::RecordConstructor {
|
||||
type_id,
|
||||
tag: index as u32,
|
||||
}),
|
||||
e => return Expression::ReductionError(format!("Bad symbol for NamedStruct: {:?}", e)),
|
||||
};
|
||||
|
||||
//TODO need to order the fields correctly, which needs symbol table information
|
||||
// Until this happens, NamedStructs won't work
|
||||
let mut ordered_args = vec![];
|
||||
for (_name, _type_id) in fields {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
Expression::Call {
|
||||
f: Box::new(constructor),
|
||||
args: ordered_args,
|
||||
}
|
||||
},
|
||||
Index { .. } => Expression::ReductionError("Index expr not implemented".to_string()),
|
||||
WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()),
|
||||
ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()),
|
||||
@ -356,199 +377,13 @@ impl ast::Pattern {
|
||||
spec => return Err(format!("Unexpected VarOrName symbol: {:?}", spec).into())
|
||||
}
|
||||
},
|
||||
ast::Pattern::Record(_name, _members/*Vec<(Rc<String>, Pattern)>*/) => {
|
||||
unimplemented!()
|
||||
},
|
||||
ast::Pattern::Record(name, _specified_members/*Vec<(Rc<String>, Pattern)>*/) => {
|
||||
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
||||
match symbol.spec() {
|
||||
SymbolSpec::RecordConstructor { index: _, members: _, type_id: _ } => unimplemented!(),
|
||||
spec => return Err(format!("Unexpected Record pattern symbol: {:?}", spec).into())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl ast::Pattern {
|
||||
fn to_subpattern(&self, symbol_table: &SymbolTable) -> Subpattern {
|
||||
use ast::Pattern::*;
|
||||
use Expression::ReductionError;
|
||||
|
||||
match self {
|
||||
Ignored => Subpattern {
|
||||
tag: None,
|
||||
subpatterns: vec![],
|
||||
guard: None,
|
||||
},
|
||||
Literal(lit) => lit.to_subpattern(symbol_table),
|
||||
/*
|
||||
TupleStruct(QualifiedName { components, id }, inner_patterns) => {
|
||||
match symbol_table.lookup_symbol(id) {
|
||||
Some(symbol) => handle_symbol(Some(symbol), inner_patterns, symbol_table),
|
||||
None => panic!("Symbol {:?} not found", components),
|
||||
}
|
||||
}
|
||||
*/
|
||||
_ => Subpattern {
|
||||
tag: None,
|
||||
subpatterns: vec![],
|
||||
guard: None,
|
||||
}
|
||||
}
|
||||
/*
|
||||
TuplePattern(inner_patterns) => handle_symbol(None, inner_patterns, symbol_table),
|
||||
Record(_name, _pairs) => {
|
||||
unimplemented!()
|
||||
}
|
||||
VarOrName(QualifiedName { components, id }) => {
|
||||
// if symbol is Some, treat this as a symbol pattern. If it's None, treat it
|
||||
// as a variable.
|
||||
match symbol_table.lookup_symbol(id) {
|
||||
Some(symbol) => handle_symbol(Some(symbol), &[], symbol_table),
|
||||
None => {
|
||||
println!("Components: {:?}", components);
|
||||
let name = if components.len() == 1 {
|
||||
components[0].clone()
|
||||
} else {
|
||||
panic!("check this line of code yo");
|
||||
};
|
||||
Subpattern {
|
||||
tag: None,
|
||||
subpatterns: vec![],
|
||||
guard: None,
|
||||
bound_vars: vec![Some(name)],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
fn handle_symbol(
|
||||
symbol: Option<&Symbol>,
|
||||
inner_patterns: &[Pattern],
|
||||
symbol_table: &SymbolTable,
|
||||
) -> Subpattern {
|
||||
use ast::Pattern::*;
|
||||
|
||||
let tag = symbol.map(|symbol| match symbol.spec {
|
||||
SymbolSpec::DataConstructor { index, .. } => index,
|
||||
_ => {
|
||||
panic!("Symbol is not a data constructor - this should've been caught in type-checking")
|
||||
}
|
||||
});
|
||||
let bound_vars = inner_patterns
|
||||
.iter()
|
||||
.map(|p| match p {
|
||||
VarOrName(qualified_name) => {
|
||||
let symbol_exists = symbol_table.lookup_symbol(&qualified_name.id).is_some();
|
||||
if symbol_exists {
|
||||
None
|
||||
} else {
|
||||
let QualifiedName { components, .. } = qualified_name;
|
||||
if components.len() == 1 {
|
||||
Some(components[0].clone())
|
||||
} else {
|
||||
panic!("Bad variable name in pattern");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let subpatterns = inner_patterns
|
||||
.iter()
|
||||
.map(|p| match p {
|
||||
Ignored => None,
|
||||
VarOrName(_) => None,
|
||||
Literal(other) => Some(other.to_subpattern(symbol_table)),
|
||||
tp @ TuplePattern(_) => Some(tp.to_subpattern(symbol_table)),
|
||||
ts @ TupleStruct(_, _) => Some(ts.to_subpattern(symbol_table)),
|
||||
Record(..) => unimplemented!(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let guard = None;
|
||||
/*
|
||||
let guard_equality_exprs: Vec<Expr> = subpatterns.iter().map(|p| match p {
|
||||
Literal(lit) => match lit {
|
||||
_ => unimplemented!()
|
||||
},
|
||||
_ => unimplemented!()
|
||||
}).collect();
|
||||
*/
|
||||
|
||||
Subpattern {
|
||||
tag,
|
||||
subpatterns,
|
||||
guard,
|
||||
bound_vars,
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
impl ast::PatternLiteral {
|
||||
fn to_subpattern(&self, _symbol_table: &SymbolTable) -> Subpattern {
|
||||
use ast::PatternLiteral::*;
|
||||
|
||||
match self {
|
||||
NumPattern { neg, num } => {
|
||||
let comparison = Expression::Literal(match (neg, num) {
|
||||
(false, ast::ExpressionKind::NatLiteral(n)) => Literal::Nat(*n),
|
||||
(false, ast::ExpressionKind::FloatLiteral(f)) => Literal::Float(*f),
|
||||
(true, ast::ExpressionKind::NatLiteral(n)) => Literal::Int(-(*n as i64)),
|
||||
(true, ast::ExpressionKind::FloatLiteral(f)) => Literal::Float(-f),
|
||||
_ => panic!("This should never happen"),
|
||||
});
|
||||
unimplemented!()
|
||||
/*
|
||||
let guard = Some(Expr::Call {
|
||||
f: Box::new(Expr::Func(Func::BuiltIn(Builtin::Equality))),
|
||||
args: vec![comparison, Expr::ConditionalTargetSigilValue],
|
||||
});
|
||||
Subpattern {
|
||||
tag: None,
|
||||
subpatterns: vec![],
|
||||
guard,
|
||||
}
|
||||
*/
|
||||
}
|
||||
_ => unimplemented!()
|
||||
/*
|
||||
StringPattern(s) => {
|
||||
let guard = Some(Expr::Call {
|
||||
f: Box::new(Expr::Func(Func::BuiltIn(Builtin::Equality))),
|
||||
args: vec![
|
||||
Expr::Lit(Lit::StringLit(s.clone())),
|
||||
Expr::ConditionalTargetSigilValue,
|
||||
],
|
||||
});
|
||||
|
||||
Subpattern {
|
||||
tag: None,
|
||||
subpatterns: vec![],
|
||||
guard,
|
||||
bound_vars: vec![],
|
||||
}
|
||||
}
|
||||
BoolPattern(b) => {
|
||||
let guard = Some(if *b {
|
||||
Expr::ConditionalTargetSigilValue
|
||||
} else {
|
||||
Expr::Call {
|
||||
f: Box::new(Expr::Func(Func::BuiltIn(Builtin::BooleanNot))),
|
||||
args: vec![Expr::ConditionalTargetSigilValue],
|
||||
}
|
||||
});
|
||||
Subpattern {
|
||||
tag: None,
|
||||
subpatterns: vec![],
|
||||
guard,
|
||||
bound_vars: vec![],
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -98,6 +98,10 @@ pub enum Callable {
|
||||
arity: u32,
|
||||
tag: u32
|
||||
},
|
||||
RecordConstructor {
|
||||
type_id: TypeId,
|
||||
tag: u32,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -358,6 +358,9 @@ impl<'a> State<'a> {
|
||||
items: evaluated_args
|
||||
})
|
||||
}
|
||||
Callable::RecordConstructor { type_id: _, tag: _ } => {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user