mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 12:24:45 +00:00
Add "check" mode
Input::File(String) -> Input::file(PathBuf)
This commit is contained in:
parent
c1d92bc0f4
commit
9b0d66a63a
16 changed files with 200 additions and 184 deletions
|
@ -1,19 +1,58 @@
|
|||
use erg_common::log;
|
||||
use erg_common::traits::Stream;
|
||||
|
||||
use crate::hir::{Expr, HIR};
|
||||
use crate::mod_cache::SharedModuleCache;
|
||||
use erg_parser::token::Token;
|
||||
|
||||
use erg_type::value::TypeKind;
|
||||
use erg_type::{SubrKind, SubrType, Type};
|
||||
|
||||
use crate::hir::{Block, ClassDef, Expr, Record, RecordAttrs, HIR};
|
||||
use crate::mod_cache::{ModuleEntry, SharedModuleCache};
|
||||
|
||||
pub struct Linker {}
|
||||
|
||||
impl Linker {
|
||||
pub fn link(mod_cache: SharedModuleCache) -> HIR {
|
||||
log!(info "the linking process has started.");
|
||||
let mut main_mod_hir = mod_cache.remove("<module>").unwrap().hir.unwrap();
|
||||
for chunk in main_mod_hir.module.iter_mut() {
|
||||
match chunk {
|
||||
Expr::Def(def) if def.def_kind().is_module() => {}
|
||||
// x = import "mod"
|
||||
// ↓
|
||||
// class x:
|
||||
// ...
|
||||
Expr::Def(ref def) if def.def_kind().is_module() => {
|
||||
// let sig = option_enum_unwrap!(&def.sig, Signature::Var)
|
||||
// .unwrap_or_else(|| todo!("module subroutines are not allowed"));
|
||||
if let Some(ModuleEntry { hir: Some(hir), .. }) =
|
||||
mod_cache.remove(def.sig.ident().inspect())
|
||||
{
|
||||
let block = Block::new(Vec::from(hir.module));
|
||||
let def = ClassDef::new(
|
||||
TypeKind::Class,
|
||||
def.sig.clone(),
|
||||
Expr::Record(Record::new(
|
||||
Token::dummy(),
|
||||
Token::dummy(),
|
||||
RecordAttrs::empty(),
|
||||
)),
|
||||
false,
|
||||
Type::Subr(SubrType::new(
|
||||
SubrKind::Func,
|
||||
vec![],
|
||||
None,
|
||||
vec![],
|
||||
Type::Failure,
|
||||
)),
|
||||
block,
|
||||
);
|
||||
*chunk = Expr::ClassDef(def);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
log!(info "linked: {main_mod_hir}");
|
||||
main_mod_hir
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue