mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
feat: add ctypes
type decl
This commit is contained in:
parent
6c07d1fbe3
commit
0667644580
8 changed files with 117 additions and 6 deletions
|
@ -3745,6 +3745,8 @@ impl Context {
|
||||||
/* ByteArray! */
|
/* ByteArray! */
|
||||||
let bytearray_mut_t = mono(MUT_BYTEARRAY);
|
let bytearray_mut_t = mono(MUT_BYTEARRAY);
|
||||||
let mut bytearray_mut = Self::builtin_mono_class(MUT_BYTEARRAY, 2);
|
let mut bytearray_mut = Self::builtin_mono_class(MUT_BYTEARRAY, 2);
|
||||||
|
// TODO: different class
|
||||||
|
bytearray_mut.register_superclass(mono(BYTES), &bytes);
|
||||||
let mut bytearray_seq = Self::builtin_methods(Some(poly(SEQUENCE, vec![ty_tp(Int)])), 2);
|
let mut bytearray_seq = Self::builtin_methods(Some(poly(SEQUENCE, vec![ty_tp(Int)])), 2);
|
||||||
bytearray_seq.register_builtin_erg_impl(
|
bytearray_seq.register_builtin_erg_impl(
|
||||||
FUNDAMENTAL_LEN,
|
FUNDAMENTAL_LEN,
|
||||||
|
|
|
@ -419,7 +419,7 @@ impl Context {
|
||||||
let t_vars = no_var_func(
|
let t_vars = no_var_func(
|
||||||
vec![],
|
vec![],
|
||||||
vec![kw_default(KW_OBJECT, Obj, Obj)],
|
vec![kw_default(KW_OBJECT, Obj, Obj)],
|
||||||
dict! { Str => Obj }.into(),
|
out_dict_t(dict! { Str => Obj }.into()),
|
||||||
);
|
);
|
||||||
let t_zip = nd_func(
|
let t_zip = nd_func(
|
||||||
vec![
|
vec![
|
||||||
|
@ -1003,7 +1003,7 @@ impl Context {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let t_exec = func(
|
let t_exec = func(
|
||||||
vec![kw(KW_CODE, Str)],
|
vec![kw(KW_CODE, Str | Code)],
|
||||||
None,
|
None,
|
||||||
vec![
|
vec![
|
||||||
kw(KW_GLOBALS, mono(GENERIC_DICT)),
|
kw(KW_GLOBALS, mono(GENERIC_DICT)),
|
||||||
|
@ -1020,7 +1020,7 @@ impl Context {
|
||||||
Some(FUNC_EXEC),
|
Some(FUNC_EXEC),
|
||||||
);
|
);
|
||||||
let t_eval = func(
|
let t_eval = func(
|
||||||
vec![kw(KW_CODE, Str)],
|
vec![kw(KW_CODE, Str | Code)],
|
||||||
None,
|
None,
|
||||||
vec![
|
vec![
|
||||||
kw(KW_GLOBALS, mono(GENERIC_DICT)),
|
kw(KW_GLOBALS, mono(GENERIC_DICT)),
|
||||||
|
|
|
@ -74,9 +74,9 @@ impl Context {
|
||||||
NoneType,
|
NoneType,
|
||||||
)
|
)
|
||||||
.quantify();
|
.quantify();
|
||||||
let t_globals = no_var_proc(vec![], vec![], dict! { Str => Obj }.into());
|
let t_globals = no_var_proc(vec![], vec![], out_dict_t(dict! { Str => Obj }.into()));
|
||||||
let t_help = nd_proc(vec![kw("object", ref_(Obj))], None, NoneType);
|
let t_help = nd_proc(vec![kw("object", ref_(Obj))], None, NoneType);
|
||||||
let t_locals = no_var_proc(vec![], vec![], dict! { Str => Obj }.into());
|
let t_locals = no_var_proc(vec![], vec![], out_dict_t(dict! { Str => Obj }.into()));
|
||||||
let t_next = nd_proc(
|
let t_next = nd_proc(
|
||||||
vec![kw(
|
vec![kw(
|
||||||
"iterable",
|
"iterable",
|
||||||
|
|
108
crates/erg_compiler/lib/pystd/ctypes.d/__init__.d.er
Normal file
108
crates/erg_compiler/lib/pystd/ctypes.d/__init__.d.er
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
._CData: ClassType
|
||||||
|
._SimpleCData: ClassType
|
||||||
|
._SimpleCData <: _CData
|
||||||
|
|
||||||
|
.CBool = 'c_bool': ClassType
|
||||||
|
.CBool <: _SimpleCData
|
||||||
|
.CBool.
|
||||||
|
__call__: (value:= Bool) -> CBool
|
||||||
|
.CChar = 'c_char': ClassType
|
||||||
|
.CChar <: _SimpleCData
|
||||||
|
.CChar.
|
||||||
|
__call__: (value:= Bytes or ByteArray! or Int) -> CChar
|
||||||
|
.CWChar = 'c_wchar': ClassType
|
||||||
|
.CWChar <: _SimpleCData
|
||||||
|
.CWChar.
|
||||||
|
__call__: (value:= Str) -> CWChar
|
||||||
|
.CByte = 'c_byte': ClassType
|
||||||
|
.CByte <: _SimpleCData
|
||||||
|
.CByte.
|
||||||
|
__call__: (value:= Int) -> CByte
|
||||||
|
.CUByte = 'c_ubyte': ClassType
|
||||||
|
.CUByte <: _SimpleCData
|
||||||
|
.CUByte.
|
||||||
|
__call__: (value:= Int) -> CUByte
|
||||||
|
.CShort = 'c_short': ClassType
|
||||||
|
.CShort <: _SimpleCData
|
||||||
|
.CShort.
|
||||||
|
__call__: (value:= Int) -> CShort
|
||||||
|
.CUShort = 'c_ushort': ClassType
|
||||||
|
.CUShort <: _SimpleCData
|
||||||
|
.CUShort.
|
||||||
|
__call__: (value:= Int) -> CUShort
|
||||||
|
.CInt = 'c_int': ClassType
|
||||||
|
.CInt <: _SimpleCData
|
||||||
|
.CInt.
|
||||||
|
__call__: (value:= Int) -> CInt
|
||||||
|
.CUInt = 'c_uint': ClassType
|
||||||
|
.CUInt <: _SimpleCData
|
||||||
|
.CUInt.
|
||||||
|
__call__: (value:= Int) -> CUInt
|
||||||
|
.CLong = 'c_long': ClassType
|
||||||
|
.CLong <: _SimpleCData
|
||||||
|
.CLong.
|
||||||
|
__call__: (value:= Int) -> CLong
|
||||||
|
.CULong = 'c_ulong': ClassType
|
||||||
|
.CULong <: _SimpleCData
|
||||||
|
.CULong.
|
||||||
|
__call__: (value:= Int) -> CULong
|
||||||
|
.CLongLong = 'c_longlong': ClassType
|
||||||
|
.CLongLong <: _SimpleCData
|
||||||
|
.CLongLong.
|
||||||
|
__call__: (value:= Int) -> CLongLong
|
||||||
|
.CULongLong = 'c_ulonglong': ClassType
|
||||||
|
.CULongLong <: _SimpleCData
|
||||||
|
.CULongLong.
|
||||||
|
__call__: (value:= Int) -> CULongLong
|
||||||
|
.CFloat = 'c_float': ClassType
|
||||||
|
.CFloat <: _SimpleCData
|
||||||
|
.CFloat.
|
||||||
|
__call__: (value:= Float) -> CFloat
|
||||||
|
.CDouble = 'c_double': ClassType
|
||||||
|
.CDouble <: _SimpleCData
|
||||||
|
.CDouble.
|
||||||
|
__call__: (value:= Float) -> CDouble
|
||||||
|
.CCharP = 'c_char_p': ClassType
|
||||||
|
.CCharP <: _SimpleCData
|
||||||
|
.CCharP.
|
||||||
|
__call__: (value:= Str or NoneType) -> CCharP
|
||||||
|
.CWCharP = 'c_wchar_p': ClassType
|
||||||
|
.CWCharP <: _SimpleCData
|
||||||
|
.CWCharP.
|
||||||
|
__call__: (value:= Str or NoneType) -> CWCharP
|
||||||
|
.CVoidP = 'c_void_p': ClassType
|
||||||
|
.CVoidP <: _SimpleCData
|
||||||
|
.CVoidP.
|
||||||
|
__call__: (value:= Int or NoneType) -> CVoidP
|
||||||
|
|
||||||
|
.CDLL: ClassType
|
||||||
|
.OleDLL: ClassType
|
||||||
|
.WinDLL: ClassType
|
||||||
|
.PyDLL: ClassType
|
||||||
|
|
||||||
|
.Array: ClassType
|
||||||
|
.ARRAY: ClassType
|
||||||
|
.Structure: ClassType
|
||||||
|
|
||||||
|
._Pointer: ClassType
|
||||||
|
._CFuncPtr: ClassType
|
||||||
|
|
||||||
|
.ArgumentError: ClassType
|
||||||
|
.ArgumentError <: Exception
|
||||||
|
|
||||||
|
.addressof!: (obj:= Obj) => Int
|
||||||
|
.alignment!: (obj_or_type:= Obj or Type) => Int
|
||||||
|
.byref!: (obj:= Obj) => Obj
|
||||||
|
.cast!: (obj:= Obj, typ:= Type) => Obj
|
||||||
|
.create_string_buffer: (init:= Str or NoneType, size:= Int) -> CCharP
|
||||||
|
.create_unicode_buffer: (init:= Str or NoneType, size:= Int) -> CWCharP
|
||||||
|
.get_errno!: () => Int
|
||||||
|
.get_last_error!: () => Int
|
||||||
|
.memmove!: (dst:= Obj, src:= Obj, count:= Int) => NoneType
|
||||||
|
.memset!: (dst:= Obj, c:= Int, count:= Int) => NoneType
|
||||||
|
.resize!: (obj:= Obj, size:= Int) => NoneType
|
||||||
|
.set_errno!: (value:= Int) => NoneType
|
||||||
|
.set_last_error!: (value:= Int) => NoneType
|
||||||
|
.sizeof!: (obj_or_type:= Obj or Type) => Nat
|
||||||
|
.string_at: (ptr:= Obj, size:= Int) -> Bytes
|
||||||
|
.wstring_at: (ptr:= Obj, size:= Int) -> Str
|
1
crates/erg_compiler/lib/pystd/ctypes.d/util.d.er
Normal file
1
crates/erg_compiler/lib/pystd/ctypes.d/util.d.er
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.find_library!: Str => Str
|
0
crates/erg_compiler/lib/pystd/ctypes.d/wintypes.d.er
Normal file
0
crates/erg_compiler/lib/pystd/ctypes.d/wintypes.d.er
Normal file
|
@ -1,4 +1,4 @@
|
||||||
.cache: |T <: Proc|(user_function: T) -> T
|
.cache: |T <: Proc|(user_function: T) -> T
|
||||||
.lru_cache: |T <: Proc|(user_function: T) -> T
|
.lru_cache: (|T <: Proc|(user_function: T) -> T) and |T <: Proc|(maxsize := Int, typed := Bool) -> (T -> T)
|
||||||
.total_ordering: (cls: ClassType) -> ClassType
|
.total_ordering: (cls: ClassType) -> ClassType
|
||||||
.reduce: |T: Type|(function!: T => T, iterable: Iterable(T), initializer := T or NoneType) -> T
|
.reduce: |T: Type|(function!: T => T, iterable: Iterable(T), initializer := T or NoneType) -> T
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue