Symbol has DefId not Option<DefId>
This commit is contained in:
parent
354dd7d8c1
commit
b778428e98
@ -32,7 +32,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
// First reduce all functions
|
// First reduce all functions
|
||||||
// TODO once this works, maybe rewrite it using the Visitor
|
// TODO once this works, maybe rewrite it using the Visitor
|
||||||
for statement in ast.statements.statements.iter() {
|
for statement in ast.statements.statements.iter() {
|
||||||
self.top_level_statement(statement);
|
self.top_level_definition(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then compute the entrypoint statements (which may reference previously-computed
|
// Then compute the entrypoint statements (which may reference previously-computed
|
||||||
@ -51,7 +51,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
||||||
let def_id = symbol.def_id().unwrap();
|
let def_id = symbol.def_id();
|
||||||
entrypoint.push(Statement::Binding {
|
entrypoint.push(Statement::Binding {
|
||||||
id: def_id,
|
id: def_id,
|
||||||
constant: *constant,
|
constant: *constant,
|
||||||
@ -65,7 +65,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
ReducedIR { functions: self.functions, entrypoint }
|
ReducedIR { functions: self.functions, entrypoint }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn top_level_statement(&mut self, statement: &ast::Statement) {
|
fn top_level_definition(&mut self, statement: &ast::Statement) {
|
||||||
let ast::Statement { id: item_id, kind, .. } = statement;
|
let ast::Statement { id: item_id, kind, .. } = statement;
|
||||||
match kind {
|
match kind {
|
||||||
ast::StatementKind::Expression(_expr) => {
|
ast::StatementKind::Expression(_expr) => {
|
||||||
@ -96,7 +96,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
}
|
}
|
||||||
ast::Declaration::Binding { constant, expr, .. } => {
|
ast::Declaration::Binding { constant, expr, .. } => {
|
||||||
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
||||||
let def_id = symbol.def_id().unwrap();
|
let def_id = symbol.def_id();
|
||||||
Some(Statement::Binding { id: def_id, constant: *constant, expr: self.expression(expr) })
|
Some(Statement::Binding { id: def_id, constant: *constant, expr: self.expression(expr) })
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -115,7 +115,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
|
|
||||||
fn insert_function_definition(&mut self, item_id: &ast::ItemId, statements: &ast::Block) {
|
fn insert_function_definition(&mut self, item_id: &ast::ItemId, statements: &ast::Block) {
|
||||||
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
||||||
let def_id = symbol.def_id().unwrap();
|
let def_id = symbol.def_id();
|
||||||
let function_def = FunctionDefinition { body: self.function_internal_block(statements) };
|
let function_def = FunctionDefinition { body: self.function_internal_block(statements) };
|
||||||
self.functions.insert(def_id, function_def);
|
self.functions.insert(def_id, function_def);
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
let lval = match &lhs.kind {
|
let lval = match &lhs.kind {
|
||||||
ast::ExpressionKind::Value(qualified_name) => {
|
ast::ExpressionKind::Value(qualified_name) => {
|
||||||
if let Some(symbol) = self.symbol_table.lookup_symbol(&qualified_name.id) {
|
if let Some(symbol) = self.symbol_table.lookup_symbol(&qualified_name.id) {
|
||||||
symbol.def_id().unwrap()
|
symbol.def_id()
|
||||||
} else {
|
} else {
|
||||||
return ReductionError(format!("Couldn't look up name: {:?}", qualified_name));
|
return ReductionError(format!("Couldn't look up name: {:?}", qualified_name));
|
||||||
}
|
}
|
||||||
@ -339,9 +339,9 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
|
|
||||||
match symbol.spec() {
|
match symbol.spec() {
|
||||||
Builtin(b) => Expression::Callable(Callable::Builtin(b)),
|
Builtin(b) => Expression::Callable(Callable::Builtin(b)),
|
||||||
Func { .. } => Expression::Lookup(Lookup::Function(def_id.unwrap())),
|
Func { .. } => Expression::Lookup(Lookup::Function(def_id)),
|
||||||
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
|
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id)),
|
||||||
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
|
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id)),
|
||||||
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
|
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
|
||||||
DataConstructor { tag, type_id } =>
|
DataConstructor { tag, type_id } =>
|
||||||
Expression::Callable(Callable::DataConstructor { type_id, tag }),
|
Expression::Callable(Callable::DataConstructor { type_id, tag }),
|
||||||
@ -394,7 +394,7 @@ impl ast::Pattern {
|
|||||||
SymbolSpec::DataConstructor { tag, type_id: _ } =>
|
SymbolSpec::DataConstructor { tag, type_id: _ } =>
|
||||||
Pattern::Tuple { tag: Some(tag), subpatterns: vec![] },
|
Pattern::Tuple { tag: Some(tag), subpatterns: vec![] },
|
||||||
SymbolSpec::LocalVariable => {
|
SymbolSpec::LocalVariable => {
|
||||||
let def_id = symbol.def_id().unwrap();
|
let def_id = symbol.def_id();
|
||||||
Pattern::Binding(def_id)
|
Pattern::Binding(def_id)
|
||||||
}
|
}
|
||||||
spec => return Err(format!("Unexpected VarOrName symbol: {:?}", spec).into()),
|
spec => return Err(format!("Unexpected VarOrName symbol: {:?}", spec).into()),
|
||||||
|
@ -188,8 +188,8 @@ impl Symbol {
|
|||||||
self.local_name.as_ref()
|
self.local_name.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_id(&self) -> Option<DefId> {
|
pub fn def_id(&self) -> DefId {
|
||||||
Some(self.def_id)
|
self.def_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spec(&self) -> SymbolSpec {
|
pub fn spec(&self) -> SymbolSpec {
|
||||||
|
Loading…
Reference in New Issue
Block a user