All examples working again.
This commit is contained in:
parent
bb2b539f9b
commit
916b6377ac
@ -5,6 +5,7 @@ use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
|
|||||||
use dm_std_lib::add_all_std_core;
|
use dm_std_lib::add_all_std_core;
|
||||||
use dmc_lib::constants_table::ConstantsTable;
|
use dmc_lib::constants_table::ConstantsTable;
|
||||||
use dmc_lib::diagnostic::Diagnostic;
|
use dmc_lib::diagnostic::Diagnostic;
|
||||||
|
use dmc_lib::intrinsics::{insert_intrinsic_symbols, insert_intrinsic_types};
|
||||||
use dmc_lib::parser::parse_compilation_unit;
|
use dmc_lib::parser::parse_compilation_unit;
|
||||||
use dmc_lib::symbol_table::SymbolTable;
|
use dmc_lib::symbol_table::SymbolTable;
|
||||||
use dmc_lib::types_table::TypesTable;
|
use dmc_lib::types_table::TypesTable;
|
||||||
@ -43,11 +44,15 @@ fn run(
|
|||||||
let mut compilation_unit = parse_compilation_unit(&input)?;
|
let mut compilation_unit = parse_compilation_unit(&input)?;
|
||||||
|
|
||||||
let mut symbol_table = SymbolTable::new();
|
let mut symbol_table = SymbolTable::new();
|
||||||
|
symbol_table.push_module_scope("global scope");
|
||||||
|
insert_intrinsic_symbols(&mut symbol_table);
|
||||||
let mut types_table = TypesTable::new();
|
let mut types_table = TypesTable::new();
|
||||||
|
insert_intrinsic_types(&symbol_table, &mut types_table);
|
||||||
|
|
||||||
compilation_unit.init_scopes(&mut symbol_table);
|
compilation_unit.init_scopes(&mut symbol_table);
|
||||||
compilation_unit.gather_symbols_into(&mut symbol_table)?;
|
compilation_unit.gather_symbols_into(&mut symbol_table)?;
|
||||||
compilation_unit.check_names(&mut symbol_table)?;
|
compilation_unit.check_names(&mut symbol_table)?;
|
||||||
|
compilation_unit.gather_types_into(&symbol_table, &mut types_table)?;
|
||||||
compilation_unit.type_check(&symbol_table, &mut types_table)?;
|
compilation_unit.type_check(&symbol_table, &mut types_table)?;
|
||||||
|
|
||||||
let (ir_classes, mut ir_functions) = compilation_unit.to_ir(&symbol_table, &types_table);
|
let (ir_classes, mut ir_functions) = compilation_unit.to_ir(&symbol_table, &types_table);
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use crate::source_range::SourceRange;
|
|||||||
use crate::symbol::Symbol;
|
use crate::symbol::Symbol;
|
||||||
use crate::symbol::function_symbol::FunctionSymbol;
|
use crate::symbol::function_symbol::FunctionSymbol;
|
||||||
use crate::symbol_table::SymbolTable;
|
use crate::symbol_table::SymbolTable;
|
||||||
|
use crate::type_info::TypeInfo;
|
||||||
use crate::types_table::TypesTable;
|
use crate::types_table::TypesTable;
|
||||||
use crate::{diagnostics_result, handle_diagnostics};
|
use crate::{diagnostics_result, handle_diagnostics};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -42,12 +43,13 @@ impl ExternFunction {
|
|||||||
pub fn init_scopes(&mut self, symbol_table: &mut SymbolTable, container_scope: usize) {
|
pub fn init_scopes(&mut self, symbol_table: &mut SymbolTable, container_scope: usize) {
|
||||||
self.scope_id = Some(container_scope);
|
self.scope_id = Some(container_scope);
|
||||||
|
|
||||||
symbol_table.push_function_scope(&format!("extern_function_scope({})", self.declared_name));
|
let function_scope = symbol_table
|
||||||
|
.push_function_scope(&format!("extern_function_scope({})", self.declared_name));
|
||||||
|
|
||||||
for parameter in &mut self.parameters {
|
for parameter in &mut self.parameters {
|
||||||
parameter.init_scopes(symbol_table, container_scope);
|
parameter.init_scopes(symbol_table, function_scope);
|
||||||
}
|
}
|
||||||
self.return_type.init_scopes(symbol_table, container_scope);
|
self.return_type.init_scopes(symbol_table, function_scope);
|
||||||
|
|
||||||
symbol_table.pop_scope();
|
symbol_table.pop_scope();
|
||||||
}
|
}
|
||||||
@ -85,6 +87,14 @@ impl ExternFunction {
|
|||||||
let function_symbol = symbol_table
|
let function_symbol = symbol_table
|
||||||
.get_function_symbol_owned(self.scope_id.unwrap(), self.declared_name())
|
.get_function_symbol_owned(self.scope_id.unwrap(), self.declared_name())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// self function type
|
||||||
|
types_table.function_types_mut().insert(
|
||||||
|
function_symbol.clone(),
|
||||||
|
TypeInfo::Function(function_symbol.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// return type (temporary)
|
||||||
let resolved_return_type = self
|
let resolved_return_type = self
|
||||||
.return_type
|
.return_type
|
||||||
.type_info(symbol_table, types_table)
|
.type_info(symbol_table, types_table)
|
||||||
|
|||||||
@ -268,9 +268,13 @@ impl Identifier {
|
|||||||
ExpressibleSymbol::Field(field_symbol) => {
|
ExpressibleSymbol::Field(field_symbol) => {
|
||||||
types_table.field_types().get(&field_symbol).unwrap()
|
types_table.field_types().get(&field_symbol).unwrap()
|
||||||
}
|
}
|
||||||
ExpressibleSymbol::Function(function_symbol) => {
|
ExpressibleSymbol::Function(function_symbol) => types_table
|
||||||
types_table.function_types().get(&function_symbol).unwrap()
|
.function_types()
|
||||||
}
|
.get(&function_symbol)
|
||||||
|
.expect(&format!(
|
||||||
|
"Unable to get function type for {:?}",
|
||||||
|
function_symbol
|
||||||
|
)),
|
||||||
ExpressibleSymbol::Parameter(parameter_symbol) => types_table
|
ExpressibleSymbol::Parameter(parameter_symbol) => types_table
|
||||||
.parameter_types()
|
.parameter_types()
|
||||||
.get(¶meter_symbol)
|
.get(¶meter_symbol)
|
||||||
|
|||||||
@ -23,6 +23,8 @@ pub fn insert_intrinsic_symbols(symbol_table: &mut SymbolTable) {
|
|||||||
create_simple_primitive("Int"),
|
create_simple_primitive("Int"),
|
||||||
create_simple_primitive("Double"),
|
create_simple_primitive("Double"),
|
||||||
create_simple_primitive("String"),
|
create_simple_primitive("String"),
|
||||||
|
create_simple_primitive("Void"),
|
||||||
|
create_simple_primitive("Any"),
|
||||||
];
|
];
|
||||||
for primitive in primitives {
|
for primitive in primitives {
|
||||||
symbol_table.insert_class_symbol(Rc::new(primitive));
|
symbol_table.insert_class_symbol(Rc::new(primitive));
|
||||||
@ -30,13 +32,15 @@ pub fn insert_intrinsic_symbols(symbol_table: &mut SymbolTable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_intrinsic_types(symbol_table: &SymbolTable, types_table: &mut TypesTable) {
|
pub fn insert_intrinsic_types(symbol_table: &SymbolTable, types_table: &mut TypesTable) {
|
||||||
let primitives = ["Int", "Double", "String"];
|
let primitives = ["Int", "Double", "String", "Void", "Any"];
|
||||||
for primitive in primitives {
|
for primitive in primitives {
|
||||||
let symbol = symbol_table.get_class_symbol(0, primitive).unwrap().clone();
|
let symbol = symbol_table.get_class_symbol(0, primitive).unwrap().clone();
|
||||||
let type_info = match primitive {
|
let type_info = match primitive {
|
||||||
"Int" => TypeInfo::Integer,
|
"Int" => TypeInfo::Integer,
|
||||||
"Double" => TypeInfo::Double,
|
"Double" => TypeInfo::Double,
|
||||||
"String" => TypeInfo::String,
|
"String" => TypeInfo::String,
|
||||||
|
"Void" => TypeInfo::Void,
|
||||||
|
"Any" => TypeInfo::Any,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
types_table.class_types_mut().insert(symbol, type_info);
|
types_table.class_types_mut().insert(symbol, type_info);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
use crate::ast::fqn_util::fqn_parts_to_string;
|
||||||
use crate::source_range::SourceRange;
|
use crate::source_range::SourceRange;
|
||||||
use crate::symbol::parameter_symbol::ParameterSymbol;
|
use crate::symbol::parameter_symbol::ParameterSymbol;
|
||||||
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -80,3 +82,13 @@ impl Hash for FunctionSymbol {
|
|||||||
self.scope_id.hash(state);
|
self.scope_id.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for FunctionSymbol {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"FunctionSymbol({})",
|
||||||
|
fqn_parts_to_string(&self.fqn_parts)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user