mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
* Add Python extension lowering pass * Add DocstringAttribute * Add extension module codegen * Handle different argument counts efficiently * Add warnings to extension lowering * Fix module name * Fix extension codegen * Fix argument check * Auto-convert Codon exceptions to Python exceptions * Fix #183 * Fix #162; Fix #135 * Fix #155 * Fix CPython interface in codegen * Fix #191 * Fix #187 * Fix #189 * Generate object file in pyext mode * Convert Codon exceptions to Python exceptions * Fix vtable init; Fix failing tests on Linux * Fix #190 * Fix #156 * Fix union routing * Remove need for import python * Automatic @export and wrapping for toplevel functions * Reorganize API * Add Python extension IR structs * Add special calls for no-suspend yield-expr * Add special calls for no-suspend yield-expr * pyextension.h support [wip] * pyextension.h support [wip] * pyextension.h support * pyextension.h support for toplevel functions * clang-format * Add PyFunction::nargs field * Update pyextension codegen (WIP) * SUpport nargs * Add support for @pycapture * PyType codegen (WIP) * Py method codegen (WIP) * Add type ptr hook * Add getset codegen * Add type alloc function * Add type pointer hook codegen * Re-organize codegen * Add member codegen * Update module init codegen * Update module init codegen * Add support for typePtrHook and new to/from_py hooks * Fix extension codegen * Fix init codegen * Fix init codegen; add "tp_new" slot * Fix type hook * Add extra flags * Specialized wrappers (PyType specs) * Add static Python link option * Fix C imports * Add guards * Remove unused field * Python mode only when pyExt set * Update python module * Fix assert * Update codegen/passes * Fix tuple parsing in index expression * Fix empty tuple unification * Do not Cythonize underscore fns * clang-format * Fix switch * Add Py support for cmp/setitem * Add Py support for cmp/setitem * Add type is support * GetSet support * clang-format * GetSet support (fixes) * Avoid useless vtable alloc * Add iter support * Fix size_t capture bug * clang-format * Fix POD type unification with tuples * Add __try_from_py__ API * Fix annotation * Add static reflection methods (setattr; internal.static.*); refactor PyExt to python.codon; handle errors and kwargs in PyExt * Python compat fixes * Update Python object conversions * Fix PyErrors * clang-format; add copyright * Add PyFunction::keywords field * Fix JIT MRO handling; Refactor out Jupyter support * Refactor out Jupyter support * Add support for custom linking args (link=[]) to TOML plugins * Fix tests * Use g++ instead of gcc * Fix Jupyter CMAKE * Fix Jupyter CMAKE * Add _PyArg_Parser definition * Add complex64 type * Add extra complex64 tests * Fix Python calls; add staticenumerate * Fix call * Fix calls * Update pyext wrappers * Fix staticenumerate; Support static calls in tuple() * Fix pyext routing * Add add/mul for tuples * clang-format * Fix pyext codegen * Fix wrap_multiple * Add seq_alloc_atomic_uncollectable * Fix default generics issue * Add binary/ternary ops * Fix missing generic issue * Fix number slots * Update pow * Remove unnecessary pyobj * Fix allocation * Refactor errors * Add test extension * Fix formatting * clang-format * Fix getitem/setitem/delitem in pyext * Fix pyext iterators * Add builtin pow() (fix #294) * Fix #244 * Fix #231 * Fix #229 * Fix #205 * Update docs * Fix error message * Add pyext tests * Add pyext support for @property * Add pyext support for toplevel fns and @tuple classes * More pyext tests * More pyext tests * Fix file error checking * More pyext tests * Update pyext tests * Update docs * Add pyext test to CI * Add pyext support for @tuple.__new__ * Add pyext support for @tuple.__new__ * Fix hetero-tuple issue with fn_overloads * More pyext tests * Bump versions * Fix del magic in pyext * Fix init magic for tuples in pyext * Have test-pypi only run on develop branch * Make exception type indices unnamed-addr * Fix #316; Fix #317 (slash issue) * Use uncollectible-alloc for vtable * Fix #249 * Add pyext docs * Fix #249; Fix clashing vtables; Fix super() and class_copy * Add content-atomic type property instruction * __contents_atomic__ support * Update internal functions * Use PIC when generating Python extension * Cleanup * Add Dockerfile & fix -fPIC * Cleanup * Fix setup.py * Fix pyext fn iteration * Fix CI * clang-format * Update long conversions in Py bridge * Support wide-int to str conversions * Fix test * Add pow for arbitrary-width ints * Fix Linux backtraces * Cleanup * Add more tests * Fix docs; Remove tuple.__add__ for scalars * Update docs --------- Co-authored-by: Ibrahim Numanagić <ibrahimpasa@gmail.com>
701 lines
7.9 KiB
Python
701 lines
7.9 KiB
Python
# Copyright (C) 2022-2023 Exaloop Inc. <https://exaloop.io>
|
|
|
|
# runtime functions
|
|
from C import seq_print(str)
|
|
from C import seq_print_full(str, cobj)
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_str_int(a: int, fmt: str, error: Ptr[bool]) -> str:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_str_uint(a: int, fmt: str, error: Ptr[bool]) -> str:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_str_float(a: float, fmt: str, error: Ptr[bool]) -> str:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_str_str(a: str, fmt: str, error: Ptr[bool]) -> str:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_str_ptr(a: cobj, fmt: str, error: Ptr[bool]) -> str:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_strdup(a: cobj) -> str:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_stdin() -> cobj:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_stdout() -> cobj:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_stderr() -> cobj:
|
|
pass
|
|
|
|
@no_side_effect
|
|
@C
|
|
def seq_env() -> Ptr[cobj]:
|
|
pass
|
|
|
|
@no_side_effect
|
|
@C
|
|
def seq_time() -> int:
|
|
pass
|
|
|
|
@no_side_effect
|
|
@C
|
|
def seq_time_monotonic() -> int:
|
|
pass
|
|
|
|
@no_side_effect
|
|
@C
|
|
def seq_time_highres() -> int:
|
|
pass
|
|
|
|
@no_side_effect
|
|
@C
|
|
def seq_localtime(a: int, b: cobj) -> bool:
|
|
pass
|
|
|
|
@no_side_effect
|
|
@C
|
|
def seq_gmtime(a: int, b: cobj) -> bool:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_mktime(a: cobj) -> int:
|
|
pass
|
|
|
|
from C import seq_sleep(float)
|
|
|
|
@pure
|
|
@C
|
|
def seq_pid() -> int:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_lock_new() -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_lock_acquire(a: cobj, b: bool, c: float) -> bool:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_lock_release(a: cobj) -> None:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_rlock_new() -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_rlock_acquire(a: cobj, b: bool, c: float) -> bool:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def seq_rlock_release(a: cobj) -> None:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def seq_i32_to_float(a: i32) -> float:
|
|
pass
|
|
|
|
# <ctype.h>
|
|
@pure
|
|
@C
|
|
def isdigit(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def isspace(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def isupper(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def islower(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def toupper(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tolower(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def isalnum(a: i32) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def isalpha(a: i32) -> i32:
|
|
pass
|
|
|
|
# <math.h>
|
|
@pure
|
|
@C
|
|
def ceil(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def floor(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def fabs(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def fmod(a: float, b: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def exp(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def expm1(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def ldexp(a: float, b: i32) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log2(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log10(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def sqrt(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def pow(a: float, b: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def round(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def acos(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def asin(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atan(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atan2(a: float, b: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def cos(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def sin(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tan(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def cosh(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def sinh(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tanh(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def acosh(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def asinh(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atanh(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def copysign(a: float, b: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log1p(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def trunc(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log2(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def erf(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def erfc(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tgamma(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def lgamma(a: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def remainder(a: float, b: float) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def hypot(a: float, b: float) -> float:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def frexp(a: float, b: Ptr[Int[32]]) -> float:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def modf(a: float, b: Ptr[float]) -> float:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def ceilf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def floorf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def fabsf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def fmodf(a: float32, b: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def expf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def expm1f(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def ldexpf(a: float32, b: i32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def logf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log2f(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log10f(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def sqrtf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def powf(a: float32, b: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def roundf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def acosf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def asinf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atanf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atan2f(a: float32, b: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def cosf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def sinf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tanf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def coshf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def sinhf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tanhf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def acoshf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def asinhf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atanhf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def copysignf(a: float32, b: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log1pf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def truncf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def log2f(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def erff(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def erfcf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def tgammaf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def lgammaf(a: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def remainderf(a: float32, b: float32) -> float32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def hypotf(a: float32, b: float32) -> float32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def frexpf(a: float32, b: Ptr[Int[32]]) -> float32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def modff(a: float32, b: Ptr[float32]) -> float32:
|
|
pass
|
|
|
|
# <stdio.h>
|
|
@pure
|
|
@C
|
|
def ferror(a: cobj) -> i32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fgetc(a: cobj) -> i32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fopen(a: cobj, b: cobj) -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fdopen(a: int, b: cobj) -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fclose(a: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fread(a: cobj, b: int, c: int, d: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fwrite(a: cobj, b: int, c: int, d: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def ftell(a: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fseek(a: cobj, b: int, c: i32) -> i32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fgets(a: cobj, b: int, c: cobj) -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def fflush(a: cobj) -> None:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def getline(a: Ptr[cobj], b: Ptr[int], c: cobj) -> int:
|
|
pass
|
|
|
|
# <stdlib.h>
|
|
from C import exit(int)
|
|
|
|
@nocapture
|
|
@C
|
|
def system(a: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def free(a: cobj) -> None:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def atoi(a: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def strtoll(a: cobj, b: Ptr[cobj], c: i32) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def strtod(a: cobj, b: Ptr[cobj]) -> float:
|
|
pass
|
|
|
|
# <zlib.h>
|
|
@nocapture
|
|
@C
|
|
def gzopen(a: cobj, b: cobj) -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzerror(a: cobj, b: Ptr[i32]) -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzgetc(a: cobj) -> i32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzgets(a: cobj, b: cobj, c: i32) -> cobj:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzclose(a: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzread(a: cobj, b: cobj, c: u32) -> i32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzwrite(a: cobj, b: cobj, c: u32) -> i32:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gztell(a: cobj) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzseek(a: cobj, b: int, c: i32) -> int:
|
|
pass
|
|
|
|
@nocapture
|
|
@C
|
|
def gzflush(a: cobj, b: i32) -> i32:
|
|
pass
|
|
|
|
# <string.h>
|
|
@pure
|
|
@C
|
|
def memcmp(lhs: Ptr[byte], rhs: Ptr[byte], count: int) -> i32:
|
|
pass
|
|
|
|
@pure
|
|
@C
|
|
def memchr(p: Ptr[byte], ch: i32, count: int) -> Ptr[byte]:
|
|
pass
|