mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 12:24:45 +00:00
Merge branch 'main' into py-method-decl
This commit is contained in:
commit
be1c603ba9
5 changed files with 29 additions and 11 deletions
|
@ -269,7 +269,7 @@ impl Context {
|
||||||
let op_t = fn1_met(
|
let op_t = fn1_met(
|
||||||
mono_q("Self"),
|
mono_q("Self"),
|
||||||
mono_q("R"),
|
mono_q("R"),
|
||||||
option(builtin_mono("Ordering")),
|
or(builtin_mono("Ordering"), NoneType),
|
||||||
);
|
);
|
||||||
let op_t = quant(
|
let op_t = quant(
|
||||||
op_t,
|
op_t,
|
||||||
|
@ -534,7 +534,7 @@ impl Context {
|
||||||
let mut int_partial_ord = Self::builtin_methods("PartialOrd", 2);
|
let mut int_partial_ord = Self::builtin_methods("PartialOrd", 2);
|
||||||
int_partial_ord.register_builtin_impl(
|
int_partial_ord.register_builtin_impl(
|
||||||
"__partial_cmp__",
|
"__partial_cmp__",
|
||||||
fn1_met(Int, Int, option(builtin_mono("Ordering"))),
|
fn1_met(Int, Int, or(builtin_mono("Ordering"), NoneType)),
|
||||||
Const,
|
Const,
|
||||||
Public,
|
Public,
|
||||||
);
|
);
|
||||||
|
@ -1575,7 +1575,7 @@ impl Context {
|
||||||
vec![param_t("err_message", Str)],
|
vec![param_t("err_message", Str)],
|
||||||
NoneType,
|
NoneType,
|
||||||
);
|
);
|
||||||
let t_classof = nd_func(vec![param_t("old", Obj)], None, option(Class));
|
let t_classof = nd_func(vec![param_t("old", Obj)], None, Class);
|
||||||
let t_compile = nd_func(vec![param_t("src", Str)], None, Code);
|
let t_compile = nd_func(vec![param_t("src", Str)], None, Code);
|
||||||
let t_cond = nd_func(
|
let t_cond = nd_func(
|
||||||
vec![
|
vec![
|
||||||
|
@ -1596,7 +1596,7 @@ impl Context {
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
vec![param_t("else", nd_func(vec![], None, mono_q("T")))],
|
vec![param_t("else", nd_func(vec![], None, mono_q("T")))],
|
||||||
option(mono_q("T")),
|
or(mono_q("T"), NoneType),
|
||||||
);
|
);
|
||||||
let t_if = quant(t_if, set! {static_instance("T", Type)});
|
let t_if = quant(t_if, set! {static_instance("T", Type)});
|
||||||
let t_import = nd_func(
|
let t_import = nd_func(
|
||||||
|
@ -1724,7 +1724,7 @@ impl Context {
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
vec![param_t("else", nd_proc(vec![], None, mono_q("T")))],
|
vec![param_t("else", nd_proc(vec![], None, mono_q("T")))],
|
||||||
option(mono_q("T")),
|
or(mono_q("T"), NoneType),
|
||||||
);
|
);
|
||||||
let t_if = quant(t_if, set! {static_instance("T", Type)});
|
let t_if = quant(t_if, set! {static_instance("T", Type)});
|
||||||
let t_for = nd_proc(
|
let t_for = nd_proc(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use erg_common::vis::Visibility;
|
use erg_common::vis::Visibility;
|
||||||
|
|
||||||
use erg_type::constructors::{builtin_mono, func, option, param_t};
|
use erg_type::constructors::{builtin_mono, func, or, param_t};
|
||||||
use erg_type::Type;
|
use erg_type::Type;
|
||||||
use Type::*;
|
use Type::*;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ impl Context {
|
||||||
param_t("family", Int),
|
param_t("family", Int),
|
||||||
param_t("type", Int),
|
param_t("type", Int),
|
||||||
param_t("proto", Int),
|
param_t("proto", Int),
|
||||||
param_t("fileno", option(Int)),
|
param_t("fileno", or(Int, NoneType)),
|
||||||
],
|
],
|
||||||
builtin_mono("Socket!"),
|
builtin_mono("Socket!"),
|
||||||
),
|
),
|
||||||
|
|
|
@ -454,6 +454,22 @@ impl Context {
|
||||||
// TODO: deref_predicate
|
// TODO: deref_predicate
|
||||||
Ok(refinement(refine.var, t, refine.preds))
|
Ok(refinement(refine.var, t, refine.preds))
|
||||||
}
|
}
|
||||||
|
Type::And(l, r) => {
|
||||||
|
let l = self.deref_tyvar(*l, variance, loc)?;
|
||||||
|
let r = self.deref_tyvar(*r, variance, loc)?;
|
||||||
|
Ok(self.intersection(&l, &r))
|
||||||
|
}
|
||||||
|
Type::Or(l, r) => {
|
||||||
|
let l = self.deref_tyvar(*l, variance, loc)?;
|
||||||
|
let r = self.deref_tyvar(*r, variance, loc)?;
|
||||||
|
Ok(self.union(&l, &r))
|
||||||
|
}
|
||||||
|
Type::Not(l, r) => {
|
||||||
|
let l = self.deref_tyvar(*l, variance, loc)?;
|
||||||
|
let r = self.deref_tyvar(*r, variance, loc)?;
|
||||||
|
// TODO: complement
|
||||||
|
Ok(not(l, r))
|
||||||
|
}
|
||||||
t => Ok(t),
|
t => Ok(t),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1301,7 +1301,10 @@ impl ASTLowerer {
|
||||||
let hir = HIR::new(ast.name, module);
|
let hir = HIR::new(ast.name, module);
|
||||||
log!(info "HIR (not resolved, current errs: {}):\n{hir}", self.errs.len());
|
log!(info "HIR (not resolved, current errs: {}):\n{hir}", self.errs.len());
|
||||||
let hir = match self.ctx.resolve(hir) {
|
let hir = match self.ctx.resolve(hir) {
|
||||||
Ok(hir) => hir,
|
Ok(hir) => {
|
||||||
|
log!(info "HIR (resolved):\n{hir}");
|
||||||
|
hir
|
||||||
|
}
|
||||||
Err((hir, errs)) => {
|
Err((hir, errs)) => {
|
||||||
self.errs.extend(errs.into_iter());
|
self.errs.extend(errs.into_iter());
|
||||||
log!(err "the resolving process has failed. errs: {}", self.errs.len());
|
log!(err "the resolving process has failed. errs: {}", self.errs.len());
|
||||||
|
@ -1315,7 +1318,6 @@ impl ASTLowerer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.errs.is_empty() {
|
if self.errs.is_empty() {
|
||||||
log!(info "HIR:\n{hir}");
|
|
||||||
log!(info "the AST lowering process has completed.");
|
log!(info "the AST lowering process has completed.");
|
||||||
Ok((hir, LowerWarnings::from(self.warns.take_all())))
|
Ok((hir, LowerWarnings::from(self.warns.take_all())))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -127,13 +127,13 @@ pub fn ref_mut(before: Type, after: Option<Type>) -> Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn option(t: Type) -> Type {
|
/*pub fn option(t: Type) -> Type {
|
||||||
builtin_poly("Option", vec![TyParam::t(t)])
|
builtin_poly("Option", vec![TyParam::t(t)])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn option_mut(t: Type) -> Type {
|
pub fn option_mut(t: Type) -> Type {
|
||||||
builtin_poly("Option!", vec![TyParam::t(t)])
|
builtin_poly("Option!", vec![TyParam::t(t)])
|
||||||
}
|
}*/
|
||||||
|
|
||||||
pub fn subr_t(
|
pub fn subr_t(
|
||||||
kind: SubrKind,
|
kind: SubrKind,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue