mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 14:04:33 +00:00
WIP: fix REPL
This commit is contained in:
parent
b56236a3b5
commit
8ce843a8df
3 changed files with 26 additions and 29 deletions
|
@ -38,10 +38,7 @@ impl HIRBuilder {
|
||||||
let ast = Reorderer::new()
|
let ast = Reorderer::new()
|
||||||
.reorder(ast)
|
.reorder(ast)
|
||||||
.map_err(|errs| self.convert(errs))?;
|
.map_err(|errs| self.convert(errs))?;
|
||||||
let (hir, ctx) = self
|
let (hir, ctx) = self.checker.check(ast, mode)?;
|
||||||
.checker
|
|
||||||
.check(ast, mode)
|
|
||||||
.map_err(|errs| self.convert(errs))?;
|
|
||||||
self.mod_cache.register(var_name, Some(hir), ctx);
|
self.mod_cache.register(var_name, Some(hir), ctx);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use erg_common::config::{ErgConfig, Input};
|
use erg_common::config::{ErgConfig, Input};
|
||||||
use erg_common::error::MultiErrorDisplay;
|
use erg_common::error::MultiErrorDisplay;
|
||||||
use erg_common::traits::Runnable;
|
use erg_common::traits::{Runnable, Stream};
|
||||||
use erg_common::Str;
|
use erg_common::Str;
|
||||||
|
|
||||||
use erg_parser::ast::AST;
|
use erg_parser::ast::AST;
|
||||||
|
@ -8,7 +8,7 @@ use erg_parser::builder::ASTBuilder;
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::effectcheck::SideEffectChecker;
|
use crate::effectcheck::SideEffectChecker;
|
||||||
use crate::error::{TyCheckError, TyCheckErrors};
|
use crate::error::{CompileError, CompileErrors, TyCheckErrors};
|
||||||
use crate::hir::HIR;
|
use crate::hir::HIR;
|
||||||
use crate::lower::ASTLowerer;
|
use crate::lower::ASTLowerer;
|
||||||
use crate::mod_cache::SharedModuleCache;
|
use crate::mod_cache::SharedModuleCache;
|
||||||
|
@ -22,8 +22,8 @@ pub struct Checker {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Runnable for Checker {
|
impl Runnable for Checker {
|
||||||
type Err = TyCheckError;
|
type Err = CompileError;
|
||||||
type Errs = TyCheckErrors;
|
type Errs = CompileErrors;
|
||||||
const NAME: &'static str = "Erg type-checker";
|
const NAME: &'static str = "Erg type-checker";
|
||||||
|
|
||||||
fn new(cfg: ErgConfig) -> Self {
|
fn new(cfg: ErgConfig) -> Self {
|
||||||
|
@ -48,7 +48,7 @@ impl Runnable for Checker {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval(&mut self, src: String) -> Result<String, TyCheckErrors> {
|
fn eval(&mut self, src: String) -> Result<String, Self::Errs> {
|
||||||
let cfg = ErgConfig {
|
let cfg = ErgConfig {
|
||||||
input: Input::Str(src),
|
input: Input::Str(src),
|
||||||
..self.cfg().copy()
|
..self.cfg().copy()
|
||||||
|
@ -72,14 +72,30 @@ impl Checker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(&mut self, ast: AST, mode: &str) -> Result<(HIR, Context), TyCheckErrors> {
|
fn convert(&self, errs: TyCheckErrors) -> CompileErrors {
|
||||||
let (hir, ctx, warns) = self.lowerer.lower(ast, mode)?;
|
errs.into_iter()
|
||||||
|
.map(|e| CompileError::new(e.core, self.input().clone(), e.caused_by))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check(&mut self, ast: AST, mode: &str) -> Result<(HIR, Context), CompileErrors> {
|
||||||
|
let (hir, ctx, warns) = self
|
||||||
|
.lowerer
|
||||||
|
.lower(ast, mode)
|
||||||
|
.map_err(|errs| self.convert(errs))?;
|
||||||
if self.cfg().verbose >= 2 {
|
if self.cfg().verbose >= 2 {
|
||||||
|
let warns = self.convert(warns);
|
||||||
warns.fmt_all_stderr();
|
warns.fmt_all_stderr();
|
||||||
}
|
}
|
||||||
let effect_checker = SideEffectChecker::new();
|
let effect_checker = SideEffectChecker::new();
|
||||||
let hir = effect_checker.check(hir)?;
|
let hir = effect_checker
|
||||||
let hir = self.ownership_checker.check(hir)?;
|
.check(hir)
|
||||||
|
.map_err(|errs| self.convert(errs))?;
|
||||||
|
let hir = self
|
||||||
|
.ownership_checker
|
||||||
|
.check(hir)
|
||||||
|
.map_err(|errs| self.convert(errs))?;
|
||||||
Ok((hir, ctx))
|
Ok((hir, ctx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,21 +246,6 @@ impl From<ParserRunnerError> for TyCheckError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ErrorDisplay for TyCheckError {
|
|
||||||
fn core(&self) -> &ErrorCore {
|
|
||||||
&self.core
|
|
||||||
}
|
|
||||||
fn input(&self) -> &Input {
|
|
||||||
&Input::Dummy
|
|
||||||
}
|
|
||||||
fn caused_by(&self) -> &str {
|
|
||||||
&self.caused_by
|
|
||||||
}
|
|
||||||
fn ref_inner(&self) -> Option<&Self> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TyCheckError {
|
impl TyCheckError {
|
||||||
pub const fn new(core: ErrorCore, caused_by: AtomicStr) -> Self {
|
pub const fn new(core: ErrorCore, caused_by: AtomicStr) -> Self {
|
||||||
Self { core, caused_by }
|
Self { core, caused_by }
|
||||||
|
@ -1313,7 +1298,6 @@ passed keyword args: {RED}{kw_args_len}{RESET}"
|
||||||
pub struct TyCheckErrors(Vec<TyCheckError>);
|
pub struct TyCheckErrors(Vec<TyCheckError>);
|
||||||
|
|
||||||
impl_stream_for_wrapper!(TyCheckErrors, TyCheckError);
|
impl_stream_for_wrapper!(TyCheckErrors, TyCheckError);
|
||||||
impl MultiErrorDisplay<TyCheckError> for TyCheckErrors {}
|
|
||||||
|
|
||||||
impl From<Vec<TyCheckError>> for TyCheckErrors {
|
impl From<Vec<TyCheckError>> for TyCheckErrors {
|
||||||
fn from(errs: Vec<TyCheckError>) -> Self {
|
fn from(errs: Vec<TyCheckError>) -> Self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue