# Copyright (C) 2022-2023 Exaloop Inc. <https://exaloop.io>
@tuple
@__internal__
class type[T]:
pass
class __internal__:
class __magic__:
@__notuple__
class bool:
class byte:
class int:
MAX = 9223372036854775807
class float:
MIN_10_EXP = -307
class float32:
MIN_10_EXP = -37
class NoneType:
class Function[T, TR]:
class Callable[T, TR]:
class Ptr[T]:
cobj = Ptr[byte]
class Generator[T]:
class Optional:
T: type = NoneType
class Int[N: Static[int]]:
class UInt[N: Static[int]]:
class pyobj:
p: Ptr[byte]
class str:
ptr: Ptr[byte]
len: int
class Array:
ptr: Ptr[T]
T: type
@extend
class type:
def __new__(obj):
function = Function
class Ref[T]:
class Union[TU]:
# compiler-generated
def __new__(val):
TU
class Function:
@llvm
def __new__() -> Function[T, TR]:
ret ptr null
# dummy
class TypeVar[T]: pass
class ByVal: pass
class ByRef: pass
class Tuple: pass
class ClassVar[T]:
class RTTI:
id: int
class ellipsis:
def __new__() -> ellipsis:
ret {} {}
Ellipsis = ellipsis()
class __array__:
def __new__(sz: Static[int]) -> Array[T]:
class Import:
__ipath__: str
__iname__: str
P: Static[str]
def __new__(path: str, name: str, P: Static[str]) -> Import[P]:
%0 = insertvalue { {=str}, {=str} } undef, {=str} %path, 0
%1 = insertvalue { {=str}, {=str} } %0, {=str} %name, 1
ret { {=str}, {=str} } %1
def __ptr__(var):
def staticlen(obj):
def compile_error(msg: Static[str]):
def isinstance(obj, what):
@__attribute__
def overload():
def hasattr(obj, attr: Static[str], *args, **kwargs):
"""Special handling"""
@overload
def hasattr(obj, attr: Static[str]):
def getattr(obj, attr: Static[str]):
def setattr(obj, attr: Static[str], what):
def tuple(iterable):
def super():
def superf(*args):
def __realized__(fn, args):
def statictuple(*args):
return args
def __has_rtti__(T: type):
#(init=False, repr=False, eq=False, order=False, hash=False, pickle=False, python=False, gpu=False, container=False)
class NamedTuple:
args: T
N: Static[int] # name cache ID
# todo)) nicer way to express type(())
def __new__(args: T = (), T: type) -> NamedTuple[0, T]:
return NamedTuple[0, T](())
def __new__(args: T, N: Static[int], T: type) -> NamedTuple[N, T]:
%0 = insertvalue { {=T} } undef, {=T} %args, 0
ret { {=T} } %0
def __getitem__(self, key: Static[str]):
return getattr(self, key)
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})"
class Partial:
args: T # format: (arg1, arg2, ..., (star_args...))
kwargs: K
F: Static[str] # function
M: Static[str] # mask
T: type # Tuple
K: type # NamedTuple
def __new__(args: T, kwargs: K, F: Static[str], M: Static[str], T: type, K: type) -> Partial[F, M, T, K]:
%0 = insertvalue { {=T}, {=K} } undef, {=T} %args, 0
%1 = insertvalue { {=T}, {=K} } %0, {=K} %kwargs, 1
ret { {=T}, {=K} } %1
return __magic__.repr_partial(self)