From b8b6acdf3a5565546042d44d81bcf65bd1deb93b Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Sat, 8 Oct 2022 10:38:46 +0900 Subject: [PATCH] Rename: Type::Class -> Type::ClassType --- compiler/erg_compiler/context/compare.rs | 2 +- .../erg_compiler/context/initialize/mod.rs | 31 ++++++++++++------- compiler/erg_compiler/lower.rs | 6 ++-- compiler/erg_type/lib.rs | 18 +++++------ compiler/erg_type/value.rs | 4 +-- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/compiler/erg_compiler/context/compare.rs b/compiler/erg_compiler/context/compare.rs index b3b3d0f8..b1648738 100644 --- a/compiler/erg_compiler/context/compare.rs +++ b/compiler/erg_compiler/context/compare.rs @@ -163,7 +163,7 @@ impl Context { | (Float | Ratio | Int, Int) | (Float | Ratio, Ratio) | (Float, Float) => (Absolutely, true), - (Type, Class | Trait) => (Absolutely, true), + (Type, ClassType | TraitType) => (Absolutely, true), (Type, Record(rec)) => ( Absolutely, rec.iter().all(|(_, attr)| self.supertype_of(&Type, attr)), diff --git a/compiler/erg_compiler/context/initialize/mod.rs b/compiler/erg_compiler/context/initialize/mod.rs index 589a7596..3a7d01e5 100644 --- a/compiler/erg_compiler/context/initialize/mod.rs +++ b/compiler/erg_compiler/context/initialize/mod.rs @@ -772,8 +772,17 @@ impl Context { class_type.register_superclass(Type, &type_); class_type.register_marker_trait(builtin_mono("Named")); let mut class_eq = Self::builtin_methods("Eq", 2); - class_eq.register_builtin_impl("__eq__", fn1_met(Class, Class, Bool), Const, Public); - class_type.register_trait(Class, builtin_poly("Eq", vec![ty_tp(Class)]), class_eq); + class_eq.register_builtin_impl( + "__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 mut generic_module = Self::builtin_mono_class("GenericModule", 2); generic_module.register_superclass(Obj, &obj); @@ -1645,7 +1654,7 @@ impl Context { self.register_builtin_type(Bool, bool_, Const); self.register_builtin_type(Str, str_, 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(module_t, module, Const); self.register_builtin_type(array_t, array_, Const); @@ -1741,7 +1750,7 @@ impl Context { vec![kw("err_message", Str)], 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_cond = nd_func( vec![ @@ -1820,15 +1829,15 @@ impl Context { vec![kw("Requirement", Type)], None, vec![kw("Impl", Type)], - Class, + ClassType, ); let class = ConstSubr::Builtin(BuiltinConstSubr::new("Class", class_func, class_t, None)); self.register_builtin_const("Class", ValueObj::Subr(class)); let inherit_t = func( - vec![kw("Super", Class)], + vec![kw("Super", ClassType)], None, vec![kw("Impl", Type), kw("Additional", Type)], - Class, + ClassType, ); let inherit = ConstSubr::Builtin(BuiltinConstSubr::new( "Inherit", @@ -1841,15 +1850,15 @@ impl Context { vec![kw("Requirement", Type)], None, vec![kw("Impl", Type)], - Trait, + TraitType, ); let trait_ = ConstSubr::Builtin(BuiltinConstSubr::new("Trait", trait_func, trait_t, None)); self.register_builtin_const("Trait", ValueObj::Subr(trait_)); let subsume_t = func( - vec![kw("Super", Trait)], + vec![kw("Super", TraitType)], None, vec![kw("Impl", Type), kw("Additional", Type)], - Trait, + TraitType, ); let subsume = ConstSubr::Builtin(BuiltinConstSubr::new( "Subsume", @@ -1859,7 +1868,7 @@ impl Context { )); self.register_builtin_const("Subsume", ValueObj::Subr(subsume)); // decorators - let inheritable_t = func1(Class, Class); + let inheritable_t = func1(ClassType, ClassType); let inheritable = ConstSubr::Builtin(BuiltinConstSubr::new( "Inheritable", inheritable_func, diff --git a/compiler/erg_compiler/lower.rs b/compiler/erg_compiler/lower.rs index 43bd9b01..d6d1ae49 100644 --- a/compiler/erg_compiler/lower.rs +++ b/compiler/erg_compiler/lower.rs @@ -1131,7 +1131,7 @@ impl ASTLowerer { loc, self.ctx.caused_by(), &impl_trait.name(), - &Type::Trait, + &Type::TraitType, &trait_obj.t(), None, None, @@ -1359,7 +1359,7 @@ impl ASTLowerer { ast::DefId(0), )?; match t { - Type::Class => { + Type::ClassType => { let ty_obj = GenTypeObj::new( TypeKind::Class, mono(self.ctx.path(), ident.inspect()), @@ -1369,7 +1369,7 @@ impl ASTLowerer { ); self.ctx.register_gen_type(&ident, ty_obj); } - Type::Trait => { + Type::TraitType => { let ty_obj = GenTypeObj::new( TypeKind::Trait, mono(self.ctx.path(), ident.inspect()), diff --git a/compiler/erg_type/lib.rs b/compiler/erg_type/lib.rs index 30b0a440..1aa7a7d8 100644 --- a/compiler/erg_type/lib.rs +++ b/compiler/erg_type/lib.rs @@ -1119,8 +1119,8 @@ pub enum Type { NegInf, // {-∞} // TODO: PolyType/Class Type, - Class, - Trait, + ClassType, + TraitType, Patch, NotImplemented, Ellipsis, // これはクラスのほうで型推論用のマーカーではない @@ -1197,8 +1197,8 @@ impl PartialEq for Type { | (Self::Inf, Self::Inf) | (Self::NegInf, Self::NegInf) | (Self::Type, Self::Type) - | (Self::Class, Self::Class) - | (Self::Trait, Self::Trait) + | (Self::ClassType, Self::ClassType) + | (Self::TraitType, Self::TraitType) | (Self::Patch, Self::Patch) | (Self::NotImplemented, Self::NotImplemented) | (Self::Ellipsis, Self::Ellipsis) @@ -1684,8 +1684,8 @@ impl Type { | Self::Inf | Self::NegInf | Self::Type - | Self::Class - | Self::Trait + | Self::ClassType + | Self::TraitType | Self::Patch | Self::NotImplemented | Self::Ellipsis @@ -1757,7 +1757,7 @@ impl Type { pub fn is_type(&self) -> bool { match self { 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(), _ => false, } @@ -1855,8 +1855,8 @@ impl Type { Self::Str => Str::ever("Str"), Self::NoneType => Str::ever("NoneType"), Self::Type => Str::ever("Type"), - Self::Class => Str::ever("ClassType"), - Self::Trait => Str::ever("TraitType"), + Self::ClassType => Str::ever("ClassType"), + Self::TraitType => Str::ever("TraitType"), Self::Patch => Str::ever("Patch"), Self::Code => Str::ever("Code"), Self::Frame => Str::ever("Frame"), diff --git a/compiler/erg_type/value.rs b/compiler/erg_type/value.rs index 66986c53..eb951748 100644 --- a/compiler/erg_type/value.rs +++ b/compiler/erg_type/value.rs @@ -70,8 +70,8 @@ impl GenTypeObj { pub fn meta_type(&self) -> Type { match self.kind { - TypeKind::Class | TypeKind::Subclass => Type::Class, - TypeKind::Trait | TypeKind::Subtrait | TypeKind::StructuralTrait => Type::Trait, + TypeKind::Class | TypeKind::Subclass => Type::ClassType, + TypeKind::Trait | TypeKind::Subtrait | TypeKind::StructuralTrait => Type::TraitType, } } }