mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 04:44:44 +00:00
Refactor
This commit is contained in:
parent
435c3c963e
commit
b3428d8129
3 changed files with 21 additions and 11 deletions
|
@ -11,8 +11,9 @@ use crate::ty::codeobj::CodeObj;
|
|||
|
||||
use crate::build_hir::HIRBuilder;
|
||||
use crate::codegen::CodeGenerator;
|
||||
use crate::desugar_hir::HIRDesugarer;
|
||||
use crate::error::{CompileError, CompileErrors};
|
||||
use crate::hir::Expr;
|
||||
use crate::hir::{Expr, HIR};
|
||||
use crate::link::Linker;
|
||||
use crate::mod_cache::SharedModuleCache;
|
||||
|
||||
|
@ -170,9 +171,7 @@ impl Compiler {
|
|||
|
||||
pub fn compile(&mut self, src: String, mode: &str) -> Result<CodeObj, CompileErrors> {
|
||||
log!(info "the compiling process has started.");
|
||||
let hir = self.builder.build(src, mode).map_err(|(_, errs)| errs)?;
|
||||
let linker = Linker::new(&self.cfg, &self.mod_cache);
|
||||
let hir = linker.link(hir);
|
||||
let hir = self.build_link_desugar(src, mode)?;
|
||||
let codeobj = self.code_generator.emit(hir);
|
||||
log!(info "code object:\n{}", codeobj.code_info());
|
||||
log!(info "the compiling process has completed");
|
||||
|
@ -185,13 +184,18 @@ impl Compiler {
|
|||
mode: &str,
|
||||
) -> Result<(CodeObj, Option<Expr>), CompileErrors> {
|
||||
log!(info "the compiling process has started.");
|
||||
let hir = self.builder.build(src, mode).map_err(|(_, errs)| errs)?;
|
||||
let hir = self.build_link_desugar(src, mode)?;
|
||||
let last = hir.module.last().cloned();
|
||||
let linker = Linker::new(&self.cfg, &self.mod_cache);
|
||||
let hir = linker.link(hir);
|
||||
let codeobj = self.code_generator.emit(hir);
|
||||
log!(info "code object:\n{}", codeobj.code_info());
|
||||
log!(info "the compiling process has completed");
|
||||
Ok((codeobj, last))
|
||||
}
|
||||
|
||||
fn build_link_desugar(&mut self, src: String, mode: &str) -> Result<HIR, CompileErrors> {
|
||||
let hir = self.builder.build(src, mode).map_err(|(_, errs)| errs)?;
|
||||
let linker = Linker::new(&self.cfg, &self.mod_cache);
|
||||
let hir = linker.link(hir);
|
||||
Ok(HIRDesugarer::desugar(hir))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
use crate::hir::HIR;
|
||||
|
||||
pub struct HIRDesugarer {}
|
||||
|
||||
impl HIRDesugarer {
|
||||
pub fn desugar(hir: HIR) -> HIR {
|
||||
hir
|
||||
}
|
||||
|
||||
// C = Class ...
|
||||
// C.
|
||||
// _Self = C
|
||||
|
@ -9,7 +15,9 @@ impl HIRDesugarer {
|
|||
// ↓
|
||||
// class C:
|
||||
// def _Self(): return C
|
||||
// def a(): return C.x
|
||||
// def a(): return C.x()
|
||||
// def x(): return 1
|
||||
fn _desugar_class_member() {}
|
||||
fn _desugar_class_member(_hir: HIR) -> HIR {
|
||||
_hir
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ impl ASTBuilder {
|
|||
let module = self.runner.parse(src)?;
|
||||
let mut desugarer = Desugarer::new();
|
||||
let module = desugarer.desugar(module);
|
||||
let mut desugarer = Desugarer::new();
|
||||
let module = desugarer.desugar(module);
|
||||
let ast = AST::new(Str::rc(self.runner.cfg().input.filename()), module);
|
||||
Ok(ast)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue