feat: add asyncio type decls

This commit is contained in:
Shunsuke Shibayama 2024-10-06 18:30:08 +09:00
parent 4cd79cbb1a
commit c6882fee53
11 changed files with 78 additions and 3 deletions

View file

@ -4023,6 +4023,12 @@ impl Context {
Immutable,
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
/* Dimension */
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(mono(SUBROUTINE), subr, vis.clone(), Const, Some(SUBROUTINE));
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(
mono(BASE_EXCEPTION),

View file

@ -553,6 +553,8 @@ const FUNC_NEARLY_EQ: &str = "nearly_eq";
const FUNC_RESOLVE_PATH: &str = "ResolvePath";
const FUNC_RESOLVE_DECL_PATH: &str = "ResolveDeclPath";
const FUNC_PROD: &str = "prod";
const COROUTINE: &str = "Coroutine";
const FUNC_COROUTINE: &str = "coroutine";
const OP_EQ: &str = "__eq__";
const OP_HASH: &str = "__hash__";

View 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"

View file

@ -0,0 +1,3 @@
.BaseEventLoop!: ClassType
.Server!: ClassType

View file

@ -0,0 +1,2 @@
.iscoroutinefunction: (obj: Obj) -> Bool
.iscoroutine: (obj: Obj) -> Bool

View file

@ -0,0 +1,8 @@
.Handle!: ClassType
.TimerHandle!: ClassType
.TimerHandle! <: Handle!
.AbstractServer!: ClassType
.AbstractEventLoop!: ClassType
.AbstractEventLoopPolicy!: ClassType

View 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

View file

@ -0,0 +1,13 @@
.QueueEmpty: ClassType
.QueueEmpty <: BaseException
.QueueFull: ClassType
.QueueFull <: BaseException
.Queue!: ClassType
.PriorityQueue!: ClassType
.PriorityQueue! <: Queue!
.LifoQueue!: ClassType
.LifoQueue! <: Queue!

View 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

View file

@ -1,4 +1,5 @@
# TODO: return value
.run!: (coro: GenericCallable, debug := Bool) => NoneType
.sleep!: (delay: Float) => NoneType
.Task!: ClassType
.current_task!: (loop := Obj) => Task!
.gather!: (*coros: GenericCallable) => NoneType
.sleep!: (delay: Float) => NoneType

View file

@ -0,0 +1 @@
.to_thread!: (func: GenericCallable) => Obj