This commit is contained in:
Shunsuke Shibayama 2022-10-14 15:12:37 +09:00
parent 435c3c963e
commit b3428d8129
3 changed files with 21 additions and 11 deletions

View file

@ -11,8 +11,9 @@ use crate::ty::codeobj::CodeObj;
use crate::build_hir::HIRBuilder; use crate::build_hir::HIRBuilder;
use crate::codegen::CodeGenerator; use crate::codegen::CodeGenerator;
use crate::desugar_hir::HIRDesugarer;
use crate::error::{CompileError, CompileErrors}; use crate::error::{CompileError, CompileErrors};
use crate::hir::Expr; use crate::hir::{Expr, HIR};
use crate::link::Linker; use crate::link::Linker;
use crate::mod_cache::SharedModuleCache; use crate::mod_cache::SharedModuleCache;
@ -170,9 +171,7 @@ impl Compiler {
pub fn compile(&mut self, src: String, mode: &str) -> Result<CodeObj, CompileErrors> { pub fn compile(&mut self, src: String, mode: &str) -> Result<CodeObj, CompileErrors> {
log!(info "the compiling process has started."); 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 linker = Linker::new(&self.cfg, &self.mod_cache);
let hir = linker.link(hir);
let codeobj = self.code_generator.emit(hir); let codeobj = self.code_generator.emit(hir);
log!(info "code object:\n{}", codeobj.code_info()); log!(info "code object:\n{}", codeobj.code_info());
log!(info "the compiling process has completed"); log!(info "the compiling process has completed");
@ -185,13 +184,18 @@ impl Compiler {
mode: &str, mode: &str,
) -> Result<(CodeObj, Option<Expr>), CompileErrors> { ) -> Result<(CodeObj, Option<Expr>), CompileErrors> {
log!(info "the compiling process has started."); 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 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); let codeobj = self.code_generator.emit(hir);
log!(info "code object:\n{}", codeobj.code_info()); log!(info "code object:\n{}", codeobj.code_info());
log!(info "the compiling process has completed"); log!(info "the compiling process has completed");
Ok((codeobj, last)) 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))
}
} }

View file

@ -1,6 +1,12 @@
use crate::hir::HIR;
pub struct HIRDesugarer {} pub struct HIRDesugarer {}
impl HIRDesugarer { impl HIRDesugarer {
pub fn desugar(hir: HIR) -> HIR {
hir
}
// C = Class ... // C = Class ...
// C. // C.
// _Self = C // _Self = C
@ -9,7 +15,9 @@ impl HIRDesugarer {
// ↓ // ↓
// class C: // class C:
// def _Self(): return C // def _Self(): return C
// def a(): return C.x // def a(): return C.x()
// def x(): return 1 // def x(): return 1
fn _desugar_class_member() {} fn _desugar_class_member(_hir: HIR) -> HIR {
_hir
}
} }

View file

@ -23,8 +23,6 @@ impl ASTBuilder {
let module = self.runner.parse(src)?; let module = self.runner.parse(src)?;
let mut desugarer = Desugarer::new(); let mut desugarer = Desugarer::new();
let module = desugarer.desugar(module); 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); let ast = AST::new(Str::rc(self.runner.cfg().input.filename()), module);
Ok(ast) Ok(ast)
} }