Skip to content

Commit

Permalink
feat: add Slice
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Jul 14, 2023
1 parent 8a47c4b commit 579615d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/erg_compiler/context/initialize/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions crates/erg_compiler/context/initialize/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/erg_compiler/context/initialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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__";
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 579615d

Please sign in to comment.