Skip to content

Commit

Permalink
(draft) improved typechecking system
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuzu-Typ committed Feb 4, 2024
1 parent 552e68f commit 3cbdc04
Show file tree
Hide file tree
Showing 112 changed files with 6,969 additions and 13,397 deletions.
54 changes: 49 additions & 5 deletions PyGLM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,37 @@
// PyGLM FUNCTIONS
#include "PyGLM/functions/all.h"

//static PyObject*
//test(PyObject*, PyObject* arg) {
//}
//#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 Expand Up @@ -265,6 +291,24 @@ extern "C" {
#endif
Py_DECREF(ctypes_module);

// add subtypes to mvec PyGLMTypeObjects
reinterpret_cast<PyGLMTypeObject*>(&hdmvec2Type)->subtype = &hdvec2Type;
reinterpret_cast<PyGLMTypeObject*>(&hdmvec3Type)->subtype = &hdvec3Type;
reinterpret_cast<PyGLMTypeObject*>(&hdmvec4Type)->subtype = &hdvec4Type;

reinterpret_cast<PyGLMTypeObject*>(&hfmvec2Type)->subtype = &hfvec2Type;
reinterpret_cast<PyGLMTypeObject*>(&hfmvec3Type)->subtype = &hfvec3Type;
reinterpret_cast<PyGLMTypeObject*>(&hfmvec4Type)->subtype = &hfvec4Type;

reinterpret_cast<PyGLMTypeObject*>(&himvec2Type)->subtype = &hivec2Type;
reinterpret_cast<PyGLMTypeObject*>(&himvec3Type)->subtype = &hivec3Type;
reinterpret_cast<PyGLMTypeObject*>(&himvec4Type)->subtype = &hivec4Type;

reinterpret_cast<PyGLMTypeObject*>(&humvec2Type)->subtype = &huvec2Type;
reinterpret_cast<PyGLMTypeObject*>(&humvec3Type)->subtype = &huvec3Type;
reinterpret_cast<PyGLMTypeObject*>(&humvec4Type)->subtype = &huvec4Type;


PyObject* module_glm;

