Make Func more complex

This commit is contained in:
Greg Shuflin 2021-11-26 02:26:46 -08:00
parent 9d9331f4b0
commit 0eccceabd9
3 changed files with 7 additions and 7 deletions

View File

@ -339,7 +339,7 @@ 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.unwrap())),
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())), GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())), LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)), FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),

View File

@ -114,7 +114,7 @@ impl SymbolTable {
) -> Result<(), Vec<SymbolError>> { ) -> Result<(), Vec<SymbolError>> {
let mut populator = SymbolTablePopulator { type_context, table: self }; let mut populator = SymbolTablePopulator { type_context, table: self };
let errs = populator.populate_name_tables(ast); let errs = populator.populate_definition_tables(ast);
if !errs.is_empty() { if !errs.is_empty() {
return Err(errs); return Err(errs);
} }
@ -212,7 +212,7 @@ impl fmt::Display for Symbol {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum SymbolSpec { pub enum SymbolSpec {
Builtin(Builtin), Builtin(Builtin),
Func, Func { method: Option<crate::ast::TypeSingletonName> },
DataConstructor { tag: u32, type_id: TypeId }, DataConstructor { tag: u32, type_id: TypeId },
RecordConstructor { tag: u32, type_id: TypeId }, RecordConstructor { tag: u32, type_id: TypeId },
GlobalBinding, //Only for global variables, not for function-local ones or ones within a `let` scope context GlobalBinding, //Only for global variables, not for function-local ones or ones within a `let` scope context
@ -225,7 +225,7 @@ impl fmt::Display for SymbolSpec {
use self::SymbolSpec::*; use self::SymbolSpec::*;
match self { match self {
Builtin(b) => write!(f, "Builtin: {:?}", b), Builtin(b) => write!(f, "Builtin: {:?}", b),
Func => write!(f, "Func"), Func { .. } => write!(f, "Func"),
DataConstructor { tag, type_id } => write!(f, "DataConstructor(tag: {}, type: {})", tag, type_id), DataConstructor { tag, type_id } => write!(f, "DataConstructor(tag: {}, type: {})", tag, type_id),
RecordConstructor { type_id, tag, .. } => RecordConstructor { type_id, tag, .. } =>
write!(f, "RecordConstructor(tag: {})(<members> -> {})", tag, type_id), write!(f, "RecordConstructor(tag: {})(<members> -> {})", tag, type_id),

View File

@ -32,7 +32,7 @@ impl<'a> SymbolTablePopulator<'a> {
/// constants, functions, types, and modules defined within. This simultaneously /// constants, functions, types, and modules defined within. This simultaneously
/// checks for dupicate definitions (and returns errors if discovered), and sets /// checks for dupicate definitions (and returns errors if discovered), and sets
/// up name tables that will be used by further parts of the compiler /// up name tables that will be used by further parts of the compiler
pub fn populate_name_tables(&mut self, ast: &AST) -> Vec<SymbolError> { pub fn populate_definition_tables(&mut self, ast: &AST) -> Vec<SymbolError> {
let mut scope_stack = vec![]; let mut scope_stack = vec![];
self.add_from_scope(ast.statements.as_ref(), &mut scope_stack, false) self.add_from_scope(ast.statements.as_ref(), &mut scope_stack, false)
} }
@ -94,7 +94,7 @@ impl<'a> SymbolTablePopulator<'a> {
.register(fq_function.clone(), NameSpec { location, kind: NameKind::Function })?; .register(fq_function.clone(), NameSpec { location, kind: NameKind::Function })?;
self.table.types.register(fq_function.clone(), NameSpec { location, kind: TypeKind })?; self.table.types.register(fq_function.clone(), NameSpec { location, kind: TypeKind })?;
self.add_symbol(id, fq_function, SymbolSpec::Func); self.add_symbol(id, fq_function, SymbolSpec::Func { method: None });
} }
StatementKind::Declaration(Declaration::FuncDecl(signature, ..)) => { StatementKind::Declaration(Declaration::FuncDecl(signature, ..)) => {
let fn_name = &signature.name; let fn_name = &signature.name;
@ -104,7 +104,7 @@ impl<'a> SymbolTablePopulator<'a> {
.register(fq_function.clone(), NameSpec { location, kind: NameKind::Function })?; .register(fq_function.clone(), NameSpec { location, kind: NameKind::Function })?;
self.table.types.register(fq_function.clone(), NameSpec { location, kind: TypeKind })?; self.table.types.register(fq_function.clone(), NameSpec { location, kind: TypeKind })?;
self.add_symbol(id, fq_function, SymbolSpec::Func); self.add_symbol(id, fq_function, SymbolSpec::Func { method: None });
} }
StatementKind::Declaration(Declaration::TypeDecl { name, .. }) => { StatementKind::Declaration(Declaration::TypeDecl { name, .. }) => {
let fq_type = Fqsn::from_scope_stack(scope_stack, name.name.clone()); let fq_type = Fqsn::from_scope_stack(scope_stack, name.name.clone());