mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 18:29:00 +00:00
feat: add Slice
This commit is contained in:
parent
8a47c4bd18
commit
579615d76e
3 changed files with 22 additions and 0 deletions
|
@ -1330,6 +1330,12 @@ impl Context {
|
|||
array_t(T.clone(), TyParam::erased(Nat)),
|
||||
);
|
||||
array_.register_py_builtin(FUNC_DEDUP, t.quantify(), Some(FUNC_DEDUP), 28);
|
||||
/* Slice */
|
||||
let mut slice = Self::builtin_mono_class(SLICE, 3);
|
||||
slice.register_superclass(Obj, &obj);
|
||||
slice.register_builtin_erg_impl(KW_START, Int, Immutable, Visibility::BUILTIN_PUBLIC);
|
||||
slice.register_builtin_erg_impl(KW_STOP, Int, Immutable, Visibility::BUILTIN_PUBLIC);
|
||||
slice.register_builtin_erg_impl(KW_STEP, Int, Immutable, Visibility::BUILTIN_PUBLIC);
|
||||
/* GenericSet */
|
||||
let mut generic_set = Self::builtin_mono_class(GENERIC_SET, 1);
|
||||
generic_set.register_superclass(Obj, &obj);
|
||||
|
@ -2370,6 +2376,7 @@ impl Context {
|
|||
Some(ARRAY),
|
||||
);
|
||||
self.register_builtin_type(arr_t, array_, vis.clone(), Const, Some(ARRAY));
|
||||
self.register_builtin_type(mono(SLICE), slice, vis.clone(), Const, Some(FUNC_SLICE));
|
||||
self.register_builtin_type(
|
||||
mono(GENERIC_SET),
|
||||
generic_set,
|
||||
|
|
|
@ -220,6 +220,12 @@ impl Context {
|
|||
)
|
||||
.quantify();
|
||||
let t_round = nd_func(vec![kw(KW_NUMBER, Float)], None, Int);
|
||||
let t_slice = func(
|
||||
vec![kw(KW_START, Int)],
|
||||
None,
|
||||
vec![kw(KW_STOP, Int), kw(KW_STEP, Int)],
|
||||
mono(SLICE),
|
||||
);
|
||||
let t_sorted = nd_func(
|
||||
vec![kw(KW_ITERABLE, poly(ITERABLE, vec![ty_tp(T.clone())]))],
|
||||
None,
|
||||
|
@ -393,6 +399,13 @@ impl Context {
|
|||
vis.clone(),
|
||||
Some(FUNC_ROUND),
|
||||
);
|
||||
self.register_builtin_py_impl(
|
||||
FUNC_SLICE,
|
||||
t_slice,
|
||||
Immutable,
|
||||
vis.clone(),
|
||||
Some(FUNC_SLICE),
|
||||
);
|
||||
self.register_builtin_py_impl(
|
||||
FUNC_SORTED,
|
||||
t_sorted,
|
||||
|
|
|
@ -284,6 +284,7 @@ const NAMED_FUNC: &str = "NamedFunc";
|
|||
const FUNC: &str = "Func";
|
||||
const QUANTIFIED: &str = "Quantified";
|
||||
const QUANTIFIED_FUNC: &str = "QuantifiedFunc";
|
||||
const SLICE: &str = "Slice";
|
||||
const FUNC_OBJECT: &str = "object";
|
||||
const FUNC_INT: &str = "int";
|
||||
const FUNC_INT__: &str = "int__";
|
||||
|
@ -335,6 +336,7 @@ const FUNC_POW: &str = "pow";
|
|||
const FUNC_QUIT: &str = "quit";
|
||||
const FUNC_REPR: &str = "repr";
|
||||
const FUNC_ROUND: &str = "round";
|
||||
const FUNC_SLICE: &str = "slice";
|
||||
const FUNC_SORTED: &str = "sorted";
|
||||
const FUNC_SUM: &str = "sum";
|
||||
const FUNC_IF: &str = "if";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue