Skip to content

Commit

Permalink
feat: add ctypes type decl
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Nov 4, 2024
1 parent 6c07d1f commit 0667644
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 6 deletions.
2 changes: 2 additions & 0 deletions crates/erg_compiler/context/initialize/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3745,6 +3745,8 @@ impl Context {
/* ByteArray! */
let bytearray_mut_t = mono(MUT_BYTEARRAY);
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);
bytearray_seq.register_builtin_erg_impl(
FUNDAMENTAL_LEN,
Expand Down
6 changes: 3 additions & 3 deletions crates/erg_compiler/context/initialize/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl Context {
let t_vars = no_var_func(
vec![],
vec![kw_default(KW_OBJECT, Obj, Obj)],
dict! { Str => Obj }.into(),
out_dict_t(dict! { Str => Obj }.into()),
);
let t_zip = nd_func(
vec![
Expand Down Expand Up @@ -1003,7 +1003,7 @@ impl Context {
None,
);
let t_exec = func(
vec![kw(KW_CODE, Str)],
vec![kw(KW_CODE, Str | Code)],
None,
vec![
kw(KW_GLOBALS, mono(GENERIC_DICT)),
Expand All @@ -1020,7 +1020,7 @@ impl Context {
Some(FUNC_EXEC),
);
let t_eval = func(
vec![kw(KW_CODE, Str)],
vec![kw(KW_CODE, Str | Code)],
None,
vec![
kw(KW_GLOBALS, mono(GENERIC_DICT)),
Expand Down
4 changes: 2 additions & 2 deletions crates/erg_compiler/context/initialize/procs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ impl Context {
NoneType,
)
.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_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(
vec![kw(
"iterable",
Expand Down
108 changes: 108 additions & 0 deletions crates/erg_compiler/lib/pystd/ctypes.d/__init__.d.er
Original file line number Diff line number Diff line change
@@ -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
Empty file.
1 change: 1 addition & 0 deletions crates/erg_compiler/lib/pystd/ctypes.d/util.d.er
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.find_library!: Str => Str
Empty file.
2 changes: 1 addition & 1 deletion crates/erg_compiler/lib/pystd/functools.d.er
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.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
.reduce: |T: Type|(function!: T => T, iterable: Iterable(T), initializer := T or NoneType) -> T

0 comments on commit 0667644

Please sign in to comment.