2021-10-21 15:23:48 -07:00
|
|
|
use crate::ast;
|
2021-10-25 13:03:31 -07:00
|
|
|
use crate::symbol_table::{DefId, SymbolSpec, SymbolTable};
|
2021-10-21 15:23:48 -07:00
|
|
|
use crate::builtin::Builtin;
|
|
|
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2021-10-24 15:59:40 -07:00
|
|
|
mod types;
|
2021-10-21 15:23:48 -07:00
|
|
|
mod test;
|
|
|
|
|
2021-10-24 15:59:40 -07:00
|
|
|
pub use types::*;
|
|
|
|
|
2021-10-21 15:23:48 -07:00
|
|
|
pub fn reduce(ast: &ast::AST, symbol_table: &SymbolTable) -> ReducedIR {
|
|
|
|
let reducer = Reducer::new(symbol_table);
|
|
|
|
reducer.reduce(ast)
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Reducer<'a> {
|
|
|
|
symbol_table: &'a SymbolTable,
|
2021-10-24 02:54:21 -07:00
|
|
|
functions: HashMap<DefId, FunctionDefinition>,
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Reducer<'a> {
|
|
|
|
fn new(symbol_table: &'a SymbolTable) -> Self {
|
|
|
|
Self {
|
|
|
|
symbol_table,
|
|
|
|
functions: HashMap::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reduce(mut self, ast: &ast::AST) -> ReducedIR {
|
|
|
|
// First reduce all functions
|
|
|
|
// TODO once this works, maybe rewrite it using the Visitor
|
2021-10-26 14:05:27 -07:00
|
|
|
for statement in ast.statements.statements.iter() {
|
2021-10-26 13:37:03 -07:00
|
|
|
self.top_level_statement(statement);
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then compute the entrypoint statements (which may reference previously-computed
|
|
|
|
// functions by ID)
|
|
|
|
let mut entrypoint = vec![];
|
2021-10-26 14:05:27 -07:00
|
|
|
for statement in ast.statements.statements.iter() {
|
2021-10-21 15:23:48 -07:00
|
|
|
let ast::Statement { id: item_id, kind, .. } = statement;
|
|
|
|
match &kind {
|
|
|
|
ast::StatementKind::Expression(expr) => {
|
2021-10-26 13:37:03 -07:00
|
|
|
entrypoint.push(Statement::Expression(self.expression(expr)));
|
2021-10-21 15:23:48 -07:00
|
|
|
},
|
2021-10-24 22:39:11 -07:00
|
|
|
ast::StatementKind::Declaration(ast::Declaration::Binding { name: _, constant, expr, ..}) => {
|
2021-10-21 15:23:48 -07:00
|
|
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
2021-10-25 13:03:31 -07:00
|
|
|
let def_id = symbol.def_id().unwrap();
|
2021-10-26 13:37:03 -07:00
|
|
|
entrypoint.push(Statement::Binding { id: def_id, constant: *constant, expr: self.expression(expr) });
|
2021-10-21 15:23:48 -07:00
|
|
|
},
|
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReducedIR {
|
|
|
|
functions: self.functions,
|
|
|
|
entrypoint,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn top_level_statement(&mut self, statement: &ast::Statement) {
|
|
|
|
let ast::Statement { id: item_id, kind, .. } = statement;
|
|
|
|
match kind {
|
|
|
|
ast::StatementKind::Expression(_expr) => {
|
|
|
|
//TODO expressions can in principle contain definitions, but I won't worry
|
|
|
|
//about it now
|
|
|
|
},
|
2021-10-26 13:37:03 -07:00
|
|
|
ast::StatementKind::Declaration(decl) => {
|
|
|
|
if let ast::Declaration::FuncDecl(_, statements) = decl {
|
2021-10-21 15:23:48 -07:00
|
|
|
self.insert_function_definition(item_id, statements);
|
2021-10-26 13:37:03 -07:00
|
|
|
}
|
2021-10-21 15:23:48 -07:00
|
|
|
},
|
|
|
|
ast::StatementKind::Import(..) => (),
|
2021-10-24 22:39:11 -07:00
|
|
|
ast::StatementKind::Module(_modspec) => {
|
2021-10-21 15:23:48 -07:00
|
|
|
//TODO handle modules
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn function_internal_statement(&mut self, statement: &ast::Statement) -> Option<Statement> {
|
|
|
|
let ast::Statement { id: item_id, kind, .. } = statement;
|
|
|
|
match kind {
|
|
|
|
ast::StatementKind::Expression(expr) => {
|
|
|
|
Some(Statement::Expression(self.expression(expr)))
|
|
|
|
},
|
|
|
|
ast::StatementKind::Declaration(decl) => match decl {
|
|
|
|
ast::Declaration::FuncDecl(_, statements) => {
|
|
|
|
self.insert_function_definition(item_id, statements);
|
|
|
|
None
|
|
|
|
},
|
2021-10-25 01:02:19 -07:00
|
|
|
ast::Declaration::Binding { constant, expr, ..} => {
|
|
|
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
2021-10-25 13:03:31 -07:00
|
|
|
let def_id = symbol.def_id().unwrap();
|
2021-10-26 13:37:03 -07:00
|
|
|
Some(Statement::Binding { id: def_id, constant: *constant, expr: self.expression(expr) })
|
2021-10-25 01:02:19 -07:00
|
|
|
},
|
|
|
|
|
2021-10-21 15:23:48 -07:00
|
|
|
_ => None
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn insert_function_definition(&mut self, item_id: &ast::ItemId, statements: &ast::Block) {
|
|
|
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
2021-10-25 13:03:31 -07:00
|
|
|
let def_id = symbol.def_id().unwrap();
|
2021-10-24 02:54:21 -07:00
|
|
|
let function_def = FunctionDefinition {
|
2021-10-25 20:26:53 -07:00
|
|
|
body: self.function_internal_block(statements)
|
2021-10-21 15:23:48 -07:00
|
|
|
};
|
2021-10-24 02:54:21 -07:00
|
|
|
self.functions.insert(def_id, function_def);
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn expression(&mut self, expr: &ast::Expression) -> Expression {
|
|
|
|
use crate::ast::ExpressionKind::*;
|
|
|
|
|
|
|
|
match &expr.kind {
|
|
|
|
NatLiteral(n) => Expression::Literal(Literal::Nat(*n)),
|
|
|
|
FloatLiteral(f) => Expression::Literal(Literal::Float(*f)),
|
|
|
|
StringLiteral(s) => Expression::Literal(Literal::StringLit(s.clone())),
|
|
|
|
BoolLiteral(b) => Expression::Literal(Literal::Bool(*b)),
|
|
|
|
BinExp(binop, lhs, rhs) => self.binop(binop, lhs, rhs),
|
|
|
|
PrefixExp(op, arg) => self.prefix(op, arg),
|
|
|
|
Value(qualified_name) => self.value(qualified_name),
|
2021-10-24 17:57:56 -07:00
|
|
|
Call { f, arguments } => Expression::Call {
|
|
|
|
f: Box::new(self.expression(f)),
|
|
|
|
args: arguments
|
|
|
|
.iter()
|
|
|
|
.map(|arg| self.invocation_argument(arg))
|
|
|
|
.collect(),
|
|
|
|
},
|
2021-10-21 15:23:48 -07:00
|
|
|
TupleLiteral(exprs) => Expression::Tuple(exprs.iter().map(|e| self.expression(e)).collect()),
|
2021-10-24 21:15:58 -07:00
|
|
|
IfExpression { discriminator, body, } => self.reduce_if_expression(discriminator.as_ref().map(|x| x.as_ref()), body),
|
2021-10-24 18:59:00 -07:00
|
|
|
Lambda { params, body, .. } => {
|
2021-10-25 19:08:03 -07:00
|
|
|
Expression::Callable(Callable::Lambda {
|
2021-10-24 18:59:00 -07:00
|
|
|
arity: params.len() as u8,
|
2021-10-25 20:26:53 -07:00
|
|
|
body: self.function_internal_block(body),
|
2021-10-24 18:59:00 -07:00
|
|
|
})
|
|
|
|
},
|
2021-10-26 15:30:42 -07:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
},
|
2021-10-24 22:13:31 -07:00
|
|
|
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()),
|
|
|
|
ListLiteral { .. } => Expression::ReductionError("ListLiteral expr not implemented".to_string()),
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:26:53 -07:00
|
|
|
fn reduce_if_expression(&mut self, discriminator: Option<&ast::Expression>, body: &ast::IfExpressionBody) -> Expression {
|
2021-10-25 21:19:26 -07:00
|
|
|
use ast::IfExpressionBody::*;
|
|
|
|
|
2021-10-25 20:26:53 -07:00
|
|
|
let cond = Box::new(match discriminator {
|
|
|
|
Some(expr) => self.expression(expr),
|
|
|
|
None => return Expression::ReductionError("blank cond if-expr not supported".to_string()),
|
|
|
|
});
|
|
|
|
match body {
|
2021-10-25 21:19:26 -07:00
|
|
|
SimpleConditional {
|
2021-10-25 20:26:53 -07:00
|
|
|
then_case,
|
|
|
|
else_case,
|
|
|
|
} => {
|
|
|
|
let then_clause = self.function_internal_block(then_case);
|
|
|
|
let else_clause = match else_case.as_ref() {
|
|
|
|
None => vec![],
|
|
|
|
Some(stmts) => self.function_internal_block(stmts),
|
|
|
|
};
|
|
|
|
Expression::Conditional {
|
|
|
|
cond,
|
|
|
|
then_clause,
|
|
|
|
else_clause,
|
|
|
|
}
|
|
|
|
},
|
2021-10-25 21:19:26 -07:00
|
|
|
SimplePatternMatch {
|
|
|
|
pattern,
|
|
|
|
then_case,
|
|
|
|
else_case,
|
|
|
|
} => {
|
|
|
|
let alternatives = vec![
|
|
|
|
Alternative {
|
2021-10-25 22:39:29 -07:00
|
|
|
pattern: match pattern.reduce(self.symbol_table) {
|
|
|
|
Ok(p) => p,
|
|
|
|
Err(e) => return Expression::ReductionError(format!("Bad pattern: {:?}", e)),
|
|
|
|
},
|
2021-10-25 21:19:26 -07:00
|
|
|
item: self.function_internal_block(then_case),
|
|
|
|
},
|
|
|
|
Alternative {
|
2021-10-25 22:39:29 -07:00
|
|
|
pattern: Pattern::Ignored,
|
2021-10-25 21:19:26 -07:00
|
|
|
item: match else_case.as_ref() {
|
|
|
|
Some(else_case) => self.function_internal_block(else_case),
|
|
|
|
None => vec![],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
Expression::CaseMatch { cond, alternatives }
|
|
|
|
},
|
|
|
|
CondList(ref condition_arms) => {
|
2021-10-25 23:26:03 -07:00
|
|
|
let mut alternatives = vec![];
|
|
|
|
for arm in condition_arms {
|
|
|
|
match arm.condition {
|
|
|
|
ast::Condition::Expression(ref _expr) => return Expression::ReductionError("case-expression".to_string()),
|
|
|
|
ast::Condition::Pattern(ref pat) => {
|
|
|
|
let alt = Alternative {
|
|
|
|
pattern: match pat.reduce(self.symbol_table) {
|
|
|
|
Ok(p) => p,
|
|
|
|
Err(e) => return Expression::ReductionError(format!("Bad pattern: {:?}", e)),
|
|
|
|
},
|
|
|
|
item: self.function_internal_block(&arm.body),
|
|
|
|
};
|
|
|
|
alternatives.push(alt);
|
|
|
|
},
|
|
|
|
ast::Condition::TruncatedOp(_, _) => return Expression::ReductionError("case-expression-trunc-op".to_string()),
|
|
|
|
ast::Condition::Else => return Expression::ReductionError("case-expression-else".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Expression::CaseMatch { cond, alternatives }
|
2021-10-25 21:19:26 -07:00
|
|
|
}
|
2021-10-25 20:26:53 -07:00
|
|
|
}
|
2021-10-24 21:15:58 -07:00
|
|
|
}
|
|
|
|
|
2021-10-24 17:57:56 -07:00
|
|
|
fn invocation_argument(&mut self, invoc: &ast::InvocationArgument) -> Expression {
|
|
|
|
use crate::ast::InvocationArgument::*;
|
|
|
|
match invoc {
|
|
|
|
Positional(ex) => self.expression(ex),
|
|
|
|
Keyword { .. } => Expression::ReductionError("Keyword arguments not supported".to_string()),
|
|
|
|
Ignored => Expression::ReductionError("Ignored arguments not supported".to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 14:05:27 -07:00
|
|
|
fn function_internal_block(&mut self, block: &ast::Block) -> Vec<Statement> {
|
|
|
|
block.statements.iter().filter_map(|stmt| self.function_internal_statement(stmt)).collect()
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn prefix(&mut self, prefix: &ast::PrefixOp, arg: &ast::Expression) -> Expression {
|
|
|
|
let builtin: Option<Builtin> = TryFrom::try_from(prefix).ok();
|
|
|
|
match builtin {
|
|
|
|
Some(op) => {
|
|
|
|
Expression::Call {
|
2021-10-25 19:08:03 -07:00
|
|
|
f: Box::new(Expression::Callable(Callable::Builtin(op))),
|
2021-10-21 15:23:48 -07:00
|
|
|
args: vec![self.expression(arg)],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
//TODO need this for custom prefix ops
|
2021-10-24 22:13:31 -07:00
|
|
|
Expression::ReductionError("User-defined prefix ops not supported".to_string())
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn binop(&mut self, binop: &ast::BinOp, lhs: &ast::Expression, rhs: &ast::Expression) -> Expression {
|
2021-10-25 19:08:03 -07:00
|
|
|
use Expression::ReductionError;
|
|
|
|
|
2021-10-21 15:23:48 -07:00
|
|
|
let operation = Builtin::from_str(binop.sigil()).ok();
|
|
|
|
match operation {
|
|
|
|
Some(Builtin::Assignment) => {
|
|
|
|
let lval = match &lhs.kind {
|
|
|
|
ast::ExpressionKind::Value(qualified_name) => {
|
2021-10-25 13:03:31 -07:00
|
|
|
if let Some(symbol) = self.symbol_table.lookup_symbol(&qualified_name.id) {
|
|
|
|
symbol.def_id().unwrap()
|
2021-10-21 15:23:48 -07:00
|
|
|
} else {
|
|
|
|
return ReductionError(format!("Couldn't look up name: {:?}", qualified_name));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => return ReductionError("Trying to assign to a non-name".to_string()),
|
|
|
|
};
|
|
|
|
|
2021-10-25 19:08:03 -07:00
|
|
|
Expression::Assign {
|
2021-10-21 15:23:48 -07:00
|
|
|
lval,
|
|
|
|
rval: Box::new(self.expression(rhs)),
|
|
|
|
}
|
|
|
|
},
|
2021-10-25 15:53:54 -07:00
|
|
|
Some(op) => Expression::Call {
|
2021-10-25 19:08:03 -07:00
|
|
|
f: Box::new(Expression::Callable(Callable::Builtin(op))),
|
2021-10-25 15:53:54 -07:00
|
|
|
args: vec![self.expression(lhs), self.expression(rhs)],
|
|
|
|
},
|
|
|
|
//TODO handle a user-defined operation
|
|
|
|
None => ReductionError("User-defined operations not supported".to_string())
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn value(&mut self, qualified_name: &ast::QualifiedName) -> Expression {
|
2021-10-24 02:54:21 -07:00
|
|
|
use SymbolSpec::*;
|
|
|
|
|
|
|
|
let symbol = match self.symbol_table.lookup_symbol(&qualified_name.id) {
|
|
|
|
Some(s) => s,
|
|
|
|
None => return Expression::ReductionError(format!("No symbol found for name: {:?}", qualified_name))
|
|
|
|
};
|
2021-10-25 13:03:31 -07:00
|
|
|
|
|
|
|
let def_id = symbol.def_id();
|
|
|
|
|
|
|
|
match symbol.spec() {
|
2021-10-25 16:12:24 -07:00
|
|
|
Func => Expression::Lookup(Lookup::Function(def_id.unwrap())),
|
2021-10-25 14:37:12 -07:00
|
|
|
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
|
|
|
|
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
|
|
|
|
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
|
2021-10-25 19:08:03 -07:00
|
|
|
DataConstructor { index, arity, type_id } => Expression::Callable(Callable::DataConstructor {
|
2021-10-26 13:37:03 -07:00
|
|
|
type_id,
|
2021-10-25 19:08:03 -07:00
|
|
|
arity: arity as u32, //TODO fix up these modifiers
|
|
|
|
tag: index as u32,
|
|
|
|
}),
|
2021-10-24 02:54:21 -07:00
|
|
|
RecordConstructor { .. } => {
|
|
|
|
Expression::ReductionError(format!("The symbol for value {:?} is unexpectdly a RecordConstructor", qualified_name))
|
|
|
|
},
|
|
|
|
}
|
2021-10-21 15:23:48 -07:00
|
|
|
}
|
|
|
|
}
|
2021-10-25 21:19:26 -07:00
|
|
|
|
|
|
|
impl ast::Pattern {
|
2021-10-25 22:39:29 -07:00
|
|
|
fn reduce(&self, symbol_table: &SymbolTable) -> Result<Pattern, PatternError> {
|
2021-10-25 23:01:32 -07:00
|
|
|
Ok(match self {
|
2021-10-26 01:53:30 -07:00
|
|
|
ast::Pattern::Ignored => Pattern::Ignored,
|
2021-10-26 00:39:24 -07:00
|
|
|
ast::Pattern::TuplePattern(subpatterns) => {
|
2021-10-26 13:37:03 -07:00
|
|
|
let items: Result<Vec<Pattern>, PatternError> = subpatterns.iter()
|
|
|
|
.map(|pat| pat.reduce(symbol_table)).into_iter().collect();
|
2021-10-26 01:53:30 -07:00
|
|
|
let items = items?;
|
|
|
|
Pattern::Tuple {
|
|
|
|
tag: None,
|
|
|
|
subpatterns: items,
|
|
|
|
}
|
2021-10-25 23:01:32 -07:00
|
|
|
},
|
|
|
|
ast::Pattern::Literal(lit) => Pattern::Literal(match lit {
|
|
|
|
ast::PatternLiteral::NumPattern { neg, num } => 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),
|
|
|
|
(_, e) => return Err(format!("Internal error, unexpected pattern literal: {:?}", e).into())
|
|
|
|
},
|
|
|
|
ast::PatternLiteral::StringPattern(s) => Literal::StringLit(s.clone()),
|
|
|
|
ast::PatternLiteral::BoolPattern(b) => Literal::Bool(*b),
|
|
|
|
}),
|
2021-10-26 01:53:30 -07:00
|
|
|
ast::Pattern::TupleStruct(name, subpatterns) => {
|
|
|
|
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
2021-10-26 13:12:24 -07:00
|
|
|
if let SymbolSpec::DataConstructor { index: tag, type_id: _, arity: _ } = symbol.spec() {
|
2021-10-26 13:37:03 -07:00
|
|
|
let items: Result<Vec<Pattern>, PatternError> = subpatterns.iter().map(|pat| pat.reduce(symbol_table))
|
|
|
|
.into_iter().collect();
|
2021-10-26 01:53:30 -07:00
|
|
|
let items = items?;
|
|
|
|
Pattern::Tuple {
|
|
|
|
tag: Some(tag as u32),
|
|
|
|
subpatterns: items,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err("Internal error, trying to match something that's not a DataConstructor".into());
|
|
|
|
}
|
2021-10-25 23:01:32 -07:00
|
|
|
},
|
2021-10-26 01:53:30 -07:00
|
|
|
ast::Pattern::VarOrName(name) => {
|
|
|
|
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
2021-10-26 13:02:40 -07:00
|
|
|
match symbol.spec() {
|
2021-10-26 13:12:24 -07:00
|
|
|
SymbolSpec::DataConstructor { index: tag, type_id: _, arity: _ } => {
|
2021-10-26 13:02:40 -07:00
|
|
|
Pattern::Tuple {
|
|
|
|
tag: Some(tag as u32),
|
|
|
|
subpatterns: vec![]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
SymbolSpec::LocalVariable => {
|
2021-10-26 13:37:03 -07:00
|
|
|
let def_id = symbol.def_id().unwrap();
|
2021-10-26 13:02:40 -07:00
|
|
|
Pattern::Binding(def_id)
|
|
|
|
},
|
|
|
|
spec => return Err(format!("Unexpected VarOrName symbol: {:?}", spec).into())
|
|
|
|
}
|
2021-10-25 23:01:32 -07:00
|
|
|
},
|
2021-10-26 14:53:28 -07:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
2021-10-25 23:01:32 -07:00
|
|
|
})
|
2021-10-25 22:39:29 -07:00
|
|
|
}
|
|
|
|
}
|