Skip to content

Commit

Permalink
(draft) added new typechecker to stable and unstable extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuzu-Typ committed Apr 1, 2024
1 parent bf6b20f commit e920b29
Show file tree
Hide file tree
Showing 24 changed files with 1,103 additions and 5,028 deletions.
62 changes: 31 additions & 31 deletions PyGLM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@
// PyGLM FUNCTIONS
#include "PyGLM/functions/all.h"

static PyObject*
test(PyObject*, PyObject* arg) {
funcstart:
if (Is_PyGLM_Object(arg)) {
GET_PyGLM_ARG_TYPE(arg);
GET_PyGLM_ARG_TYPE_OFFSET(arg);

ptrdiff_t offset = GET_PyGLMTypeObjectArrayOffsetOfType(argType->subtype);

if (offset == PyGLMTypeObjectArrayOffsetVec<3, float>()) {
return pack(PyGLM_VecOrMVec_Get(3, float, arg));
}

return PyLong_FromSsize_t(offset);

//switch (argTypeOffset) {
//case PyGLMTypeObjectArrayOffsetMat<2, 4, float>():
// return PyUnicode_FromFormat("Argument is mat2x4");
//case PyGLMTypeObjectArrayOffsetMat<4, 3, double>():
// return PyUnicode_FromFormat("Argument is dmat4x3");
//}
}
PyGLM_PTI_Init0(arg, PyGLM_DT_ALL | PyGLM_T_ALL | PyGLM_SHAPE_ALL);
if (PyGLM_PTI_IsNone(0)) {
Py_RETURN_FALSE;
}
arg = PTI0.asPyObject();
goto funcstart;
}
#define HAS_TEST
#define TEST_FUNC_TYPE METH_O
//static PyObject*
//test(PyObject*, PyObject* arg) {
// funcstart:
// if (Is_PyGLM_Object(arg)) {
// GET_PyGLM_ARG_TYPE(arg);
// GET_PyGLM_ARG_TYPE_OFFSET(arg);
//
// ptrdiff_t offset = GET_PyGLMTypeObjectArrayOffsetOfType(argType->subtype);
//
// if (offset == PyGLMTypeObjectArrayOffsetVec<3, float>()) {
// return pack(PyGLM_VecOrMVec_Get(3, float, arg));
// }
//
// return PyLong_FromSsize_t(offset);
//
// //switch (argTypeOffset) {
// //case PyGLMTypeObjectArrayOffsetMat<2, 4, float>():
// // return PyUnicode_FromFormat("Argument is mat2x4");
// //case PyGLMTypeObjectArrayOffsetMat<4, 3, double>():
// // return PyUnicode_FromFormat("Argument is dmat4x3");
// //}
// }
// PyGLM_PTI_Init0(arg, PyGLM_DT_ALL | PyGLM_T_ALL | PyGLM_SHAPE_ALL);
// if (PyGLM_PTI_IsNone(0)) {
// Py_RETURN_FALSE;
// }
// arg = PTI0.asPyObject();
// goto funcstart;
//}
//#define HAS_TEST
//#define TEST_FUNC_TYPE METH_O

static PyMethodDef glmmethods[] = {
// DETAIL
Expand Down
19 changes: 17 additions & 2 deletions PyGLM/functions/function_generator_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ MACRO(L, uint16)\
MACRO(L, int8)\
MACRO(L, uint8)

// Repeats the code with T in [int32, int64, int16, int8]
#define PyGLM_CODEGEN_PARAM_T_Vec_iqsu(MACRO, L)\
MACRO(L, int32)\
MACRO(L, int64)\
MACRO(L, int16)\
MACRO(L, int8)

// Repeats the code with T in [int32, uint32, int64, uint64]
#define PyGLM_CODEGEN_PARAM_T_Vec_iqIQ(MACRO, L)\
MACRO(L, int32)\
Expand Down Expand Up @@ -117,6 +124,16 @@ T_MACRO(CODE_MACRO, 2) \
T_MACRO(CODE_MACRO, 3) \
T_MACRO(CODE_MACRO, 4)

// Runs T_MACRO(CODE_MACRO, L) for L in [2, 3]
#define PyGLM_CODEGEN_PARAM_L_2_AND_3(T_MACRO, CODE_MACRO)\
T_MACRO(CODE_MACRO, 2) \
T_MACRO(CODE_MACRO, 3)

// Runs T_MACRO(CODE_MACRO, L) for L in [3, 4]
#define PyGLM_CODEGEN_PARAM_L_3_AND_4(T_MACRO, CODE_MACRO)\
T_MACRO(CODE_MACRO, 3) \
T_MACRO(CODE_MACRO, 4)

// Runs T_MACRO(CODE_MACRO, S, S) for S in [2, 3, 4]
#define PyGLM_CODEGEN_PARAM_S_ALL(T_MACRO, CODE_MACRO)\
T_MACRO(CODE_MACRO, 2, 2) \
Expand Down Expand Up @@ -709,8 +726,6 @@ NAME##_(PyObject*, PyObject*) {\
return pack(glm::NAME<double>());\
}



#define PyGLM_MAKE_GLM_FUNC_M3N__tfF(NAME)\
static PyObject*\
NAME##_(PyObject*, PyObject* args) {\
Expand Down
170 changes: 64 additions & 106 deletions PyGLM/functions/stable_extensions/color_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,41 @@ convertLinearToSRGB_(PyObject*, PyObject* args) {
PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for convertLinearToSRGB()");
return NULL;
}
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg1)) {
glm::vec1 o = PyGLM_Vec_PTI_Get0(1, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(2, float, arg1)) {
glm::vec2 o = PyGLM_Vec_PTI_Get0(2, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(3, float, arg1)) {
glm::vec3 o = PyGLM_Vec_PTI_Get0(3, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(4, float, arg1)) {
glm::vec4 o = PyGLM_Vec_PTI_Get0(4, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg1)) {
glm::dvec1 o = PyGLM_Vec_PTI_Get0(1, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<double>(arg2)));
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(2, double, arg1)) {
glm::dvec2 o = PyGLM_Vec_PTI_Get0(2, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<double>(arg2)));
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg1)) {
glm::dvec3 o = PyGLM_Vec_PTI_Get0(3, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<double>(arg2)));
if (arg2 == NULL) {
switch (GET_PyGLMTypeObjectArrayOffsetOf(arg1)) {
#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetVec<L, T>(): \
return pack(glm::convertLinearToSRGB(PyGLM_Vec_Get(L, T, arg1)));

PyGLM_CODEGEN_PARAM_L_ALL(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE

#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetMVec<L, T>(): \
return pack(glm::convertLinearToSRGB(PyGLM_MVec_Get(L, T, arg1)));

PyGLM_CODEGEN_PARAM_L_MVEC(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
return pack(glm::convertLinearToSRGB(o));
}
if (PyGLM_Vec_PTI_Check0(4, double, arg1)) {
glm::dvec4 o = PyGLM_Vec_PTI_Get0(4, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertLinearToSRGB(o, PyGLM_Number_FromPyObject<double>(arg2)));
else {
if (PyGLM_Number_Check(arg2)) {
switch (GET_PyGLMTypeObjectArrayOffsetOf(arg1)) {
#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetVec<L, T>(): \
return pack(glm::convertLinearToSRGB(PyGLM_Vec_Get(L, T, arg1), PyGLM_Number_FromPyObject<T>(arg2)));

PyGLM_CODEGEN_PARAM_L_ALL(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE

#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetMVec<L, T>(): \
return pack(glm::convertLinearToSRGB(PyGLM_MVec_Get(L, T, arg1), PyGLM_Number_FromPyObject<T>(arg2)));

PyGLM_CODEGEN_PARAM_L_MVEC(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
}
return pack(glm::convertLinearToSRGB(o));
}
PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for convertLinearToSRGB()");
return NULL;
Expand All @@ -97,62 +76,41 @@ convertSRGBToLinear_(PyObject*, PyObject* args) {
PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for convertSRGBToLinear()");
return NULL;
}
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg1)) {
glm::vec1 o = PyGLM_Vec_PTI_Get0(1, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(2, float, arg1)) {
glm::vec2 o = PyGLM_Vec_PTI_Get0(2, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(3, float, arg1)) {
glm::vec3 o = PyGLM_Vec_PTI_Get0(3, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(4, float, arg1)) {
glm::vec4 o = PyGLM_Vec_PTI_Get0(4, float, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<float>(arg2)));
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg1)) {
glm::dvec1 o = PyGLM_Vec_PTI_Get0(1, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<double>(arg2)));
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(2, double, arg1)) {
glm::dvec2 o = PyGLM_Vec_PTI_Get0(2, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<double>(arg2)));
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg1)) {
glm::dvec3 o = PyGLM_Vec_PTI_Get0(3, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<double>(arg2)));
if (arg2 == NULL) {
switch (GET_PyGLMTypeObjectArrayOffsetOf(arg1)) {
#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetVec<L, T>(): \
return pack(glm::convertSRGBToLinear(PyGLM_Vec_Get(L, T, arg1)));

PyGLM_CODEGEN_PARAM_L_ALL(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE

#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetMVec<L, T>(): \
return pack(glm::convertSRGBToLinear(PyGLM_MVec_Get(L, T, arg1)));

PyGLM_CODEGEN_PARAM_L_MVEC(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
return pack(glm::convertSRGBToLinear(o));
}
if (PyGLM_Vec_PTI_Check0(4, double, arg1)) {
glm::dvec4 o = PyGLM_Vec_PTI_Get0(4, double, arg1);
if (arg2 != NULL && PyGLM_Number_Check(arg2)) {
return pack(glm::convertSRGBToLinear(o, PyGLM_Number_FromPyObject<double>(arg2)));
else {
if (PyGLM_Number_Check(arg2)) {
switch (GET_PyGLMTypeObjectArrayOffsetOf(arg1)) {
#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetVec<L, T>(): \
return pack(glm::convertSRGBToLinear(PyGLM_Vec_Get(L, T, arg1), PyGLM_Number_FromPyObject<T>(arg2)));

PyGLM_CODEGEN_PARAM_L_ALL(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE

#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetMVec<L, T>(): \
return pack(glm::convertSRGBToLinear(PyGLM_MVec_Get(L, T, arg1), PyGLM_Number_FromPyObject<T>(arg2)));

PyGLM_CODEGEN_PARAM_L_MVEC(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
}
return pack(glm::convertSRGBToLinear(o));
}
PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for convertSRGBToLinear()");
return NULL;
Expand Down
Loading

0 comments on commit e920b29

Please sign in to comment.