mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
feat: add exception
module
This commit is contained in:
parent
8548ea89fe
commit
951c85a344
9 changed files with 105 additions and 4 deletions
|
@ -2992,7 +2992,10 @@ impl Context {
|
|||
named_func.register_marker_trait(self, mono(NAMED)).unwrap();
|
||||
let mut quant = Self::builtin_mono_class(QUANTIFIED, 2);
|
||||
quant.register_superclass(mono(PROC), &proc);
|
||||
let mut qproc = Self::builtin_mono_class(QUANTIFIED_PROC, 2);
|
||||
qproc.register_superclass(mono(PROC), &proc);
|
||||
let mut qfunc = Self::builtin_mono_class(QUANTIFIED_FUNC, 2);
|
||||
qfunc.register_superclass(mono(QUANTIFIED_PROC), &qproc);
|
||||
qfunc.register_superclass(mono(FUNC), &func);
|
||||
let mut proc_meta_type = Self::builtin_mono_class(PROC_META_TYPE, 2);
|
||||
proc_meta_type.register_superclass(mono(PROC), &proc);
|
||||
|
@ -3000,6 +3003,12 @@ impl Context {
|
|||
let mut func_meta_type = Self::builtin_mono_class(FUNC_META_TYPE, 2);
|
||||
func_meta_type.register_superclass(mono(FUNC), &func);
|
||||
func_meta_type.register_superclass(mono(PROC_META_TYPE), &proc_meta_type);
|
||||
let mut qproc_meta_type = Self::builtin_mono_class(QUANTIFIED_PROC_META_TYPE, 2);
|
||||
qproc_meta_type.register_superclass(mono(PROC_META_TYPE), &proc);
|
||||
qproc_meta_type.register_superclass(mono(QUANTIFIED_PROC), &qproc);
|
||||
let mut qfunc_meta_type = Self::builtin_mono_class(QUANTIFIED_FUNC_META_TYPE, 2);
|
||||
qfunc_meta_type.register_superclass(mono(QUANTIFIED_PROC_META_TYPE), &qproc_meta_type);
|
||||
qfunc_meta_type.register_superclass(mono(QUANTIFIED_FUNC), &qfunc);
|
||||
self.register_builtin_type(Never, never, vis.clone(), Const, Some(NEVER));
|
||||
self.register_builtin_type(Obj, obj, vis.clone(), Const, Some(FUNC_OBJECT));
|
||||
// self.register_type(mono(RECORD), vec![], record, Visibility::BUILTIN_PRIVATE, Const);
|
||||
|
@ -3260,6 +3269,13 @@ impl Context {
|
|||
Const,
|
||||
Some(QUANTIFIED),
|
||||
);
|
||||
self.register_builtin_type(
|
||||
mono(QUANTIFIED_PROC),
|
||||
qproc,
|
||||
Visibility::BUILTIN_PRIVATE,
|
||||
Const,
|
||||
Some(QUANTIFIED_PROC),
|
||||
);
|
||||
self.register_builtin_type(
|
||||
mono(QUANTIFIED_FUNC),
|
||||
qfunc,
|
||||
|
@ -3281,6 +3297,20 @@ impl Context {
|
|||
Const,
|
||||
Some(FUNC_META_TYPE),
|
||||
);
|
||||
self.register_builtin_type(
|
||||
mono(QUANTIFIED_PROC_META_TYPE),
|
||||
qproc_meta_type,
|
||||
Visibility::BUILTIN_PRIVATE,
|
||||
Const,
|
||||
Some(QUANTIFIED_PROC_META_TYPE),
|
||||
);
|
||||
self.register_builtin_type(
|
||||
mono(QUANTIFIED_FUNC_META_TYPE),
|
||||
qfunc_meta_type,
|
||||
Visibility::BUILTIN_PRIVATE,
|
||||
Const,
|
||||
Some(QUANTIFIED_FUNC_META_TYPE),
|
||||
);
|
||||
} else {
|
||||
self.register_builtin_const(MUT_INT, vis.clone(), ValueObj::builtin_class(Int));
|
||||
self.register_builtin_const(MUT_STR, vis, ValueObj::builtin_class(Str));
|
||||
|
|
|
@ -848,7 +848,8 @@ impl Context {
|
|||
tp_enum(Type, set! { ty_tp(U.clone()) }),
|
||||
tp_enum(Type, set! { ty_tp(T.clone() | U.clone()) }),
|
||||
)
|
||||
.quantify();
|
||||
.quantify()
|
||||
& bin_op(Type, Type, Type);
|
||||
self.register_builtin_py_impl(OP_OR, or_t, Const, Visibility::BUILTIN_PRIVATE, Some("or_"));
|
||||
let and_t = bin_op(Bool, Bool, Bool)
|
||||
& bin_op(
|
||||
|
|
|
@ -317,8 +317,11 @@ const NAMED_FUNC: &str = "NamedFunc";
|
|||
const FUNC: &str = "Func";
|
||||
const QUANTIFIED: &str = "Quantified";
|
||||
const QUANTIFIED_FUNC: &str = "QuantifiedFunc";
|
||||
const QUANTIFIED_PROC: &str = "QuantifiedProc";
|
||||
const PROC_META_TYPE: &str = "ProcMetaType";
|
||||
const FUNC_META_TYPE: &str = "FuncMetaType";
|
||||
const QUANTIFIED_FUNC_META_TYPE: &str = "QuantifiedFuncMetaType";
|
||||
const QUANTIFIED_PROC_META_TYPE: &str = "QuantifiedProcMetaType";
|
||||
const SLICE: &str = "Slice";
|
||||
const FUNC_OBJECT: &str = "object";
|
||||
const FUNC_INT: &str = "int";
|
||||
|
|
|
@ -2734,7 +2734,30 @@ impl Context {
|
|||
return Some(res);
|
||||
}
|
||||
}
|
||||
Type::Quantified(_) => {
|
||||
Type::Quantified(quant) => {
|
||||
if self
|
||||
.get_nominal_type_ctx(quant)
|
||||
.is_some_and(|ctx| &ctx.typ.qual_name() == "ProcMetaType")
|
||||
{
|
||||
if let Some(ctx) = self
|
||||
.get_builtins()
|
||||
.unwrap_or(self)
|
||||
.rec_local_get_mono_type("QuantifiedProcMetaType")
|
||||
{
|
||||
return Some(ctx);
|
||||
}
|
||||
} else if self
|
||||
.get_nominal_type_ctx(quant)
|
||||
.is_some_and(|ctx| &ctx.typ.qual_name() == "FuncMetaType")
|
||||
{
|
||||
if let Some(ctx) = self
|
||||
.get_builtins()
|
||||
.unwrap_or(self)
|
||||
.rec_local_get_mono_type("QuantifiedFuncMetaType")
|
||||
{
|
||||
return Some(ctx);
|
||||
}
|
||||
}
|
||||
if let Some(ctx) = self
|
||||
.get_builtins()
|
||||
.unwrap_or(self)
|
||||
|
|
|
@ -17,7 +17,7 @@ use erg_parser::ast::{
|
|||
use erg_parser::token::TokenKind;
|
||||
use erg_parser::Parser;
|
||||
|
||||
use crate::ty::free::{CanbeFree, Constraint};
|
||||
use crate::ty::free::{CanbeFree, Constraint, HasLevel};
|
||||
use crate::ty::typaram::{IntervalOp, OpKind, TyParam, TyParamLambda, TyParamOrdering};
|
||||
use crate::ty::value::ValueObj;
|
||||
use crate::ty::{constructors::*, Predicate, RefinementType, VisibilityModifier};
|
||||
|
@ -1798,7 +1798,16 @@ impl Context {
|
|||
t_spec: &ast::TypeSpec,
|
||||
tv_cache: &mut TyVarCache,
|
||||
) -> TyCheckResult<Type> {
|
||||
self.instantiate_typespec_full(t_spec, None, tv_cache, RegistrationMode::Normal, false)
|
||||
let t = self.instantiate_typespec_full(
|
||||
t_spec,
|
||||
None,
|
||||
tv_cache,
|
||||
RegistrationMode::Normal,
|
||||
false,
|
||||
)?;
|
||||
t.lift();
|
||||
let t = self.generalize_t(t);
|
||||
Ok(t)
|
||||
}
|
||||
|
||||
pub(crate) fn instantiate_field(&self, ident: &Identifier) -> TyCheckResult<Field> {
|
||||
|
|
|
@ -1405,6 +1405,7 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
|
|||
}
|
||||
}
|
||||
(Subr(_) | Record(_), Type) => {}
|
||||
(Guard(_), Bool) | (Bool, Guard(_)) => {}
|
||||
// REVIEW: correct?
|
||||
(Poly { name, .. }, Type) if &name[..] == "Array" || &name[..] == "Tuple" => {}
|
||||
(Poly { .. }, _) => {
|
||||
|
@ -1457,6 +1458,9 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
|
|||
sub_ctx.super_traits.iter()
|
||||
};
|
||||
let mut min_compatible = None;
|
||||
if sups.clone().count() == 0 {
|
||||
min_compatible = Some(&sub_ctx.typ);
|
||||
}
|
||||
for sup_ty in sups {
|
||||
if self.ctx.subtype_of(sup_ty, maybe_sup) {
|
||||
if let Some(min) = min_compatible {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue