mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
chore: Str, Array: Sized
This commit is contained in:
parent
9cb98b8af0
commit
5e8d1b987a
2 changed files with 21 additions and 12 deletions
|
@ -923,17 +923,11 @@ impl Context {
|
|||
str_.register_trait(Str, str_eq);
|
||||
let mut str_seq = Self::builtin_methods(Some(poly(SEQUENCE, vec![ty_tp(Str)])), 2);
|
||||
str_seq.register_builtin_erg_impl(
|
||||
FUNC_LEN,
|
||||
FUNDAMENTAL_LEN,
|
||||
fn0_met(Str, Nat),
|
||||
Const,
|
||||
Visibility::BUILTIN_PUBLIC,
|
||||
);
|
||||
str_seq.register_builtin_erg_impl(
|
||||
FUNC_GET,
|
||||
fn1_met(Str, Nat, Str),
|
||||
Const,
|
||||
Visibility::BUILTIN_PUBLIC,
|
||||
);
|
||||
str_.register_trait(Str, str_seq);
|
||||
let mut str_add = Self::builtin_methods(Some(poly(ADD, vec![ty_tp(Str)])), 2);
|
||||
str_add.register_builtin_erg_impl(
|
||||
|
@ -1262,6 +1256,14 @@ impl Context {
|
|||
array_
|
||||
.register_marker_trait(self, poly(INDEXABLE, vec![ty_tp(input), ty_tp(T.clone())]))
|
||||
.unwrap();
|
||||
let mut array_sized = Self::builtin_methods(Some(mono(SIZED)), 2);
|
||||
array_sized.register_builtin_erg_impl(
|
||||
FUNDAMENTAL_LEN,
|
||||
fn0_met(arr_t.clone(), Nat).quantify(),
|
||||
Const,
|
||||
Visibility::BUILTIN_PUBLIC,
|
||||
);
|
||||
array_.register_trait(arr_t.clone(), array_sized);
|
||||
// union: (self: [Type; _]) -> Type
|
||||
let array_union_t = fn0_met(array_t(Type, TyParam::erased(Nat)), Type).quantify();
|
||||
let union = ValueObj::Subr(ConstSubr::Builtin(BuiltinConstSubr::new(
|
||||
|
|
|
@ -129,11 +129,18 @@ impl Context {
|
|||
);
|
||||
let I = mono_q(TY_I, subtypeof(poly(ITERABLE, vec![ty_tp(T.clone())])));
|
||||
let t_iter = nd_func(vec![kw(KW_OBJECT, I.clone())], None, proj(I, ITERATOR)).quantify();
|
||||
let t_len = nd_func(
|
||||
vec![kw(KW_S, poly(SEQUENCE, vec![TyParam::erased(Type)]))],
|
||||
None,
|
||||
Nat,
|
||||
);
|
||||
// Python : |L|(seq: Structural({ .__len__ = (L) -> Nat })) -> Nat
|
||||
let t_len = if ERG_MODE {
|
||||
nd_func(
|
||||
vec![kw(KW_S, poly(SEQUENCE, vec![TyParam::erased(Type)]))],
|
||||
None,
|
||||
Nat,
|
||||
)
|
||||
} else {
|
||||
let S = Type::from(dict! { Field::public("__len__".into()) => fn0_met(Never, Nat) })
|
||||
.structuralize();
|
||||
func1(S, Nat)
|
||||
};
|
||||
let t_log = func(
|
||||
vec![],
|
||||
Some(kw(KW_OBJECTS, ref_(Obj))),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue