diff --git a/.helix/cache/build_cache/test_hlx.py b/.helix/cache/build_cache/test_hlx.py index 894c862..f26fb50 100644 --- a/.helix/cache/build_cache/test_hlx.py +++ b/.helix/cache/build_cache/test_hlx.py @@ -4,7 +4,7 @@ # GENERATED FILE # -------------------------------------------------------------------------------- # Filename: test.hlx -# Generation Date: 2024-03-09 21:43:31 +# Generation Date: 2024-03-11 23:27:01 # Generator: Helix Transpiler # -------------------------------------------------------------------------------- # WARNING: This file is AUTO-GENERATED by the Helix Transpiler. Any modifications @@ -29,18 +29,18 @@ import os # type: ignore import sys # type: ignore import types # type: ignore -sys.path.append(os.path.dirname(os.path.realpath("c:\\Users\\dhruv\\Documents\\Projects\\helix\\helix.py")) + os.sep + ".helix") # type: ignore -sys.path.append(os.path.dirname(os.path.realpath("c:\\Users\\dhruv\\Documents\\Projects\\helix\\helix.py"))) # type: ignore +sys.path.append(os.path.dirname(os.path.realpath("z:\\devolopment\\helix\\helix-lang\\helix.py")) + os.sep + ".helix") # type: ignore +sys.path.append(os.path.dirname(os.path.realpath("z:\\devolopment\\helix\\helix-lang\\helix.py"))) # type: ignore sys.path.append(os.path.dirname(os.path.realpath(os.getcwd()))) # type: ignore # trunk-ignore(ruff/F401) -from include.core import ABC, Any, C_For, Callable, DEFAULT_VALUE, DispatchError, Enum, FastMap, FunctionType, Iterator, Literal, NoReturn, NoneType, Optional, Self, Thread, Type, TypeVar, UnionType, __import_c__, __import_cpp__, __import_py__, __import_rs__, annotations, array, auto, dataclass, double, getcontext, hx__abstract_method, hx__async, hx__multi_method, hx_array, hx_bool, hx_bytes, hx_char, hx_double, hx_float, hx_int, hx_list, hx_map, hx_set, hx_string, hx_tuple, hx_unknown, hx_void, inspect, multimeta, panic, printf, ref, replace_primitives, scanf, sleep, std, string, subtype, unknown, void, wraps # type: ignore +from include.core import ABC, Any, BuiltinFunctionType, C_For, Callable, DEFAULT_VALUE, DispatchError, Enum, FastMap, FunctionType, Iterator, Literal, NoReturn, NoneType, Optional, Self, T, Thread, Type, TypeVar, UnionType, __import_c__, __import_cpp__, __import_py__, __import_rs__, annotations, array, auto, beartype, dataclass, double, getcontext, hx__abstract_method, hx__async, hx__multi_method, hx_array, hx_bool, hx_bytes, hx_char, hx_double, hx_float, hx_int, hx_list, hx_map, hx_set, hx_string, hx_tuple, hx_unknown, hx_void, inspect, multimeta, panic, printf, ref, replace_primitives, scanf, sleep, std, string, subtype, unknown, void, wraps # type: ignore # trunk-ignore(ruff/F401) # trunk-ignore(ruff/F811) from include.core import __import_c__, __import_cpp__, __import_py__, __import_rs__ # type: ignore import threading # type: ignore import functools # type: ignore __lock = threading.Lock() -__file__ = "C:\\Users\\dhruv\\Documents\\Projects\\helix\\syntax\\test.hlx" +__file__ = "Z:\\devolopment\\helix\\helix-lang\\syntax\\test.hlx" # trunk-ignore(ruff/F821) def exception_handler(exception_type: type[BaseException] | threading.ExceptHookArgs, exception: Optional[Exception] = None, tb: Optional[types.TracebackType] = None, debug_hook: bool = False, thread_error: bool = False): import traceback @@ -173,7 +173,7 @@ def exception_handler(exception_type: type[BaseException] | threading.ExceptHook exit(1) sys.excepthook = exception_handler # type: ignore threading.excepthook = functools.partial(exception_handler, thread_error=True) -sys.argv = ["C:\\Users\\dhruv\\Documents\\Projects\\helix\\helix.py", "C:\\Users\\dhruv\\Documents\\Projects\\helix\\syntax\\test.hlx"] + list(sys.argv)[2:] +sys.argv = ["Z:\\devolopment\\helix\\helix-lang\\helix.py", "Z:\\devolopment\\helix\\helix-lang\\syntax\\test.hlx"] + list(sys.argv)[2:] del os, threading, functools overload_with_type_check = beartype(conf=BeartypeConf(is_color=False)) # type: ignore class C_cout(): @@ -184,23 +184,32 @@ def __lshift__(self: Any, a: str | hx_string): print ( a ) @overload_with_type_check def main(argv: list[str | hx_string] | hx_list[str | hx_string]): - do_something ( ) a: int | hx_int = int("12") - print ( add ( a , [ "a" , "b" , "c" ] ) ) + add ( 123 , 123 ) + print ( add . join ( ) ) + do_something ( ) + for i in C_For(i = int(0)).set_con('i < 10').set_inc('i ++'): + printf ( "doing something else eeeee: %d" , i ) + del i + do_something . join ( ) + print ( "done" ) + return 0 +@hx__async +def add(a: int | hx_int, b: int | hx_int) -> int: + printf ( "adding: %d + %d" , a , b ) + return a + b @overload_with_type_check def subtract(a: int | hx_int, b: int | hx_int) -> int: return a - b -@overload_with_type_check -def add(a: int | hx_int, b: int | hx_int) -> int: - a: Type = Type(10) - print ( a ) - return a - b -@overload_with_type_check @hx__async def do_something(): for i in C_For(i = int(0)).set_con('i < 10').set_inc('i ++'): - print ( "doing something: %d" , i ) + printf ( "doing something: %d" , i ) del i +@overload_with_type_check +def a_cursed_fucntion(a: int | hx_int) -> FunctionType: + printf ( "new something: %d" , a ) + return a_cursed_fucntion if __name__ == "__main__": try: main() # type: ignore diff --git a/.helix/cache/build_cache/test_hlx.py.lines b/.helix/cache/build_cache/test_hlx.py.lines index 7b4cb02..bfe8dd3 100644 --- a/.helix/cache/build_cache/test_hlx.py.lines +++ b/.helix/cache/build_cache/test_hlx.py.lines @@ -185,19 +185,33 @@ 85 85 86 -87 88 -92 +89 +91 92 93 -96 +92 +95 96 97 -98 -99 -102 -102 +100 +100 +101 102 -103 -104 -103 \ No newline at end of file +105 +105 +106 +110 +110 +111 +112 +111 +117 +117 +117 +117 +-1 +-1 +-1 +-1 +-1 \ No newline at end of file diff --git a/.helix/include/core.py b/.helix/include/core.py index 2ac4185..9789624 100644 --- a/.helix/include/core.py +++ b/.helix/include/core.py @@ -12,7 +12,7 @@ from functools import wraps import inspect from threading import Thread -from types import MappingProxyType as FastMap, NoneType, FunctionType, UnionType +from types import MappingProxyType as FastMap, NoneType, FunctionType, UnionType, BuiltinFunctionType from beartype.typing import Any, Callable, Literal, NoReturn, Self from weakref import ref @@ -20,7 +20,7 @@ from multimethod import subtype from typing import Type, TypeVar, Optional -from core.panic import panic, standalone_tokenize_line as _H_tokenize_line__ +from src.panic import panic, standalone_tokenize_line as _H_tokenize_line__ from time import sleep #from include.c_cpp import __import_c__ @@ -197,6 +197,42 @@ def __void__(self) -> bool: DEFAULT_VALUE = void() +#class C_For: +# def __init__(self, **kwargs): +# # Initialize loop variables +# self.loop_vars = kwargs +# # Extract condition and increment expressions +# self.condition = "True" +# self.increment = "" +# # Evaluate initial conditions +# [exec(f"{var} = {value}") for var, value in self.loop_vars.items()] +# +# def __iter__(self): +# return self +# +# def __next__(self): +# if not self.loop_condition_met: +# raise StopIteration +# current_values = tuple(self.loop_vars.values()) +# exec(self.increment, None, self.loop_vars) +# self.loop_condition_met = eval(self.condition, None, self.loop_vars) +# return current_values if len(current_values) > 1 else current_values[0] +# +# def set_con(self, condition): +# self.condition = condition +# self.loop_condition_met = eval(self.condition, None, self.loop_vars) +# return self +# +# def set_inc(self, increment): +# self.increment = ( +# increment.replace("++", "+= 1") +# .replace("--", "-= 1") +# .replace("+*", "*= 1") +# .replace("-*", "*= -1") +# .replace("/-", "/ -1") +# .replace("/*", "*= 1") +# ) +# return self class C_For: def __init__(self, **kwargs): # Initialize loop variables @@ -206,16 +242,18 @@ def __init__(self, **kwargs): self.increment = "" # Evaluate initial conditions [exec(f"{var} = {value}") for var, value in self.loop_vars.items()] + self.loop_condition_met = eval(self.condition, None, self.loop_vars) - def __iter__(self): + async def __aiter__(self): return self - def __next__(self): + async def __anext__(self): if not self.loop_condition_met: - raise StopIteration + raise StopAsyncIteration current_values = tuple(self.loop_vars.values()) exec(self.increment, None, self.loop_vars) self.loop_condition_met = eval(self.condition, None, self.loop_vars) + await asyncio.sleep(0) # Yield control to allow other tasks to run return current_values if len(current_values) > 1 else current_values[0] def set_con(self, condition): @@ -234,10 +272,30 @@ def set_inc(self, increment): ) return self -def hx__async(func): - def wrapper(*args, **kwargs): - Thread(target=func, args=args, kwargs=kwargs, daemon=True).start() +from beartype import beartype + +def hx__async(func: Callable) -> Callable: + def run_thread(func, args, kwargs): + func._result = func(*args, **kwargs) + func._thread_started = False + + @wraps(func) + def wrapper(*args, **kwargs): + if not hasattr(func, "_thread_started") or not func._thread_started: + func._thread = Thread(target=run_thread, args=(func, args, kwargs)) + func._thread_started = True + func._thread.start() + return func + + def join(timeout=None): + if hasattr(func, "_thread"): + func._thread.join(timeout) + return getattr(func, "_result", None) + return None + + func.join = join + wrapper.join = join return wrapper class hx_void(void): pass @@ -710,7 +768,9 @@ def __repr__(self) -> str: def __bytes__(self) -> bytes: return self.__value__ -class hx_tuple[T](tuple, metaclass=multimeta): +T = TypeVar("T") + +class hx_tuple(tuple, metaclass=multimeta): __value__: tuple | hx_tuple | None = () __generic__: subtype = None @@ -792,7 +852,7 @@ def last(self) -> T: return self.__value__[-1] # Derived Types -class hx_list[T](list, metaclass=multimeta): +class hx_list(list, metaclass=multimeta): __value__: list = None __generic__: subtype = None __initialized__ = False @@ -821,7 +881,7 @@ def __type_check__(self, __o: Any) -> None: def __set_generic__(self, __o: str) -> Self: exec( - f"self.__generic__ = subtype(list{__o} | {((" | ".join(["list[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + " | ") if " | ".join(["list[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ""} void {'| list' if not __o.endswith(']') else ''})" + f"self.__generic__ = subtype(list{__o} | {((' | '.join(['list[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + ' | ') if ' | '.join(['list[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ''} void {'| list' if not __o.endswith(']') else ''})" ) if self.__initialized__: panic( @@ -860,7 +920,7 @@ def length(self) -> int: self.__check_if_initialed() return len(self.__value__) -class hx_array[T](array, metaclass=multimeta): +class hx_array(array, metaclass=multimeta): __value__: list = None __generic__: subtype = None __initialized__ = False @@ -889,7 +949,7 @@ def __type_check__(self, __o: Any) -> None: def __set_generic__(self, __o: str) -> Self: exec( - f"self.__generic__ = subtype(list{__o} | {((" | ".join(["list[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + " | ") if " | ".join(["array[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ""} void {'| array' if not __o.endswith(']') else ''})" + f"self.__generic__ = subtype(list{__o} | {((' | '.join(['list[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + ' | ') if ' | '.join(['array[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ''} void {'| array' if not __o.endswith(']') else ''})" ) if self.__initialized__: panic( @@ -927,7 +987,7 @@ def length(self) -> int: self.__check_if_initialed() return len(self.__value__) -class hx_set[T](set, metaclass=multimeta): +class hx_set(set, metaclass=multimeta): __value__: list = None __generic__: subtype = None __initialized__ = False @@ -956,7 +1016,7 @@ def __type_check__(self, __o: Any) -> None: def __set_generic__(self, __o: str) -> Self: exec( - f"self.__generic__ = subtype(set{__o} | {((" | ".join(["set[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + " | ") if " | ".join(["set[" + _ + "]" for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ""} void {'| set' if not __o.endswith(']') else ''})" + f"self.__generic__ = subtype(set{__o} | {((' | '.join(['set[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o]])) + ' | ') if ' | '.join(['set[' + _ + ']' for _ in [replace_primitives[_] for _ in replace_primitives if _ in __o] if _]) else ''} void {'| set' if not __o.endswith(']') else ''})" ) if self.__initialized__: panic( @@ -997,7 +1057,7 @@ def length(self) -> int: -class hx_map[T](dict, metaclass=multimeta): +class hx_map(dict, metaclass=multimeta): __value__: list = None __generic__: subtype = None __initialized__ = False diff --git a/README.md b/README.md index 8a6f103..4552894 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # Installation +### create a virtual environment +### install the requirements +### run helix.py with a test file + ```bash -./init -.venv/bin/python3.12 helix.py -``` \ No newline at end of file +python3 -m venv .venv +source .venv/bin/activate +pip install -r requirements.txt +python helix.py syntax/test.hlx +deactivate # to exit the virtual environment when done +``` diff --git a/build/__native.c b/build/__native.c new file mode 100644 index 0000000..cee8eae --- /dev/null +++ b/build/__native.c @@ -0,0 +1,1782 @@ +#include "init.c" +#include "getargs.c" +#include "getargsfast.c" +#include "int_ops.c" +#include "float_ops.c" +#include "str_ops.c" +#include "bytes_ops.c" +#include "list_ops.c" +#include "dict_ops.c" +#include "set_ops.c" +#include "tuple_ops.c" +#include "exc_ops.c" +#include "misc_ops.c" +#include "generic_ops.c" +#include "__native.h" +#include "__native_internal.h" + +static PyObject *test_env_setup(PyTypeObject *type); +PyObject *CPyDef_test_env(void); + +static PyObject * +test_env_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + if (type != CPyType_test_env) { + PyErr_SetString(PyExc_TypeError, "interpreted classes cannot inherit from compiled"); + return NULL; + } + return test_env_setup(type); +} + +static int +test_env_traverse(test___test_envObject *self, visitproc visit, void *arg) +{ + Py_VISIT(self->___mypyc_self__); + Py_VISIT(self->_transpose); + Py_VISIT(self->_multiply_matrix); + Py_VISIT(self->_mat1); + Py_VISIT(self->_mat2); + return 0; +} + +static int +test_env_clear(test___test_envObject *self) +{ + Py_CLEAR(self->___mypyc_self__); + Py_CLEAR(self->_transpose); + Py_CLEAR(self->_multiply_matrix); + Py_CLEAR(self->_mat1); + Py_CLEAR(self->_mat2); + return 0; +} + +static void +test_env_dealloc(test___test_envObject *self) +{ + PyObject_GC_UnTrack(self); + CPy_TRASHCAN_BEGIN(self, test_env_dealloc) + test_env_clear(self); + Py_TYPE(self)->tp_free((PyObject *)self); + CPy_TRASHCAN_END(self) +} + +static CPyVTableItem test_env_vtable[1]; +static bool +CPyDef_test_env_trait_vtable_setup(void) +{ + CPyVTableItem test_env_vtable_scratch[] = { + NULL + }; + memcpy(test_env_vtable, test_env_vtable_scratch, sizeof(test_env_vtable)); + return 1; +} + +static PyMethodDef test_env_methods[] = { + {"__setstate__", (PyCFunction)CPyPickle_SetState, METH_O, NULL}, + {"__getstate__", (PyCFunction)CPyPickle_GetState, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ +}; + +static PyTypeObject CPyType_test_env_template_ = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "test_env", + .tp_new = test_env_new, + .tp_dealloc = (destructor)test_env_dealloc, + .tp_traverse = (traverseproc)test_env_traverse, + .tp_clear = (inquiry)test_env_clear, + .tp_methods = test_env_methods, + .tp_basicsize = sizeof(test___test_envObject), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, +}; +static PyTypeObject *CPyType_test_env_template = &CPyType_test_env_template_; + +static PyObject * +test_env_setup(PyTypeObject *type) +{ + test___test_envObject *self; + self = (test___test_envObject *)type->tp_alloc(type, 0); + if (self == NULL) + return NULL; + self->vtable = test_env_vtable; + return (PyObject *)self; +} + +PyObject *CPyDef_test_env(void) +{ + PyObject *self = test_env_setup(CPyType_test_env); + if (self == NULL) + return NULL; + return self; +} + + +static PyObject *CPyDunder___get__transpose_test_obj(PyObject *self, PyObject *instance, PyObject *owner) { + instance = instance ? instance : Py_None; + return CPyDef_transpose_test_obj_____get__(self, instance, owner); +} +static PyObject *transpose_test_obj_setup(PyTypeObject *type); +PyObject *CPyDef_transpose_test_obj(void); + +static PyObject * +transpose_test_obj_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + if (type != CPyType_transpose_test_obj) { + PyErr_SetString(PyExc_TypeError, "interpreted classes cannot inherit from compiled"); + return NULL; + } + return transpose_test_obj_setup(type); +} + +static int +transpose_test_obj_traverse(test___transpose_test_objObject *self, visitproc visit, void *arg) +{ + Py_VISIT(self->___mypyc_env__); + _PyObject_VisitManagedDict((PyObject *)self, visit, arg); + return 0; +} + +static int +transpose_test_obj_clear(test___transpose_test_objObject *self) +{ + Py_CLEAR(self->___mypyc_env__); + _PyObject_ClearManagedDict((PyObject *)self); + return 0; +} + +static void +transpose_test_obj_dealloc(test___transpose_test_objObject *self) +{ + PyObject_GC_UnTrack(self); + CPy_TRASHCAN_BEGIN(self, transpose_test_obj_dealloc) + transpose_test_obj_clear(self); + Py_TYPE(self)->tp_free((PyObject *)self); + CPy_TRASHCAN_END(self) +} + +static CPyVTableItem transpose_test_obj_vtable[2]; +static bool +CPyDef_transpose_test_obj_trait_vtable_setup(void) +{ + CPyVTableItem transpose_test_obj_vtable_scratch[] = { + (CPyVTableItem)CPyDef_transpose_test_obj_____call__, + (CPyVTableItem)CPyDef_transpose_test_obj_____get__, + }; + memcpy(transpose_test_obj_vtable, transpose_test_obj_vtable_scratch, sizeof(transpose_test_obj_vtable)); + return 1; +} + +static PyObject * +transpose_test_obj_get___3_mypyc_env__(test___transpose_test_objObject *self, void *closure); +static int +transpose_test_obj_set___3_mypyc_env__(test___transpose_test_objObject *self, PyObject *value, void *closure); + +static PyGetSetDef transpose_test_obj_getseters[] = { + {"__mypyc_env__", + (getter)transpose_test_obj_get___3_mypyc_env__, (setter)transpose_test_obj_set___3_mypyc_env__, + NULL, NULL}, + {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, + {NULL} /* Sentinel */ +}; + +static PyMethodDef transpose_test_obj_methods[] = { + {"__call__", + (PyCFunction)CPyPy_transpose_test_obj_____call__, + METH_FASTCALL | METH_KEYWORDS, NULL}, + {"__get__", + (PyCFunction)CPyPy_transpose_test_obj_____get__, + METH_FASTCALL | METH_KEYWORDS, NULL}, + {"__setstate__", (PyCFunction)CPyPickle_SetState, METH_O, NULL}, + {"__getstate__", (PyCFunction)CPyPickle_GetState, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ +}; + +static PyTypeObject CPyType_transpose_test_obj_template_ = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "transpose_test_obj", + .tp_new = transpose_test_obj_new, + .tp_dealloc = (destructor)transpose_test_obj_dealloc, + .tp_traverse = (traverseproc)transpose_test_obj_traverse, + .tp_clear = (inquiry)transpose_test_obj_clear, + .tp_getset = transpose_test_obj_getseters, + .tp_methods = transpose_test_obj_methods, + .tp_call = PyVectorcall_Call, + .tp_descr_get = CPyDunder___get__transpose_test_obj, + .tp_basicsize = sizeof(test___transpose_test_objObject), + .tp_vectorcall_offset = offsetof(test___transpose_test_objObject, vectorcall), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | _Py_TPFLAGS_HAVE_VECTORCALL | Py_TPFLAGS_MANAGED_DICT, +}; +static PyTypeObject *CPyType_transpose_test_obj_template = &CPyType_transpose_test_obj_template_; + +static PyObject * +transpose_test_obj_setup(PyTypeObject *type) +{ + test___transpose_test_objObject *self; + self = (test___transpose_test_objObject *)type->tp_alloc(type, 0); + if (self == NULL) + return NULL; + self->vtable = transpose_test_obj_vtable; + self->vectorcall = CPyPy_transpose_test_obj_____call__; + return (PyObject *)self; +} + +PyObject *CPyDef_transpose_test_obj(void) +{ + PyObject *self = transpose_test_obj_setup(CPyType_transpose_test_obj); + if (self == NULL) + return NULL; + return self; +} + +static PyObject * +transpose_test_obj_get___3_mypyc_env__(test___transpose_test_objObject *self, void *closure) +{ + if (unlikely(self->___mypyc_env__ == NULL)) { + PyErr_SetString(PyExc_AttributeError, + "attribute '__mypyc_env__' of 'transpose_test_obj' undefined"); + return NULL; + } + CPy_INCREF(self->___mypyc_env__); + PyObject *retval = self->___mypyc_env__; + return retval; +} + +static int +transpose_test_obj_set___3_mypyc_env__(test___transpose_test_objObject *self, PyObject *value, void *closure) +{ + if (value == NULL) { + PyErr_SetString(PyExc_AttributeError, + "'transpose_test_obj' object attribute '__mypyc_env__' cannot be deleted"); + return -1; + } + if (self->___mypyc_env__ != NULL) { + CPy_DECREF(self->___mypyc_env__); + } + PyObject *tmp; + if (likely(Py_TYPE(value) == CPyType_test_env)) + tmp = value; + else { + CPy_TypeError("test.test_env", value); + tmp = NULL; + } + if (!tmp) + return -1; + CPy_INCREF(tmp); + self->___mypyc_env__ = tmp; + return 0; +} + +static PyObject *CPyDunder___get__multiply_matrix_test_obj(PyObject *self, PyObject *instance, PyObject *owner) { + instance = instance ? instance : Py_None; + return CPyDef_multiply_matrix_test_obj_____get__(self, instance, owner); +} +static PyObject *multiply_matrix_test_obj_setup(PyTypeObject *type); +PyObject *CPyDef_multiply_matrix_test_obj(void); + +static PyObject * +multiply_matrix_test_obj_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + if (type != CPyType_multiply_matrix_test_obj) { + PyErr_SetString(PyExc_TypeError, "interpreted classes cannot inherit from compiled"); + return NULL; + } + return multiply_matrix_test_obj_setup(type); +} + +static int +multiply_matrix_test_obj_traverse(test___multiply_matrix_test_objObject *self, visitproc visit, void *arg) +{ + Py_VISIT(self->___mypyc_env__); + _PyObject_VisitManagedDict((PyObject *)self, visit, arg); + return 0; +} + +static int +multiply_matrix_test_obj_clear(test___multiply_matrix_test_objObject *self) +{ + Py_CLEAR(self->___mypyc_env__); + _PyObject_ClearManagedDict((PyObject *)self); + return 0; +} + +static void +multiply_matrix_test_obj_dealloc(test___multiply_matrix_test_objObject *self) +{ + PyObject_GC_UnTrack(self); + CPy_TRASHCAN_BEGIN(self, multiply_matrix_test_obj_dealloc) + multiply_matrix_test_obj_clear(self); + Py_TYPE(self)->tp_free((PyObject *)self); + CPy_TRASHCAN_END(self) +} + +static CPyVTableItem multiply_matrix_test_obj_vtable[2]; +static bool +CPyDef_multiply_matrix_test_obj_trait_vtable_setup(void) +{ + CPyVTableItem multiply_matrix_test_obj_vtable_scratch[] = { + (CPyVTableItem)CPyDef_multiply_matrix_test_obj_____call__, + (CPyVTableItem)CPyDef_multiply_matrix_test_obj_____get__, + }; + memcpy(multiply_matrix_test_obj_vtable, multiply_matrix_test_obj_vtable_scratch, sizeof(multiply_matrix_test_obj_vtable)); + return 1; +} + +static PyObject * +multiply_matrix_test_obj_get___3_mypyc_env__(test___multiply_matrix_test_objObject *self, void *closure); +static int +multiply_matrix_test_obj_set___3_mypyc_env__(test___multiply_matrix_test_objObject *self, PyObject *value, void *closure); + +static PyGetSetDef multiply_matrix_test_obj_getseters[] = { + {"__mypyc_env__", + (getter)multiply_matrix_test_obj_get___3_mypyc_env__, (setter)multiply_matrix_test_obj_set___3_mypyc_env__, + NULL, NULL}, + {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, + {NULL} /* Sentinel */ +}; + +static PyMethodDef multiply_matrix_test_obj_methods[] = { + {"__call__", + (PyCFunction)CPyPy_multiply_matrix_test_obj_____call__, + METH_FASTCALL | METH_KEYWORDS, NULL}, + {"__get__", + (PyCFunction)CPyPy_multiply_matrix_test_obj_____get__, + METH_FASTCALL | METH_KEYWORDS, NULL}, + {"__setstate__", (PyCFunction)CPyPickle_SetState, METH_O, NULL}, + {"__getstate__", (PyCFunction)CPyPickle_GetState, METH_NOARGS, NULL}, + {NULL} /* Sentinel */ +}; + +static PyTypeObject CPyType_multiply_matrix_test_obj_template_ = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "multiply_matrix_test_obj", + .tp_new = multiply_matrix_test_obj_new, + .tp_dealloc = (destructor)multiply_matrix_test_obj_dealloc, + .tp_traverse = (traverseproc)multiply_matrix_test_obj_traverse, + .tp_clear = (inquiry)multiply_matrix_test_obj_clear, + .tp_getset = multiply_matrix_test_obj_getseters, + .tp_methods = multiply_matrix_test_obj_methods, + .tp_call = PyVectorcall_Call, + .tp_descr_get = CPyDunder___get__multiply_matrix_test_obj, + .tp_basicsize = sizeof(test___multiply_matrix_test_objObject), + .tp_vectorcall_offset = offsetof(test___multiply_matrix_test_objObject, vectorcall), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | _Py_TPFLAGS_HAVE_VECTORCALL | Py_TPFLAGS_MANAGED_DICT, +}; +static PyTypeObject *CPyType_multiply_matrix_test_obj_template = &CPyType_multiply_matrix_test_obj_template_; + +static PyObject * +multiply_matrix_test_obj_setup(PyTypeObject *type) +{ + test___multiply_matrix_test_objObject *self; + self = (test___multiply_matrix_test_objObject *)type->tp_alloc(type, 0); + if (self == NULL) + return NULL; + self->vtable = multiply_matrix_test_obj_vtable; + self->vectorcall = CPyPy_multiply_matrix_test_obj_____call__; + return (PyObject *)self; +} + +PyObject *CPyDef_multiply_matrix_test_obj(void) +{ + PyObject *self = multiply_matrix_test_obj_setup(CPyType_multiply_matrix_test_obj); + if (self == NULL) + return NULL; + return self; +} + +static PyObject * +multiply_matrix_test_obj_get___3_mypyc_env__(test___multiply_matrix_test_objObject *self, void *closure) +{ + if (unlikely(self->___mypyc_env__ == NULL)) { + PyErr_SetString(PyExc_AttributeError, + "attribute '__mypyc_env__' of 'multiply_matrix_test_obj' undefined"); + return NULL; + } + CPy_INCREF(self->___mypyc_env__); + PyObject *retval = self->___mypyc_env__; + return retval; +} + +static int +multiply_matrix_test_obj_set___3_mypyc_env__(test___multiply_matrix_test_objObject *self, PyObject *value, void *closure) +{ + if (value == NULL) { + PyErr_SetString(PyExc_AttributeError, + "'multiply_matrix_test_obj' object attribute '__mypyc_env__' cannot be deleted"); + return -1; + } + if (self->___mypyc_env__ != NULL) { + CPy_DECREF(self->___mypyc_env__); + } + PyObject *tmp; + if (likely(Py_TYPE(value) == CPyType_test_env)) + tmp = value; + else { + CPy_TypeError("test.test_env", value); + tmp = NULL; + } + if (!tmp) + return -1; + CPy_INCREF(tmp); + self->___mypyc_env__ = tmp; + return 0; +} +static PyMethodDef module_methods[] = { + {"test", (PyCFunction)CPyPy_test, METH_FASTCALL | METH_KEYWORDS, NULL /* docstring */}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef module = { + PyModuleDef_HEAD_INIT, + "test", + NULL, /* docstring */ + -1, /* size of per-interpreter state of the module, + or -1 if the module keeps state in global variables. */ + module_methods +}; + +PyMODINIT_FUNC PyInit_test(void) +{ + PyObject* modname = NULL; + if (CPyModule_test_internal) { + Py_INCREF(CPyModule_test_internal); + return CPyModule_test_internal; + } + CPyModule_test_internal = PyModule_Create(&module); + if (unlikely(CPyModule_test_internal == NULL)) + goto fail; + modname = PyObject_GetAttrString((PyObject *)CPyModule_test_internal, "__name__"); + CPyStatic_globals = PyModule_GetDict(CPyModule_test_internal); + if (unlikely(CPyStatic_globals == NULL)) + goto fail; + CPyType_test_env = (PyTypeObject *)CPyType_FromTemplate((PyObject *)CPyType_test_env_template, NULL, modname); + if (unlikely(!CPyType_test_env)) + goto fail; + CPyType_transpose_test_obj = (PyTypeObject *)CPyType_FromTemplate((PyObject *)CPyType_transpose_test_obj_template, NULL, modname); + if (unlikely(!CPyType_transpose_test_obj)) + goto fail; + CPyType_multiply_matrix_test_obj = (PyTypeObject *)CPyType_FromTemplate((PyObject *)CPyType_multiply_matrix_test_obj_template, NULL, modname); + if (unlikely(!CPyType_multiply_matrix_test_obj)) + goto fail; + if (CPyGlobalsInit() < 0) + goto fail; + char result = CPyDef___top_level__(); + if (result == 2) + goto fail; + Py_DECREF(modname); + return CPyModule_test_internal; + fail: + Py_CLEAR(CPyModule_test_internal); + Py_CLEAR(modname); + Py_CLEAR(CPyType_test_env); + Py_CLEAR(CPyType_transpose_test_obj); + Py_CLEAR(CPyType_multiply_matrix_test_obj); + return NULL; +} + +PyObject *CPyDef_transpose_test_obj_____get__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_instance, PyObject *cpy_r_owner) { + PyObject *cpy_r_r0; + char cpy_r_r1; + PyObject *cpy_r_r2; + PyObject *cpy_r_r3; + cpy_r_r0 = (PyObject *)&_Py_NoneStruct; + cpy_r_r1 = cpy_r_instance == cpy_r_r0; + if (!cpy_r_r1) goto CPyL2; + CPy_INCREF(cpy_r___mypyc_self__); + return cpy_r___mypyc_self__; +CPyL2: ; + cpy_r_r2 = PyMethod_New(cpy_r___mypyc_self__, cpy_r_instance); + if (cpy_r_r2 == NULL) goto CPyL4; + return cpy_r_r2; +CPyL4: ; + cpy_r_r3 = NULL; + return cpy_r_r3; +} + +PyObject *CPyPy_transpose_test_obj_____get__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) { + PyObject *obj___mypyc_self__ = self; + static const char * const kwlist[] = {"instance", "owner", 0}; + static CPyArg_Parser parser = {"OO:__get__", kwlist, 0}; + PyObject *obj_instance; + PyObject *obj_owner; + if (!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &obj_instance, &obj_owner)) { + return NULL; + } + PyObject *arg___mypyc_self__ = obj___mypyc_self__; + PyObject *arg_instance = obj_instance; + PyObject *arg_owner = obj_owner; + PyObject *retval = CPyDef_transpose_test_obj_____get__(arg___mypyc_self__, arg_instance, arg_owner); + return retval; +fail: ; + CPy_AddTraceback("test.py", "__get__", -1, CPyStatic_globals); + return NULL; +} + +PyObject *CPyDef_transpose_test_obj_____call__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_matrix) { + PyObject *cpy_r_r0; + PyObject *cpy_r_r1; + PyObject *cpy_r_r2; + PyObject *cpy_r_r3; + CPyPtr cpy_r_r4; + int64_t cpy_r_r5; + CPyTagged cpy_r_r6; + CPyTagged cpy_r_r7; + CPyTagged cpy_r_i; + char cpy_r_r8; + PyObject *cpy_r_r9; + CPyPtr cpy_r_r10; + int64_t cpy_r_r11; + CPyTagged cpy_r_r12; + CPyTagged cpy_r_r13; + CPyTagged cpy_r_j; + char cpy_r_r14; + PyObject *cpy_r_r15; + PyObject *cpy_r_r16; + PyObject *cpy_r_r17; + CPyTagged cpy_r_r18; + PyObject *cpy_r_r19; + int32_t cpy_r_r20; + char cpy_r_r21; + CPyTagged cpy_r_r22; + int32_t cpy_r_r23; + char cpy_r_r24; + CPyTagged cpy_r_r25; + PyObject *cpy_r_r26; + cpy_r_r0 = ((test___transpose_test_objObject *)cpy_r___mypyc_self__)->___mypyc_env__; + if (unlikely(cpy_r_r0 == NULL)) { + CPy_AttributeError("test.py", "transpose", "transpose_test_obj", "__mypyc_env__", 4, CPyStatic_globals); + goto CPyL18; + } + CPy_INCREF(cpy_r_r0); + goto CPyL19; +CPyL1: ; + cpy_r_r1 = PyList_New(0); + if (unlikely(cpy_r_r1 == NULL)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL18; + } + cpy_r_r2 = CPyList_GetItemShortBorrow(cpy_r_matrix, 0); + if (unlikely(cpy_r_r2 == NULL)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL20; + } + if (likely(PyList_Check(cpy_r_r2))) + cpy_r_r3 = cpy_r_r2; + else { + CPy_TypeErrorTraceback("test.py", "transpose", 5, CPyStatic_globals, "list", cpy_r_r2); + goto CPyL20; + } + cpy_r_r4 = (CPyPtr)&((PyVarObject *)cpy_r_r3)->ob_size; + cpy_r_r5 = *(int64_t *)cpy_r_r4; + cpy_r_r6 = cpy_r_r5 << 1; + cpy_r_r7 = 0; + cpy_r_i = cpy_r_r7; +CPyL5: ; + cpy_r_r8 = (Py_ssize_t)cpy_r_r7 < (Py_ssize_t)cpy_r_r6; + if (!cpy_r_r8) goto CPyL21; + cpy_r_r9 = PyList_New(0); + if (unlikely(cpy_r_r9 == NULL)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r10 = (CPyPtr)&((PyVarObject *)cpy_r_matrix)->ob_size; + cpy_r_r11 = *(int64_t *)cpy_r_r10; + cpy_r_r12 = cpy_r_r11 << 1; + cpy_r_r13 = 0; + cpy_r_j = cpy_r_r13; +CPyL8: ; + cpy_r_r14 = (Py_ssize_t)cpy_r_r13 < (Py_ssize_t)cpy_r_r12; + if (!cpy_r_r14) goto CPyL23; + cpy_r_r15 = CPyList_GetItemBorrow(cpy_r_matrix, cpy_r_j); + if (unlikely(cpy_r_r15 == NULL)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL24; + } + if (likely(PyList_Check(cpy_r_r15))) + cpy_r_r16 = cpy_r_r15; + else { + CPy_TypeErrorTraceback("test.py", "transpose", 5, CPyStatic_globals, "list", cpy_r_r15); + goto CPyL24; + } + cpy_r_r17 = CPyList_GetItem(cpy_r_r16, cpy_r_i); + if (unlikely(cpy_r_r17 == NULL)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL24; + } + if (likely(PyLong_Check(cpy_r_r17))) + cpy_r_r18 = CPyTagged_FromObject(cpy_r_r17); + else { + CPy_TypeError("int", cpy_r_r17); cpy_r_r18 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r17); + if (unlikely(cpy_r_r18 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL24; + } + CPyTagged_DECREF(cpy_r_j); + cpy_r_r19 = CPyTagged_StealAsObject(cpy_r_r18); + cpy_r_r20 = PyList_Append(cpy_r_r9, cpy_r_r19); + CPy_DECREF(cpy_r_r19); + cpy_r_r21 = cpy_r_r20 >= 0; + if (unlikely(!cpy_r_r21)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL25; + } + cpy_r_r22 = cpy_r_r13 + 2; + cpy_r_r13 = cpy_r_r22; + cpy_r_j = cpy_r_r22; + goto CPyL8; +CPyL15: ; + cpy_r_r23 = PyList_Append(cpy_r_r1, cpy_r_r9); + CPy_DECREF(cpy_r_r9); + cpy_r_r24 = cpy_r_r23 >= 0; + if (unlikely(!cpy_r_r24)) { + CPy_AddTraceback("test.py", "transpose", 5, CPyStatic_globals); + goto CPyL20; + } + cpy_r_r25 = cpy_r_r7 + 2; + cpy_r_r7 = cpy_r_r25; + cpy_r_i = cpy_r_r25; + goto CPyL5; +CPyL17: ; + return cpy_r_r1; +CPyL18: ; + cpy_r_r26 = NULL; + return cpy_r_r26; +CPyL19: ; + CPy_DECREF(cpy_r_r0); + goto CPyL1; +CPyL20: ; + CPy_DecRef(cpy_r_r1); + goto CPyL18; +CPyL21: ; + CPyTagged_DECREF(cpy_r_i); + goto CPyL17; +CPyL22: ; + CPy_DecRef(cpy_r_r1); + CPyTagged_DecRef(cpy_r_i); + goto CPyL18; +CPyL23: ; + CPyTagged_DECREF(cpy_r_i); + CPyTagged_DECREF(cpy_r_j); + goto CPyL15; +CPyL24: ; + CPy_DecRef(cpy_r_r1); + CPyTagged_DecRef(cpy_r_i); + CPy_DecRef(cpy_r_r9); + CPyTagged_DecRef(cpy_r_j); + goto CPyL18; +CPyL25: ; + CPy_DecRef(cpy_r_r1); + CPyTagged_DecRef(cpy_r_i); + CPy_DecRef(cpy_r_r9); + goto CPyL18; +} + +PyObject *CPyPy_transpose_test_obj_____call__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) { + PyObject *obj___mypyc_self__ = self; + static const char * const kwlist[] = {"matrix", 0}; + static CPyArg_Parser parser = {"O:__call__", kwlist, 0}; + PyObject *obj_matrix; + if (!CPyArg_ParseStackAndKeywordsOneArg(args, PyVectorcall_NARGS(nargs), kwnames, &parser, &obj_matrix)) { + return NULL; + } + PyObject *arg___mypyc_self__ = obj___mypyc_self__; + PyObject *arg_matrix; + if (likely(PyList_Check(obj_matrix))) + arg_matrix = obj_matrix; + else { + CPy_TypeError("list", obj_matrix); + goto fail; + } + PyObject *retval = CPyDef_transpose_test_obj_____call__(arg___mypyc_self__, arg_matrix); + return retval; +fail: ; + CPy_AddTraceback("test.py", "transpose", 4, CPyStatic_globals); + return NULL; +} + +PyObject *CPyDef_multiply_matrix_test_obj_____get__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_instance, PyObject *cpy_r_owner) { + PyObject *cpy_r_r0; + char cpy_r_r1; + PyObject *cpy_r_r2; + PyObject *cpy_r_r3; + cpy_r_r0 = (PyObject *)&_Py_NoneStruct; + cpy_r_r1 = cpy_r_instance == cpy_r_r0; + if (!cpy_r_r1) goto CPyL2; + CPy_INCREF(cpy_r___mypyc_self__); + return cpy_r___mypyc_self__; +CPyL2: ; + cpy_r_r2 = PyMethod_New(cpy_r___mypyc_self__, cpy_r_instance); + if (cpy_r_r2 == NULL) goto CPyL4; + return cpy_r_r2; +CPyL4: ; + cpy_r_r3 = NULL; + return cpy_r_r3; +} + +PyObject *CPyPy_multiply_matrix_test_obj_____get__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) { + PyObject *obj___mypyc_self__ = self; + static const char * const kwlist[] = {"instance", "owner", 0}; + static CPyArg_Parser parser = {"OO:__get__", kwlist, 0}; + PyObject *obj_instance; + PyObject *obj_owner; + if (!CPyArg_ParseStackAndKeywordsSimple(args, nargs, kwnames, &parser, &obj_instance, &obj_owner)) { + return NULL; + } + PyObject *arg___mypyc_self__ = obj___mypyc_self__; + PyObject *arg_instance = obj_instance; + PyObject *arg_owner = obj_owner; + PyObject *retval = CPyDef_multiply_matrix_test_obj_____get__(arg___mypyc_self__, arg_instance, arg_owner); + return retval; +fail: ; + CPy_AddTraceback("test.py", "__get__", -1, CPyStatic_globals); + return NULL; +} + +PyObject *CPyDef_multiply_matrix_test_obj_____call__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_matrix1, PyObject *cpy_r_matrix2) { + PyObject *cpy_r_r0; + CPyPtr cpy_r_r1; + int64_t cpy_r_r2; + PyObject *cpy_r_r3; + CPyTagged cpy_r_r4; + CPyPtr cpy_r_r5; + int64_t cpy_r_r6; + CPyTagged cpy_r_r7; + char cpy_r_r8; + PyObject *cpy_r_r9; + PyObject *cpy_r_r10; + PyObject *cpy_r_X_row; + PyObject *cpy_r_r11; + PyObject *cpy_r_r12; + PyObject *cpy_r_r13; + PyObject *cpy_r_r14; + PyObject *cpy_r_r15; + PyObject *cpy_r_r16; + PyObject *cpy_r_r17; + PyObject *cpy_r_r18; + PyObject *cpy_r_r19; + PyObject *cpy_r_r20; + PyObject *cpy_r_r21; + PyObject *cpy_r_r22; + PyObject *cpy_r_Y_col; + CPyTagged cpy_r_r23; + CPyTagged cpy_r_r24; + CPyTagged cpy_r_r25; + CPyPtr cpy_r_r26; + int64_t cpy_r_r27; + CPyTagged cpy_r_r28; + char cpy_r_r29; + CPyPtr cpy_r_r30; + int64_t cpy_r_r31; + CPyTagged cpy_r_r32; + char cpy_r_r33; + PyObject *cpy_r_r34; + CPyTagged cpy_r_r35; + CPyTagged cpy_r_a; + PyObject *cpy_r_r36; + PyObject *cpy_r_b; + PyObject *cpy_r_r37; + PyObject *cpy_r_r38; + PyObject *cpy_r_r39; + PyObject *cpy_r_r40; + CPyTagged cpy_r_r41; + CPyTagged cpy_r_r42; + CPyTagged cpy_r_r43; + PyObject *cpy_r_r44; + int32_t cpy_r_r45; + char cpy_r_r46; + char cpy_r_r47; + char cpy_r_r48; + CPyTagged cpy_r_r49; + PyObject *cpy_r_r50; + cpy_r_r0 = ((test___multiply_matrix_test_objObject *)cpy_r___mypyc_self__)->___mypyc_env__; + if (unlikely(cpy_r_r0 == NULL)) { + CPy_AttributeError("test.py", "multiply_matrix", "multiply_matrix_test_obj", "__mypyc_env__", 9, CPyStatic_globals); + goto CPyL30; + } + CPy_INCREF(cpy_r_r0); + goto CPyL31; +CPyL1: ; + cpy_r_r1 = (CPyPtr)&((PyVarObject *)cpy_r_matrix1)->ob_size; + cpy_r_r2 = *(int64_t *)cpy_r_r1; + cpy_r_r3 = PyList_New(cpy_r_r2); + if (unlikely(cpy_r_r3 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL30; + } + cpy_r_r4 = 0; +CPyL3: ; + cpy_r_r5 = (CPyPtr)&((PyVarObject *)cpy_r_matrix1)->ob_size; + cpy_r_r6 = *(int64_t *)cpy_r_r5; + cpy_r_r7 = cpy_r_r6 << 1; + cpy_r_r8 = (Py_ssize_t)cpy_r_r4 < (Py_ssize_t)cpy_r_r7; + if (!cpy_r_r8) goto CPyL29; + cpy_r_r9 = CPyList_GetItemUnsafe(cpy_r_matrix1, cpy_r_r4); + if (likely(PyList_Check(cpy_r_r9))) + cpy_r_r10 = cpy_r_r9; + else { + CPy_TypeErrorTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals, "list", cpy_r_r9); + goto CPyL32; + } + cpy_r_X_row = cpy_r_r10; + cpy_r_r11 = PyList_New(0); + if (unlikely(cpy_r_r11 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL33; + } + cpy_r_r12 = CPyModule_builtins; + cpy_r_r13 = CPyStatics[3]; /* 'zip' */ + cpy_r_r14 = CPyObject_GetAttr(cpy_r_r12, cpy_r_r13); + if (unlikely(cpy_r_r14 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL34; + } + cpy_r_r15 = PyList_New(0); + if (unlikely(cpy_r_r15 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL35; + } + cpy_r_r16 = CPyList_Extend(cpy_r_r15, cpy_r_matrix2); + if (unlikely(cpy_r_r16 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL36; + } else + goto CPyL37; +CPyL9: ; + cpy_r_r17 = PyList_AsTuple(cpy_r_r15); + CPy_DECREF(cpy_r_r15); + if (unlikely(cpy_r_r17 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL35; + } + cpy_r_r18 = PyDict_New(); + if (unlikely(cpy_r_r18 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL38; + } + cpy_r_r19 = PyObject_Call(cpy_r_r14, cpy_r_r17, cpy_r_r18); + CPy_DECREF(cpy_r_r14); + CPy_DECREF(cpy_r_r17); + CPy_DECREF(cpy_r_r18); + if (unlikely(cpy_r_r19 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL34; + } + cpy_r_r20 = PyObject_GetIter(cpy_r_r19); + CPy_DECREF(cpy_r_r19); + if (unlikely(cpy_r_r20 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL34; + } +CPyL13: ; + cpy_r_r21 = PyIter_Next(cpy_r_r20); + if (cpy_r_r21 == NULL) goto CPyL39; + if (likely(PyTuple_Check(cpy_r_r21))) + cpy_r_r22 = cpy_r_r21; + else { + CPy_TypeErrorTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals, "tuple", cpy_r_r21); + goto CPyL40; + } + cpy_r_Y_col = cpy_r_r22; + cpy_r_r23 = 0; + cpy_r_r24 = 0; + cpy_r_r25 = 0; +CPyL16: ; + cpy_r_r26 = (CPyPtr)&((PyVarObject *)cpy_r_X_row)->ob_size; + cpy_r_r27 = *(int64_t *)cpy_r_r26; + cpy_r_r28 = cpy_r_r27 << 1; + cpy_r_r29 = (Py_ssize_t)cpy_r_r24 < (Py_ssize_t)cpy_r_r28; + if (!cpy_r_r29) goto CPyL41; + cpy_r_r30 = (CPyPtr)&((PyVarObject *)cpy_r_Y_col)->ob_size; + cpy_r_r31 = *(int64_t *)cpy_r_r30; + cpy_r_r32 = cpy_r_r31 << 1; + cpy_r_r33 = (Py_ssize_t)cpy_r_r25 < (Py_ssize_t)cpy_r_r32; + if (!cpy_r_r33) goto CPyL41; + cpy_r_r34 = CPyList_GetItemUnsafe(cpy_r_X_row, cpy_r_r24); + if (likely(PyLong_Check(cpy_r_r34))) + cpy_r_r35 = CPyTagged_FromObject(cpy_r_r34); + else { + CPy_TypeError("int", cpy_r_r34); cpy_r_r35 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r34); + if (unlikely(cpy_r_r35 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL42; + } + cpy_r_a = cpy_r_r35; + cpy_r_r36 = CPySequenceTuple_GetItem(cpy_r_Y_col, cpy_r_r25); + if (unlikely(cpy_r_r36 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL43; + } + cpy_r_b = cpy_r_r36; + cpy_r_r37 = CPyTagged_StealAsObject(cpy_r_a); + cpy_r_r38 = PyNumber_Multiply(cpy_r_r37, cpy_r_b); + CPy_DECREF(cpy_r_r37); + CPy_DECREF(cpy_r_b); + if (unlikely(cpy_r_r38 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL42; + } + cpy_r_r39 = CPyTagged_StealAsObject(cpy_r_r23); + cpy_r_r40 = PyNumber_Add(cpy_r_r39, cpy_r_r38); + CPy_DECREF(cpy_r_r39); + CPy_DECREF(cpy_r_r38); + if (unlikely(cpy_r_r40 == NULL)) { + CPy_AddTraceback("test.py", "multiply_matrix", -1, CPyStatic_globals); + goto CPyL44; + } + if (likely(PyLong_Check(cpy_r_r40))) + cpy_r_r41 = CPyTagged_FromObject(cpy_r_r40); + else { + CPy_TypeError("int", cpy_r_r40); cpy_r_r41 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r40); + if (unlikely(cpy_r_r41 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "multiply_matrix", -1, CPyStatic_globals); + goto CPyL44; + } + cpy_r_r23 = cpy_r_r41; + cpy_r_r42 = cpy_r_r24 + 2; + cpy_r_r24 = cpy_r_r42; + cpy_r_r43 = cpy_r_r25 + 2; + cpy_r_r25 = cpy_r_r43; + goto CPyL16; +CPyL25: ; + cpy_r_r44 = CPyTagged_StealAsObject(cpy_r_r23); + cpy_r_r45 = PyList_Append(cpy_r_r11, cpy_r_r44); + CPy_DECREF(cpy_r_r44); + cpy_r_r46 = cpy_r_r45 >= 0; + if (unlikely(!cpy_r_r46)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL40; + } else + goto CPyL13; +CPyL26: ; + cpy_r_r47 = CPy_NoErrOccured(); + if (unlikely(!cpy_r_r47)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL45; + } + cpy_r_r48 = CPyList_SetItemUnsafe(cpy_r_r3, cpy_r_r4, cpy_r_r11); + if (unlikely(!cpy_r_r48)) { + CPy_AddTraceback("test.py", "multiply_matrix", 10, CPyStatic_globals); + goto CPyL32; + } + cpy_r_r49 = cpy_r_r4 + 2; + cpy_r_r4 = cpy_r_r49; + goto CPyL3; +CPyL29: ; + return cpy_r_r3; +CPyL30: ; + cpy_r_r50 = NULL; + return cpy_r_r50; +CPyL31: ; + CPy_DECREF(cpy_r_r0); + goto CPyL1; +CPyL32: ; + CPy_DecRef(cpy_r_r3); + goto CPyL30; +CPyL33: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + goto CPyL30; +CPyL34: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + goto CPyL30; +CPyL35: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r14); + goto CPyL30; +CPyL36: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r14); + CPy_DecRef(cpy_r_r15); + goto CPyL30; +CPyL37: ; + CPy_DECREF(cpy_r_r16); + goto CPyL9; +CPyL38: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r14); + CPy_DecRef(cpy_r_r17); + goto CPyL30; +CPyL39: ; + CPy_DECREF(cpy_r_X_row); + CPy_DECREF(cpy_r_r20); + goto CPyL26; +CPyL40: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r20); + goto CPyL30; +CPyL41: ; + CPy_DECREF(cpy_r_Y_col); + goto CPyL25; +CPyL42: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r20); + CPy_DecRef(cpy_r_Y_col); + CPyTagged_DecRef(cpy_r_r23); + goto CPyL30; +CPyL43: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r20); + CPy_DecRef(cpy_r_Y_col); + CPyTagged_DecRef(cpy_r_r23); + CPyTagged_DecRef(cpy_r_a); + goto CPyL30; +CPyL44: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_X_row); + CPy_DecRef(cpy_r_r11); + CPy_DecRef(cpy_r_r20); + CPy_DecRef(cpy_r_Y_col); + goto CPyL30; +CPyL45: ; + CPy_DecRef(cpy_r_r3); + CPy_DecRef(cpy_r_r11); + goto CPyL30; +} + +PyObject *CPyPy_multiply_matrix_test_obj_____call__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) { + PyObject *obj___mypyc_self__ = self; + static const char * const kwlist[] = {"matrix1", "matrix2", 0}; + static CPyArg_Parser parser = {"OO:__call__", kwlist, 0}; + PyObject *obj_matrix1; + PyObject *obj_matrix2; + if (!CPyArg_ParseStackAndKeywordsSimple(args, PyVectorcall_NARGS(nargs), kwnames, &parser, &obj_matrix1, &obj_matrix2)) { + return NULL; + } + PyObject *arg___mypyc_self__ = obj___mypyc_self__; + PyObject *arg_matrix1; + if (likely(PyList_Check(obj_matrix1))) + arg_matrix1 = obj_matrix1; + else { + CPy_TypeError("list", obj_matrix1); + goto fail; + } + PyObject *arg_matrix2; + if (likely(PyList_Check(obj_matrix2))) + arg_matrix2 = obj_matrix2; + else { + CPy_TypeError("list", obj_matrix2); + goto fail; + } + PyObject *retval = CPyDef_multiply_matrix_test_obj_____call__(arg___mypyc_self__, arg_matrix1, arg_matrix2); + return retval; +fail: ; + CPy_AddTraceback("test.py", "multiply_matrix", 9, CPyStatic_globals); + return NULL; +} + +PyObject *CPyDef_test(void) { + PyObject *cpy_r_r0; + PyObject *cpy_r_r1; + PyObject *cpy_r_r2; + PyObject *cpy_r_r3; + PyObject *cpy_r_r4; + CPyPtr cpy_r_r5; + CPyPtr cpy_r_r6; + CPyPtr cpy_r_r7; + CPyPtr cpy_r_r8; + PyObject *cpy_r_r9; + PyObject *cpy_r_r10; + PyObject *cpy_r_r11; + PyObject *cpy_r_r12; + CPyPtr cpy_r_r13; + CPyPtr cpy_r_r14; + CPyPtr cpy_r_r15; + CPyPtr cpy_r_r16; + PyObject *cpy_r_r17; + PyObject *cpy_r_r18; + PyObject *cpy_r_r19; + PyObject *cpy_r_r20; + CPyPtr cpy_r_r21; + CPyPtr cpy_r_r22; + CPyPtr cpy_r_r23; + CPyPtr cpy_r_r24; + PyObject *cpy_r_r25; + CPyPtr cpy_r_r26; + CPyPtr cpy_r_r27; + CPyPtr cpy_r_r28; + CPyPtr cpy_r_r29; + PyObject *cpy_r_mat1; + PyObject *cpy_r_r30; + PyObject *cpy_r_r31; + PyObject *cpy_r_r32; + PyObject *cpy_r_r33; + CPyPtr cpy_r_r34; + CPyPtr cpy_r_r35; + CPyPtr cpy_r_r36; + CPyPtr cpy_r_r37; + PyObject *cpy_r_r38; + PyObject *cpy_r_r39; + PyObject *cpy_r_r40; + PyObject *cpy_r_r41; + CPyPtr cpy_r_r42; + CPyPtr cpy_r_r43; + CPyPtr cpy_r_r44; + CPyPtr cpy_r_r45; + PyObject *cpy_r_r46; + PyObject *cpy_r_r47; + PyObject *cpy_r_r48; + PyObject *cpy_r_r49; + CPyPtr cpy_r_r50; + CPyPtr cpy_r_r51; + CPyPtr cpy_r_r52; + CPyPtr cpy_r_r53; + PyObject *cpy_r_r54; + CPyPtr cpy_r_r55; + CPyPtr cpy_r_r56; + CPyPtr cpy_r_r57; + CPyPtr cpy_r_r58; + PyObject *cpy_r_mat2; + PyObject *cpy_r_r59; + char cpy_r_r60; + PyObject *cpy_r_transpose; + PyObject **cpy_r_r62; + PyObject *cpy_r_r63; + PyObject *cpy_r_r64; + PyObject *cpy_r_r65; + PyObject *cpy_r_r66; + PyObject **cpy_r_r68; + PyObject *cpy_r_r69; + PyObject *cpy_r_r70; + char cpy_r_r71; + PyObject *cpy_r_multiply_matrix; + PyObject **cpy_r_r73; + PyObject *cpy_r_r74; + PyObject *cpy_r_r75; + PyObject *cpy_r_r76; + PyObject *cpy_r_r77; + PyObject **cpy_r_r79; + PyObject *cpy_r_r80; + PyObject *cpy_r_r81; + PyObject *cpy_r_r82; + cpy_r_r0 = CPyDef_test_env(); + if (unlikely(cpy_r_r0 == NULL)) { + CPy_AddTraceback("test.py", "test", 1, CPyStatic_globals); + goto CPyL20; + } + cpy_r_r1 = PyList_New(3); + if (unlikely(cpy_r_r1 == NULL)) { + CPy_AddTraceback("test.py", "test", 2, CPyStatic_globals); + goto CPyL21; + } + cpy_r_r2 = CPyStatics[14]; /* 1 */ + cpy_r_r3 = CPyStatics[15]; /* 2 */ + cpy_r_r4 = CPyStatics[16]; /* 3 */ + cpy_r_r5 = (CPyPtr)&((PyListObject *)cpy_r_r1)->ob_item; + cpy_r_r6 = *(CPyPtr *)cpy_r_r5; + CPy_INCREF(cpy_r_r2); + *(PyObject * *)cpy_r_r6 = cpy_r_r2; + cpy_r_r7 = cpy_r_r6 + 8; + CPy_INCREF(cpy_r_r3); + *(PyObject * *)cpy_r_r7 = cpy_r_r3; + cpy_r_r8 = cpy_r_r6 + 16; + CPy_INCREF(cpy_r_r4); + *(PyObject * *)cpy_r_r8 = cpy_r_r4; + cpy_r_r9 = PyList_New(3); + if (unlikely(cpy_r_r9 == NULL)) { + CPy_AddTraceback("test.py", "test", 2, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r10 = CPyStatics[17]; /* 4 */ + cpy_r_r11 = CPyStatics[18]; /* 5 */ + cpy_r_r12 = CPyStatics[19]; /* 6 */ + cpy_r_r13 = (CPyPtr)&((PyListObject *)cpy_r_r9)->ob_item; + cpy_r_r14 = *(CPyPtr *)cpy_r_r13; + CPy_INCREF(cpy_r_r10); + *(PyObject * *)cpy_r_r14 = cpy_r_r10; + cpy_r_r15 = cpy_r_r14 + 8; + CPy_INCREF(cpy_r_r11); + *(PyObject * *)cpy_r_r15 = cpy_r_r11; + cpy_r_r16 = cpy_r_r14 + 16; + CPy_INCREF(cpy_r_r12); + *(PyObject * *)cpy_r_r16 = cpy_r_r12; + cpy_r_r17 = PyList_New(3); + if (unlikely(cpy_r_r17 == NULL)) { + CPy_AddTraceback("test.py", "test", 2, CPyStatic_globals); + goto CPyL23; + } + cpy_r_r18 = CPyStatics[20]; /* 7 */ + cpy_r_r19 = CPyStatics[21]; /* 8 */ + cpy_r_r20 = CPyStatics[22]; /* 9 */ + cpy_r_r21 = (CPyPtr)&((PyListObject *)cpy_r_r17)->ob_item; + cpy_r_r22 = *(CPyPtr *)cpy_r_r21; + CPy_INCREF(cpy_r_r18); + *(PyObject * *)cpy_r_r22 = cpy_r_r18; + cpy_r_r23 = cpy_r_r22 + 8; + CPy_INCREF(cpy_r_r19); + *(PyObject * *)cpy_r_r23 = cpy_r_r19; + cpy_r_r24 = cpy_r_r22 + 16; + CPy_INCREF(cpy_r_r20); + *(PyObject * *)cpy_r_r24 = cpy_r_r20; + cpy_r_r25 = PyList_New(3); + if (unlikely(cpy_r_r25 == NULL)) { + CPy_AddTraceback("test.py", "test", 2, CPyStatic_globals); + goto CPyL24; + } + cpy_r_r26 = (CPyPtr)&((PyListObject *)cpy_r_r25)->ob_item; + cpy_r_r27 = *(CPyPtr *)cpy_r_r26; + *(PyObject * *)cpy_r_r27 = cpy_r_r1; + cpy_r_r28 = cpy_r_r27 + 8; + *(PyObject * *)cpy_r_r28 = cpy_r_r9; + cpy_r_r29 = cpy_r_r27 + 16; + *(PyObject * *)cpy_r_r29 = cpy_r_r17; + cpy_r_mat1 = cpy_r_r25; + cpy_r_r30 = PyList_New(3); + if (unlikely(cpy_r_r30 == NULL)) { + CPy_AddTraceback("test.py", "test", 3, CPyStatic_globals); + goto CPyL25; + } + cpy_r_r31 = CPyStatics[14]; /* 1 */ + cpy_r_r32 = CPyStatics[15]; /* 2 */ + cpy_r_r33 = CPyStatics[16]; /* 3 */ + cpy_r_r34 = (CPyPtr)&((PyListObject *)cpy_r_r30)->ob_item; + cpy_r_r35 = *(CPyPtr *)cpy_r_r34; + CPy_INCREF(cpy_r_r31); + *(PyObject * *)cpy_r_r35 = cpy_r_r31; + cpy_r_r36 = cpy_r_r35 + 8; + CPy_INCREF(cpy_r_r32); + *(PyObject * *)cpy_r_r36 = cpy_r_r32; + cpy_r_r37 = cpy_r_r35 + 16; + CPy_INCREF(cpy_r_r33); + *(PyObject * *)cpy_r_r37 = cpy_r_r33; + cpy_r_r38 = PyList_New(3); + if (unlikely(cpy_r_r38 == NULL)) { + CPy_AddTraceback("test.py", "test", 3, CPyStatic_globals); + goto CPyL26; + } + cpy_r_r39 = CPyStatics[17]; /* 4 */ + cpy_r_r40 = CPyStatics[18]; /* 5 */ + cpy_r_r41 = CPyStatics[19]; /* 6 */ + cpy_r_r42 = (CPyPtr)&((PyListObject *)cpy_r_r38)->ob_item; + cpy_r_r43 = *(CPyPtr *)cpy_r_r42; + CPy_INCREF(cpy_r_r39); + *(PyObject * *)cpy_r_r43 = cpy_r_r39; + cpy_r_r44 = cpy_r_r43 + 8; + CPy_INCREF(cpy_r_r40); + *(PyObject * *)cpy_r_r44 = cpy_r_r40; + cpy_r_r45 = cpy_r_r43 + 16; + CPy_INCREF(cpy_r_r41); + *(PyObject * *)cpy_r_r45 = cpy_r_r41; + cpy_r_r46 = PyList_New(3); + if (unlikely(cpy_r_r46 == NULL)) { + CPy_AddTraceback("test.py", "test", 3, CPyStatic_globals); + goto CPyL27; + } + cpy_r_r47 = CPyStatics[20]; /* 7 */ + cpy_r_r48 = CPyStatics[21]; /* 8 */ + cpy_r_r49 = CPyStatics[22]; /* 9 */ + cpy_r_r50 = (CPyPtr)&((PyListObject *)cpy_r_r46)->ob_item; + cpy_r_r51 = *(CPyPtr *)cpy_r_r50; + CPy_INCREF(cpy_r_r47); + *(PyObject * *)cpy_r_r51 = cpy_r_r47; + cpy_r_r52 = cpy_r_r51 + 8; + CPy_INCREF(cpy_r_r48); + *(PyObject * *)cpy_r_r52 = cpy_r_r48; + cpy_r_r53 = cpy_r_r51 + 16; + CPy_INCREF(cpy_r_r49); + *(PyObject * *)cpy_r_r53 = cpy_r_r49; + cpy_r_r54 = PyList_New(3); + if (unlikely(cpy_r_r54 == NULL)) { + CPy_AddTraceback("test.py", "test", 3, CPyStatic_globals); + goto CPyL28; + } + cpy_r_r55 = (CPyPtr)&((PyListObject *)cpy_r_r54)->ob_item; + cpy_r_r56 = *(CPyPtr *)cpy_r_r55; + *(PyObject * *)cpy_r_r56 = cpy_r_r30; + cpy_r_r57 = cpy_r_r56 + 8; + *(PyObject * *)cpy_r_r57 = cpy_r_r38; + cpy_r_r58 = cpy_r_r56 + 16; + *(PyObject * *)cpy_r_r58 = cpy_r_r46; + cpy_r_mat2 = cpy_r_r54; + cpy_r_r59 = CPyDef_transpose_test_obj(); + if (unlikely(cpy_r_r59 == NULL)) { + CPy_AddTraceback("test.py", "test", 4, CPyStatic_globals); + goto CPyL29; + } + CPy_INCREF(cpy_r_r0); + if (((test___transpose_test_objObject *)cpy_r_r59)->___mypyc_env__ != NULL) { + CPy_DECREF(((test___transpose_test_objObject *)cpy_r_r59)->___mypyc_env__); + } + ((test___transpose_test_objObject *)cpy_r_r59)->___mypyc_env__ = cpy_r_r0; + cpy_r_r60 = 1; + if (unlikely(!cpy_r_r60)) { + CPy_AddTraceback("test.py", "test", 4, CPyStatic_globals); + goto CPyL30; + } + cpy_r_transpose = cpy_r_r59; + PyObject *cpy_r_r61[1] = {cpy_r_mat1}; + cpy_r_r62 = (PyObject **)&cpy_r_r61; + cpy_r_r63 = _PyObject_Vectorcall(cpy_r_transpose, cpy_r_r62, 1, 0); + CPy_DECREF(cpy_r_transpose); + if (unlikely(cpy_r_r63 == NULL)) { + CPy_AddTraceback("test.py", "test", 7, CPyStatic_globals); + goto CPyL29; + } + cpy_r_r64 = CPyModule_builtins; + cpy_r_r65 = CPyStatics[4]; /* 'print' */ + cpy_r_r66 = CPyObject_GetAttr(cpy_r_r64, cpy_r_r65); + if (unlikely(cpy_r_r66 == NULL)) { + CPy_AddTraceback("test.py", "test", 7, CPyStatic_globals); + goto CPyL31; + } + PyObject *cpy_r_r67[1] = {cpy_r_r63}; + cpy_r_r68 = (PyObject **)&cpy_r_r67; + cpy_r_r69 = _PyObject_Vectorcall(cpy_r_r66, cpy_r_r68, 1, 0); + CPy_DECREF(cpy_r_r66); + if (unlikely(cpy_r_r69 == NULL)) { + CPy_AddTraceback("test.py", "test", 7, CPyStatic_globals); + goto CPyL31; + } else + goto CPyL32; +CPyL14: ; + CPy_DECREF(cpy_r_r63); + cpy_r_r70 = CPyDef_multiply_matrix_test_obj(); + if (unlikely(cpy_r_r70 == NULL)) { + CPy_AddTraceback("test.py", "test", 9, CPyStatic_globals); + goto CPyL29; + } + if (((test___multiply_matrix_test_objObject *)cpy_r_r70)->___mypyc_env__ != NULL) { + CPy_DECREF(((test___multiply_matrix_test_objObject *)cpy_r_r70)->___mypyc_env__); + } + ((test___multiply_matrix_test_objObject *)cpy_r_r70)->___mypyc_env__ = cpy_r_r0; + cpy_r_r71 = 1; + if (unlikely(!cpy_r_r71)) { + CPy_AddTraceback("test.py", "test", 9, CPyStatic_globals); + goto CPyL33; + } + cpy_r_multiply_matrix = cpy_r_r70; + PyObject *cpy_r_r72[2] = {cpy_r_mat1, cpy_r_mat2}; + cpy_r_r73 = (PyObject **)&cpy_r_r72; + cpy_r_r74 = _PyObject_Vectorcall(cpy_r_multiply_matrix, cpy_r_r73, 2, 0); + CPy_DECREF(cpy_r_multiply_matrix); + if (unlikely(cpy_r_r74 == NULL)) { + CPy_AddTraceback("test.py", "test", 12, CPyStatic_globals); + goto CPyL34; + } + CPy_DECREF(cpy_r_mat1); + CPy_DECREF(cpy_r_mat2); + cpy_r_r75 = CPyModule_builtins; + cpy_r_r76 = CPyStatics[4]; /* 'print' */ + cpy_r_r77 = CPyObject_GetAttr(cpy_r_r75, cpy_r_r76); + if (unlikely(cpy_r_r77 == NULL)) { + CPy_AddTraceback("test.py", "test", 12, CPyStatic_globals); + goto CPyL35; + } + PyObject *cpy_r_r78[1] = {cpy_r_r74}; + cpy_r_r79 = (PyObject **)&cpy_r_r78; + cpy_r_r80 = _PyObject_Vectorcall(cpy_r_r77, cpy_r_r79, 1, 0); + CPy_DECREF(cpy_r_r77); + if (unlikely(cpy_r_r80 == NULL)) { + CPy_AddTraceback("test.py", "test", 12, CPyStatic_globals); + goto CPyL35; + } else + goto CPyL36; +CPyL19: ; + CPy_DECREF(cpy_r_r74); + cpy_r_r81 = Py_None; + CPy_INCREF(cpy_r_r81); + return cpy_r_r81; +CPyL20: ; + cpy_r_r82 = NULL; + return cpy_r_r82; +CPyL21: ; + CPy_DecRef(cpy_r_r0); + goto CPyL20; +CPyL22: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_r1); + goto CPyL20; +CPyL23: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_r1); + CPy_DecRef(cpy_r_r9); + goto CPyL20; +CPyL24: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_r1); + CPy_DecRef(cpy_r_r9); + CPy_DecRef(cpy_r_r17); + goto CPyL20; +CPyL25: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + goto CPyL20; +CPyL26: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_r30); + goto CPyL20; +CPyL27: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_r30); + CPy_DecRef(cpy_r_r38); + goto CPyL20; +CPyL28: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_r30); + CPy_DecRef(cpy_r_r38); + CPy_DecRef(cpy_r_r46); + goto CPyL20; +CPyL29: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_mat2); + goto CPyL20; +CPyL30: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_mat2); + CPy_DecRef(cpy_r_r59); + goto CPyL20; +CPyL31: ; + CPy_DecRef(cpy_r_r0); + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_mat2); + CPy_DecRef(cpy_r_r63); + goto CPyL20; +CPyL32: ; + CPy_DECREF(cpy_r_r69); + goto CPyL14; +CPyL33: ; + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_mat2); + CPy_DecRef(cpy_r_r70); + goto CPyL20; +CPyL34: ; + CPy_DecRef(cpy_r_mat1); + CPy_DecRef(cpy_r_mat2); + goto CPyL20; +CPyL35: ; + CPy_DecRef(cpy_r_r74); + goto CPyL20; +CPyL36: ; + CPy_DECREF(cpy_r_r80); + goto CPyL19; +} + +PyObject *CPyPy_test(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames) { + static const char * const kwlist[] = {0}; + static CPyArg_Parser parser = {":test", kwlist, 0}; + if (!CPyArg_ParseStackAndKeywordsNoArgs(args, nargs, kwnames, &parser)) { + return NULL; + } + PyObject *retval = CPyDef_test(); + return retval; +fail: ; + CPy_AddTraceback("test.py", "test", 1, CPyStatic_globals); + return NULL; +} + +char CPyDef___top_level__(void) { + PyObject *cpy_r_r0; + PyObject *cpy_r_r1; + char cpy_r_r2; + PyObject *cpy_r_r3; + PyObject *cpy_r_r4; + PyObject **cpy_r_r5; + void *cpy_r_r7; + void *cpy_r_r9; + PyObject *cpy_r_r10; + PyObject *cpy_r_r11; + PyObject *cpy_r_r12; + PyObject *cpy_r_r13; + char cpy_r_r14; + PyObject *cpy_r_r15; + PyObject *cpy_r_r16; + PyObject *cpy_r_r17; + PyObject *cpy_r_r18; + CPyTagged cpy_r_r19; + PyObject *cpy_r_r20; + PyObject *cpy_r_r21; + PyObject *cpy_r_r22; + int32_t cpy_r_r23; + char cpy_r_r24; + PyObject *cpy_r_r25; + PyObject *cpy_r_r26; + PyObject *cpy_r_r27; + PyObject *cpy_r_r28; + PyObject *cpy_r_r29; + CPyTagged cpy_r_r30; + PyObject *cpy_r_r31; + PyObject *cpy_r_r32; + PyObject *cpy_r_r33; + int32_t cpy_r_r34; + char cpy_r_r35; + PyObject *cpy_r_r36; + PyObject *cpy_r_r37; + PyObject *cpy_r_r38; + PyObject *cpy_r_r39; + CPyTagged cpy_r_r40; + PyObject *cpy_r_r41; + PyObject *cpy_r_r42; + PyObject *cpy_r_r43; + CPyTagged cpy_r_r44; + CPyTagged cpy_r_r45; + PyObject *cpy_r_r46; + PyObject *cpy_r_r47; + PyObject *cpy_r_r48; + PyObject *cpy_r_r49; + PyObject *cpy_r_r50; + PyObject *cpy_r_r51; + PyObject **cpy_r_r53; + PyObject *cpy_r_r54; + char cpy_r_r55; + cpy_r_r0 = CPyModule_builtins; + cpy_r_r1 = (PyObject *)&_Py_NoneStruct; + cpy_r_r2 = cpy_r_r0 != cpy_r_r1; + if (cpy_r_r2) goto CPyL3; + cpy_r_r3 = CPyStatics[5]; /* 'builtins' */ + cpy_r_r4 = PyImport_Import(cpy_r_r3); + if (unlikely(cpy_r_r4 == NULL)) { + CPy_AddTraceback("test.py", "", -1, CPyStatic_globals); + goto CPyL22; + } + CPyModule_builtins = cpy_r_r4; + CPy_INCREF(CPyModule_builtins); + CPy_DECREF(cpy_r_r4); +CPyL3: ; + cpy_r_r5 = (PyObject **)&CPyModule_time; + PyObject **cpy_r_r6[1] = {cpy_r_r5}; + cpy_r_r7 = (void *)&cpy_r_r6; + int64_t cpy_r_r8[1] = {14}; + cpy_r_r9 = (void *)&cpy_r_r8; + cpy_r_r10 = CPyStatics[24]; /* (('time', 'time', 'time'),) */ + cpy_r_r11 = CPyStatic_globals; + cpy_r_r12 = CPyStatics[7]; /* 'test.py' */ + cpy_r_r13 = CPyStatics[8]; /* '' */ + cpy_r_r14 = CPyImport_ImportMany(cpy_r_r10, cpy_r_r7, cpy_r_r11, cpy_r_r12, cpy_r_r13, cpy_r_r9); + if (!cpy_r_r14) goto CPyL22; + cpy_r_r15 = CPyModule_time; + cpy_r_r16 = CPyStatics[9]; /* 'perf_counter_ns' */ + cpy_r_r17 = CPyObject_GetAttr(cpy_r_r15, cpy_r_r16); + if (unlikely(cpy_r_r17 == NULL)) { + CPy_AddTraceback("test.py", "", 15, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r18 = _PyObject_Vectorcall(cpy_r_r17, 0, 0, 0); + CPy_DECREF(cpy_r_r17); + if (unlikely(cpy_r_r18 == NULL)) { + CPy_AddTraceback("test.py", "", 15, CPyStatic_globals); + goto CPyL22; + } + if (likely(PyLong_Check(cpy_r_r18))) + cpy_r_r19 = CPyTagged_FromObject(cpy_r_r18); + else { + CPy_TypeError("int", cpy_r_r18); cpy_r_r19 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r18); + if (unlikely(cpy_r_r19 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "", 15, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r20 = CPyStatic_globals; + cpy_r_r21 = CPyStatics[10]; /* 'start' */ + cpy_r_r22 = CPyTagged_StealAsObject(cpy_r_r19); + cpy_r_r23 = CPyDict_SetItem(cpy_r_r20, cpy_r_r21, cpy_r_r22); + CPy_DECREF(cpy_r_r22); + cpy_r_r24 = cpy_r_r23 >= 0; + if (unlikely(!cpy_r_r24)) { + CPy_AddTraceback("test.py", "", 15, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r25 = CPyDef_test(); + if (unlikely(cpy_r_r25 == NULL)) { + CPy_AddTraceback("test.py", "", 16, CPyStatic_globals); + goto CPyL22; + } else + goto CPyL23; +CPyL9: ; + cpy_r_r26 = CPyModule_time; + cpy_r_r27 = CPyStatics[9]; /* 'perf_counter_ns' */ + cpy_r_r28 = CPyObject_GetAttr(cpy_r_r26, cpy_r_r27); + if (unlikely(cpy_r_r28 == NULL)) { + CPy_AddTraceback("test.py", "", 17, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r29 = _PyObject_Vectorcall(cpy_r_r28, 0, 0, 0); + CPy_DECREF(cpy_r_r28); + if (unlikely(cpy_r_r29 == NULL)) { + CPy_AddTraceback("test.py", "", 17, CPyStatic_globals); + goto CPyL22; + } + if (likely(PyLong_Check(cpy_r_r29))) + cpy_r_r30 = CPyTagged_FromObject(cpy_r_r29); + else { + CPy_TypeError("int", cpy_r_r29); cpy_r_r30 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r29); + if (unlikely(cpy_r_r30 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "", 17, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r31 = CPyStatic_globals; + cpy_r_r32 = CPyStatics[11]; /* 'end' */ + cpy_r_r33 = CPyTagged_StealAsObject(cpy_r_r30); + cpy_r_r34 = CPyDict_SetItem(cpy_r_r31, cpy_r_r32, cpy_r_r33); + CPy_DECREF(cpy_r_r33); + cpy_r_r35 = cpy_r_r34 >= 0; + if (unlikely(!cpy_r_r35)) { + CPy_AddTraceback("test.py", "", 17, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r36 = CPyStatics[12]; /* 'Time: ' */ + cpy_r_r37 = CPyStatic_globals; + cpy_r_r38 = CPyStatics[11]; /* 'end' */ + cpy_r_r39 = CPyDict_GetItem(cpy_r_r37, cpy_r_r38); + if (unlikely(cpy_r_r39 == NULL)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL22; + } + if (likely(PyLong_Check(cpy_r_r39))) + cpy_r_r40 = CPyTagged_FromObject(cpy_r_r39); + else { + CPy_TypeError("int", cpy_r_r39); cpy_r_r40 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r39); + if (unlikely(cpy_r_r40 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r41 = CPyStatic_globals; + cpy_r_r42 = CPyStatics[10]; /* 'start' */ + cpy_r_r43 = CPyDict_GetItem(cpy_r_r41, cpy_r_r42); + if (unlikely(cpy_r_r43 == NULL)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL24; + } + if (likely(PyLong_Check(cpy_r_r43))) + cpy_r_r44 = CPyTagged_FromObject(cpy_r_r43); + else { + CPy_TypeError("int", cpy_r_r43); cpy_r_r44 = CPY_INT_TAG; + } + CPy_DECREF(cpy_r_r43); + if (unlikely(cpy_r_r44 == CPY_INT_TAG)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL24; + } + cpy_r_r45 = CPyTagged_Subtract(cpy_r_r40, cpy_r_r44); + CPyTagged_DECREF(cpy_r_r40); + CPyTagged_DECREF(cpy_r_r44); + cpy_r_r46 = CPyTagged_Str(cpy_r_r45); + CPyTagged_DECREF(cpy_r_r45); + if (unlikely(cpy_r_r46 == NULL)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r47 = CPyStatics[13]; /* 'ns' */ + cpy_r_r48 = CPyStr_Build(3, cpy_r_r36, cpy_r_r46, cpy_r_r47); + CPy_DECREF(cpy_r_r46); + if (unlikely(cpy_r_r48 == NULL)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL22; + } + cpy_r_r49 = CPyModule_builtins; + cpy_r_r50 = CPyStatics[4]; /* 'print' */ + cpy_r_r51 = CPyObject_GetAttr(cpy_r_r49, cpy_r_r50); + if (unlikely(cpy_r_r51 == NULL)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL25; + } + PyObject *cpy_r_r52[1] = {cpy_r_r48}; + cpy_r_r53 = (PyObject **)&cpy_r_r52; + cpy_r_r54 = _PyObject_Vectorcall(cpy_r_r51, cpy_r_r53, 1, 0); + CPy_DECREF(cpy_r_r51); + if (unlikely(cpy_r_r54 == NULL)) { + CPy_AddTraceback("test.py", "", 18, CPyStatic_globals); + goto CPyL25; + } else + goto CPyL26; +CPyL21: ; + CPy_DECREF(cpy_r_r48); + return 1; +CPyL22: ; + cpy_r_r55 = 2; + return cpy_r_r55; +CPyL23: ; + CPy_DECREF(cpy_r_r25); + goto CPyL9; +CPyL24: ; + CPyTagged_DecRef(cpy_r_r40); + goto CPyL22; +CPyL25: ; + CPy_DecRef(cpy_r_r48); + goto CPyL22; +CPyL26: ; + CPy_DECREF(cpy_r_r54); + goto CPyL21; +} + +int CPyGlobalsInit(void) +{ + static int is_initialized = 0; + if (is_initialized) return 0; + + CPy_Init(); + CPyModule_test = Py_None; + CPyModule_builtins = Py_None; + CPyModule_time = Py_None; + if (CPyStatics_Initialize(CPyStatics, CPyLit_Str, CPyLit_Bytes, CPyLit_Int, CPyLit_Float, CPyLit_Complex, CPyLit_Tuple, CPyLit_FrozenSet) < 0) { + return -1; + } + is_initialized = 1; + return 0; +} + +PyObject *CPyStatics[25]; +const char * const CPyLit_Str[] = { + "\t\003zip\005print\bbuiltins\004time\atest.py\b\017perf_counter_ns\005start\003end", + "\002\006Time: \002ns", + "", +}; +const char * const CPyLit_Bytes[] = { + "", +}; +const char * const CPyLit_Int[] = { + "\t1\0002\0003\0004\0005\0006\0007\0008\0009", + "", +}; +const double CPyLit_Float[] = {0}; +const double CPyLit_Complex[] = {0}; +const int CPyLit_Tuple[] = {2, 3, 6, 6, 6, 1, 23}; +const int CPyLit_FrozenSet[] = {0}; +CPyModule *CPyModule_test_internal = NULL; +CPyModule *CPyModule_test; +PyObject *CPyStatic_globals; +CPyModule *CPyModule_builtins; +CPyModule *CPyModule_time; +PyTypeObject *CPyType_test_env; +PyObject *CPyDef_test_env(void); +PyTypeObject *CPyType_transpose_test_obj; +PyObject *CPyDef_transpose_test_obj(void); +PyTypeObject *CPyType_multiply_matrix_test_obj; +PyObject *CPyDef_multiply_matrix_test_obj(void); +PyObject *CPyDef_transpose_test_obj_____get__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_instance, PyObject *cpy_r_owner); +PyObject *CPyPy_transpose_test_obj_____get__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +PyObject *CPyDef_transpose_test_obj_____call__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_matrix); +PyObject *CPyPy_transpose_test_obj_____call__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +PyObject *CPyDef_multiply_matrix_test_obj_____get__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_instance, PyObject *cpy_r_owner); +PyObject *CPyPy_multiply_matrix_test_obj_____get__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +PyObject *CPyDef_multiply_matrix_test_obj_____call__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_matrix1, PyObject *cpy_r_matrix2); +PyObject *CPyPy_multiply_matrix_test_obj_____call__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +PyObject *CPyDef_test(void); +PyObject *CPyPy_test(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +char CPyDef___top_level__(void); diff --git a/build/__native.h b/build/__native.h new file mode 100644 index 0000000..4a533c0 --- /dev/null +++ b/build/__native.h @@ -0,0 +1,29 @@ +#ifndef MYPYC_NATIVE_H +#define MYPYC_NATIVE_H +#include +#include +typedef struct { + PyObject_HEAD + CPyVTableItem *vtable; + PyObject *___mypyc_self__; + PyObject *_transpose; + PyObject *_multiply_matrix; + PyObject *_mat1; + PyObject *_mat2; +} test___test_envObject; + +typedef struct { + PyObject_HEAD + CPyVTableItem *vtable; + vectorcallfunc vectorcall; + PyObject *___mypyc_env__; +} test___transpose_test_objObject; + +typedef struct { + PyObject_HEAD + CPyVTableItem *vtable; + vectorcallfunc vectorcall; + PyObject *___mypyc_env__; +} test___multiply_matrix_test_objObject; + +#endif diff --git a/build/__native_internal.h b/build/__native_internal.h new file mode 100644 index 0000000..091d68b --- /dev/null +++ b/build/__native_internal.h @@ -0,0 +1,39 @@ +#ifndef MYPYC_NATIVE_INTERNAL_H +#define MYPYC_NATIVE_INTERNAL_H +#include +#include +#include "__native.h" + +int CPyGlobalsInit(void); + +extern PyObject *CPyStatics[25]; +extern const char * const CPyLit_Str[]; +extern const char * const CPyLit_Bytes[]; +extern const char * const CPyLit_Int[]; +extern const double CPyLit_Float[]; +extern const double CPyLit_Complex[]; +extern const int CPyLit_Tuple[]; +extern const int CPyLit_FrozenSet[]; +extern CPyModule *CPyModule_test_internal; +extern CPyModule *CPyModule_test; +extern PyObject *CPyStatic_globals; +extern CPyModule *CPyModule_builtins; +extern CPyModule *CPyModule_time; +extern PyTypeObject *CPyType_test_env; +extern PyObject *CPyDef_test_env(void); +extern PyTypeObject *CPyType_transpose_test_obj; +extern PyObject *CPyDef_transpose_test_obj(void); +extern PyTypeObject *CPyType_multiply_matrix_test_obj; +extern PyObject *CPyDef_multiply_matrix_test_obj(void); +extern PyObject *CPyDef_transpose_test_obj_____get__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_instance, PyObject *cpy_r_owner); +extern PyObject *CPyPy_transpose_test_obj_____get__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +extern PyObject *CPyDef_transpose_test_obj_____call__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_matrix); +extern PyObject *CPyPy_transpose_test_obj_____call__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +extern PyObject *CPyDef_multiply_matrix_test_obj_____get__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_instance, PyObject *cpy_r_owner); +extern PyObject *CPyPy_multiply_matrix_test_obj_____get__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +extern PyObject *CPyDef_multiply_matrix_test_obj_____call__(PyObject *cpy_r___mypyc_self__, PyObject *cpy_r_matrix1, PyObject *cpy_r_matrix2); +extern PyObject *CPyPy_multiply_matrix_test_obj_____call__(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +extern PyObject *CPyDef_test(void); +extern PyObject *CPyPy_test(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames); +extern char CPyDef___top_level__(void); +#endif diff --git a/build/ops.txt b/build/ops.txt new file mode 100644 index 0000000..d4912c9 --- /dev/null +++ b/build/ops.txt @@ -0,0 +1,908 @@ +def transpose_test_obj.__get__(__mypyc_self__, instance, owner): + __mypyc_self__, instance, owner, r0 :: object + r1 :: bit + r2, r3 :: object +L0: + r0 = load_address _Py_NoneStruct + r1 = instance == r0 + if r1 goto L1 else goto L2 :: bool +L1: + inc_ref __mypyc_self__ + return __mypyc_self__ +L2: + r2 = PyMethod_New(__mypyc_self__, instance) + if is_error(r2) goto L4 else goto L3 +L3: + return r2 +L4: + r3 = :: object + return r3 + +def transpose_test_obj.__call__(__mypyc_self__, matrix): + __mypyc_self__ :: test.transpose_test_obj + matrix :: list + r0 :: test.test_env + r1 :: list + r2 :: object + r3 :: list + r4 :: ptr + r5 :: native_int + r6, r7 :: short_int + i :: int + r8 :: bit + r9 :: list + r10 :: ptr + r11 :: native_int + r12, r13 :: short_int + j :: int + r14 :: bit + r15 :: object + r16 :: list + r17 :: object + r18 :: int + r19 :: object + r20 :: i32 + r21 :: bit + r22 :: short_int + r23 :: i32 + r24 :: bit + r25 :: short_int + r26 :: list +L0: + r0 = __mypyc_self__.__mypyc_env__ + if is_error(r0) goto L18 (error at transpose:4) else goto L19 +L1: + r1 = PyList_New(0) + if is_error(r1) goto L18 (error at transpose:5) else goto L2 +L2: + r2 = CPyList_GetItemShortBorrow(matrix, 0) + if is_error(r2) goto L20 (error at transpose:5) else goto L3 +L3: + r3 = borrow cast(list, r2) + if is_error(r3) goto L20 (error at transpose:5) else goto L4 +L4: + r4 = get_element_ptr r3 ob_size :: PyVarObject + r5 = load_mem r4 :: native_int* + r6 = r5 << 1 + r7 = 0 + i = r7 +L5: + r8 = r7 < r6 :: signed + if r8 goto L6 else goto L21 :: bool +L6: + r9 = PyList_New(0) + if is_error(r9) goto L22 (error at transpose:5) else goto L7 +L7: + r10 = get_element_ptr matrix ob_size :: PyVarObject + r11 = load_mem r10 :: native_int* + r12 = r11 << 1 + r13 = 0 + j = r13 +L8: + r14 = r13 < r12 :: signed + if r14 goto L9 else goto L23 :: bool +L9: + r15 = CPyList_GetItemBorrow(matrix, j) + if is_error(r15) goto L24 (error at transpose:5) else goto L10 +L10: + r16 = borrow cast(list, r15) + if is_error(r16) goto L24 (error at transpose:5) else goto L11 +L11: + r17 = CPyList_GetItem(r16, i) + if is_error(r17) goto L24 (error at transpose:5) else goto L12 +L12: + r18 = unbox(int, r17) + dec_ref r17 + if is_error(r18) goto L24 (error at transpose:5) else goto L13 +L13: + dec_ref j :: int + r19 = box(int, r18) + r20 = PyList_Append(r9, r19) + dec_ref r19 + r21 = r20 >= 0 :: signed + if not r21 goto L25 (error at transpose:5) else goto L14 :: bool +L14: + r22 = r13 + 2 + r13 = r22 + j = r22 + goto L8 +L15: + r23 = PyList_Append(r1, r9) + dec_ref r9 + r24 = r23 >= 0 :: signed + if not r24 goto L20 (error at transpose:5) else goto L16 :: bool +L16: + r25 = r7 + 2 + r7 = r25 + i = r25 + goto L5 +L17: + return r1 +L18: + r26 = :: list + return r26 +L19: + dec_ref r0 + goto L1 +L20: + dec_ref r1 + goto L18 +L21: + dec_ref i :: int + goto L17 +L22: + dec_ref r1 + dec_ref i :: int + goto L18 +L23: + dec_ref i :: int + dec_ref j :: int + goto L15 +L24: + dec_ref r1 + dec_ref i :: int + dec_ref r9 + dec_ref j :: int + goto L18 +L25: + dec_ref r1 + dec_ref i :: int + dec_ref r9 + goto L18 + +def multiply_matrix_test_obj.__get__(__mypyc_self__, instance, owner): + __mypyc_self__, instance, owner, r0 :: object + r1 :: bit + r2, r3 :: object +L0: + r0 = load_address _Py_NoneStruct + r1 = instance == r0 + if r1 goto L1 else goto L2 :: bool +L1: + inc_ref __mypyc_self__ + return __mypyc_self__ +L2: + r2 = PyMethod_New(__mypyc_self__, instance) + if is_error(r2) goto L4 else goto L3 +L3: + return r2 +L4: + r3 = :: object + return r3 + +def multiply_matrix_test_obj.__call__(__mypyc_self__, matrix1, matrix2): + __mypyc_self__ :: test.multiply_matrix_test_obj + matrix1, matrix2 :: list + r0 :: test.test_env + r1 :: ptr + r2 :: native_int + r3 :: list + r4 :: short_int + r5 :: ptr + r6 :: native_int + r7 :: short_int + r8 :: bit + r9 :: object + r10, X_row, r11 :: list + r12 :: object + r13 :: str + r14 :: object + r15 :: list + r16 :: object + r17 :: tuple + r18 :: dict + r19, r20, r21 :: object + r22, Y_col :: tuple + r23 :: int + r24, r25 :: short_int + r26 :: ptr + r27 :: native_int + r28 :: short_int + r29 :: bit + r30 :: ptr + r31 :: native_int + r32 :: short_int + r33 :: bit + r34 :: object + r35, a :: int + r36, b, r37, r38, r39, r40 :: object + r41 :: int + r42, r43 :: short_int + r44 :: object + r45 :: i32 + r46, r47, r48 :: bit + r49 :: short_int + r50 :: list +L0: + r0 = __mypyc_self__.__mypyc_env__ + if is_error(r0) goto L30 (error at multiply_matrix:9) else goto L31 +L1: + r1 = get_element_ptr matrix1 ob_size :: PyVarObject + r2 = load_mem r1 :: native_int* + r3 = PyList_New(r2) + if is_error(r3) goto L30 (error at multiply_matrix:10) else goto L2 +L2: + r4 = 0 +L3: + r5 = get_element_ptr matrix1 ob_size :: PyVarObject + r6 = load_mem r5 :: native_int* + r7 = r6 << 1 + r8 = r4 < r7 :: signed + if r8 goto L4 else goto L29 :: bool +L4: + r9 = CPyList_GetItemUnsafe(matrix1, r4) + r10 = cast(list, r9) + if is_error(r10) goto L32 (error at multiply_matrix:10) else goto L5 +L5: + X_row = r10 + r11 = PyList_New(0) + if is_error(r11) goto L33 (error at multiply_matrix:10) else goto L6 +L6: + r12 = builtins :: module + r13 = 'zip' + r14 = CPyObject_GetAttr(r12, r13) + if is_error(r14) goto L34 (error at multiply_matrix:10) else goto L7 +L7: + r15 = PyList_New(0) + if is_error(r15) goto L35 (error at multiply_matrix:10) else goto L8 +L8: + r16 = CPyList_Extend(r15, matrix2) + if is_error(r16) goto L36 (error at multiply_matrix:10) else goto L37 +L9: + r17 = PyList_AsTuple(r15) + dec_ref r15 + if is_error(r17) goto L35 (error at multiply_matrix:10) else goto L10 +L10: + r18 = PyDict_New() + if is_error(r18) goto L38 (error at multiply_matrix:10) else goto L11 +L11: + r19 = PyObject_Call(r14, r17, r18) + dec_ref r14 + dec_ref r17 + dec_ref r18 + if is_error(r19) goto L34 (error at multiply_matrix:10) else goto L12 +L12: + r20 = PyObject_GetIter(r19) + dec_ref r19 + if is_error(r20) goto L34 (error at multiply_matrix:10) else goto L13 +L13: + r21 = PyIter_Next(r20) + if is_error(r21) goto L39 else goto L14 +L14: + r22 = cast(tuple, r21) + if is_error(r22) goto L40 (error at multiply_matrix:10) else goto L15 +L15: + Y_col = r22 + r23 = 0 + r24 = 0 + r25 = 0 +L16: + r26 = get_element_ptr X_row ob_size :: PyVarObject + r27 = load_mem r26 :: native_int* + r28 = r27 << 1 + r29 = r24 < r28 :: signed + if r29 goto L17 else goto L41 :: bool +L17: + r30 = get_element_ptr Y_col ob_size :: PyVarObject + r31 = load_mem r30 :: native_int* + r32 = r31 << 1 + r33 = r25 < r32 :: signed + if r33 goto L18 else goto L41 :: bool +L18: + r34 = CPyList_GetItemUnsafe(X_row, r24) + r35 = unbox(int, r34) + dec_ref r34 + if is_error(r35) goto L42 (error at multiply_matrix:10) else goto L19 +L19: + a = r35 + r36 = CPySequenceTuple_GetItem(Y_col, r25) + if is_error(r36) goto L43 (error at multiply_matrix:10) else goto L20 +L20: + b = r36 + r37 = box(int, a) + r38 = PyNumber_Multiply(r37, b) + dec_ref r37 + dec_ref b + if is_error(r38) goto L42 (error at multiply_matrix:10) else goto L21 +L21: + r39 = box(int, r23) + r40 = PyNumber_Add(r39, r38) + dec_ref r39 + dec_ref r38 + if is_error(r40) goto L44 (error at multiply_matrix:-1) else goto L22 +L22: + r41 = unbox(int, r40) + dec_ref r40 + if is_error(r41) goto L44 (error at multiply_matrix:-1) else goto L23 +L23: + r23 = r41 +L24: + r42 = r24 + 2 + r24 = r42 + r43 = r25 + 2 + r25 = r43 + goto L16 +L25: + r44 = box(int, r23) + r45 = PyList_Append(r11, r44) + dec_ref r44 + r46 = r45 >= 0 :: signed + if not r46 goto L40 (error at multiply_matrix:10) else goto L13 :: bool +L26: + r47 = CPy_NoErrOccured() + if not r47 goto L45 (error at multiply_matrix:10) else goto L27 :: bool +L27: + r48 = CPyList_SetItemUnsafe(r3, r4, r11) + if not r48 goto L32 (error at multiply_matrix:10) else goto L28 :: bool +L28: + r49 = r4 + 2 + r4 = r49 + goto L3 +L29: + return r3 +L30: + r50 = :: list + return r50 +L31: + dec_ref r0 + goto L1 +L32: + dec_ref r3 + goto L30 +L33: + dec_ref r3 + dec_ref X_row + goto L30 +L34: + dec_ref r3 + dec_ref X_row + dec_ref r11 + goto L30 +L35: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r14 + goto L30 +L36: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r14 + dec_ref r15 + goto L30 +L37: + dec_ref r16 + goto L9 +L38: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r14 + dec_ref r17 + goto L30 +L39: + dec_ref X_row + dec_ref r20 + goto L26 +L40: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r20 + goto L30 +L41: + dec_ref Y_col + goto L25 +L42: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r20 + dec_ref Y_col + dec_ref r23 :: int + goto L30 +L43: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r20 + dec_ref Y_col + dec_ref r23 :: int + dec_ref a :: int + goto L30 +L44: + dec_ref r3 + dec_ref X_row + dec_ref r11 + dec_ref r20 + dec_ref Y_col + goto L30 +L45: + dec_ref r3 + dec_ref r11 + goto L30 + +def test(): + r0 :: test.test_env + r1 :: list + r2, r3, r4 :: object + r5, r6, r7, r8 :: ptr + r9 :: list + r10, r11, r12 :: object + r13, r14, r15, r16 :: ptr + r17 :: list + r18, r19, r20 :: object + r21, r22, r23, r24 :: ptr + r25 :: list + r26, r27, r28, r29 :: ptr + mat1 :: object + r30 :: list + r31, r32, r33 :: object + r34, r35, r36, r37 :: ptr + r38 :: list + r39, r40, r41 :: object + r42, r43, r44, r45 :: ptr + r46 :: list + r47, r48, r49 :: object + r50, r51, r52, r53 :: ptr + r54 :: list + r55, r56, r57, r58 :: ptr + mat2 :: object + r59 :: test.transpose_test_obj + r60 :: bool + transpose :: object + r61 :: object[1] + r62 :: object_ptr + r63, r64 :: object + r65 :: str + r66 :: object + r67 :: object[1] + r68 :: object_ptr + r69 :: object + r70 :: test.multiply_matrix_test_obj + r71 :: bool + multiply_matrix :: object + r72 :: object[2] + r73 :: object_ptr + r74, r75 :: object + r76 :: str + r77 :: object + r78 :: object[1] + r79 :: object_ptr + r80, r81, r82 :: object +L0: + r0 = test_env() + if is_error(r0) goto L20 (error at test:1) else goto L1 +L1: + r1 = PyList_New(3) + if is_error(r1) goto L21 (error at test:2) else goto L2 +L2: + r2 = object 1 + r3 = object 2 + r4 = object 3 + r5 = get_element_ptr r1 ob_item :: PyListObject + r6 = load_mem r5 :: ptr* + inc_ref r2 + set_mem r6, r2 :: builtins.object* + r7 = r6 + 8 + inc_ref r3 + set_mem r7, r3 :: builtins.object* + r8 = r6 + 16 + inc_ref r4 + set_mem r8, r4 :: builtins.object* + r9 = PyList_New(3) + if is_error(r9) goto L22 (error at test:2) else goto L3 +L3: + r10 = object 4 + r11 = object 5 + r12 = object 6 + r13 = get_element_ptr r9 ob_item :: PyListObject + r14 = load_mem r13 :: ptr* + inc_ref r10 + set_mem r14, r10 :: builtins.object* + r15 = r14 + 8 + inc_ref r11 + set_mem r15, r11 :: builtins.object* + r16 = r14 + 16 + inc_ref r12 + set_mem r16, r12 :: builtins.object* + r17 = PyList_New(3) + if is_error(r17) goto L23 (error at test:2) else goto L4 +L4: + r18 = object 7 + r19 = object 8 + r20 = object 9 + r21 = get_element_ptr r17 ob_item :: PyListObject + r22 = load_mem r21 :: ptr* + inc_ref r18 + set_mem r22, r18 :: builtins.object* + r23 = r22 + 8 + inc_ref r19 + set_mem r23, r19 :: builtins.object* + r24 = r22 + 16 + inc_ref r20 + set_mem r24, r20 :: builtins.object* + r25 = PyList_New(3) + if is_error(r25) goto L24 (error at test:2) else goto L5 +L5: + r26 = get_element_ptr r25 ob_item :: PyListObject + r27 = load_mem r26 :: ptr* + set_mem r27, r1 :: builtins.object* + r28 = r27 + 8 + set_mem r28, r9 :: builtins.object* + r29 = r27 + 16 + set_mem r29, r17 :: builtins.object* + mat1 = r25 + r30 = PyList_New(3) + if is_error(r30) goto L25 (error at test:3) else goto L6 +L6: + r31 = object 1 + r32 = object 2 + r33 = object 3 + r34 = get_element_ptr r30 ob_item :: PyListObject + r35 = load_mem r34 :: ptr* + inc_ref r31 + set_mem r35, r31 :: builtins.object* + r36 = r35 + 8 + inc_ref r32 + set_mem r36, r32 :: builtins.object* + r37 = r35 + 16 + inc_ref r33 + set_mem r37, r33 :: builtins.object* + r38 = PyList_New(3) + if is_error(r38) goto L26 (error at test:3) else goto L7 +L7: + r39 = object 4 + r40 = object 5 + r41 = object 6 + r42 = get_element_ptr r38 ob_item :: PyListObject + r43 = load_mem r42 :: ptr* + inc_ref r39 + set_mem r43, r39 :: builtins.object* + r44 = r43 + 8 + inc_ref r40 + set_mem r44, r40 :: builtins.object* + r45 = r43 + 16 + inc_ref r41 + set_mem r45, r41 :: builtins.object* + r46 = PyList_New(3) + if is_error(r46) goto L27 (error at test:3) else goto L8 +L8: + r47 = object 7 + r48 = object 8 + r49 = object 9 + r50 = get_element_ptr r46 ob_item :: PyListObject + r51 = load_mem r50 :: ptr* + inc_ref r47 + set_mem r51, r47 :: builtins.object* + r52 = r51 + 8 + inc_ref r48 + set_mem r52, r48 :: builtins.object* + r53 = r51 + 16 + inc_ref r49 + set_mem r53, r49 :: builtins.object* + r54 = PyList_New(3) + if is_error(r54) goto L28 (error at test:3) else goto L9 +L9: + r55 = get_element_ptr r54 ob_item :: PyListObject + r56 = load_mem r55 :: ptr* + set_mem r56, r30 :: builtins.object* + r57 = r56 + 8 + set_mem r57, r38 :: builtins.object* + r58 = r56 + 16 + set_mem r58, r46 :: builtins.object* + mat2 = r54 + r59 = transpose_test_obj() + if is_error(r59) goto L29 (error at test:4) else goto L10 +L10: + inc_ref r0 + r59.__mypyc_env__ = r0; r60 = is_error + if not r60 goto L30 (error at test:4) else goto L11 :: bool +L11: + transpose = r59 + r61 = [mat1] + r62 = load_address r61 + r63 = _PyObject_Vectorcall(transpose, r62, 1, 0) + dec_ref transpose + if is_error(r63) goto L29 (error at test:7) else goto L12 +L12: + r64 = builtins :: module + r65 = 'print' + r66 = CPyObject_GetAttr(r64, r65) + if is_error(r66) goto L31 (error at test:7) else goto L13 +L13: + r67 = [r63] + r68 = load_address r67 + r69 = _PyObject_Vectorcall(r66, r68, 1, 0) + dec_ref r66 + if is_error(r69) goto L31 (error at test:7) else goto L32 +L14: + dec_ref r63 + r70 = multiply_matrix_test_obj() + if is_error(r70) goto L29 (error at test:9) else goto L15 +L15: + r70.__mypyc_env__ = r0; r71 = is_error + if not r71 goto L33 (error at test:9) else goto L16 :: bool +L16: + multiply_matrix = r70 + r72 = [mat1, mat2] + r73 = load_address r72 + r74 = _PyObject_Vectorcall(multiply_matrix, r73, 2, 0) + dec_ref multiply_matrix + if is_error(r74) goto L34 (error at test:12) else goto L17 +L17: + dec_ref mat1 + dec_ref mat2 + r75 = builtins :: module + r76 = 'print' + r77 = CPyObject_GetAttr(r75, r76) + if is_error(r77) goto L35 (error at test:12) else goto L18 +L18: + r78 = [r74] + r79 = load_address r78 + r80 = _PyObject_Vectorcall(r77, r79, 1, 0) + dec_ref r77 + if is_error(r80) goto L35 (error at test:12) else goto L36 +L19: + dec_ref r74 + r81 = box(None, 1) + inc_ref r81 + return r81 +L20: + r82 = :: object + return r82 +L21: + dec_ref r0 + goto L20 +L22: + dec_ref r0 + dec_ref r1 + goto L20 +L23: + dec_ref r0 + dec_ref r1 + dec_ref r9 + goto L20 +L24: + dec_ref r0 + dec_ref r1 + dec_ref r9 + dec_ref r17 + goto L20 +L25: + dec_ref r0 + dec_ref mat1 + goto L20 +L26: + dec_ref r0 + dec_ref mat1 + dec_ref r30 + goto L20 +L27: + dec_ref r0 + dec_ref mat1 + dec_ref r30 + dec_ref r38 + goto L20 +L28: + dec_ref r0 + dec_ref mat1 + dec_ref r30 + dec_ref r38 + dec_ref r46 + goto L20 +L29: + dec_ref r0 + dec_ref mat1 + dec_ref mat2 + goto L20 +L30: + dec_ref r0 + dec_ref mat1 + dec_ref mat2 + dec_ref r59 + goto L20 +L31: + dec_ref r0 + dec_ref mat1 + dec_ref mat2 + dec_ref r63 + goto L20 +L32: + dec_ref r69 + goto L14 +L33: + dec_ref mat1 + dec_ref mat2 + dec_ref r70 + goto L20 +L34: + dec_ref mat1 + dec_ref mat2 + goto L20 +L35: + dec_ref r74 + goto L20 +L36: + dec_ref r80 + goto L19 + +def __top_level__(): + r0, r1 :: object + r2 :: bit + r3 :: str + r4 :: object + r5 :: object_ptr + r6 :: object_ptr[1] + r7 :: c_ptr + r8 :: native_int[1] + r9 :: c_ptr + r10 :: object + r11 :: dict + r12, r13 :: str + r14 :: bit + r15 :: object + r16 :: str + r17, r18 :: object + r19 :: int + r20 :: dict + r21 :: str + r22 :: object + r23 :: i32 + r24 :: bit + r25, r26 :: object + r27 :: str + r28, r29 :: object + r30 :: int + r31 :: dict + r32 :: str + r33 :: object + r34 :: i32 + r35 :: bit + r36 :: str + r37 :: dict + r38 :: str + r39 :: object + r40 :: int + r41 :: dict + r42 :: str + r43 :: object + r44, r45 :: int + r46, r47, r48 :: str + r49 :: object + r50 :: str + r51 :: object + r52 :: object[1] + r53 :: object_ptr + r54 :: object + r55 :: None +L0: + r0 = builtins :: module + r1 = load_address _Py_NoneStruct + r2 = r0 != r1 + if r2 goto L3 else goto L1 :: bool +L1: + r3 = 'builtins' + r4 = PyImport_Import(r3) + if is_error(r4) goto L22 (error at :-1) else goto L2 +L2: + builtins = r4 :: module + dec_ref r4 +L3: + r5 = load_address time :: module + r6 = [r5] + r7 = load_address r6 + r8 = [14] + r9 = load_address r8 + r10 = (('time', 'time', 'time'),) + r11 = test.globals :: static + r12 = 'test.py' + r13 = '' + r14 = CPyImport_ImportMany(r10, r7, r11, r12, r13, r9) + if not r14 goto L22 else goto L4 :: bool +L4: + r15 = time :: module + r16 = 'perf_counter_ns' + r17 = CPyObject_GetAttr(r15, r16) + if is_error(r17) goto L22 (error at :15) else goto L5 +L5: + r18 = _PyObject_Vectorcall(r17, 0, 0, 0) + dec_ref r17 + if is_error(r18) goto L22 (error at :15) else goto L6 +L6: + r19 = unbox(int, r18) + dec_ref r18 + if is_error(r19) goto L22 (error at :15) else goto L7 +L7: + r20 = test.globals :: static + r21 = 'start' + r22 = box(int, r19) + r23 = CPyDict_SetItem(r20, r21, r22) + dec_ref r22 + r24 = r23 >= 0 :: signed + if not r24 goto L22 (error at :15) else goto L8 :: bool +L8: + r25 = test() + if is_error(r25) goto L22 (error at :16) else goto L23 +L9: + r26 = time :: module + r27 = 'perf_counter_ns' + r28 = CPyObject_GetAttr(r26, r27) + if is_error(r28) goto L22 (error at :17) else goto L10 +L10: + r29 = _PyObject_Vectorcall(r28, 0, 0, 0) + dec_ref r28 + if is_error(r29) goto L22 (error at :17) else goto L11 +L11: + r30 = unbox(int, r29) + dec_ref r29 + if is_error(r30) goto L22 (error at :17) else goto L12 +L12: + r31 = test.globals :: static + r32 = 'end' + r33 = box(int, r30) + r34 = CPyDict_SetItem(r31, r32, r33) + dec_ref r33 + r35 = r34 >= 0 :: signed + if not r35 goto L22 (error at :17) else goto L13 :: bool +L13: + r36 = 'Time: ' + r37 = test.globals :: static + r38 = 'end' + r39 = CPyDict_GetItem(r37, r38) + if is_error(r39) goto L22 (error at :18) else goto L14 +L14: + r40 = unbox(int, r39) + dec_ref r39 + if is_error(r40) goto L22 (error at :18) else goto L15 +L15: + r41 = test.globals :: static + r42 = 'start' + r43 = CPyDict_GetItem(r41, r42) + if is_error(r43) goto L24 (error at :18) else goto L16 +L16: + r44 = unbox(int, r43) + dec_ref r43 + if is_error(r44) goto L24 (error at :18) else goto L17 +L17: + r45 = CPyTagged_Subtract(r40, r44) + dec_ref r40 :: int + dec_ref r44 :: int + r46 = CPyTagged_Str(r45) + dec_ref r45 :: int + if is_error(r46) goto L22 (error at :18) else goto L18 +L18: + r47 = 'ns' + r48 = CPyStr_Build(3, r36, r46, r47) + dec_ref r46 + if is_error(r48) goto L22 (error at :18) else goto L19 +L19: + r49 = builtins :: module + r50 = 'print' + r51 = CPyObject_GetAttr(r49, r50) + if is_error(r51) goto L25 (error at :18) else goto L20 +L20: + r52 = [r48] + r53 = load_address r52 + r54 = _PyObject_Vectorcall(r51, r53, 1, 0) + dec_ref r51 + if is_error(r54) goto L25 (error at :18) else goto L26 +L21: + dec_ref r48 + return 1 +L22: + r55 = :: None + return r55 +L23: + dec_ref r25 + goto L9 +L24: + dec_ref r40 :: int + goto L22 +L25: + dec_ref r48 + goto L22 +L26: + dec_ref r54 + goto L21 diff --git a/build/setup.py b/build/setup.py index e7b69dc..b99e71a 100644 --- a/build/setup.py +++ b/build/setup.py @@ -2,5 +2,5 @@ from mypyc.build import mypycify setup(name='mypyc_output', - ext_modules=mypycify(['helix.py'], opt_level="3", debug_level="1"), + ext_modules=mypycify(['test.py'], opt_level="3", debug_level="1"), ) diff --git a/build/temp.win-amd64-cpython-311/Release/build/__native.obj b/build/temp.win-amd64-cpython-311/Release/build/__native.obj new file mode 100644 index 0000000..f7dc805 Binary files /dev/null and b/build/temp.win-amd64-cpython-311/Release/build/__native.obj differ diff --git a/build/temp.win-amd64-cpython-311/Release/build/test.cp311-win_amd64.exp b/build/temp.win-amd64-cpython-311/Release/build/test.cp311-win_amd64.exp new file mode 100644 index 0000000..93db03c Binary files /dev/null and b/build/temp.win-amd64-cpython-311/Release/build/test.cp311-win_amd64.exp differ diff --git a/build/temp.win-amd64-cpython-311/Release/build/test.cp311-win_amd64.lib b/build/temp.win-amd64-cpython-311/Release/build/test.cp311-win_amd64.lib new file mode 100644 index 0000000..b49772d Binary files /dev/null and b/build/temp.win-amd64-cpython-311/Release/build/test.cp311-win_amd64.lib differ diff --git a/core/__pycache__/better_print.cpython-312.pyc b/core/__pycache__/better_print.cpython-312.pyc deleted file mode 100644 index 46889f9..0000000 Binary files a/core/__pycache__/better_print.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/cache_store.cpython-312.pyc b/core/__pycache__/cache_store.cpython-312.pyc deleted file mode 100644 index 6b8b32e..0000000 Binary files a/core/__pycache__/cache_store.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/compile_bar.cpython-312.pyc b/core/__pycache__/compile_bar.cpython-312.pyc deleted file mode 100644 index 8c91697..0000000 Binary files a/core/__pycache__/compile_bar.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/config.cpython-312.pyc b/core/__pycache__/config.cpython-312.pyc deleted file mode 100644 index 097b953..0000000 Binary files a/core/__pycache__/config.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/panic.cpython-312.pyc b/core/__pycache__/panic.cpython-312.pyc deleted file mode 100644 index c7e91ce..0000000 Binary files a/core/__pycache__/panic.cpython-312.pyc and /dev/null differ diff --git a/core/token/__pycache__/normalize_tokens.cpython-312.pyc b/core/token/__pycache__/normalize_tokens.cpython-312.pyc deleted file mode 100644 index 5e01e2e..0000000 Binary files a/core/token/__pycache__/normalize_tokens.cpython-312.pyc and /dev/null differ diff --git a/core/token/__pycache__/remove_comments.cpython-312.pyc b/core/token/__pycache__/remove_comments.cpython-312.pyc deleted file mode 100644 index 24af520..0000000 Binary files a/core/token/__pycache__/remove_comments.cpython-312.pyc and /dev/null differ diff --git a/core/token/__pycache__/tokenize_file.cpython-312.pyc b/core/token/__pycache__/tokenize_file.cpython-312.pyc deleted file mode 100644 index 16ea2ea..0000000 Binary files a/core/token/__pycache__/tokenize_file.cpython-312.pyc and /dev/null differ diff --git a/core/token/__pycache__/tokenize_line.cpython-312.pyc b/core/token/__pycache__/tokenize_line.cpython-312.pyc deleted file mode 100644 index 874d177..0000000 Binary files a/core/token/__pycache__/tokenize_line.cpython-312.pyc and /dev/null differ diff --git a/docs/doc.py b/docs/doc.py index cbe46b6..1060980 100644 --- a/docs/doc.py +++ b/docs/doc.py @@ -1,7 +1,7 @@ -from rich.markdown import Markdown -from rich.console import Console -from rich.style import Style -from globals import HelixSyntaxHighlightingLexer, lexer, highlight_code, formatter +from rich.markdown import Markdown +from rich.console import Console +from rich.style import Style +import src.core.base as base console = Console() @@ -38,7 +38,7 @@ def doc(doc_id: str): from rich.syntax import Syntax - md = Panel(Markdown(md_file, inline_code_lexer=lexer, style=special_style, inline_code_theme="ansi_dark", code_theme="ansi_dark"), title=doc_id, border_style="yellow") + md = Panel(Markdown(md_file, inline_code_lexer=base.lexer, style=special_style, inline_code_theme="ansi_dark", code_theme="ansi_dark"), title=doc_id, border_style="yellow") # terminal width should always be greater then 40 but if it is then minus the width by 50 if terminal_width > 70: console.print(md, width=100) diff --git a/functions/__pycache__/_async_pre.cpython-312.pyc b/functions/__pycache__/_async_pre.cpython-312.pyc deleted file mode 100644 index b0def47..0000000 Binary files a/functions/__pycache__/_async_pre.cpython-312.pyc and /dev/null differ diff --git a/functions/__pycache__/_functions.cpython-312.pyc b/functions/__pycache__/_functions.cpython-312.pyc deleted file mode 100644 index 7aa420c..0000000 Binary files a/functions/__pycache__/_functions.cpython-312.pyc and /dev/null differ diff --git a/functions/__pycache__/_include.cpython-312.pyc b/functions/__pycache__/_include.cpython-312.pyc deleted file mode 100644 index ab5402b..0000000 Binary files a/functions/__pycache__/_include.cpython-312.pyc and /dev/null differ diff --git a/functions/_match.py b/functions/_match.py deleted file mode 100644 index 515ddf1..0000000 --- a/functions/_match.py +++ /dev/null @@ -1,13 +0,0 @@ -from classes.Token import Processed_Line, Token, Token_List -from core.config import load_config - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic -from functions._class import _class - - -def _match(ast_list: Token_List, current_scope, parent_scope, root_scope, modifiers=None) -> Processed_Line: - print(ast_list) - return Processed_Line("yessir", ast_list) \ No newline at end of file diff --git a/helix.py b/helix.py index e9436f1..1a9f8b5 100644 --- a/helix.py +++ b/helix.py @@ -1,40 +1,44 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import annotations -from datetime import datetime -import gc +#import tracemalloc +#import atexit + +#tracemalloc.start() +#atexit.register(tracemalloc.stop) -gc.disable() - -import os -import signal -import sys -import shutil -import hashlib -import threading -import subprocess -import functools -from sys import exit -from threading import Event -from io import TextIOWrapper -from types import FrameType, ModuleType -from typing import Any, Callable, Iterable, Optional, Tuple -from argparse import Namespace, ArgumentParser -from time import perf_counter_ns as time - -from black import FileMode, format_file_contents - -# from black.parsing import InvalidInput -from classes.Token import Processed_Line, Token_List - -from globals import POOL, EARLY_REPLACEMENTS -from core.better_print import color_print as print -from core.token.tokenize_file import Tokenizer -from core.config import load_config -from core.panic import panic -from classes.Scope import Scope -from classes.Transpiler import Transpiler +import gc +import atexit +gc.disable() # disable garbage collection for performance + +import src.core.base as base +from src.core.imports import ( + os, + signal, + sys, + shutil, + hashlib, + threading, + subprocess, + functools, + datetime, + exit, + Event, + Any, Callable, Iterable, Optional, Tuple, FrameType, ModuleType, + Namespace, ArgumentParser, + perf_counter_ns as time, + TextIOWrapper, + Processed_Line, Token_List, + Tokenizer, + load_config, + panic, + Scope, + Transpiler, + FileMode, format_file_contents, + color_print as print, + framework, +) __version__: str = "0.1.0-alpha.a" USE_CACHE: bool = False @@ -222,6 +226,36 @@ def watch_processes() -> None: del ThreadedProcess.__processes_queue__[pid] +def clean_docstring(docstring: str) -> str: + """ + Cleans up the given docstring by removing unnecessary whitespace and newlines. + + Parameters + ---------- + docstring : str + The docstring to be cleaned. + + Returns + ------- + str + The cleaned docstring. + """ + if not docstring: + return "" + + indentation_level: int = 0 + for char in docstring.splitlines()[1]: + if not char.isspace(): + break + indentation_level += 1 + + return "\n".join( + [ + line[indentation_level:] + for line in docstring.splitlines() + ] + ) + class ThreadedProcess: """ Manages threaded execution of processes. @@ -305,16 +339,6 @@ def __str__(self) -> str: def __repr__(self) -> str: return self.__str__() - -# @ThreadedProcess -# def test() -> None: -# for i in range(10): -# print(i) -# sleep(1/3) - -# test() - - class ArgParser: """ Parses command-line arguments for the Helix language application. @@ -336,8 +360,8 @@ class ArgParser: Returns the namespace of parsed command-line arguments. """ def help_screen(self): - print( - """usage: helix [-h] [-v] [-o COMPILE] [-d] [-l LOG] [-c CONFIG] [-s] file ... + print(clean_docstring(""" + usage: helix [-h] [-v] [-o COMPILE] [-d] [-l LOG] [-c CONFIG] [-s] file ... Welcome to the Helix CLI, the gateway to harnessing the power and simplicity of Helix, a programming language designed for developers who cherish Python's ease but crave more @@ -361,7 +385,7 @@ def help_screen(self): -i, --install PACKAGE_NAME install new packages -u, --uninstall PACKAGE_NAME uninstall packages -doc DOC the name of the documentation page to be displayed - """, + """), word_wrap=False, end="", ) @@ -741,7 +765,7 @@ def __exit__( self.old_handler(*self.signal_received) # type: ignore -class Helix: +class Helix(framework.HelixLanguage): """ Main class for the Helix programming language interpreter and compiler. @@ -917,6 +941,25 @@ def run(self) -> None: ) self.timer.start("run") + #_locals = {} + #_globals = {} + #try: + # exec( + # compile( + # open(self.__out_file__).read(), + # self.__out_file__, + # "exec", + # ), + # _globals, + # _locals, + # ) + #except Exception as e: + # panic( + # "THIS NEEDS TO BE CHANGED TO A CUSTOM EXCEPTION", + # file=self.__out_file__, + # line_no=1, + # no_lines=True, + # ) try: subprocess.Popen( [sys.executable, self.__out_file__] @@ -959,6 +1002,11 @@ def cleanup(self) -> None: style="bold", border=True, ) + + gc.collect(0) + gc.collect(1) + gc.collect(2) + def compile_file( self, file: Optional[str] = None @@ -1237,7 +1285,7 @@ def exception_handler(exception_type: type[BaseException] | threading.ExceptHook current_exception = exception relevant_frames = [] - early_replacements = dict((v, k) for k, v in {EARLY_REPLACEMENTS}.items()) + early_replacements = dict((v, k) for k, v in {base.EARLY_REPLACEMENTS}.items()) # First loop: filter out irrelevant frames index = 0 @@ -1481,21 +1529,31 @@ def __hook_import__( return helix_import - -if __name__ == "__main__": - try: - Helix.factory( - os.path.join(".helix", "config.toml"), - profile=True, - ) - Helix.__hook_import__("syntax/test.hlx") - # from test_hlx import subtract - # subtract(5, 3) - # Helix.REPL() - finally: - if POOL.is_alive: - POOL.close() - + def __del__(self) -> None: gc.collect(0) gc.collect(1) gc.collect(2) + +def exit_func(*args: Any) -> None: + if base.POOL.is_alive: + base.POOL.close() + + #print("Memory Usage: ", tracemalloc.get_traced_memory()[1] / 10**6, "MB") + + gc.collect(0) + gc.collect(1) + gc.collect(2) + +atexit.register(exit_func) +signal.signal(signal.SIGTERM, exit_func) + +if __name__ == "__main__": + Helix.factory( + os.path.join(".helix", "config.toml"), + profile=True, + ) + #Helix.__hook_import__("syntax/test.hlx") + # from test_hlx import subtract + # subtract(5, 3) + # Helix.REPL() + \ No newline at end of file diff --git a/init b/init index 079178c..608435f 100644 --- a/init +++ b/init @@ -5,20 +5,27 @@ command_exists () { type "$1" &> /dev/null ; } -# Clone the repository -git clone https://github.com/kneorain/helix -cd helix/helix-lang +# make sure python version is 3.12 or higher # Python execution logic -if command_exists python3 ; then - PYTHON_CMD=python3 -elif command_exists python ; then +if command_exists python ; then PYTHON_CMD=python +elif command_exists python3 ; then + PYTHON_CMD=python3 else echo "Python is not installed or not found in PATH" exit 1 fi +echo "Using Python command: $PYTHON_CMD" + +version = $("$PYTHON_CMD --version") + +if [[ "$version" < "3.12" ]]; then + echo "Python version is too low. Please install Python 3.12 or higher." + exit 1 +fi + # Creating a virtual environment $PYTHON_CMD -m venv .venv diff --git a/out/helix.pyi b/out/helix.pyi index 7ec5e95..8ff1571 100644 --- a/out/helix.pyi +++ b/out/helix.pyi @@ -1,10 +1,5 @@ -import threading from _typeshed import Incomplete -from argparse import Namespace -from classes.Scope import Scope -from classes.Token import Processed_Line as Processed_Line, Token_List as Token_List -from types import ModuleType -from typing import Any, Callable, Iterable, Optional +from src.core.imports import Any as Any, Callable as Callable, FrameType as FrameType, Iterable as Iterable, ModuleType as ModuleType, Namespace, Optional as Optional, Processed_Line as Processed_Line, Scope, TextIOWrapper as TextIOWrapper, Token_List as Token_List, Tuple as Tuple, threading __version__: str USE_CACHE: bool @@ -23,6 +18,7 @@ class Hashing: def get_hash(self) -> bytes | None: ... def watch_processes() -> None: ... +def clean_docstring(docstring: str) -> str: ... class ThreadedProcess: __processes_queue__: dict[int, threading.Thread] @@ -53,6 +49,8 @@ class HelixLanguage: def generate_folder_structure(directory: str = ...): ... @staticmethod def install_helix(config: dict) -> None: ... + @staticmethod + def remove_blank_lines(file: str, hash: Hashing | None) -> None: ... class Timer: def __init__(self) -> None: ... @@ -73,10 +71,6 @@ class Helix: @classmethod def interpreter(cls, code: str, globals_: dict, locals_: dict) -> str: ... def build_path(self) -> str: ... - def remove_blank_lines(self, file: str, hash: Hashing | None) -> None: ... - def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None) -> None: ... - def __del__(self) -> None: ... - def __delattr__(self, name) -> None: ... profile: Incomplete import_: Incomplete timer: Incomplete diff --git a/requirements.txt b/requirements.txt index 5dc8781..902314f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ multipledispatch argparse black beartype -multimethod \ No newline at end of file +multimethod +mypy \ No newline at end of file diff --git a/core/better_print.py b/src/better_print.py similarity index 97% rename from core/better_print.py rename to src/better_print.py index 59dad0f..8c97258 100644 --- a/core/better_print.py +++ b/src/better_print.py @@ -123,16 +123,17 @@ def _process_bg_color(bg: str) -> str: Returns: str: the background color as a unicode escape sequence """ - + bg_list: list[str] = [] + if not bg.startswith('rgb('): try: bg = BG_COLORS[bg.lower().strip()] except KeyError: raise ValueError('Invalid color ' + str(bg).strip()) else: - bg = bg.split('rgb')[1].split('(')[1].split(')')[0].split(',') - if len(bg) != 3 or not isdigit(bg) or any([int(i.strip()) > 255 for i in bg]): - raise ValueError('Invalid rgb color ' + str(bg)) - for index, i in enumerate(bg): bg[index] = int(i.strip()) - bg = _make_bg_color(bg[0], bg[1], bg[2]) + bg_list = bg_list.split('rgb')[1].split('(')[1].split(')')[0].split(',') + if len(bg_list) != 3 or not isdigit(bg_list) or any([int(i.strip()) > 255 for i in bg_list]): + raise ValueError('Invalid rgb color ' + str(bg_list)) + for index, i in enumerate(bg_list): bg_list[index] = int(i.strip()) + bg = _make_bg_color(bg_list[0], bg_list[1], bg_list[2]) return bg def _process_style(color: list[str]) -> str: """Processes the color and style and returns the unicode escape sequence diff --git a/core/cache_store.py b/src/cache_store.py similarity index 79% rename from core/cache_store.py rename to src/cache_store.py index 72727b4..b9ee8c6 100644 --- a/core/cache_store.py +++ b/src/cache_store.py @@ -1,16 +1,18 @@ DISABLED: bool = False -from os import (path as os_path, mkdir) -from pickle import dump, load -from threading import Thread -from functools import wraps -from typing import Callable, Tuple, Union +from src.core.imports import ( + dump, load, + wraps, + Callable, Tuple, Union, + lru_cache, + os, +) -CACHE_DIR: str = os_path.join(os_path.dirname(os_path.dirname(__file__)), "cache") +CACHE_DIR: str = os.path.join(os.path.dirname(os.path.dirname(__file__)), "cache") local_cache: dict[str, any] = {} -if not os_path.isdir(CACHE_DIR): - mkdir(CACHE_DIR) +if not os.path.isdir(CACHE_DIR): + os.mkdir(CACHE_DIR) def async_cache(path: str, args: tuple, result: any) -> None: global local_cache @@ -22,7 +24,7 @@ def async_cache(path: str, args: tuple, result: any) -> None: def get_cache(path: str, args: tuple) -> Union[any, None]: global local_cache - if os_path.isfile(path): + if os.path.isfile(path): with open(path, "rb") as file: try: local_cache = load(file) @@ -32,7 +34,6 @@ def get_cache(path: str, args: tuple) -> Union[any, None]: return None -from functools import lru_cache def cache(func: Callable) -> Callable: return lru_cache(maxsize=None)(func) @@ -43,7 +44,7 @@ def wrapper(*args: Tuple[any, ...], **kwargs: dict[str, any]) -> any: global local_cache - cache_file_path: str = os_path.join(CACHE_DIR, f"{func.__name__}.cache") + cache_file_path: str = os.path.join(CACHE_DIR, f"{func.__name__}.cache") if args in local_cache: return local_cache[args] diff --git a/classes/Scope.py b/src/classes/Scope.py similarity index 79% rename from classes/Scope.py rename to src/classes/Scope.py index 5aca152..b7d784a 100644 --- a/classes/Scope.py +++ b/src/classes/Scope.py @@ -1,12 +1,11 @@ -from concurrent.futures import Future -from dataclasses import dataclass -from threading import Thread -from time import time -from typing import Any, Optional -from core.cache_store import cache -from core.panic import panic -from classes.Token import Token_List, Token -import globals +import src.core.base as base +from src.core.imports import ( + Optional, + Token_List, + Token, + cache, + Any, +) class Scope: name: str | Token_List @@ -97,7 +96,7 @@ def contains(cls, line: Token_List | tuple[str, ...], keys: tuple): @classmethod def get_match(cls, line: Token_List, keys: Optional[tuple] = None, depth: int = 0) -> Optional[str]: - all_keywords = tuple(globals.KEYWORDS.keys()) if not keys else keys + all_keywords = tuple(base.KEYWORDS.keys()) if not keys else keys matches = [ast.token for ast in line if ast.token in all_keywords] if len(matches) >= depth + 1: return matches[depth] @@ -114,8 +113,8 @@ def process_scope_from_scope(cls, scope: 'Scope') -> 'Scope': in_scope = False for index in range(len(scope.children)): - if not in_scope and cls.contains(scope.children[index], globals.NAMESPACED_KEYWORD.keys()) and temp_scope.indent_level != scope.children[index].indent_level: - new_scope = Scope(scope.children[index], globals.NAMESPACED_KEYWORD[cls.get_match(scope.children[index], globals.NAMESPACED_KEYWORD.keys())], [scope.children[index]], scope.children[index].indent_level) + if not in_scope and cls.contains(scope.children[index], base.NAMESPACED_KEYWORD.keys()) and temp_scope.indent_level != scope.children[index].indent_level: + new_scope = Scope(scope.children[index], base.NAMESPACED_KEYWORD[cls.get_match(scope.children[index], base.NAMESPACED_KEYWORD.keys())], [scope.children[index]], scope.children[index].indent_level) new_scope.namespace_header = scope.children[index] in_scope = True continue @@ -124,8 +123,8 @@ def process_scope_from_scope(cls, scope: 'Scope') -> 'Scope': temp_scope.append_child(new_scope) new_scope = None in_scope = False - if cls.contains(scope.children[index], globals.NAMESPACED_KEYWORD.keys()): - new_scope = Scope(scope.children[index], globals.NAMESPACED_KEYWORD[cls.get_match(scope.children[index], globals.NAMESPACED_KEYWORD.keys())], [scope.children[index]], scope.children[index].indent_level) + if cls.contains(scope.children[index], base.NAMESPACED_KEYWORD.keys()): + new_scope = Scope(scope.children[index], base.NAMESPACED_KEYWORD[cls.get_match(scope.children[index], base.NAMESPACED_KEYWORD.keys())], [scope.children[index]], scope.children[index].indent_level) new_scope.namespace_header = scope.children[index] in_scope = True continue @@ -148,8 +147,8 @@ def process_from_lines(cls, lines: tuple[Token_List, ...]) -> 'Scope': in_scope = False for index in range(len(lines)): - if not in_scope and cls.contains(lines[index], globals.NAMESPACED_KEYWORD.keys()): - new_scope = Scope(lines[index], globals.NAMESPACED_KEYWORD[cls.get_match(lines[index], globals.NAMESPACED_KEYWORD.keys())], [lines[index]], lines[index].indent_level) + if not in_scope and cls.contains(lines[index], base.NAMESPACED_KEYWORD.keys()): + new_scope = Scope(lines[index], base.NAMESPACED_KEYWORD[cls.get_match(lines[index], base.NAMESPACED_KEYWORD.keys())], [lines[index]], lines[index].indent_level) new_scope.namespace_header = lines[index] in_scope = True continue @@ -158,8 +157,8 @@ def process_from_lines(cls, lines: tuple[Token_List, ...]) -> 'Scope': root_scope.append_child(new_scope) new_scope = None in_scope = False - if cls.contains(lines[index], globals.NAMESPACED_KEYWORD.keys()): - new_scope = Scope(lines[index], globals.NAMESPACED_KEYWORD[cls.get_match(lines[index], globals.NAMESPACED_KEYWORD.keys())], [lines[index]], lines[index].indent_level) + if cls.contains(lines[index], base.NAMESPACED_KEYWORD.keys()): + new_scope = Scope(lines[index], base.NAMESPACED_KEYWORD[cls.get_match(lines[index], base.NAMESPACED_KEYWORD.keys())], [lines[index]], lines[index].indent_level) new_scope.namespace_header = lines[index] in_scope = True continue @@ -177,4 +176,4 @@ def process_from_lines(cls, lines: tuple[Token_List, ...]) -> 'Scope': @cache def get_keyword(self, internal_name: str) -> str: - return next((keyword for keyword in globals.KEYWORDS if globals.KEYWORDS[keyword]["internal_name"] == internal_name), None) \ No newline at end of file + return next((keyword for keyword in base.KEYWORDS if base.KEYWORDS[keyword]["internal_name"] == internal_name), None) \ No newline at end of file diff --git a/classes/Token.py b/src/classes/Token.py similarity index 99% rename from classes/Token.py rename to src/classes/Token.py index 5d4303f..0356744 100644 --- a/classes/Token.py +++ b/src/classes/Token.py @@ -1,8 +1,10 @@ from __future__ import annotations -import json -from typing import Iterable, Iterator, override - -from multimethod import subtype +from src.core.imports import ( + json, + subtype, + Iterable, + Iterator, +) class Token: _: str = "Helix Token" diff --git a/classes/Transpiler.py b/src/classes/Transpiler.py similarity index 82% rename from classes/Transpiler.py rename to src/classes/Transpiler.py index c43face..dc54233 100644 --- a/classes/Transpiler.py +++ b/src/classes/Transpiler.py @@ -1,16 +1,14 @@ -from concurrent.futures import ThreadPoolExecutor -from logging import root -from typing import Callable, Optional - -from classes.Scope import Scope -from classes.Token import Processed_Line, Token_List -from core.config import load_config -from functions._unmarked import _unmarked -import globals -from core.better_print import color_print - - -INDENT_CHAR = load_config().Formatter["indent_char"] +import src.core.base as base +from src.functions._unmarked import _unmarked +from src.core.imports import ( + Callable, + Optional, + Scope, + Processed_Line, + Token_List, + color_print, + INDENT_CHAR, +) class Transpiler: @@ -27,10 +25,10 @@ def parse_non_keyword(self, line: Token_List, *_: Scope) -> str: return _unmarked(line, self.scope_stack[-1] if len(self.scope_stack) >= 1 else self.root_scope, self.scope_stack[-2] if len(self.scope_stack) >= 2 else self.root_scope, self.root_scope, self.ignore_main) def get_match_function(self, child: Token_List) -> Callable[[Token_List, Optional[Scope], Optional[Scope], Scope], Processed_Line]: - match = Scope.get_match(child, tuple(globals.KEYWORDS.keys())) + match = Scope.get_match(child, tuple(base.KEYWORDS.keys())) if match: - return globals.KEYWORDS[match]["parser"] + return base.KEYWORDS[match]["parser"] else: return self.parse_non_keyword @@ -79,10 +77,7 @@ def transpile(self, root_scope: Scope, ignore_main: bool = False): self.ignore_main = ignore_main self.root_scope.transpiler_instance = self - if globals.USE_POOL: - globals.POOL.map(self.__transpile, root_scope.children, chunksize=6) - else: - [self.__transpile(child) for child in root_scope.children] + [self.__transpile(child) for child in root_scope.children] self.__add_from_queue(root_scope) diff --git a/classes/WorkerPool.py b/src/classes/WorkerPool.py similarity index 99% rename from classes/WorkerPool.py rename to src/classes/WorkerPool.py index e31cdfc..5d6c08f 100644 --- a/classes/WorkerPool.py +++ b/src/classes/WorkerPool.py @@ -3,7 +3,6 @@ ProcessPoolExecutor as ProcessPool, ThreadPoolExecutor as ThreadPool, ) -import multiprocessing from typing import ( Literal, diff --git a/core/compile_bar.py b/src/compile_bar.py similarity index 95% rename from core/compile_bar.py rename to src/compile_bar.py index 10e602b..6dc9799 100644 --- a/core/compile_bar.py +++ b/src/compile_bar.py @@ -1,4 +1,4 @@ -from globals import ASYNC +import src.core.base as base # get the signal int to see when the program ends import signal @@ -19,7 +19,7 @@ def exponential_decay_generator(current, base_sleep=0.01): x = current / MAX return base_sleep - (base_sleep * math.exp(-b * x)) -@ASYNC +@base.ASYNC def show_bar(event: Event): global current while current < MAX and not event.is_set(): diff --git a/core/config.py b/src/config.py similarity index 91% rename from core/config.py rename to src/config.py index c2673c3..c35d131 100644 --- a/core/config.py +++ b/src/config.py @@ -1,7 +1,9 @@ -import os -import toml -from argparse import Namespace -from core.panic import panic +from src.core.imports import ( + os, + toml, + Namespace, + panic, +) CACHE: dict[str, Namespace] = {} CONFIG_PATH = ".helix/config.toml" diff --git a/globals.py b/src/core/base.py similarity index 75% rename from globals.py rename to src/core/base.py index 7b1e000..883bba9 100644 --- a/globals.py +++ b/src/core/base.py @@ -1,21 +1,55 @@ -import re -from sys import stdout as sys_stdout -from threading import Thread -from types import MappingProxyType as map -from typing import Callable, Iterable, Optional - -from classes.Token import Processed_Line, Token_List -from classes.WorkerPool import WorkerPool -from functions._class import _class -from functions._for import _for -from functions._functions import function as _function -from functions._include import include as _include -from functions._let import _let -from functions._match import _match -from functions._unless import _unless -from enum import Enum, unique +from src.core.imports import ( + re, + map, + enum, + Thread, + Callable, + Iterable, + Optional, + Token_List, + WorkerPool, + Processed_Line, + + _unless, + _for, + _match, + _function, + _class, + _let, + _include, + file_cache, + +) + +# All Primitive Types +# int; +# string; +# float; +# map; +# list; +# bool; +# char; +# void; +# tuple; +# array; +# set; +# +# u8; +# u16; +# u32; +# u64; +# u128; +# i8; +# i16; +# i32; +# i64; +# i128; +# f32; +# f64; +# f128; + def dummy( line: Token_List, current_scope, @@ -24,7 +58,7 @@ def dummy( ) -> Processed_Line: return Processed_Line( " " * line.indent_level - + " ".join([_.token for _ in line]), + + " ".join([str(_.token) for _ in line]), line, ) @@ -32,17 +66,25 @@ def dummy( def _no_change(line: Token_List, *args) -> Processed_Line: return Processed_Line( " " * line.indent_level - + " ".join([_.token for _ in line]), + + " ".join([str(_.token) for _ in line]), line, ) + CACHE: dict[str, tuple[Token_List, ...]] = {} POOL: WorkerPool = WorkerPool(50) USE_POOL: bool = True LINE_BREAK: str = "\x03" SUB_LINE_BREAK: str = "\x04" +PUNCTUATION = r".,:?()[]{}<>+-*/=|&^%$#~" +COMMENT = r"\~\~.*" +BLOCK_COMMENT = r"\~\*\~" +INLINE_COMMENT = r"\~\*.*\*\~" +STRING = r"\".*\"" +CHAR = r"'.*'" +INDENT_CHAR = " " FAT_CHARACTER: list[str] = [ r"\=\=\=", # === @@ -80,215 +122,187 @@ def _no_change(line: Token_List, *args) -> Processed_Line: r"\?\=", # ?= ] -# All Primitive Types -# int; -# string; -# float; -# map; -# list; -# bool; -# char; -# void; -# tuple; -# array; -# set; -# -# u8; -# u16; -# u32; -# u64; -# u128; -# i8; -# i16; -# i32; -# i64; -# i128; -# f32; -# f64; -# f128; - - -@unique -class ERROR_CODES(Enum): +@enum.unique +class ERROR_CODES(enum.Enum): # Command-Line Interface Errors CLI_ARGUMENT_INVALID = ( - "[HEX-001]", + "HEX-001", "Invalid command-line argument: {argument}", ValueError, ) CLI_FILE_NOT_FOUND = ( - "[HEX-002]", + "HEX-002", "Input file not found: {filename}", FileNotFoundError, ) CLI_OPTION_UNSUPPORTED = ( - "[HEX-003]", + "HEX-003", "Unsupported command-line option: {option}", ValueError, ) # Syntax Errors SYNTAX_UNEXPECTED_TOKEN = ( - "[HEX-100]", + "HEX-100", "Unexpected token in source code: {token}", SyntaxError, ) SYNTAX_INVALID_SYNTAX = ( - "[HEX-101]", + "HEX-101", "General syntax error at {location}", SyntaxError, ) SYNTAX_MISSING_SEMICOLON = ( - "[HEX-102]", + "HEX-102", "Missing semicolon at end of statement", SyntaxError, ) SYNTAX_UNBALANCED_PARENTHESIS = ( - "[HEX-103]", + "HEX-103", "Unbalanced parenthesis", SyntaxError, ) SYNTAX_INVALID_LITERAL = ( - "[HEX-104]", + "HEX-104", "Invalid literal: {literal}", ValueError, ) SYNTAX_UNSUPPORTED_SYNTAX = ( - "[HEX-105]", + "HEX-105", "Unsupported syntax in Helix: {syntax}", SyntaxError, ) # Type and Declaration Errors TYPE_INVALID_CAST = ( - "[HEX-200]", + "HEX-200", "Invalid type cast: {details}", TypeError, ) TYPE_UNDECLARED_VARIABLE = ( - "[HEX-201]", + "HEX-201", "Use of undeclared variable: {variable}", NameError, ) TYPE_MISMATCH = ( - "[HEX-202]", + "HEX-202", "Type mismatch in expression: {expression}", TypeError, ) TYPE_REDECLARATION = ( - "[HEX-203]", + "HEX-203", "Redeclaration of a variable or function: {identifier}", SyntaxError, ) # Semantic Errors SEMANTIC_UNRESOLVED_REFERENCE = ( - "[HEX-300]", + "HEX-300", "Unresolved reference: {reference}", NameError, ) SEMANTIC_ARGUMENT_MISMATCH = ( - "[HEX-301]", + "HEX-301", "Function argument mismatch in {function}", TypeError, ) SEMANTIC_INFINITE_LOOP_DETECTED = ( - "[HEX-302]", + "HEX-302", "Potential infinite loop detected", RuntimeError, ) SEMANTIC_INVALID_OPERATION = ( - "[HEX-303]", + "HEX-303", "Invalid operation: {operation}", ValueError, ) # Linking and Dependency Errors LINKING_FAILED = ( - "[HEX-400]", + "HEX-400", "Linking failed: {details}", ImportError, ) DEPENDENCY_NOT_FOUND = ( - "[HEX-401]", + "HEX-401", "Dependency not found: {dependency}", ImportError, ) DEPENDENCY_CONFLICT = ( - "[HEX-402]", + "HEX-402", "Dependency version conflict: {details}", ImportError, ) # File and I/O Errors FILE_READ_ERROR = ( - "[HEX-500]", + "HEX-500", "Error reading file: {filename}", IOError, ) FILE_WRITE_ERROR = ( - "[HEX-501]", + "HEX-501", "Error writing file: {filename}", IOError, ) FILE_FORMAT_UNSUPPORTED = ( - "[HEX-502]", + "HEX-502", "Unsupported file format: {format}", ValueError, ) IO_PERMISSION_DENIED = ( - "[HEX-503]", + "HEX-503", "Permission denied for file operation: {filename}", PermissionError, ) # Resource and Memory Errors RESOURCE_LIMIT_EXCEEDED = ( - "[HEX-600]", + "HEX-600", "Resource limit exceeded: {resource}", MemoryError, ) MEMORY_ALLOCATION_ERROR = ( - "[HEX-601]", + "HEX-601", "Memory allocation error", MemoryError, ) RESOURCE_LEAK_DETECTED = ( - "[HEX-602]", + "HEX-602", "Resource leak detected: {resource}", ResourceWarning, ) # Environment and System Errors SYSTEM_ERROR = ( - "[HEX-700]", + "HEX-700", "System error encountered: {details}", SystemError, ) ENVIRONMENT_VARIABLE_NOT_FOUND = ( - "[HEX-701]", + "HEX-701", "Environment variable not found: {variable}", EnvironmentError, ) UNSUPPORTED_PLATFORM = ( - "[HEX-702]", + "HEX-702", "Unsupported operating system or platform: {platform}", OSError, ) # Miscellaneous Errors INTERNAL_COMPILER_ERROR = ( - "[HEX-800]", + "HEX-800", "Internal compiler error: {details}", RuntimeError, ) FEATURE_NOT_IMPLEMENTED = ( - "[HEX-801]", + "HEX-801", "Feature not yet implemented: {feature}", NotImplementedError, ) UNEXPECTED_ERROR = ( - "[HEX-802]", + "HEX-802", "Unexpected error occurred: {details}", RuntimeError, ) @@ -307,7 +321,6 @@ def raise_as_python_exception(self, **kwargs): """Raise the corresponding Python exception with the formatted error message.""" raise self.py_exception(self.format_error(**kwargs)) - IGNORE_TYPES_MAP: tuple[str, ...] = ("Callable",) PRIMITIVES_MAP: map[str, tuple[str, str]] = map( @@ -382,108 +395,6 @@ def raise_as_python_exception(self, **kwargs): } ) - -def multi_split( - string: str, - *separators: str, - discard: Optional[Iterable[str]] = None, -) -> list[str]: - # split the string by all the separators but keep the separators - # so like "a + b" would become ["a", "+", "b"], if the separators are [" ", "+"] - # Escape special regex characters in separators and join them with '|' for regex 'or' - if not discard: - discard = [] - - regex_pattern = "|".join( - re.escape(sep) for sep in separators - ) - - # Use re.split with a capturing group to keep separators - return [ - s - for s in re.split(f"({regex_pattern})", string) - if s and s not in discard - ] - - -def replace_primitive( - type: str, operation: int = 0 -) -> ( - str -): # 0: helix ir type | python type, 1: python type, 2: helix ir type - full_type: list[str] = multi_split( - type, " ", "[", "]", ",", discard=["", " "] - ) - - # for each type in full_type, replace it with the python type | helix ir type - if isinstance(full_type, str): - return ( - PRIMITIVES_MAP[full_type][1] - if operation == 2 - else ( - PRIMITIVES_MAP[full_type][0] - if operation == 0 - else f"{PRIMITIVES_MAP[full_type][0]} | {PRIMITIVES_MAP[full_type][1]}" - ) - ) - - for i, t in enumerate(full_type): - if t in PRIMITIVES_MAP: - match operation: - case 0: - if ( - len(full_type) - i - ) > 1 and full_type[i + 1] == "[": - # get everything after the current type and keep track of the brackets, then process that again - # and then set a copy of the full_type to the processed type - # so like if the type is "list[int]" then it would become "list[hx_int|int] | hx_list[hx_int|int]" - # Process the nested type - end_index = i + 2 - brackets = 1 - while ( - end_index < len(full_type) - and brackets - ): - if full_type[end_index] == "[": - brackets += 1 - elif ( - full_type[end_index] == "]" - ): - brackets -= 1 - end_index += 1 - - nested_type = replace_primitive( - " ".join( - full_type[ - i + 2 : end_index - 1 - ] - ), - operation, - ) - python_type = f"{PRIMITIVES_MAP[t][0]}[{nested_type}]" - helix_type = f"{PRIMITIVES_MAP[t][1]}[{nested_type}]" - full_type[i:end_index] = [ - f"{python_type} | {helix_type}" - ] - else: - full_type[i] = ( - f"{PRIMITIVES_MAP[t][0]} | {PRIMITIVES_MAP[t][1]}" - ) - case 1: - full_type[i] = PRIMITIVES_MAP[t][0] - case 2: - full_type[i] = PRIMITIVES_MAP[t][0] - case 3: - # only the base type no generics - return PRIMITIVES_MAP[t][0] - case _: - raise ValueError("Invalid operation") - elif operation == 3: - return full_type[0] - - return " ".join(full_type) - - KEYWORDS: map[str, map[str, str | bool | Callable[..., Processed_Line]]] = map({ # Control Flow "if" : map({"internal_name": "IF" , "parser": _unless , "scoped": False, "body_required": True , "keyword_type": "control_flow"}), @@ -576,34 +487,14 @@ def replace_primitive( } ) -PUNCTUATION = r".,:?()[]{}<>+-*/=|&^%$#~" -COMMENT = r"\~\~.*" -BLOCK_COMMENT = r"\~\*\~" -INLINE_COMMENT = r"\~\*.*\*\~" -STRING = r"\".*\"" -CHAR = r"'.*'" -INDENT_CHAR = " " - -from core.cache_store import file_cache +from src.core.utils import ( + multi_split, + replace_primitive, + find_keyword, + ASYNC +) -@file_cache -def find_keyword(internal_name: str) -> str: - return [ - keyword - for keyword in KEYWORDS.keys() - if KEYWORDS[keyword]["internal_name"] - == internal_name - ][0] - - -def ASYNC(func): - def wrapper(*args, **kwargs): - Thread( - target=func, args=args, kwargs=kwargs - ).start() - - return wrapper # print(highlight_code(""" @@ -625,4 +516,4 @@ def wrapper(*args, **kwargs): # } # } # """)) -# exit() \ No newline at end of file +# exit() diff --git a/src/core/framework.py b/src/core/framework.py new file mode 100644 index 0000000..3b32080 --- /dev/null +++ b/src/core/framework.py @@ -0,0 +1,169 @@ +from abc import ABC, abstractmethod +from src.core.imports import ( + Any, + Callable, + Iterable, + ModuleType, + Namespace, + Optional, + Processed_Line, + Scope, + threading +) + +class Hashing(ABC): + @abstractmethod + def __init__(self, file_path: str, output_path: str) -> None: + pass + @abstractmethod + def __int__(self) -> int: + pass + @staticmethod + @abstractmethod + def compute_hash(code: str) -> bytes: + pass + @abstractmethod + def create_hash_only(self) -> None: + pass + @staticmethod + @abstractmethod + def get_mount(path): + pass + @abstractmethod + def create_file(self, code: str) -> None: + pass + @abstractmethod + def is_code_altered(self) -> bool: + pass + @abstractmethod + def get_hash(self) -> bytes | None: + pass + +class ThreadedProcess: + __processes_queue__: dict[int, threading.Thread] + @abstractmethod + def __new__(cls, func: Callable[..., None]): + pass + @abstractmethod + def __init__(self, func: Callable[..., None]) -> None: + pass + @abstractmethod + def __call__(self, *args, **kwargs) -> None: + pass + @property + @abstractmethod + def processes(self) -> dict[int, threading.Thread]: + pass + +class ArgParser: + @abstractmethod + def help_screen(self) -> None: + pass + @abstractmethod + def version_screen(self) -> None: + pass + @abstractmethod + def __init__(self, argv: Optional[Iterable[str]] = None) -> None: + pass + @property + @abstractmethod + def args(self) -> Namespace: + pass + +class HelixLanguage: + @abstractmethod + def __init__(self, *args: str, **kwargs: str) -> None: + pass + @staticmethod + @abstractmethod + def make_folder(directory: str) -> None: + pass + @staticmethod + @abstractmethod + def make_file(file: str) -> None: + pass + @staticmethod + @abstractmethod + def generate_folder_structure(directory: str = ...): + pass + @staticmethod + @abstractmethod + def install_helix(config: dict) -> None: + pass + @staticmethod + @abstractmethod + def remove_blank_lines(file: str, hash: Hashing | None) -> None: + pass + +class Timer: + @abstractmethod + def __init__(self) -> None: + pass + @abstractmethod + def start(self, name: str) -> None: + pass + @abstractmethod + def end(self, name: str) -> None: + pass + @abstractmethod + def get_time(self, name: str) -> float: + pass + @abstractmethod + def decorator(self, func: Callable) -> Callable: + pass + +class DisabledKeyboardInterrupt: + @abstractmethod + def __enter__(self) -> None: + pass + @abstractmethod + def handler(self, sig: int, frame: Any) -> None: + pass + @abstractmethod + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: + pass + +class Helix: + @classmethod + @abstractmethod + def interpreter(cls, code: str, globals_: dict, locals_: dict) -> str: + pass + @abstractmethod + def build_path(self) -> str: + pass + @abstractmethod + def __init__(self, conf_file: Optional[str] = None, *args: str, profile: bool = False, import_: bool = False) -> None: + pass + @classmethod + @abstractmethod + def factory(cls, config_file: str, *args: str, **kwargs: Any) -> None: + pass + @abstractmethod + def run(self) -> None: + pass + @abstractmethod + def cleanup(self) -> None: + pass + @abstractmethod + def compile_file(self, file: Optional[str] = None) -> Scope: + pass + @abstractmethod + def transpile(self, file: Optional[str] = None) -> tuple[Scope, list[Processed_Line]]: + pass + @abstractmethod + def generate_line_numbers(self, transpiled: list[Processed_Line]) -> str: + pass + @abstractmethod + def generate_source_code(self, scope_parsed: Scope, transpiled_lines: list[Processed_Line], format_source: bool = False, is_main: bool = True, no_inject: bool = False) -> str: + pass + @abstractmethod + def inject_core(self, code: Optional[str] = None, is_main: bool = True) -> str: + pass + @staticmethod + @abstractmethod + def REPL() -> None: + pass + @classmethod + @abstractmethod + def __hook_import__(cls, file: str, *args: str, config_file: Optional[str] = None, **kwargs: Any) -> ModuleType: + pass diff --git a/src/core/imports.py b/src/core/imports.py new file mode 100644 index 0000000..9f844a8 --- /dev/null +++ b/src/core/imports.py @@ -0,0 +1,112 @@ +import enum +import re +import os +import sys +import signal +import shutil +import hashlib +import threading +import subprocess +import functools +import json +import toml + +from sys import exit +from io import TextIOWrapper +from pickle import ( + dump, + load +) +from functools import ( + wraps, + lru_cache +) +from argparse import ( + Namespace, + ArgumentParser +) + +from threading import ( + Thread, + Event, + Lock, +) + +from typing import ( + Any, + Optional, + Union, + Tuple, + Mapping, + Type, + TypeVar, + Generic, + Callable, + Iterable, + Iterator, + Sequence, + Protocol, +) + +from concurrent.futures import ( + Future, + ThreadPoolExecutor, + ProcessPoolExecutor +) +from multimethod import subtype +from black import FileMode, format_file_contents +from dataclasses import dataclass +from datetime import datetime +from time import ( + time, + sleep, + perf_counter, + perf_counter_ns, + process_time, +) + +from types import ( + MappingProxyType as map, + UnionType, + FunctionType, + MethodType, + FrameType, + ModuleType, +) + +from src.panic import panic +from src.better_print import color_print +from src.config import load_config +from src.cache_store import ( + cache, + file_cache +) + +from src.token.normalize_tokens import normalize_tokens +from src.token.remove_comments import remove_comment +from src.token.tokenize_file import Tokenizer +from src.token.tokenize_line import tokenize_line + +INDENT_CHAR = load_config().Formatter["indent_char"] +re = __import__(load_config().Transpiler["regex_module"]) + +from src.classes.WorkerPool import WorkerPool +from src.classes.Token import ( + Processed_Line, + Token_List, + Token, +) +from src.classes.Scope import Scope +from src.classes.Transpiler import Transpiler + + +from src.functions._class import _class +from src.functions._for import _for +from src.functions._functions import _function +from src.functions._include import _include +from src.functions._let import _let +from src.functions._match import _match +from src.functions._unless import _unless +from src.functions._unmarked import _unmarked + +import src.core.framework as framework \ No newline at end of file diff --git a/src/core/utils.py b/src/core/utils.py new file mode 100644 index 0000000..27dec1b --- /dev/null +++ b/src/core/utils.py @@ -0,0 +1,145 @@ +from src.core.base import ( + Processed_Line, + Token_List, + INDENT_CHAR, + re, + Optional, + Iterable, + PRIMITIVES_MAP, + file_cache, + KEYWORDS, + Thread, +) + +def multi_split( + string: str, + *separators: str, + discard: Optional[Iterable[str]] = None, +) -> list[str]: + # split the string by all the separators but keep the separators + # so like "a + b" would become ["a", "+", "b"], if the separators are [" ", "+"] + # Escape special regex characters in separators and join them with '|' for regex 'or' + if not discard: + discard = [] + + regex_pattern = "|".join( + re.escape(sep) for sep in separators + ) + + # Use re.split with a capturing group to keep separators + return [ + s + for s in re.split(f"({regex_pattern})", string) + if s and s not in discard + ] + + +def replace_primitive( + type: str, operation: int = 0 +) -> ( + str +): # 0: helix ir type | python type, 1: python type, 2: helix ir type + full_type: list[str] = multi_split( + type, " ", "[", "]", ",", discard=["", " "] + ) + + # for each type in full_type, replace it with the python type | helix ir type + if isinstance(full_type, str): + return ( + PRIMITIVES_MAP[full_type][1] + if operation == 2 + else ( + PRIMITIVES_MAP[full_type][0] + if operation == 0 + else f"{PRIMITIVES_MAP[full_type][0]} | {PRIMITIVES_MAP[full_type][1]}" + ) + ) + + for i, t in enumerate(full_type): + if t in PRIMITIVES_MAP: + match operation: + case 0: + if ( + len(full_type) - i + ) > 1 and full_type[i + 1] == "[": + # get everything after the current type and keep track of the brackets, then process that again + # and then set a copy of the full_type to the processed type + # so like if the type is "list[int]" then it would become "list[hx_int|int] | hx_list[hx_int|int]" + # Process the nested type + end_index = i + 2 + brackets = 1 + while ( + end_index < len(full_type) + and brackets + ): + if full_type[end_index] == "[": + brackets += 1 + elif ( + full_type[end_index] == "]" + ): + brackets -= 1 + end_index += 1 + + nested_type = replace_primitive( + " ".join( + full_type[ + i + 2 : end_index - 1 + ] + ), + operation, + ) + python_type = f"{PRIMITIVES_MAP[t][0]}[{nested_type}]" + helix_type = f"{PRIMITIVES_MAP[t][1]}[{nested_type}]" + full_type[i:end_index] = [ + f"{python_type} | {helix_type}" + ] + else: + full_type[i] = ( + f"{PRIMITIVES_MAP[t][0]} | {PRIMITIVES_MAP[t][1]}" + ) + case 1: + full_type[i] = PRIMITIVES_MAP[t][0] + case 2: + full_type[i] = PRIMITIVES_MAP[t][0] + case 3: + # only the base type no generics + return PRIMITIVES_MAP[t][0] + case _: + raise ValueError("Invalid operation") + elif operation == 3: + return full_type[0] + + return " ".join(full_type) + +@file_cache +def find_keyword(internal_name: str) -> str: + return [ + keyword + for keyword in KEYWORDS.keys() + if KEYWORDS[keyword]["internal_name"] + == internal_name + ][0] + + +def ASYNC(func): + def run_thread(func, args, kwargs): + func._result = func(*args, **kwargs) + func._thread_started = False + + @wraps(func) + def wrapper(*args, **kwargs): + if not hasattr(func, "_thread_started") or not func._thread_started: + func._thread = Thread(target=run_thread, args=(func, args, kwargs)) + func._thread_started = True + func._thread.start() + return func + + def join(timeout=None): + if hasattr(func, "_thread"): + func._thread.join(timeout) + return getattr(func, "_result", None) + return None + + func.join = join + wrapper.join = join + return wrapper diff --git a/functions/_class.py b/src/functions/_class.py similarity index 96% rename from functions/_class.py rename to src/functions/_class.py index c2ecfb5..85b0195 100644 --- a/functions/_class.py +++ b/src/functions/_class.py @@ -1,10 +1,11 @@ -from classes.Token import Processed_Line, Token, Token_List -from core.config import load_config - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic +from src.core.imports import ( + Processed_Line, + Token, + Token_List, + panic, + INDENT_CHAR, + re, +) CLASS_EXTENSION = "::" SEPARATOR_FOR_CLASSES = "+" @@ -15,7 +16,6 @@ def generate_default_code(indent_chars: str, class_name) -> str: {indent_chars} raise NotImplementedError("Define an __init__ method for this class with the function signature new(self: Any, inst_class: '{class_name}')") """ - def _class(ast_list: Token_List, current_scope, parent_scope, root_scope, modifiers=None) -> Processed_Line: data_structure_types = ( parent_scope.get_keyword("INTERFACE"), diff --git a/functions/_for.py b/src/functions/_for.py similarity index 80% rename from functions/_for.py rename to src/functions/_for.py index 4a9d133..1d72d44 100644 --- a/functions/_for.py +++ b/src/functions/_for.py @@ -1,16 +1,15 @@ # THIS TOOK ME 2 DAYS TO WRITE, I'M SO PROUD OF MYSELF -import classes.Transpiler as Transpiler -import globals -from classes.Scope import Scope -from classes.Token import Processed_Line, Token, Token_List -from core.cache_store import cache -from core.config import load_config - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic - +import src.core.base as base +from src.core.imports import ( + Scope, + Processed_Line, + Token, + Token_List, + cache, + panic, + INDENT_CHAR, + re, +) def _for(ast_list: Token_List, current_scope: Scope, parent_scope: Scope, root_scope: Scope, modifiers=None) -> Processed_Line: output = "" @@ -59,17 +58,17 @@ def process_init_statement(init_statement: Token_List) -> dict: def extract_variables(index: int, token: Token) -> None: nonlocal current_var_name, in_generic, generic_count, current_var_type, current_var_value, current_var_unsafe, current_var_discard, expecting_type, expecting_value, excepting_name - if token in [globals.find_keyword("LET"), globals.find_keyword("VAR"), globals.find_keyword("UNSAFE")]: + if token in [base.find_keyword("LET"), base.find_keyword("VAR"), base.find_keyword("UNSAFE")]: if expecting_value: excepting_name = True expecting_value = False processed_decls[stack[-1]]["value"] = current_var_value.strip()[:-2] current_var_value = "" - current_var_unsafe = token == globals.find_keyword("UNSAFE") or init_statement[index-1] == globals.find_keyword("UNSAFE") + current_var_unsafe = token == base.find_keyword("UNSAFE") or init_statement[index-1] == base.find_keyword("UNSAFE") - current_var_discard = not (token == globals.find_keyword("LET")) - current_var_discard = not (token == globals.find_keyword("LET") or init_statement[index+1] == globals.find_keyword("LET")) + current_var_discard = not (token == base.find_keyword("LET")) + current_var_discard = not (token == base.find_keyword("LET") or init_statement[index+1] == base.find_keyword("LET")) excepting_name = True return @@ -80,7 +79,7 @@ def extract_variables(index: int, token: Token) -> None: processed_decls[current_var_name.strip()] = { "type": current_var_type.strip(), "value": current_var_value.strip(), - globals.find_keyword("UNSAFE"): current_var_unsafe, + base.find_keyword("UNSAFE"): current_var_unsafe, "discard": current_var_discard } current_var_name = "" @@ -92,7 +91,7 @@ def extract_variables(index: int, token: Token) -> None: processed_decls[current_var_name.strip()] = { "type": current_var_type.strip(), "value": current_var_value.strip(), - globals.find_keyword("UNSAFE"): current_var_unsafe, + base.find_keyword("UNSAFE"): current_var_unsafe, "discard": current_var_discard } current_var_name = "" @@ -115,11 +114,11 @@ def extract_variables(index: int, token: Token) -> None: expecting_type = False for _name in stack: processed_decls[_name] = { - "type": processed_decls[_name]["type"] if processed_decls[_name]["type"] != '' else current_var_type.strip(), + "type": processed_decls[_name]['type'] if processed_decls[_name]['type'] != '' else current_var_type.strip(), "value": processed_decls[_name]["value"] if processed_decls[_name]["value"] != '' else current_var_value.strip(), - globals.find_keyword("UNSAFE"): processed_decls[_name][globals.find_keyword("UNSAFE")], + base.find_keyword("UNSAFE"): processed_decls[_name][base.find_keyword("UNSAFE")], "discard": processed_decls[_name]["discard"] - } if processed_decls[_name]["type"] == "" and processed_decls[_name]["value"] == "" else processed_decls[_name] + } if processed_decls[_name]['type'] == "" and processed_decls[_name]["value"] == "" else processed_decls[_name] current_var_type = "" return if token == ",": @@ -128,7 +127,7 @@ def extract_variables(index: int, token: Token) -> None: processed_decls[stack[-1]] = { "type": current_var_type.strip(), "value": current_var_value.strip(), - globals.find_keyword("UNSAFE"): current_var_unsafe, + base.find_keyword("UNSAFE"): current_var_unsafe, "discard": current_var_discard } current_var_type = "" @@ -149,36 +148,36 @@ def extract_variables(index: int, token: Token) -> None: [extract_variables(index, token) for index, token in enumerate(init_statement)] if expecting_type: - processed_decls[stack[-1]]["type"] = current_var_type.strip() + processed_decls[stack[-1]]['type'] = current_var_type.strip() if expecting_value: processed_decls[stack[-1]]["value"] = current_var_value.strip() def re_process_stack(_name: str, processed_decls: dict[str, dict[str, str]]) -> dict[str, dict[str, str]]: if processed_decls[_name]["value"] == "": - if processed_decls[_name]["type"].endswith("?"): - processed_decls[_name]["type"] = processed_decls[_name]["type"][:-1].strip() - processed_decls[_name]["value"] = f"{processed_decls[_name]["type"]}(None)" - elif processed_decls[_name]["type"] != "": - processed_decls[_name]["value"] = f"{processed_decls[_name]["type"]}()" + if processed_decls[_name]['type'].endswith("?"): + processed_decls[_name]['type'] = processed_decls[_name]['type'][:-1].strip() + processed_decls[_name]["value"] = f"{processed_decls[_name]['type']}(None)" + elif processed_decls[_name]['type'] != "": + processed_decls[_name]["value"] = f"{processed_decls[_name]['type']}()" else: # set the type to the type of the next non empty type for __name in reversed(stack): - if processed_decls[__name]["type"] != "": - processed_decls[_name]["value"] = f"{processed_decls[__name]["type"]}()" if not processed_decls[__name]["type"].endswith("?") else f"{processed_decls[__name]["type"][:-1].strip()}(None)" - processed_decls[_name]["type"] = processed_decls[__name]["type"] + if processed_decls[__name]['type'] != "": + processed_decls[_name]["value"] = f"{processed_decls[__name]['type']}()" if not processed_decls[__name]['type'].endswith("?") else f"{processed_decls[__name]['type'][:-1].strip()}(None)" + processed_decls[_name]['type'] = processed_decls[__name]['type'] break else: - if processed_decls[_name]["type"].endswith("?"): - processed_decls[_name]["type"] = processed_decls[_name]["type"][:-1].strip() - processed_decls[_name]["value"] = f"{processed_decls[_name]["type"]}(None)" if processed_decls[_name]["value"] == "" else f"{processed_decls[_name]["type"]}({processed_decls[_name]['value']})" - elif processed_decls[_name]["type"] != "": - processed_decls[_name]["value"] = f"{processed_decls[_name]["type"]}({processed_decls[_name]['value']})" + if processed_decls[_name]['type'].endswith("?"): + processed_decls[_name]['type'] = processed_decls[_name]['type'][:-1].strip() + processed_decls[_name]["value"] = f"{processed_decls[_name]['type']}(None)" if processed_decls[_name]["value"] == "" else f"{processed_decls[_name]['type']}({processed_decls[_name]['value']})" + elif processed_decls[_name]['type'] != "": + processed_decls[_name]["value"] = f"{processed_decls[_name]['type']}({processed_decls[_name]['value']})" [re_process_stack(_name, processed_decls) for _name in stack] return processed_decls - if len(init_statement) > 1 and init_statement[0].token in (globals.find_keyword("LET"), globals.find_keyword("VAR"), globals.find_keyword("UNSAFE")): + if len(init_statement) > 1 and init_statement[0].token in (base.find_keyword("LET"), base.find_keyword("VAR"), base.find_keyword("UNSAFE")): declarations = process_init_statement(init_statement) # if any vars need to be discarded if any([declarations[_name]["discard"] for _name in declarations]): @@ -262,11 +261,11 @@ def process_init_statement(init_statement: Token_List) -> dict: def extract_variables(index: int, token: Token) -> None: nonlocal current_var_name, current_var_unsafe, current_var_discard, excepting_name - if token in [globals.find_keyword("LET"), globals.find_keyword("VAR"), globals.find_keyword("UNSAFE")]: - current_var_unsafe = token == globals.find_keyword("UNSAFE") or init_statement[index-1] == globals.find_keyword("UNSAFE") + if token in [base.find_keyword("LET"), base.find_keyword("VAR"), base.find_keyword("UNSAFE")]: + current_var_unsafe = token == base.find_keyword("UNSAFE") or init_statement[index-1] == base.find_keyword("UNSAFE") - current_var_discard = not (token == globals.find_keyword("LET")) - current_var_discard = not (token == globals.find_keyword("LET") or init_statement[index+1] == globals.find_keyword("LET")) + current_var_discard = not (token == base.find_keyword("LET")) + current_var_discard = not (token == base.find_keyword("LET") or init_statement[index+1] == base.find_keyword("LET")) excepting_name = True return @@ -275,7 +274,7 @@ def extract_variables(index: int, token: Token) -> None: if token == ",": stack.append(current_var_name.strip()) processed_decls[current_var_name.strip()] = { - globals.find_keyword("UNSAFE"): current_var_unsafe, + base.find_keyword("UNSAFE"): current_var_unsafe, "discard": current_var_discard } current_var_name = "" @@ -289,14 +288,14 @@ def extract_variables(index: int, token: Token) -> None: if excepting_name: stack.append(current_var_name.strip()) processed_decls[current_var_name.strip()] = { - globals.find_keyword("UNSAFE"): current_var_unsafe, + base.find_keyword("UNSAFE"): current_var_unsafe, "discard": current_var_discard } for _name in stack: processed_decls[_name] = { - globals.find_keyword("UNSAFE"): processed_decls[_name][globals.find_keyword("UNSAFE")], + base.find_keyword("UNSAFE"): processed_decls[_name][base.find_keyword("UNSAFE")], "discard": processed_decls[_name]["discard"] } diff --git a/functions/_functions.py b/src/functions/_functions.py similarity index 94% rename from functions/_functions.py rename to src/functions/_functions.py index 82f88aa..58c0565 100644 --- a/functions/_functions.py +++ b/src/functions/_functions.py @@ -1,16 +1,13 @@ -from classes.Token import Processed_Line, Token, Token_List -from core.config import load_config - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from types import MappingProxyType as map - -from classes.Scope import Scope -from core.panic import panic -from functions._class import _class - -import globals +import src.core.base as base +from src.core.imports import ( + Processed_Line, + Token_List, + map, + Scope, + panic, + _class, + INDENT_CHAR, +) replace_function_name = map({ "==" : "__eq__", @@ -47,13 +44,13 @@ "@" : "__matmul__", }) -def extract_variables(ast_line: Token_List, root_scope: Scope) -> str: +def extract_variables(ast_line: Token_List, root_scope: Scope) -> dict[str, dict[str, str]]: allowed_untyped = ( "self", "cls", "super" ) - variables = {} + variables: dict[str, dict[str, str]] = {} # remove the fn keyword line = ast_line.line[1:] @@ -184,7 +181,7 @@ def contains(line: Token_List, compare: tuple): return any([_ in line for _ in compare]) # static async fn factorial(n: int) -> int { -def function(ast_list: Token_List, current_scope: Scope, parent_scope: Scope, root_scope: Scope) -> Processed_Line: +def _function(ast_list: Token_List, current_scope: Scope, parent_scope: Scope, root_scope: Scope) -> Processed_Line: decorators = [] if ast_list.line[0].token == "#": for _ in range(ast_list.count("#")): @@ -226,7 +223,7 @@ def function(ast_list: Token_List, current_scope: Scope, parent_scope: Scope, ro for k, v in variables["params"].items(): if v["type"] == "void": panic(SyntaxError(f": The type void is not allowed for variables"), file=ast_list.file, line_no=ast_list.find_line_number(k)) - output += f"{k}: {globals.replace_primitive(v['type'], 0)}, " + output += f"{k}: {base.replace_primitive(v['type'], 0)}, " current_scope.variables[k] = v["type"] output = output[:-2] + ")" @@ -297,4 +294,4 @@ def function(ast_list: Token_List, current_scope: Scope, parent_scope: Scope, ro for _, decorator in enumerate(reversed(decorators)): output = f"{INDENT_CHAR*ast_list.indent_level}{decorator}\n{INDENT_CHAR*ast_list.indent_level}{output.strip()}" - return Processed_Line(f'\n{INDENT_CHAR*ast_list.indent_level}@overload_with_type_check' + output, ast_list) \ No newline at end of file + return Processed_Line((f'\n{INDENT_CHAR*ast_list.indent_level}@overload_with_type_check' if not async_ else '\n') + output, ast_list) \ No newline at end of file diff --git a/functions/_include.py b/src/functions/_include.py similarity index 92% rename from functions/_include.py rename to src/functions/_include.py index bb691e9..305f54c 100644 --- a/functions/_include.py +++ b/src/functions/_include.py @@ -1,14 +1,11 @@ -from classes.Token import Processed_Line, Token, Token_List -from core.config import load_config - -INDENT_CHAR = load_config().Formatter["indent_char"] - -from os import path as os_path - -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic - +from src.core.imports import ( + Processed_Line, + Token_List, + panic, + os, + INDENT_CHAR, + re, +) def is_in_string(token: str) -> bool: return re.search(r"\".*?\"", token) or re.search(r"\'[a-zA-Z0-9]\'", token) @@ -32,7 +29,7 @@ def identify_import_type(combined_line: str, ast_list: Token_List) -> dict: if match: match = match.groupdict() if not match.get('type', ""): - match["type"] = os_path.splitext(match["path"])[1][1:].upper() + match["type"] = os.path.splitext(match["path"])[1][1:].upper() if not match.get('modules', ""): match["modules"] = False else: @@ -50,7 +47,7 @@ def identify_import_type(combined_line: str, ast_list: Token_List) -> dict: return match panic(SyntaxError(f"Invalid include statement: {combined_line}"), file=ast_list.file, line_no=ast_list.line[0].line_number) -def include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Processed_Line: +def _include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Processed_Line: combined_line: str = ' '.join([_.token for _ in ast_list.line]) match = identify_import_type(combined_line, ast_list) @@ -62,7 +59,7 @@ def include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Pr import_statement = "" if type == "C": if not alias and not modules: - return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n", ast_list) + return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n", ast_list) elif alias and modules and len(modules) == 1: return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{alias} = __import_c__(\"{path}\").{modules[0]}\n", ast_list) elif alias and modules and len(modules) > 1: @@ -70,18 +67,18 @@ def include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Pr elif alias and not modules: return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{alias} = __import_c__(\"{path}\")\n", ast_list) elif not alias and modules and len(modules) == 1: - return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __import_c__(\"{path}\").{modules[0]}\n", ast_list) + return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __import_c__(\"{path}\").{modules[0]}\n", ast_list) elif not alias and modules and len(modules) > 1: - import_statement = f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n" + import_statement = f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n" for module in modules: - import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}{module.strip()} = {os_path.splitext(path)[0].strip()}.{module}\n" - import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}del {os_path.splitext(path)[0].strip()}\n" + import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}{module.strip()} = {os.path.splitext(path)[0].strip()}.{module}\n" + import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}del {os.path.splitext(path)[0].strip()}\n" return Processed_Line(import_statement, ast_list) else: panic(SyntaxError(f"Invalid include statement: {combined_line}"), file=ast_list.file, line_no=ast_list.line[0].line_number) elif type == "CPP": if not alias and not modules: - return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n", ast_list) + return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n", ast_list) elif alias and modules and len(modules) == 1: return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{alias} = __import_c__(\"{path}\").{modules[0]}\n", ast_list) elif alias and modules and len(modules) > 1: @@ -89,12 +86,12 @@ def include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Pr elif alias and not modules: return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{alias} = __import_c__(\"{path}\")\n", ast_list) elif not alias and modules and len(modules) == 1: - return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __import_c__(\"{path}\").{modules[0]}\n", ast_list) + return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __import_c__(\"{path}\").{modules[0]}\n", ast_list) elif not alias and modules and len(modules) > 1: - import_statement = f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n" + import_statement = f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __import_c__(\"{path}\")\n" for module in modules: - import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}{module} = {os_path.splitext(path)[0].strip()}.{module}\n" - import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}del {os_path.splitext(path)[0].strip()}\n" + import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}{module} = {os.path.splitext(path)[0].strip()}.{module}\n" + import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}del {os.path.splitext(path)[0].strip()}\n" return Processed_Line(import_statement, ast_list) else: panic(SyntaxError(f"Invalid include statement: {combined_line}"), file=ast_list.file, line_no=ast_list.line[0].line_number) @@ -113,7 +110,7 @@ def include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Pr panic(SyntaxError(f"Invalid include statement: {combined_line}"), file=ast_list.file, line_no=ast_list.line[0].line_number) elif type == "RS": if not alias and not modules: - return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __rs_import__(\"{path}\")\n", ast_list) + return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __rs_import__(\"{path}\")\n", ast_list) elif alias and not modules: return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{alias} = __rs_import__(\"{path}\")\n", ast_list) elif alias and modules and len(modules) == 1: @@ -121,12 +118,12 @@ def include(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Pr elif alias and modules and len(modules) > 1: panic(SyntaxError(f"Invalid include statement: {combined_line} cannot have multiple modules and an alias"), file=ast_list.file, line_no=ast_list.line[0].line_number) elif not alias and modules and len(modules) == 1: - return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __rs_import__(\"{path}\").{modules[0]}\n", ast_list) + return Processed_Line(f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __rs_import__(\"{path}\").{modules[0]}\n", ast_list) elif not alias and modules and len(modules) > 1: - import_statement = f"{INDENT_CHAR*ast_list.line[0].indent_level}{os_path.splitext(path)[0].strip()} = __rs_import__(\"{path}\")\n" + import_statement = f"{INDENT_CHAR*ast_list.line[0].indent_level}{os.path.splitext(path)[0].strip()} = __rs_import__(\"{path}\")\n" for module in modules: - import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}{module} = {os_path.splitext(path)[0].strip()}.{module}\n" - import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}del {os_path.splitext(path)[0].strip()}\n" + import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}{module} = {os.path.splitext(path)[0].strip()}.{module}\n" + import_statement += f"{INDENT_CHAR*ast_list.line[0].indent_level}del {os.path.splitext(path)[0].strip()}\n" return Processed_Line(import_statement, ast_list) else: panic(SyntaxError(f"Invalid include statement: {combined_line}"), file=ast_list.file, line_no=ast_list.line[0].line_number) diff --git a/functions/_let.py b/src/functions/_let.py similarity index 90% rename from functions/_let.py rename to src/functions/_let.py index 8e27be8..a879186 100644 --- a/functions/_let.py +++ b/src/functions/_let.py @@ -1,13 +1,10 @@ -from classes.Token import Token, Token_List, Processed_Line -from core.config import load_config -from core.token.tokenize_line import tokenize_line -import globals - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic - +import src.core.base as base +from src.core.imports import ( + Token_List, + Processed_Line, + INDENT_CHAR, + panic, +) def _let(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Processed_Line: output = "" @@ -195,7 +192,7 @@ def mass_replace(string: str, replacements: dict[str, str]) -> str: ) - for values in globals.IGNORE_TYPES_MAP: + for values in base.IGNORE_TYPES_MAP: if values in value["type"]: value["value"] = "Any" broken_type = True @@ -203,11 +200,11 @@ def mass_replace(string: str, replacements: dict[str, str]) -> str: value["type"] = mass_replace(value["type"].full_line().strip(), cleaning) if not broken_type else "Any" if not null_value: - output += f"{INDENT_CHAR*(ast_list.indent_level + (1 if override_dispatch_error else 0))}{name}: {globals.replace_primitive(value['type'])} = {globals.replace_primitive(value['type'], 3) if globals.replace_primitive(value['type'], 3) not in value['value'] else ''}({value['value']})\n" + output += f"{INDENT_CHAR*(ast_list.indent_level + (1 if override_dispatch_error else 0))}{name}: {base.replace_primitive(value['type'])} = {base.replace_primitive(value['type'], 3) if base.replace_primitive(value['type'], 3) not in value['value'] else ''}({value['value']})\n" elif null_value and value["value"] == "None": - output += f"{INDENT_CHAR*(ast_list.indent_level + (1 if override_dispatch_error else 0))}{name}: Optional[{globals.replace_primitive(value['type'])}] = {value['value']}\n" + output += f"{INDENT_CHAR*(ast_list.indent_level + (1 if override_dispatch_error else 0))}{name}: Optional[{base.replace_primitive(value['type'])}] = {value['value']}\n" elif null_value and value["value"]: - output += f"{INDENT_CHAR*(ast_list.indent_level + (1 if override_dispatch_error else 0))}{name}: Optional[{globals.replace_primitive(value['type'])}]= {globals.replace_primitive(value['type'], 3) if globals.replace_primitive(value['type'], 3) not in value['value'] else ''}({value['value']})\n" + output += f"{INDENT_CHAR*(ast_list.indent_level + (1 if override_dispatch_error else 0))}{name}: Optional[{base.replace_primitive(value['type'])}]= {base.replace_primitive(value['type'], 3) if base.replace_primitive(value['type'], 3) not in value['value'] else ''}({value['value']})\n" # + "\n" + ( # ( # INDENT_CHAR*(ast_list.indent_level) + "print(" + name + ")\n" diff --git a/src/functions/_match.py b/src/functions/_match.py new file mode 100644 index 0000000..81b1464 --- /dev/null +++ b/src/functions/_match.py @@ -0,0 +1,14 @@ +from src.core.imports import ( + Processed_Line, + Token, + Token_List, + load_config, + INDENT_CHAR, + re, + panic, + _class, +) + +def _match(ast_list: Token_List, current_scope, parent_scope, root_scope, modifiers=None) -> Processed_Line: + print(ast_list) + return Processed_Line("yessir", ast_list) \ No newline at end of file diff --git a/functions/_process.py b/src/functions/_process.py similarity index 85% rename from functions/_process.py rename to src/functions/_process.py index 8964de9..ce6aac6 100644 --- a/functions/_process.py +++ b/src/functions/_process.py @@ -1,19 +1,9 @@ -# move the dir one up -import os -import sys - -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - -from classes.Scope import Scope -from classes.Token import Processed_Line, Token, Token_List -from core.config import load_config - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic -from functions._class import _class - +from src.core.imports import ( + Scope, + Processed_Line, + Token, + Token_List, +) def _match(ast_list: Token_List, current_scope, parent_scope, root_scope) -> Token_List: return Processed_Line("JOSH!!!!!!!!!!!!!!!!!!!!!!!!", ast_list) diff --git a/functions/_unless.py b/src/functions/_unless.py similarity index 53% rename from functions/_unless.py rename to src/functions/_unless.py index dc7ef43..d3ecd77 100644 --- a/functions/_unless.py +++ b/src/functions/_unless.py @@ -1,27 +1,25 @@ -from classes.Token import Processed_Line, Token, Token_List -import globals -from core.cache_store import cache -from core.config import load_config -from classes.Scope import Scope - -INDENT_CHAR = load_config().Formatter["indent_char"] -re = __import__(load_config().Transpiler["regex_module"]) - -from core.panic import panic +import src.core.base as base +from src.core.imports import ( + Processed_Line, + Token_List, + Scope, + INDENT_CHAR, + panic, +) def _unless(ast_list: Token_List, current_scope: Scope, parent_scope: Scope, root_scope: Scope, modifiers=None) -> Processed_Line: # unless condition: -> if not condition: # else if condition: -> elif condition: output = "" - if ast_list[0].token == globals.find_keyword("UNLESS"): + if ast_list[0].token == base.find_keyword("UNLESS"): output = f"if not ({ast_list.splice(1, -1).full_line()}):" - elif ast_list[0].token == globals.find_keyword("IF"): + elif ast_list[0].token == base.find_keyword("IF"): output = f"if ({ast_list.splice(1, -1).full_line()}):" - elif ast_list[0].token == globals.find_keyword("ELSE_IF"): + elif ast_list[0].token == base.find_keyword("ELSE_IF"): output = f"elif ({ast_list.splice(1, -1).full_line()}):" - elif ast_list[0].token == globals.find_keyword("ELSE") and ast_list[1].token == globals.find_keyword("IF"): + elif ast_list[0].token == base.find_keyword("ELSE") and ast_list[1].token == base.find_keyword("IF"): output = f"elif ({ast_list.splice(2, -1).full_line()}):" - elif ast_list[0].token == globals.find_keyword("ELSE") and len(ast_list) == 2: + elif ast_list[0].token == base.find_keyword("ELSE") and len(ast_list) == 2: output = "else:" else: panic(SyntaxError(f"Unexpected token '{ast_list[0].token}'"), ast_list[0].token, file=ast_list.file, line_no=ast_list.find_line_number(ast_list[0].token)) diff --git a/functions/_unmarked.py b/src/functions/_unmarked.py similarity index 95% rename from functions/_unmarked.py rename to src/functions/_unmarked.py index 2720c74..1b6f840 100644 --- a/functions/_unmarked.py +++ b/src/functions/_unmarked.py @@ -1,13 +1,22 @@ from types import UnionType -from classes.Token import Token, Token_List, Processed_Line -from core.config import load_config -from core.token.tokenize_line import tokenize_line +from src.classes.Token import Token, Token_List, Processed_Line +from src.config import load_config +from src.token.tokenize_line import tokenize_line INDENT_CHAR = load_config().Formatter["indent_char"] re = __import__(load_config().Transpiler["regex_module"]) -from core.panic import panic +from src.panic import panic +""" +from src.core.imports import ( + Token_List, + UnionType, + Processed_Line, + INDENT_CHAR, + panic, +) +""" def _unmarked(ast_list: Token_List, current_scope, parent_scope, root_scope, ignore_main) -> str: diff --git a/core/panic.py b/src/panic.py similarity index 93% rename from core/panic.py rename to src/panic.py index ab3b779..82403f0 100644 --- a/core/panic.py +++ b/src/panic.py @@ -4,7 +4,7 @@ from sys import exit from sys import stdout as sys_stdout from types import FrameType -from typing import Any, Callable, NoReturn, Optional +from typing import Any, Optional from weakref import ref from pygments import highlight # type: ignore @@ -26,7 +26,6 @@ Whitespace, ) - class HelixSyntaxHighlightingLexer(RegexLexer): name = "Helix" aliases = ["Helix"] @@ -188,18 +187,22 @@ def standalone_tokenize_line(line: str, preserve_spaces: bool = False) -> list[s # Pattern for ANSI color escape sequences color_escape_pattern = r"(\x1b\[[0-9;]*m)" + double_character_operators = ['\\=\\=\\=', '\\!\\=\\=', '\\.\\.\\.', '\\=\\=', '\\!\\=', '\\-\\>', '\\<\\-', '\\<\\=', '\\>\\=', '\\&\\&', '\\-\\-', '\\:\\:', '\\|\\|', '\\+\\+', '\\+\\=', '\\-\\=', '\\*\\=', '\\/\\=', '\\&\\=', '\\|\\=', '\\^\\=', '\\%\\=', '\\*\\*', '\\<\\<', '\\>\\>', '\\<\\<\\=', '\\>\\>\\=', '\\=\\>', '\\@\\=', '\\_\\_', '\\?\\?', '\\?\\:', '\\?\\='] + comment_pattern = r"\~\~.*" + multi_line_comment_pattern = r"\~\*\~" + pattern = re.compile( rf""" - {color_escape_pattern} | # ANSI color escape sequences - ({back_slash.join(r"\~\~.*".split())}[^\n]*) | # Single line comments (~~) - ({back_slash.join(r"\~\*\~".split())}[\s\S]*?{back_slash.join(r"\~\*\~".split())}) | # Multi line comments (~*~ ... ~*~) - (\b\d+\.\d+\b) | # Decimal numbers - (\b\w+\b) | # Words (identifiers, keywords) - ({'|'.join(['\\=\\=\\=', '\\!\\=\\=', '\\.\\.\\.', '\\=\\=', '\\!\\=', '\\-\\>', '\\<\\-', '\\<\\=', '\\>\\=', '\\&\\&', '\\-\\-', '\\:\\:', '\\|\\|', '\\+\\+', '\\+\\=', '\\-\\=', '\\*\\=', '\\/\\=', '\\&\\=', '\\|\\=', '\\^\\=', '\\%\\=', '\\*\\*', '\\<\\<', '\\>\\>', '\\<\\<\\=', '\\>\\>\\=', '\\=\\>', '\\@\\=', '\\_\\_', '\\?\\?', '\\?\\:', '\\?\\='])}) | # Double character operators - ([\(\){{}};,]) | # Single character delimiters - {space_group} | # Spaces - (\S) | # Catch other characters - """, + {color_escape_pattern} | # ANSI color escape sequences + ({back_slash.join(comment_pattern.split())}[^\n]*) | # Single line comments (~~) + ({back_slash.join(multi_line_comment_pattern.split())}[\s\S]*?{back_slash.join(multi_line_comment_pattern.split())}) | # Multi line comments (~*~ ... ~*~) + (\b\d+\.\d+\b) | # Decimal numbers + (\b\w+\b) | # Words (identifiers, keywords) + ({'|'.join(double_character_operators)}) | # Double character operators + ([\(\){{}};,]) | # Single character delimiters + {space_group} | # Spaces + (\S) | # Catch other characters + """, re.MULTILINE | re.VERBOSE, ) diff --git a/core/token/normalize_tokens.py b/src/token/normalize_tokens.py similarity index 95% rename from core/token/normalize_tokens.py rename to src/token/normalize_tokens.py index 882168a..88c5004 100644 --- a/core/token/normalize_tokens.py +++ b/src/token/normalize_tokens.py @@ -1,7 +1,7 @@ -from core.cache_store import cache -from core.panic import panic -from globals import BODY_REQUIRED_KEYWORDS, find_keyword -from classes.Token import Token, Token_List +from src.cache_store import cache +from src.panic import panic +import src.core.base as base +from src.classes.Token import Token, Token_List @cache def normalize_tokens(_lines: tuple[Token, ...], path: str) -> tuple[Token_List, ...]: @@ -43,7 +43,7 @@ def process_line(index: int): nonlocal stack, indent_level, firs_inst, previous_element token = lines[index].line - if token in BODY_REQUIRED_KEYWORDS.keys() and lines[index-1].line not in (find_keyword("ELSE"), ): + if token in base.BODY_REQUIRED_KEYWORDS.keys() and lines[index-1].line not in (base.find_keyword("ELSE"), ): # append the line to the stack for i in range(index, len(lines)): if lines[i].line == "{": diff --git a/core/token/remove_comments.py b/src/token/remove_comments.py similarity index 78% rename from core/token/remove_comments.py rename to src/token/remove_comments.py index ee3fffd..c65ae15 100644 --- a/core/token/remove_comments.py +++ b/src/token/remove_comments.py @@ -1,11 +1,11 @@ import ast from functools import cache -from core.config import load_config +from src.config import load_config re = __import__(load_config().Transpiler["regex_module"]) -from classes.Token import Token -from globals import BLOCK_COMMENT, COMMENT, INLINE_COMMENT +from src.classes.Token import Token +import src.core.base as base in_block_comment: bool = False @@ -26,12 +26,12 @@ def remove_comment(_code: Token): global in_block_comment code: str = _code.original_line - code = re.sub(INLINE_COMMENT, "", re.sub(COMMENT, "", code)) + code = re.sub(base.INLINE_COMMENT, "", re.sub(base.COMMENT, "", code)) code = re.sub(r"override\s+.*\:", "", code) code = re.sub(r"impl\s+.*:", "", code) - if re.search(BLOCK_COMMENT, code): + if re.search(base.BLOCK_COMMENT, code): in_block_comment = ~in_block_comment # type: ignore code = "" diff --git a/core/token/tokenize_file.py b/src/token/tokenize_file.py similarity index 70% rename from core/token/tokenize_file.py rename to src/token/tokenize_file.py index 4bf7b31..10d32d2 100644 --- a/core/token/tokenize_file.py +++ b/src/token/tokenize_file.py @@ -1,9 +1,9 @@ import functools -from core.token.normalize_tokens import normalize_tokens -from core.token.remove_comments import remove_comment -from core.token.tokenize_line import tokenize_line, standalone_tokenize_line -from classes.Token import Token, Token_List -import globals +from src.token.normalize_tokens import normalize_tokens +from src.token.remove_comments import remove_comment +from src.token.tokenize_line import tokenize_line +from src.classes.Token import Token, Token_List +import src.core.base as base class Tokenizer: @@ -21,28 +21,28 @@ def tokenize_file(path: str) -> tuple[Token_List, ...]: list[list[str]]: The normalized and tokenized file """ - if path in globals.CACHE: - return globals.CACHE[path] + if path in base.CACHE: + return base.CACHE[path] lines: tuple[Token, ...] = tuple( Token(line, "", index + 1, 0) for index, line in enumerate(open(path, "r").readlines()) ) - if globals.USE_POOL: - [globals.POOL.append(remove_comment, line) for line in lines] - globals.POOL.execute() + if base.USE_POOL: + [base.POOL.append(remove_comment, line) for line in lines] + base.POOL.execute() _tokenize_line = functools.partial(tokenize_line, path=path) - [globals.POOL.append(_tokenize_line, line) for line in lines] - globals.POOL.execute() + [base.POOL.append(_tokenize_line, line) for line in lines] + base.POOL.execute() else: tuple(map(remove_comment, lines)) tuple(map(lambda _: tokenize_line(_, path), lines)) - globals.CACHE[path] = normalize_tokens(lines, path) - return globals.CACHE[path] + base.CACHE[path] = normalize_tokens(lines, path) + return base.CACHE[path] @staticmethod def tokenize_line(line: str, path: str, indent: int = 0, line_no: int = 0) -> tuple[Token_List, ...]: diff --git a/core/token/tokenize_line.py b/src/token/tokenize_line.py similarity index 68% rename from core/token/tokenize_line.py rename to src/token/tokenize_line.py index 2c66b4e..5bc2ed4 100644 --- a/core/token/tokenize_line.py +++ b/src/token/tokenize_line.py @@ -1,9 +1,9 @@ import re # #### Keep from functools import cache -from core.panic import panic +from src.panic import panic -import globals -from classes.Token import Token +import src.core.base as base +from src.classes.Token import Token COMPILED_RE: re.Pattern = None @@ -14,21 +14,21 @@ def compiled_re(ignore_strings: bool = False) -> re.Pattern: COMPILED_RE = re.compile(rf""" ([fbur]*"[^"\\]*(?:\\.[^"\\]*)*") | # Double quotes strings, including f, b, r, u strings ([fbur]*'[^'\\]*(?:\\.[^'\\]*)*') | # Single quotes strings, including f, b, r, u strings - ({back_slash.join(globals.COMMENT.split())}[^\n]*) | # Single line comments (~~) - ({back_slash.join(globals.BLOCK_COMMENT.split())}[\s\S]*?{back_slash.join(globals.BLOCK_COMMENT.split())}) | # Multi line comments (~*~ ... ~*~) + ({back_slash.join(base.COMMENT.split())}[^\n]*) | # Single line comments (~~) + ({back_slash.join(base.BLOCK_COMMENT.split())}[\s\S]*?{back_slash.join(base.BLOCK_COMMENT.split())}) | # Multi line comments (~*~ ... ~*~) (\b\d+\.\d+\b) | # Decimal numbers (\b\w+\b) | # Words (identifiers, keywords) - ({'|'.join(globals.FAT_CHARACTER)}) | # Double character operators + ({'|'.join(base.FAT_CHARACTER)}) | # Double character operators ([\(\){{}};,]) | # Single character delimiters (\S) | # Catch other characters """, re.MULTILINE | re.VERBOSE) if ignore_strings: return re.compile(rf""" - ({back_slash.join(globals.COMMENT.split())}[^\n]*) | # Single line comments (~~) - ({back_slash.join(globals.BLOCK_COMMENT.split())}[\s\S]*?{back_slash.join(globals.BLOCK_COMMENT.split())}) | # Multi line comments (~*~ ... ~*~) + ({back_slash.join(base.COMMENT.split())}[^\n]*) | # Single line comments (~~) + ({back_slash.join(base.BLOCK_COMMENT.split())}[\s\S]*?{back_slash.join(base.BLOCK_COMMENT.split())}) | # Multi line comments (~*~ ... ~*~) (\b\d+\.\d+\b) | # Decimal numbers (\b\w+\b) | # Words (identifiers, keywords) - ({'|'.join(globals.FAT_CHARACTER)}) | # Double character operators + ({'|'.join(base.FAT_CHARACTER)}) | # Double character operators ([\(\){{}};,]) | # Single character delimiters (\S) | # Catch other characters """, re.MULTILINE | re.VERBOSE) @@ -61,7 +61,7 @@ def tokenize_line(code: Token | str, path: str = None, ignore_errors: bool = Fal token for group in tokens for token in group - if token and not token.startswith(globals.COMMENT) and not token.startswith(globals.BLOCK_COMMENT) and not token.endswith(globals.BLOCK_COMMENT) + if token and not token.startswith(base.COMMENT) and not token.startswith(base.BLOCK_COMMENT) and not token.endswith(base.BLOCK_COMMENT) ] [ @@ -72,13 +72,13 @@ def tokenize_line(code: Token | str, path: str = None, ignore_errors: bool = Fal line_no=code.line_number ) for token in flattened_tokens - if token.strip() in globals.RESERVED_KEYWORDS and not ignore_errors + if token.strip() in base.RESERVED_KEYWORDS and not ignore_errors ] code.line = [ - globals.EARLY_REPLACEMENTS[token] + base.EARLY_REPLACEMENTS[token] if ( - token in globals.EARLY_REPLACEMENTS + token in base.EARLY_REPLACEMENTS ) else ( token ) for token in flattened_tokens @@ -94,11 +94,11 @@ def standalone_tokenize_line(line: str | Token) -> list[str]: back_slash = "\\" pattern = re.compile(rf""" - ({back_slash.join(globals.COMMENT.split())}[^\n]*) | # Single line comments (~~) - ({back_slash.join(globals.BLOCK_COMMENT.split())}[\s\S]*?{back_slash.join(globals.BLOCK_COMMENT.split())}) | # Multi line comments (~*~ ... ~*~) + ({back_slash.join(base.COMMENT.split())}[^\n]*) | # Single line comments (~~) + ({back_slash.join(base.BLOCK_COMMENT.split())}[\s\S]*?{back_slash.join(base.BLOCK_COMMENT.split())}) | # Multi line comments (~*~ ... ~*~) (\b\d+\.\d+\b) | # Decimal numbers (\b\w+\b) | # Words (identifiers, keywords) - ({'|'.join(globals.FAT_CHARACTER)}) | # Double character operators + ({'|'.join(base.FAT_CHARACTER)}) | # Double character operators ([\(\){{}};,]) | # Single character delimiters (\S) | # Catch other characters """, re.MULTILINE | re.VERBOSE) @@ -116,5 +116,5 @@ def standalone_tokenize_line(line: str | Token) -> list[str]: token for group in tokens for token in group - if token and not token.startswith(globals.COMMENT) and not token.startswith(globals.BLOCK_COMMENT) and not token.endswith(globals.BLOCK_COMMENT) + if token and not token.startswith(base.COMMENT) and not token.startswith(base.BLOCK_COMMENT) and not token.endswith(base.BLOCK_COMMENT) ] \ No newline at end of file diff --git a/syntax/head_syntax.hdlx b/syntax/head_syntax.hdlx index 400ebb0..9704a3b 100644 --- a/syntax/head_syntax.hdlx +++ b/syntax/head_syntax.hdlx @@ -1,9 +1,17 @@ -target "rust"; use "syntax.hlx"; -include system; -if system::is_windows() { +if sys::is_windows() { define set_something(int value) -> void; } else { define set_something_else(int value) -> void; -} \ No newline at end of file +} + +namespace python { + fn set_something(value: int) -> None; + fn set_something_else(value: int) -> None; +} + +namespace c { + fn set_something(value: int) -> void; + fn set_something_else(value: int) -> void; +} diff --git a/syntax/syntax.hlx b/syntax/syntax.hlx index 7606b26..fcfdfc6 100644 --- a/syntax/syntax.hlx +++ b/syntax/syntax.hlx @@ -176,7 +176,8 @@ enum dog { } -or and is as use elif switch union enum unsafe +~~ all keywords to make sure the syntax highlighting works +or and is as use elif switch union enum unsafe in auto diff --git a/syntax/test.hlx b/syntax/test.hlx index 8724e32..bbb1289 100644 --- a/syntax/test.hlx +++ b/syntax/test.hlx @@ -83,35 +83,40 @@ class C_cout { } fn main(argv: list) { - do_something(); let a: int = "12"; - print(add(a, ["a", "b", "c"])); + + add(123, 123); + print(add.join()); + + do_something(); + for (var i: int = 0; i < 10; i++) { + printf("doing something else eeeee: %d", i); + } + do_something.join(); + print("done"); + return 0; } +async fn add(a: int, b: int) -> int { + printf("adding: %d + %d", a, b); + return a + b; +} private fn subtract(a: int, b: int) -> int { return a - b } -fn add(a: int, b: int) -> int { - let a: Type = 10; - print(a); - return a - b -} async fn do_something() { for (var i: int = 0; i < 10; i++) { - print("doing something: %d", i); + printf("doing something: %d", i); } } -~*~ -fn a_cursed_fucntion(a: int) -> FunctionType { printf("new something: %d", a); return a_cursed_fucntion } -fn a_cursed_fucntion(a: string) -> FunctionType { let data: list = []; return "kys" } - - +fn a_cursed_fucntion(a: int) -> FunctionType { printf("new something: %d", a); return a_cursed_fucntion } +~*~ fn test_int() { let a: int = 21; let b: int = 42; diff --git a/test.py b/test.py deleted file mode 100644 index afacb01..0000000 --- a/test.py +++ /dev/null @@ -1,10 +0,0 @@ -from helix import HelixProcess -helix_import = HelixProcess.__hook_import__("syntax/test.hlx") - - - -a: list[int] = [1, 2, 3, 4, 5] -b: list[str] = ["a", "b", "c", "d", "e"] - - -print(helix_import.is_typeof(b, list[str])) \ No newline at end of file diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..29b92d6 --- /dev/null +++ b/tests.py @@ -0,0 +1 @@ +import helix \ No newline at end of file diff --git a/tests/ThreadPool_test.py b/tests/ThreadPool_test.py index cad0cc1..0cad76a 100644 --- a/tests/ThreadPool_test.py +++ b/tests/ThreadPool_test.py @@ -8,7 +8,7 @@ from concurrent.futures import Future from multiprocessing import cpu_count -from classes.WorkerPool import WorkerPool +from src.classes.WorkerPool import WorkerPool def test_func(x):