diff --git a/config.m4 b/config.m4 index fe52deb..cb07ab0 100644 --- a/config.m4 +++ b/config.m4 @@ -3,10 +3,15 @@ PHP_ARG_ENABLE(arma, for armadillo support, if test "$PHP_ARMA" != "no"; then PHP_REQUIRE_CXX() + ARMA_SRC=" \ src/php_arma.cc \ src/interfaces.cc \ src/constants.cc \ - src/complex.cc" + src/complex.cc \ + src/subview_val.cc" PHP_NEW_EXTENSION(arma, $ARMA_SRC, $ext_shared, , -std=c++17) + + PHP_ADD_LIBRARY(armadillo, 1, ARMA_SHARED_LIBADD) + PHP_SUBST(ARMA_SHARED_LIBADD) fi diff --git a/src/complex.cc b/src/complex.cc index 62b821d..60870be 100644 --- a/src/complex.cc +++ b/src/complex.cc @@ -9,7 +9,7 @@ namespace php_arma { template - ZEND_NAMED_FUNCTION(complex::__construct) + PHP_ARMA_FUNCTION(complex, __construct, T) { zval *real, *imag; ZEND_PARSE_PARAMETERS_START(0, 2) @@ -45,7 +45,7 @@ namespace php_arma object_set_property(Z_OBJ_P(current), 1, &zero_val); } - Z_OBJ_HT_P(current) = PHP_ARMA_HANDLERS(complex, T); + Z_OBJ_HT_P(current) = &handlers; } template @@ -74,9 +74,10 @@ namespace php_arma } template - void complex::ce_init(zend_class_entry *parent_ce) + zend_always_inline + void complex::ce_init(const char *name, zend_class_entry *parent_ce) { - ce = class_register("CxDouble", parent_ce, me); + ce = class_register(name, parent_ce, me); property_declare(ce, "real"); property_declare(ce, "imag"); object_handlers_init(&handlers); @@ -87,6 +88,6 @@ namespace php_arma { complex_ce = abstract_class_register("Complex"); - complex::ce_init(complex_ce); + complex::ce_init("CxDouble", complex_ce); } } diff --git a/src/complex.hh b/src/complex.hh index 19e756e..36ded19 100644 --- a/src/complex.hh +++ b/src/complex.hh @@ -20,16 +20,14 @@ namespace php_arma { friend void complex_init(); - PHP_ARMA_CE_DECLARE(); - PHP_ARMA_HANDLERS_DECLARE(); + PHP_ARMA_CE_HANDLRES_DECLARE(); private: static ZEND_NAMED_FUNCTION(__construct); static void write_property(zval*, zval*, zval*, void**); - zend_always_inline - static void ce_init(zend_class_entry*); + static void ce_init(const char*, zend_class_entry*); PHP_ARMA_START_ME() PHP_ARMA_ME(__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) diff --git a/src/constants.cc b/src/constants.cc index 14a49f3..92e98ef 100644 --- a/src/constants.cc +++ b/src/constants.cc @@ -1,5 +1,5 @@ // -// php-armadillo/fill.cc +// php-armadillo/constants.cc // // @Author CismonX // diff --git a/src/php_arma.cc b/src/php_arma.cc index f468eac..c0beb0c 100644 --- a/src/php_arma.cc +++ b/src/php_arma.cc @@ -8,6 +8,7 @@ #include "interfaces.hh" #include "constants.hh" #include "complex.hh" +#include "subview_val.hh" #include diff --git a/src/php_arma.hh b/src/php_arma.hh index e54c25c..83b71b6 100644 --- a/src/php_arma.hh +++ b/src/php_arma.hh @@ -26,9 +26,6 @@ extern zend_module_entry arma_module_entry; /// Helper macros for method entry. -#define Z_OBJNAME_P(zval_p) \ - ZSTR_VAL(Z_OBJCE_P(zval_p)->name) - #define PHP_ARMA_START_ME() \ static constexpr zend_function_entry const me[] = { @@ -42,12 +39,13 @@ extern zend_module_entry arma_module_entry; #define PHP_ARMA_METHODS(cls, ...) \ cls<__VA_ARGS__>::me +#define PHP_ARMA_FUNCTION(cls, func, ...) \ + void ZEND_FASTCALL cls<__VA_ARGS__>::func(INTERNAL_FUNCTION_PARAMETERS) + /// Helper macros for class entry and object handlers -#define PHP_ARMA_CE_DECLARE() \ - static inline zend_class_entry *ce - -#define PHP_ARMA_HANDLERS_DECLARE() \ +#define PHP_ARMA_CE_HANDLRES_DECLARE() \ + static inline zend_class_entry *ce; \ static inline zend_object_handlers handlers #define PHP_ARMA_CE(cls, ...) \ @@ -56,6 +54,9 @@ extern zend_module_entry arma_module_entry; #define PHP_ARMA_HANDLERS(cls, ...) \ &cls<__VA_ARGS__>::handlers +#define Z_OBJNAME_P(zval_p) \ + ZSTR_VAL(Z_OBJCE_P(zval_p)->name) + namespace php_arma { /// Helper functions for initializing class entry and object handlers. @@ -138,21 +139,20 @@ namespace php_arma { auto obj = reinterpret_cast(ecalloc(1, sizeof(T) + sizeof(zend_object) + zend_object_properties_size(ce))); - auto handlers = init(obj); auto zobj = to_zend_object(obj); + zobj->handlers = init(obj); zend_object_std_init(zobj, ce); - zobj->handlers = handlers ? handlers : &std_object_handlers; return zobj; } zend_always_inline - zend_object *object_create(zend_class_entry *ce, const zend_object_handlers *handlers = &std_object_handlers) + zend_object *object_create(zend_class_entry *ce, const zend_object_handlers *handlers) { - auto zobj = reinterpret_cast(ecalloc(1, + auto zobj = reinterpret_cast(ecalloc(1, sizeof(zend_object) + zend_object_properties_size(ce))); + zobj->handlers = handlers; zend_object_std_init(zobj, ce); object_properties_init(zobj, ce); - zobj->handlers = handlers; return zobj; } diff --git a/src/subview_val.cc b/src/subview_val.cc index e69de29..14b4ef5 100644 --- a/src/subview_val.cc +++ b/src/subview_val.cc @@ -0,0 +1,38 @@ +// +// php-armadillo/subview_val.cc +// +// @Author CismonX +// + +#include "subview_val.hh" + +namespace php_arma +{ + template + zend_always_inline + T subview_val::get_val(zend_object *zobj) + { + return static_cast(*to_native_object(zobj)); + } + + template + PHP_ARMA_FUNCTION(subview_val, val, T, B1, B2) + { + zval *current = getThis(); + + zval_set_scalar(return_value, get_val(Z_OBJ_P(current))); + } + + template + PHP_ARMA_FUNCTION(subview_val, setTo, T, B1, B2) + { + + } + + template + zend_always_inline + void subview_val::ce_init(const char *name, zend_class_entry *parent_ce) + { + + } +} diff --git a/src/subview_val.hh b/src/subview_val.hh index e69de29..1676ab1 100644 --- a/src/subview_val.hh +++ b/src/subview_val.hh @@ -0,0 +1,48 @@ +// +// php-armadillo/subview_val.hh +// +// @Author CismonX +// + +#ifndef PHP_ARMA_SVVAL_HH +#define PHP_ARMA_SVVAL_HH + +#include "php_arma.hh" + +#include + +namespace php_arma +{ + template + struct subview_val + { + using sp_svval_t = std::conditional_t, arma::SpMat_MapMat_val>; + + using native_t = std::conditional_t; + + zend_always_inline + static void set_val(zend_object *zobj, native_t &&val) + { + *to_native_object(zobj) = std::move(val); + } + + static T get_val(zend_object*); + + PHP_ARMA_CE_HANDLRES_DECLARE(); + + private: + static ZEND_NAMED_FUNCTION(val); + static ZEND_NAMED_FUNCTION(setTo); + + static void ce_init(const char*, zend_class_entry*); + + PHP_ARMA_START_ME() + PHP_ARMA_ME(val, ZEND_ACC_PUBLIC) + PHP_ARMA_ME(setTo, ZEND_ACC_PUBLIC) + PHP_ARMA_END_ME(); + }; + +} + +#endif //!PHP_ARMA_SVVAL_HH diff --git a/stubs/MapVal.php b/stubs/MapVal.php new file mode 100644 index 0000000..d2c86d1 --- /dev/null +++ b/stubs/MapVal.php @@ -0,0 +1,8 @@ +