mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
feat: add Generator
* remove `GenericGenerator`
This commit is contained in:
parent
0cffbd7249
commit
1f5e9cbc9f
3 changed files with 11 additions and 14 deletions
|
@ -4045,10 +4045,14 @@ impl Context {
|
||||||
Immutable,
|
Immutable,
|
||||||
Visibility::BUILTIN_PRIVATE,
|
Visibility::BUILTIN_PRIVATE,
|
||||||
);
|
);
|
||||||
let mut g_generator = Self::builtin_mono_class(GENERIC_GENERATOR, 2);
|
let generator_t = poly(GENERATOR, vec![ty_tp(T.clone())]);
|
||||||
g_generator.register_superclass(mono(SUBROUTINE), &subr);
|
let mut generator = Self::builtin_poly_class(GENERATOR, vec![PS::t_nd(TY_T)], 2);
|
||||||
let t_yield = fn1_met(mono(GENERIC_GENERATOR), Obj, Never).quantify();
|
generator.register_superclass(mono(SUBROUTINE), &subr);
|
||||||
g_generator.register_builtin_erg_impl(
|
generator
|
||||||
|
.register_trait(self, poly(ITERATOR, vec![ty_tp(T.clone())]))
|
||||||
|
.unwrap();
|
||||||
|
let t_yield = fn1_met(generator_t.clone(), T.clone(), Never).quantify();
|
||||||
|
generator.register_builtin_erg_impl(
|
||||||
FUNC_YIELD,
|
FUNC_YIELD,
|
||||||
t_yield,
|
t_yield,
|
||||||
Immutable,
|
Immutable,
|
||||||
|
@ -4674,13 +4678,7 @@ impl Context {
|
||||||
self.register_builtin_type(dict_mut_t, dict_mut, vis.clone(), Const, Some(DICT));
|
self.register_builtin_type(dict_mut_t, dict_mut, vis.clone(), Const, Some(DICT));
|
||||||
self.register_builtin_type(set_mut_t, set_mut_, vis.clone(), Const, Some(SET));
|
self.register_builtin_type(set_mut_t, set_mut_, vis.clone(), Const, Some(SET));
|
||||||
self.register_builtin_type(mono(SUBROUTINE), subr, vis.clone(), Const, Some(SUBROUTINE));
|
self.register_builtin_type(mono(SUBROUTINE), subr, vis.clone(), Const, Some(SUBROUTINE));
|
||||||
self.register_builtin_type(
|
self.register_builtin_type(generator_t, generator, vis.clone(), Const, Some(GENERATOR));
|
||||||
mono(GENERIC_GENERATOR),
|
|
||||||
g_generator,
|
|
||||||
vis.clone(),
|
|
||||||
Const,
|
|
||||||
Some(GENERATOR),
|
|
||||||
);
|
|
||||||
self.register_builtin_type(dimension_t, dimension, vis.clone(), Const, Some(DIMENSION));
|
self.register_builtin_type(dimension_t, dimension, vis.clone(), Const, Some(DIMENSION));
|
||||||
self.register_builtin_type(
|
self.register_builtin_type(
|
||||||
mono(BASE_EXCEPTION),
|
mono(BASE_EXCEPTION),
|
||||||
|
|
|
@ -352,7 +352,6 @@ const PROC_INVERT: &str = "invert!";
|
||||||
const RANGE: &str = "Range";
|
const RANGE: &str = "Range";
|
||||||
const GENERIC_CALLABLE: &str = "GenericCallable";
|
const GENERIC_CALLABLE: &str = "GenericCallable";
|
||||||
const SUBROUTINE: &str = "Subroutine";
|
const SUBROUTINE: &str = "Subroutine";
|
||||||
const GENERIC_GENERATOR: &str = "GenericGenerator";
|
|
||||||
const FUNC_RETURN: &str = "return";
|
const FUNC_RETURN: &str = "return";
|
||||||
const FUNC_YIELD: &str = "yield";
|
const FUNC_YIELD: &str = "yield";
|
||||||
const PROC: &str = "Proc";
|
const PROC: &str = "Proc";
|
||||||
|
|
|
@ -45,9 +45,9 @@
|
||||||
chmod!: (self: .Path, mode: Nat) => NoneType
|
chmod!: (self: .Path, mode: Nat) => NoneType
|
||||||
exists!: (self: .Path) => Bool
|
exists!: (self: .Path) => Bool
|
||||||
expanduser!: (self: .Path) => .Path
|
expanduser!: (self: .Path) => .Path
|
||||||
glob!: (self: .Path, pattern: Str) -> Iterable .Path
|
glob!: (self: .Path, pattern: Str) -> Generator .Path
|
||||||
home!: () => .Path
|
home!: () => .Path
|
||||||
iterdir!: (self: .Path) => Iterable .Path
|
iterdir!: (self: .Path) => Generator .Path
|
||||||
joinpath: (self: .Path, *other: PathLike) -> .Path
|
joinpath: (self: .Path, *other: PathLike) -> .Path
|
||||||
mkdir!: (self: .Path, mode := Nat, parents := Bool, exist_ok := Bool) => NoneType
|
mkdir!: (self: .Path, mode := Nat, parents := Bool, exist_ok := Bool) => NoneType
|
||||||
open!: (self: .Path, mode := Str) => File!
|
open!: (self: .Path, mode := Str) => File!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue