mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 12:24:45 +00:00
Rename: Type::Class -> Type::ClassType
This commit is contained in:
parent
5396b13e6d
commit
b8b6acdf3a
5 changed files with 35 additions and 26 deletions
|
@ -163,7 +163,7 @@ impl Context {
|
||||||
| (Float | Ratio | Int, Int)
|
| (Float | Ratio | Int, Int)
|
||||||
| (Float | Ratio, Ratio)
|
| (Float | Ratio, Ratio)
|
||||||
| (Float, Float) => (Absolutely, true),
|
| (Float, Float) => (Absolutely, true),
|
||||||
(Type, Class | Trait) => (Absolutely, true),
|
(Type, ClassType | TraitType) => (Absolutely, true),
|
||||||
(Type, Record(rec)) => (
|
(Type, Record(rec)) => (
|
||||||
Absolutely,
|
Absolutely,
|
||||||
rec.iter().all(|(_, attr)| self.supertype_of(&Type, attr)),
|
rec.iter().all(|(_, attr)| self.supertype_of(&Type, attr)),
|
||||||
|
|
|
@ -772,8 +772,17 @@ impl Context {
|
||||||
class_type.register_superclass(Type, &type_);
|
class_type.register_superclass(Type, &type_);
|
||||||
class_type.register_marker_trait(builtin_mono("Named"));
|
class_type.register_marker_trait(builtin_mono("Named"));
|
||||||
let mut class_eq = Self::builtin_methods("Eq", 2);
|
let mut class_eq = Self::builtin_methods("Eq", 2);
|
||||||
class_eq.register_builtin_impl("__eq__", fn1_met(Class, Class, Bool), Const, Public);
|
class_eq.register_builtin_impl(
|
||||||
class_type.register_trait(Class, builtin_poly("Eq", vec![ty_tp(Class)]), class_eq);
|
"__eq__",
|
||||||
|
fn1_met(ClassType, ClassType, Bool),
|
||||||
|
Const,
|
||||||
|
Public,
|
||||||
|
);
|
||||||
|
class_type.register_trait(
|
||||||
|
ClassType,
|
||||||
|
builtin_poly("Eq", vec![ty_tp(ClassType)]),
|
||||||
|
class_eq,
|
||||||
|
);
|
||||||
let g_module_t = builtin_mono("GenericModule");
|
let g_module_t = builtin_mono("GenericModule");
|
||||||
let mut generic_module = Self::builtin_mono_class("GenericModule", 2);
|
let mut generic_module = Self::builtin_mono_class("GenericModule", 2);
|
||||||
generic_module.register_superclass(Obj, &obj);
|
generic_module.register_superclass(Obj, &obj);
|
||||||
|
@ -1645,7 +1654,7 @@ impl Context {
|
||||||
self.register_builtin_type(Bool, bool_, Const);
|
self.register_builtin_type(Bool, bool_, Const);
|
||||||
self.register_builtin_type(Str, str_, Const);
|
self.register_builtin_type(Str, str_, Const);
|
||||||
self.register_builtin_type(Type, type_, Const);
|
self.register_builtin_type(Type, type_, Const);
|
||||||
self.register_builtin_type(Class, class_type, Const);
|
self.register_builtin_type(ClassType, class_type, Const);
|
||||||
self.register_builtin_type(g_module_t, generic_module, Const);
|
self.register_builtin_type(g_module_t, generic_module, Const);
|
||||||
self.register_builtin_type(module_t, module, Const);
|
self.register_builtin_type(module_t, module, Const);
|
||||||
self.register_builtin_type(array_t, array_, Const);
|
self.register_builtin_type(array_t, array_, Const);
|
||||||
|
@ -1741,7 +1750,7 @@ impl Context {
|
||||||
vec![kw("err_message", Str)],
|
vec![kw("err_message", Str)],
|
||||||
NoneType,
|
NoneType,
|
||||||
);
|
);
|
||||||
let t_classof = nd_func(vec![kw("old", Obj)], None, Class);
|
let t_classof = nd_func(vec![kw("old", Obj)], None, ClassType);
|
||||||
let t_compile = nd_func(vec![kw("src", Str)], None, Code);
|
let t_compile = nd_func(vec![kw("src", Str)], None, Code);
|
||||||
let t_cond = nd_func(
|
let t_cond = nd_func(
|
||||||
vec![
|
vec![
|
||||||
|
@ -1820,15 +1829,15 @@ impl Context {
|
||||||
vec![kw("Requirement", Type)],
|
vec![kw("Requirement", Type)],
|
||||||
None,
|
None,
|
||||||
vec![kw("Impl", Type)],
|
vec![kw("Impl", Type)],
|
||||||
Class,
|
ClassType,
|
||||||
);
|
);
|
||||||
let class = ConstSubr::Builtin(BuiltinConstSubr::new("Class", class_func, class_t, None));
|
let class = ConstSubr::Builtin(BuiltinConstSubr::new("Class", class_func, class_t, None));
|
||||||
self.register_builtin_const("Class", ValueObj::Subr(class));
|
self.register_builtin_const("Class", ValueObj::Subr(class));
|
||||||
let inherit_t = func(
|
let inherit_t = func(
|
||||||
vec![kw("Super", Class)],
|
vec![kw("Super", ClassType)],
|
||||||
None,
|
None,
|
||||||
vec![kw("Impl", Type), kw("Additional", Type)],
|
vec![kw("Impl", Type), kw("Additional", Type)],
|
||||||
Class,
|
ClassType,
|
||||||
);
|
);
|
||||||
let inherit = ConstSubr::Builtin(BuiltinConstSubr::new(
|
let inherit = ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||||
"Inherit",
|
"Inherit",
|
||||||
|
@ -1841,15 +1850,15 @@ impl Context {
|
||||||
vec![kw("Requirement", Type)],
|
vec![kw("Requirement", Type)],
|
||||||
None,
|
None,
|
||||||
vec![kw("Impl", Type)],
|
vec![kw("Impl", Type)],
|
||||||
Trait,
|
TraitType,
|
||||||
);
|
);
|
||||||
let trait_ = ConstSubr::Builtin(BuiltinConstSubr::new("Trait", trait_func, trait_t, None));
|
let trait_ = ConstSubr::Builtin(BuiltinConstSubr::new("Trait", trait_func, trait_t, None));
|
||||||
self.register_builtin_const("Trait", ValueObj::Subr(trait_));
|
self.register_builtin_const("Trait", ValueObj::Subr(trait_));
|
||||||
let subsume_t = func(
|
let subsume_t = func(
|
||||||
vec![kw("Super", Trait)],
|
vec![kw("Super", TraitType)],
|
||||||
None,
|
None,
|
||||||
vec![kw("Impl", Type), kw("Additional", Type)],
|
vec![kw("Impl", Type), kw("Additional", Type)],
|
||||||
Trait,
|
TraitType,
|
||||||
);
|
);
|
||||||
let subsume = ConstSubr::Builtin(BuiltinConstSubr::new(
|
let subsume = ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||||
"Subsume",
|
"Subsume",
|
||||||
|
@ -1859,7 +1868,7 @@ impl Context {
|
||||||
));
|
));
|
||||||
self.register_builtin_const("Subsume", ValueObj::Subr(subsume));
|
self.register_builtin_const("Subsume", ValueObj::Subr(subsume));
|
||||||
// decorators
|
// decorators
|
||||||
let inheritable_t = func1(Class, Class);
|
let inheritable_t = func1(ClassType, ClassType);
|
||||||
let inheritable = ConstSubr::Builtin(BuiltinConstSubr::new(
|
let inheritable = ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||||
"Inheritable",
|
"Inheritable",
|
||||||
inheritable_func,
|
inheritable_func,
|
||||||
|
|
|
@ -1131,7 +1131,7 @@ impl ASTLowerer {
|
||||||
loc,
|
loc,
|
||||||
self.ctx.caused_by(),
|
self.ctx.caused_by(),
|
||||||
&impl_trait.name(),
|
&impl_trait.name(),
|
||||||
&Type::Trait,
|
&Type::TraitType,
|
||||||
&trait_obj.t(),
|
&trait_obj.t(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -1359,7 +1359,7 @@ impl ASTLowerer {
|
||||||
ast::DefId(0),
|
ast::DefId(0),
|
||||||
)?;
|
)?;
|
||||||
match t {
|
match t {
|
||||||
Type::Class => {
|
Type::ClassType => {
|
||||||
let ty_obj = GenTypeObj::new(
|
let ty_obj = GenTypeObj::new(
|
||||||
TypeKind::Class,
|
TypeKind::Class,
|
||||||
mono(self.ctx.path(), ident.inspect()),
|
mono(self.ctx.path(), ident.inspect()),
|
||||||
|
@ -1369,7 +1369,7 @@ impl ASTLowerer {
|
||||||
);
|
);
|
||||||
self.ctx.register_gen_type(&ident, ty_obj);
|
self.ctx.register_gen_type(&ident, ty_obj);
|
||||||
}
|
}
|
||||||
Type::Trait => {
|
Type::TraitType => {
|
||||||
let ty_obj = GenTypeObj::new(
|
let ty_obj = GenTypeObj::new(
|
||||||
TypeKind::Trait,
|
TypeKind::Trait,
|
||||||
mono(self.ctx.path(), ident.inspect()),
|
mono(self.ctx.path(), ident.inspect()),
|
||||||
|
|
|
@ -1119,8 +1119,8 @@ pub enum Type {
|
||||||
NegInf, // {-∞}
|
NegInf, // {-∞}
|
||||||
// TODO: PolyType/Class
|
// TODO: PolyType/Class
|
||||||
Type,
|
Type,
|
||||||
Class,
|
ClassType,
|
||||||
Trait,
|
TraitType,
|
||||||
Patch,
|
Patch,
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
Ellipsis, // これはクラスのほうで型推論用のマーカーではない
|
Ellipsis, // これはクラスのほうで型推論用のマーカーではない
|
||||||
|
@ -1197,8 +1197,8 @@ impl PartialEq for Type {
|
||||||
| (Self::Inf, Self::Inf)
|
| (Self::Inf, Self::Inf)
|
||||||
| (Self::NegInf, Self::NegInf)
|
| (Self::NegInf, Self::NegInf)
|
||||||
| (Self::Type, Self::Type)
|
| (Self::Type, Self::Type)
|
||||||
| (Self::Class, Self::Class)
|
| (Self::ClassType, Self::ClassType)
|
||||||
| (Self::Trait, Self::Trait)
|
| (Self::TraitType, Self::TraitType)
|
||||||
| (Self::Patch, Self::Patch)
|
| (Self::Patch, Self::Patch)
|
||||||
| (Self::NotImplemented, Self::NotImplemented)
|
| (Self::NotImplemented, Self::NotImplemented)
|
||||||
| (Self::Ellipsis, Self::Ellipsis)
|
| (Self::Ellipsis, Self::Ellipsis)
|
||||||
|
@ -1684,8 +1684,8 @@ impl Type {
|
||||||
| Self::Inf
|
| Self::Inf
|
||||||
| Self::NegInf
|
| Self::NegInf
|
||||||
| Self::Type
|
| Self::Type
|
||||||
| Self::Class
|
| Self::ClassType
|
||||||
| Self::Trait
|
| Self::TraitType
|
||||||
| Self::Patch
|
| Self::Patch
|
||||||
| Self::NotImplemented
|
| Self::NotImplemented
|
||||||
| Self::Ellipsis
|
| Self::Ellipsis
|
||||||
|
@ -1757,7 +1757,7 @@ impl Type {
|
||||||
pub fn is_type(&self) -> bool {
|
pub fn is_type(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_type(),
|
Self::FreeVar(fv) if fv.is_linked() => fv.crack().is_type(),
|
||||||
Self::Type | Self::Class | Self::Trait => true,
|
Self::Type | Self::ClassType | Self::TraitType => true,
|
||||||
Self::Refinement(refine) => refine.t.is_type(),
|
Self::Refinement(refine) => refine.t.is_type(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -1855,8 +1855,8 @@ impl Type {
|
||||||
Self::Str => Str::ever("Str"),
|
Self::Str => Str::ever("Str"),
|
||||||
Self::NoneType => Str::ever("NoneType"),
|
Self::NoneType => Str::ever("NoneType"),
|
||||||
Self::Type => Str::ever("Type"),
|
Self::Type => Str::ever("Type"),
|
||||||
Self::Class => Str::ever("ClassType"),
|
Self::ClassType => Str::ever("ClassType"),
|
||||||
Self::Trait => Str::ever("TraitType"),
|
Self::TraitType => Str::ever("TraitType"),
|
||||||
Self::Patch => Str::ever("Patch"),
|
Self::Patch => Str::ever("Patch"),
|
||||||
Self::Code => Str::ever("Code"),
|
Self::Code => Str::ever("Code"),
|
||||||
Self::Frame => Str::ever("Frame"),
|
Self::Frame => Str::ever("Frame"),
|
||||||
|
|
|
@ -70,8 +70,8 @@ impl GenTypeObj {
|
||||||
|
|
||||||
pub fn meta_type(&self) -> Type {
|
pub fn meta_type(&self) -> Type {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
TypeKind::Class | TypeKind::Subclass => Type::Class,
|
TypeKind::Class | TypeKind::Subclass => Type::ClassType,
|
||||||
TypeKind::Trait | TypeKind::Subtrait | TypeKind::StructuralTrait => Type::Trait,
|
TypeKind::Trait | TypeKind::Subtrait | TypeKind::StructuralTrait => Type::TraitType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue