[core] add module type
This commit is contained in:
parent
4bd5349381
commit
febfd1241d
@ -713,6 +713,7 @@ impl Nac3 {
|
||||
"Unsupported @rpc annotation on global variable",
|
||||
)))
|
||||
}
|
||||
TopLevelDef::Module { .. } => unreachable!("Type module cannot be decorated with @rpc"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -979,7 +979,7 @@ pub fn gen_call<'ctx, G: CodeGenerator>(
|
||||
TopLevelDef::Class { .. } => {
|
||||
return Ok(Some(generator.gen_constructor(ctx, fun.0, &def, params)?))
|
||||
}
|
||||
TopLevelDef::Variable { .. } => unreachable!(),
|
||||
TopLevelDef::Variable { .. } | TopLevelDef::Module { .. } => unreachable!(),
|
||||
}
|
||||
}
|
||||
.or_else(|_: String| {
|
||||
|
@ -101,7 +101,8 @@ impl TopLevelComposer {
|
||||
let builtin_name_list = definition_ast_list
|
||||
.iter()
|
||||
.map(|def_ast| match *def_ast.0.read() {
|
||||
TopLevelDef::Class { name, .. } => name.to_string(),
|
||||
TopLevelDef::Class { name, .. }
|
||||
| TopLevelDef::Module { name, .. } => name.to_string(),
|
||||
TopLevelDef::Function { simple_name, .. }
|
||||
| TopLevelDef::Variable { simple_name, .. } => simple_name.to_string(),
|
||||
})
|
||||
|
@ -379,6 +379,13 @@ pub fn make_exception_fields(int32: Type, int64: Type, str: Type) -> Vec<(StrRef
|
||||
impl TopLevelDef {
|
||||
pub fn to_string(&self, unifier: &mut Unifier) -> String {
|
||||
match self {
|
||||
TopLevelDef::Module { name, attributes, .. } => {
|
||||
let method_str = attributes.iter().map(|(n, _)| n.to_string()).collect_vec();
|
||||
format!(
|
||||
"Module {{\nname: {:?},\nattributes{:?}\n}}",
|
||||
name, method_str
|
||||
)
|
||||
}
|
||||
TopLevelDef::Class {
|
||||
name, ancestors, fields, methods, attributes, type_vars, ..
|
||||
} => {
|
||||
|
@ -92,6 +92,18 @@ pub struct FunInstance {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TopLevelDef {
|
||||
Module {
|
||||
/// Name of the module
|
||||
name: StrRef,
|
||||
/// Module ID used for [`TypeEnum`]
|
||||
module_id: DefinitionId,
|
||||
/// DefinitionId of `TopLevelDef::{Class, Function, Variable}` within the module
|
||||
attributes: HashMap<StrRef, DefinitionId>,
|
||||
/// Symbol resolver of the module defined the class.
|
||||
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
||||
/// Definition location.
|
||||
loc: Option<Location>,
|
||||
},
|
||||
Class {
|
||||
/// Name for error messages and symbols.
|
||||
name: StrRef,
|
||||
|
@ -2734,7 +2734,8 @@ impl Inferencer<'_> {
|
||||
.read()
|
||||
.iter()
|
||||
.map(|def| match *def.read() {
|
||||
TopLevelDef::Class { name, .. } => (name, false),
|
||||
TopLevelDef::Class { name, .. }
|
||||
| TopLevelDef::Module { name, .. } => (name, false),
|
||||
TopLevelDef::Function { simple_name, .. } => (simple_name, false),
|
||||
TopLevelDef::Variable { simple_name, .. } => (simple_name, true),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user