if (PyType_Ready(&hfvec1Type) < 0 || PyType_Ready(&hfvec1IterType) < 0
Expand Down
4,385 changes: 619 additions & 3,766 deletions PyGLM/functions/detail/func_common.h

Large diffs are not rendered by default.

59 changes: 28 additions & 31 deletions PyGLM/functions/detail/func_exponential.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,35 @@ pow_(PyObject*, PyObject* args) {
if (PyGLM_Number_Check(arg1) && PyGLM_Number_Check(arg2)) {
return pack(glm::pow(PyGLM_Number_FromPyObject<double>(arg1), PyGLM_Number_FromPyObject<double>(arg2)));
}
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_T_QUA | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_SHAPE_ALL | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(1, float, arg1) && PyGLM_Vec_PTI_Check1(1, float, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(1, float, arg1), PyGLM_Vec_PTI_Get1(1, float, arg2)));
}
if (PyGLM_Vec_PTI_Check0(1, double, arg1) && PyGLM_Vec_PTI_Check1(1, double, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(1, double, arg1), PyGLM_Vec_PTI_Get1(1, double, arg2)));
}
if (PyGLM_Vec_PTI_Check0(2, float, arg1) && PyGLM_Vec_PTI_Check1(2, float, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(2, float, arg1), PyGLM_Vec_PTI_Get1(2, float, arg2)));
}
if (PyGLM_Vec_PTI_Check0(2, double, arg1) && PyGLM_Vec_PTI_Check1(2, double, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(2, double, arg1), PyGLM_Vec_PTI_Get1(2, double, arg2)));
}
if (PyGLM_Vec_PTI_Check0(3, float, arg1) && PyGLM_Vec_PTI_Check1(3, float, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(3, float, arg1), PyGLM_Vec_PTI_Get1(3, float, arg2)));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg1) && PyGLM_Vec_PTI_Check1(3, double, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(3, double, arg1), PyGLM_Vec_PTI_Get1(3, double, arg2)));
}
if (PyGLM_Vec_PTI_Check0(4, float, arg1) && PyGLM_Vec_PTI_Check1(4, float, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(4, float, arg1), PyGLM_Vec_PTI_Get1(4, float, arg2)));
}
if (PyGLM_Vec_PTI_Check0(4, double, arg1) && PyGLM_Vec_PTI_Check1(4, double, arg2)) {
return pack(glm::pow(PyGLM_Vec_PTI_Get0(4, double, arg1), PyGLM_Vec_PTI_Get1(4, double, arg2)));
}
if (Is_PyGLM_Object(arg1)) {
if (Is_PyGLM_Object(arg2)) {
GET_PyGLM_ARG_TYPE(arg1);
GET_PyGLM_ARG_TYPE(arg2);

if (PyGLM_Qua_PTI_Check0(float, arg1) && PyGLM_Number_Check(arg2)) {
return pack(glm::pow(PyGLM_Qua_PTI_Get0(float, arg1), PyGLM_Number_FromPyObject<float>(arg2)));
}
if (PyGLM_Qua_PTI_Check0(double, arg1) && PyGLM_Number_Check(arg2)) {
return pack(glm::pow(PyGLM_Qua_PTI_Get0(double, arg1), PyGLM_Number_FromPyObject<double>(arg2)));
GET_PyGLM_ARG_SUBTYPE(arg1);
GET_PyGLM_ARG_SUBTYPE(arg2);

if (arg1Subtype == arg2Subtype) {
switch (GET_PyGLMTypeObjectArrayOffsetOfType(arg1Subtype)) {
#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetVec<L, T>(): \
return pack(glm::pow(PyGLM_VecOrMVec_Get(L, T, arg1), PyGLM_VecOrMVec_Get(L, T, arg2)));

PyGLM_CODEGEN_PARAM_L_ALL(PyGLM_CODEGEN_PARAM_T_Vec_fF, PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
}
}
if (PyGLM_Number_Check(arg2)) {
switch (GET_PyGLMTypeObjectArrayOffsetOf(arg1)) {
#define PyGLM_FUNC_TEMPLATE(T) \
case PyGLMTypeObjectArrayOffsetQua<T>(): \
return pack(glm::pow(PyGLM_Qua_Get(T, arg1), PyGLM_Number_FromPyObject<T>(arg2)));

PyGLM_CODEGEN_PARAM_T_Qua_fF(PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
}
}
PyGLM_TYPEERROR_2O("invalid argument type(s) for pow(): ", arg1, arg2);
return NULL;
Expand Down
45 changes: 24 additions & 21 deletions PyGLM/functions/detail/func_geometric.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,30 @@ static PyObject*
cross_(PyObject*, PyObject* args) {
PyObject *arg1, *arg2;
PyGLM_Arg_Unpack_2O(args, "cross", arg1, arg2);
PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_T_QUA | PyGLM_SHAPE_3 | PyGLM_DT_FD);
PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_T_QUA | PyGLM_SHAPE_3 | PyGLM_DT_FD);
if (PyGLM_Vec_PTI_Check0(3, float, arg1) && PyGLM_Vec_PTI_Check1(3, float, arg2)) {
glm::vec<3, float> o = PyGLM_Vec_PTI_Get0(3, float, arg1);
glm::vec<3, float> o2 = PyGLM_Vec_PTI_Get1(3, float, arg2);
return pack(glm::cross(o, o2));
}
if (PyGLM_Vec_PTI_Check0(3, double, arg1) && PyGLM_Vec_PTI_Check1(3, double, arg2)) {
glm::vec<3, double> o = PyGLM_Vec_PTI_Get0(3, double, arg1);
glm::vec<3, double> o2 = PyGLM_Vec_PTI_Get1(3, double, arg2);
return pack(glm::cross(o, o2));
}
if (PyGLM_Qua_PTI_Check0(float, arg1) && PyGLM_Qua_PTI_Check1(float, arg2)) {
glm::qua<float> o = PyGLM_Qua_PTI_Get0(float, arg1);
glm::qua<float> o2 = PyGLM_Qua_PTI_Get1(float, arg2);
return pack(glm::cross(o, o2));
}
if (PyGLM_Qua_PTI_Check0(double, arg1) && PyGLM_Qua_PTI_Check1(double, arg2)) {
glm::qua<double> o = PyGLM_Qua_PTI_Get0(double, arg1);
glm::qua<double> o2 = PyGLM_Qua_PTI_Get1(double, arg2);
return pack(glm::cross(o, o2));
if (Is_PyGLM_Object(arg1) && Is_PyGLM_Object(arg2)) {
GET_PyGLM_ARG_TYPE(arg1);
GET_PyGLM_ARG_TYPE(arg2);

GET_PyGLM_ARG_SUBTYPE(arg1);
GET_PyGLM_ARG_SUBTYPE(arg2);

if (arg1Subtype == arg2Subtype) {
switch (GET_PyGLMTypeObjectArrayOffsetOfType(arg1Subtype)) {
#define PyGLM_FUNC_TEMPLATE(L, T) \
case PyGLMTypeObjectArrayOffsetVec<L, T>(): \
return pack(glm::cross(PyGLM_VecOrMVec_Get(L, T, arg1), PyGLM_VecOrMVec_Get(L, T, arg2)));

PyGLM_CODEGEN_PARAM_T_Vec_fF(PyGLM_FUNC_TEMPLATE, 3)
#undef PyGLM_FUNC_TEMPLATE

#define PyGLM_FUNC_TEMPLATE(T) \
case PyGLMTypeObjectArrayOffsetQua<T>(): \
return pack(glm::cross(PyGLM_Qua_Get(T, arg1), PyGLM_Qua_Get(T, arg2)));

PyGLM_CODEGEN_PARAM_T_Qua_fF(PyGLM_FUNC_TEMPLATE)
#undef PyGLM_FUNC_TEMPLATE
}
}
}
PyGLM_TYPEERROR_2O("invalid argument type(s) for cross(): ", arg1, arg2);
return NULL;
Expand Down
Loading

0 comments on commit 3cbdc04

Please sign in to comment.