mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 12:14:43 +00:00
feat: add asyncio
type decls
This commit is contained in:
parent
4cd79cbb1a
commit
c6882fee53
11 changed files with 78 additions and 3 deletions
|
@ -4023,6 +4023,12 @@ impl Context {
|
||||||
Immutable,
|
Immutable,
|
||||||
Visibility::BUILTIN_PRIVATE,
|
Visibility::BUILTIN_PRIVATE,
|
||||||
);
|
);
|
||||||
|
let coro_t = poly(COROUTINE, vec![ty_tp(T.clone())]);
|
||||||
|
let mut coroutine = Self::builtin_poly_class(COROUTINE, vec![PS::t_nd(TY_T)], 2);
|
||||||
|
coroutine.register_superclass(mono(SUBROUTINE), &subr);
|
||||||
|
coroutine
|
||||||
|
.register_trait(self, poly(OUTPUT, vec![ty_tp(T.clone())]))
|
||||||
|
.unwrap();
|
||||||
// TODO: non-builtin
|
// TODO: non-builtin
|
||||||
/* Dimension */
|
/* Dimension */
|
||||||
let Ty = type_q("Ty");
|
let Ty = type_q("Ty");
|
||||||
|
@ -4644,6 +4650,7 @@ impl Context {
|
||||||
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(generator_t, generator, vis.clone(), Const, Some(GENERATOR));
|
self.register_builtin_type(generator_t, generator, vis.clone(), Const, Some(GENERATOR));
|
||||||
|
self.register_builtin_type(coro_t, coroutine, vis.clone(), Const, Some(FUNC_COROUTINE));
|
||||||
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),
|
||||||
|
|
|
@ -553,6 +553,8 @@ const FUNC_NEARLY_EQ: &str = "nearly_eq";
|
||||||
const FUNC_RESOLVE_PATH: &str = "ResolvePath";
|
const FUNC_RESOLVE_PATH: &str = "ResolvePath";
|
||||||
const FUNC_RESOLVE_DECL_PATH: &str = "ResolveDeclPath";
|
const FUNC_RESOLVE_DECL_PATH: &str = "ResolveDeclPath";
|
||||||
const FUNC_PROD: &str = "prod";
|
const FUNC_PROD: &str = "prod";
|
||||||
|
const COROUTINE: &str = "Coroutine";
|
||||||
|
const FUNC_COROUTINE: &str = "coroutine";
|
||||||
|
|
||||||
const OP_EQ: &str = "__eq__";
|
const OP_EQ: &str = "__eq__";
|
||||||
const OP_HASH: &str = "__hash__";
|
const OP_HASH: &str = "__hash__";
|
||||||
|
|
19
crates/erg_compiler/lib/pystd/asyncio.d/__init__.d.er
Normal file
19
crates/erg_compiler/lib/pystd/asyncio.d/__init__.d.er
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{.BaseEventLoop!; .Server!} = import "base_events"
|
||||||
|
{.iscoroutine;. iscoroutinefunction;} = pyimport "coroutines"
|
||||||
|
{
|
||||||
|
.AbstractEventLoop!;
|
||||||
|
.AbstractEventLoopPolicy!;
|
||||||
|
.AbstractServer!;
|
||||||
|
.Handle!;
|
||||||
|
.TimerHandle!;
|
||||||
|
} = pyimport "events"
|
||||||
|
{
|
||||||
|
.LifoQueue!;
|
||||||
|
.PriorityQueue!;
|
||||||
|
.Queue!;
|
||||||
|
.QueueEmpty;
|
||||||
|
.QueueFull;
|
||||||
|
} = pyimport "queues"
|
||||||
|
{.Runner!; .run!;} = pyimport "runners"
|
||||||
|
{.Task!; .current_task!; .gather!; .sleep!;} = pyimport "tasks"
|
||||||
|
{.to_thread!;} = pyimport "threads"
|
3
crates/erg_compiler/lib/pystd/asyncio.d/base_events.d.er
Normal file
3
crates/erg_compiler/lib/pystd/asyncio.d/base_events.d.er
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.BaseEventLoop!: ClassType
|
||||||
|
|
||||||
|
.Server!: ClassType
|
2
crates/erg_compiler/lib/pystd/asyncio.d/coroutines.d.er
Normal file
2
crates/erg_compiler/lib/pystd/asyncio.d/coroutines.d.er
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.iscoroutinefunction: (obj: Obj) -> Bool
|
||||||
|
.iscoroutine: (obj: Obj) -> Bool
|
8
crates/erg_compiler/lib/pystd/asyncio.d/events.d.er
Normal file
8
crates/erg_compiler/lib/pystd/asyncio.d/events.d.er
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
.Handle!: ClassType
|
||||||
|
|
||||||
|
.TimerHandle!: ClassType
|
||||||
|
.TimerHandle! <: Handle!
|
||||||
|
|
||||||
|
.AbstractServer!: ClassType
|
||||||
|
.AbstractEventLoop!: ClassType
|
||||||
|
.AbstractEventLoopPolicy!: ClassType
|
11
crates/erg_compiler/lib/pystd/asyncio.d/futures.d.er
Normal file
11
crates/erg_compiler/lib/pystd/asyncio.d/futures.d.er
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.Future!: ClassType
|
||||||
|
.Future!.
|
||||||
|
result: (self: Ref Future!) -> Obj
|
||||||
|
exception: (self: Ref Future!) -> Exception
|
||||||
|
done: (self: Ref Future!) -> Bool
|
||||||
|
cancelled: (self: Ref Future!) -> Bool
|
||||||
|
set_result!: (self: RefMut Future!, result: Obj) => NoneType
|
||||||
|
set_exception!: (self: RefMut Future!, exception: Exception) => NoneType
|
||||||
|
cancel!: (self: RefMut Future!, msg := Str) => Bool
|
||||||
|
|
||||||
|
.isfuture: (obj: Obj) -> Bool
|
13
crates/erg_compiler/lib/pystd/asyncio.d/queues.d.er
Normal file
13
crates/erg_compiler/lib/pystd/asyncio.d/queues.d.er
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
.QueueEmpty: ClassType
|
||||||
|
.QueueEmpty <: BaseException
|
||||||
|
|
||||||
|
.QueueFull: ClassType
|
||||||
|
.QueueFull <: BaseException
|
||||||
|
|
||||||
|
.Queue!: ClassType
|
||||||
|
|
||||||
|
.PriorityQueue!: ClassType
|
||||||
|
.PriorityQueue! <: Queue!
|
||||||
|
|
||||||
|
.LifoQueue!: ClassType
|
||||||
|
.LifoQueue! <: Queue!
|
8
crates/erg_compiler/lib/pystd/asyncio.d/runners.d.er
Normal file
8
crates/erg_compiler/lib/pystd/asyncio.d/runners.d.er
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
.Runner!: ClassType
|
||||||
|
.Runner!.
|
||||||
|
run!: (self: Runner!, coro: GenericCallable, debug := Bool) => NoneType
|
||||||
|
close!: (self: Runner!) => NoneType
|
||||||
|
get_loop!: (self: Runner!) => NoneType
|
||||||
|
|
||||||
|
# TODO: return value
|
||||||
|
.run!: (coro: GenericCallable, debug := Bool) => NoneType
|
|
@ -1,4 +1,5 @@
|
||||||
# TODO: return value
|
.Task!: ClassType
|
||||||
.run!: (coro: GenericCallable, debug := Bool) => NoneType
|
|
||||||
.sleep!: (delay: Float) => NoneType
|
.current_task!: (loop := Obj) => Task!
|
||||||
.gather!: (*coros: GenericCallable) => NoneType
|
.gather!: (*coros: GenericCallable) => NoneType
|
||||||
|
.sleep!: (delay: Float) => NoneType
|
1
crates/erg_compiler/lib/pystd/asyncio.d/threads.d.er
Normal file
1
crates/erg_compiler/lib/pystd/asyncio.d/threads.d.er
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.to_thread!: (func: GenericCallable) => Obj
|
Loading…
Add table
Add a link
Reference in a new issue