2023-01-08 14:24:10 -05:00
|
|
|
# Copyright (C) 2022-2023 Exaloop Inc. <https://exaloop.io>
|
2022-09-15 15:40:00 -04:00
|
|
|
|
2024-03-01 14:11:23 -08:00
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class type[T]:
|
2024-03-20 13:47:50 -07:00
|
|
|
# __new__ / __init__: always done internally
|
|
|
|
# __repr__
|
|
|
|
# __call__
|
|
|
|
# __name__
|
|
|
|
# __module__
|
|
|
|
# __doc__
|
2024-03-01 14:11:23 -08:00
|
|
|
pass
|
|
|
|
|
2024-03-21 14:42:43 -07:00
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class unrealized_type[T]:
|
|
|
|
pass
|
|
|
|
|
2022-07-26 13:06:00 -07:00
|
|
|
@__internal__
|
|
|
|
class __internal__:
|
|
|
|
pass
|
2023-05-02 13:09:19 -07:00
|
|
|
@__internal__
|
|
|
|
class __magic__:
|
|
|
|
pass
|
2022-07-26 13:06:00 -07:00
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class bool:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class byte:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class int:
|
2022-09-15 15:40:00 -04:00
|
|
|
MAX = 9223372036854775807
|
2022-07-26 13:06:00 -07:00
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class float:
|
2022-09-15 15:40:00 -04:00
|
|
|
MIN_10_EXP = -307
|
2022-07-26 13:06:00 -07:00
|
|
|
pass
|
|
|
|
|
2022-09-15 15:40:00 -04:00
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-09-15 15:40:00 -04:00
|
|
|
class float32:
|
|
|
|
MIN_10_EXP = -37
|
|
|
|
pass
|
|
|
|
|
2022-07-26 13:06:00 -07:00
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class NoneType:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class Function[T, TR]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class Callable[T, TR]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class Ptr[T]:
|
|
|
|
pass
|
|
|
|
cobj = Ptr[byte]
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class Generator[T]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class Optional:
|
|
|
|
T: type = NoneType
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class Int[N: Static[int]]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
2023-04-12 18:13:54 -04:00
|
|
|
@__notuple__
|
2022-07-26 13:06:00 -07:00
|
|
|
class UInt[N: Static[int]]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@__internal__
|
|
|
|
class pyobj:
|
|
|
|
p: Ptr[byte]
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class str:
|
|
|
|
ptr: Ptr[byte]
|
|
|
|
len: int
|
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class Array:
|
|
|
|
len: int
|
|
|
|
ptr: Ptr[T]
|
|
|
|
T: type
|
|
|
|
|
|
|
|
@extend
|
|
|
|
class type:
|
|
|
|
def __new__(obj):
|
|
|
|
pass
|
|
|
|
function = Function
|
|
|
|
|
2022-12-04 16:45:21 -08:00
|
|
|
@__internal__
|
|
|
|
class Ref[T]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@tuple
|
2023-04-12 18:13:54 -04:00
|
|
|
@__internal__
|
|
|
|
@__notuple__
|
2022-12-04 16:45:21 -08:00
|
|
|
class Union[TU]:
|
2023-02-05 15:53:15 -08:00
|
|
|
# compiler-generated
|
|
|
|
def __new__(val):
|
|
|
|
TU
|
2022-12-04 16:45:21 -08:00
|
|
|
|
2023-12-13 17:23:50 -08:00
|
|
|
@extend
|
|
|
|
class Function:
|
|
|
|
@llvm
|
|
|
|
def __new__() -> Function[T, TR]:
|
|
|
|
ret ptr null
|
|
|
|
|
2022-07-26 13:06:00 -07:00
|
|
|
# dummy
|
|
|
|
@__internal__
|
2022-09-15 15:40:00 -04:00
|
|
|
class TypeVar[T]: pass
|
2022-07-26 13:06:00 -07:00
|
|
|
@__internal__
|
|
|
|
class ByVal: pass
|
|
|
|
@__internal__
|
|
|
|
class ByRef: pass
|
|
|
|
@__internal__
|
|
|
|
class Tuple: pass
|
|
|
|
|
|
|
|
@__internal__
|
|
|
|
class ClassVar[T]:
|
|
|
|
pass
|
|
|
|
|
2023-05-01 16:18:18 -07:00
|
|
|
@__internal__
|
|
|
|
class RTTI:
|
|
|
|
id: int
|
|
|
|
|
|
|
|
@__internal__
|
2022-07-26 13:06:00 -07:00
|
|
|
@tuple
|
2023-05-10 06:28:25 -07:00
|
|
|
class ellipsis:
|
2024-03-09 18:18:10 -08:00
|
|
|
@llvm
|
2023-05-10 06:28:25 -07:00
|
|
|
def __new__() -> ellipsis:
|
2024-03-09 18:18:10 -08:00
|
|
|
ret {} {}
|
2023-05-10 06:28:25 -07:00
|
|
|
Ellipsis = ellipsis()
|
2022-07-26 13:06:00 -07:00
|
|
|
|
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class __array__:
|
|
|
|
T: type
|
|
|
|
def __new__(sz: Static[int]) -> Array[T]:
|
|
|
|
pass
|
|
|
|
|
2023-06-25 00:17:52 +02:00
|
|
|
@tuple
|
|
|
|
@__internal__
|
|
|
|
class Import:
|
2024-01-17 21:33:13 -08:00
|
|
|
__ipath__: str
|
|
|
|
__iname__: str
|
|
|
|
P: Static[str]
|
2024-03-09 18:18:10 -08:00
|
|
|
|
|
|
|
@llvm
|
2024-03-18 16:15:36 -07:00
|
|
|
def __new__(path: str, name: str, P: Static[str]) -> Import[P]:
|
2024-03-09 18:18:10 -08:00
|
|
|
%0 = insertvalue { {=str}, {=str} } undef, {=str} %path, 0
|
|
|
|
%1 = insertvalue { {=str}, {=str} } %0, {=str} %name, 1
|
|
|
|
ret { {=str}, {=str} } %1
|
2023-06-25 00:17:52 +02:00
|
|
|
|
2022-07-26 13:06:00 -07:00
|
|
|
def __ptr__(var):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def staticlen(obj):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def compile_error(msg: Static[str]):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def isinstance(obj, what):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@__attribute__
|
|
|
|
def overload():
|
|
|
|
pass
|
|
|
|
|
2023-02-05 15:53:15 -08:00
|
|
|
def hasattr(obj, attr: Static[str], *args, **kwargs):
|
2022-07-26 13:06:00 -07:00
|
|
|
"""Special handling"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@overload
|
|
|
|
def hasattr(obj, attr: Static[str]):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def getattr(obj, attr: Static[str]):
|
|
|
|
pass
|
|
|
|
|
2023-04-12 18:13:54 -04:00
|
|
|
def setattr(obj, attr: Static[str], what):
|
|
|
|
pass
|
|
|
|
|
2022-07-26 13:06:00 -07:00
|
|
|
def tuple(iterable):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def super():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def superf(*args):
|
|
|
|
"""Special handling"""
|
|
|
|
pass
|
2022-09-15 15:40:00 -04:00
|
|
|
|
|
|
|
def __realized__(fn, args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def statictuple(*args):
|
|
|
|
return args
|
2023-04-27 13:03:14 -07:00
|
|
|
|
|
|
|
def __has_rtti__(T: type):
|
|
|
|
pass
|
2023-07-10 11:24:33 +02:00
|
|
|
|
2023-08-01 13:27:17 +02:00
|
|
|
#(init=False, repr=False, eq=False, order=False, hash=False, pickle=False, python=False, gpu=False, container=False)
|
|
|
|
@__internal__
|
|
|
|
@tuple
|
|
|
|
class NamedTuple:
|
|
|
|
args: T
|
|
|
|
N: Static[int] # name cache ID
|
|
|
|
T: type
|
|
|
|
|
|
|
|
# todo)) nicer way to express type(())
|
|
|
|
def __new__(args: T = (), T: type) -> NamedTuple[0, T]:
|
2024-03-09 18:18:10 -08:00
|
|
|
return NamedTuple[0, T](())
|
2023-08-01 13:27:17 +02:00
|
|
|
|
2024-03-09 18:18:10 -08:00
|
|
|
@llvm
|
2023-08-01 13:27:17 +02:00
|
|
|
def __new__(args: T, N: Static[int], T: type) -> NamedTuple[N, T]:
|
2024-03-09 18:18:10 -08:00
|
|
|
%0 = insertvalue { {=T} } undef, {=T} %args, 0
|
|
|
|
ret { {=T} } %0
|
2023-08-01 13:27:17 +02:00
|
|
|
|
|
|
|
def __getitem__(self, key: Static[str]):
|
|
|
|
return getattr(self, key)
|
|
|
|
|
2023-11-20 21:09:50 -08:00
|
|
|
def __keys__(self):
|
|
|
|
return __internal__.namedkeys(N)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
keys = self.__keys__()
|
|
|
|
values = [v.__repr__() for v in self.args]
|
|
|
|
s = ', '.join(f"{keys[i]}: {values[i]}" for i in range(len(keys)))
|
|
|
|
return f"({s})"
|
|
|
|
|
2023-08-01 13:27:17 +02:00
|
|
|
@__internal__
|
|
|
|
@tuple
|
|
|
|
class Partial:
|
2024-03-09 18:18:10 -08:00
|
|
|
args: T # format: (arg1, arg2, ..., (star_args...))
|
2023-08-01 13:27:17 +02:00
|
|
|
kwargs: K
|
|
|
|
|
|
|
|
M: Static[str] # mask
|
|
|
|
T: type # Tuple
|
|
|
|
K: type # NamedTuple
|
2024-03-21 14:42:43 -07:00
|
|
|
# F: type # generic function; handled specially in Codon
|
|
|
|
# def __new__(args: T, kwargs: K, M: Static[str], T: type, K: type, F: type) -> Partial[M, T, K, F]:
|
2023-08-01 13:27:17 +02:00
|
|
|
|
2024-03-09 18:18:10 -08:00
|
|
|
@llvm
|
2024-03-21 11:29:07 -07:00
|
|
|
def __new__(args: T, kwargs: K, M: Static[str], T: type, K: type) -> Partial[M, T, K]:
|
2024-03-09 18:18:10 -08:00
|
|
|
%0 = insertvalue { {=T}, {=K} } undef, {=T} %args, 0
|
|
|
|
%1 = insertvalue { {=T}, {=K} } %0, {=K} %kwargs, 1
|
|
|
|
ret { {=T}, {=K} } %1
|
2023-08-01 13:27:17 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return __magic__.repr_partial(self)
|