5 extern zend_module_entry psi_module_entry
;
6 #define phpext_psi_ptr &psi_module_entry
8 #define PHP_PSI_VERSION "0.1.0"
11 # define PHP_PSI_API __declspec(dllexport)
12 #elif defined(__GNUC__) && __GNUC__ >= 4
13 # define PHP_PSI_API __attribute__ ((visibility("default")))
25 void psi_error(int type
, const char *msg
, ...);
27 static inline int psi_check_env(const char *var
) {
28 char *set
= getenv(var
);
29 return (set
&& *set
&& '0' != *set
);
32 typedef struct psi_object
{
38 static inline psi_object
*PSI_OBJ(zval
*zv
, zend_object
*zo
) {
42 return (void *) (((char *) zo
) - zo
->handlers
->offset
);
45 size_t psi_t_alignment(token_t t
);
46 size_t psi_t_size(token_t t
);
47 size_t psi_t_align(token_t t
, size_t s
);
49 int psi_internal_type(impl_type
*type
);
50 zend_internal_arg_info
*psi_internal_arginfo(impl
*impl
);
51 size_t psi_num_min_args(impl
*impl
);
53 void psi_to_void(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
54 void psi_to_bool(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
55 void psi_to_int(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
56 void psi_to_double(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
57 void psi_to_string(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
58 void psi_to_array(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
59 void psi_to_object(zval
*return_value
, set_value
*set
, impl_val
*ret_val
);
61 void psi_call(zend_execute_data
*execute_data
, zval
*return_value
, impl
*impl
);
63 static inline int psi_calc_num_exp_value(num_exp
*exp
, impl_val
*val
) {
66 switch (is_numeric_string(exp
->u
.numb
, strlen(exp
->u
.numb
), (zend_long
*) val
, (double *) val
, 0)) {
75 switch (exp
->u
.cnst
->type
->type
) {
77 val
->i64
= zend_get_constant_str(exp
->u
.cnst
->name
, strlen(exp
->u
.cnst
->name
))->value
.lval
;
80 val
->dval
= zend_get_constant_str(exp
->u
.cnst
->name
, strlen(exp
->u
.cnst
->name
))->value
.dval
;
88 switch (real_decl_type(exp
->u
.dvar
->arg
->type
)->type
) {
97 memcpy(val
, deref_impl_val(exp
->u
.dvar
->arg
->let
->ptr
, exp
->u
.dvar
), sizeof(*val
));
98 return real_decl_type(exp
->u
.dvar
->arg
->type
)->type
;
102 memcpy(val
, deref_impl_val(exp
->u
.dvar
->arg
->let
->ptr
, exp
->u
.dvar
), sizeof(*val
));
103 return real_decl_type(exp
->u
.dvar
->arg
->type
)->type
;
105 EMPTY_SWITCH_DEFAULT_CASE();
109 EMPTY_SWITCH_DEFAULT_CASE();
114 static inline int psi_calc_num_exp(num_exp
*exp
, impl_val
*val
) {
116 int num_type
= psi_calc_num_exp_value(exp
, &num
);
120 int tmp_type
= psi_calc_num_exp(exp
->operand
, &tmp
);
122 return exp
->calculator(num_type
, &num
, tmp_type
, &tmp
, val
);
125 memcpy(val
, &num
, sizeof(*val
));
129 static inline zend_long
psi_long_num_exp(num_exp
*exp
) {
132 switch (psi_calc_num_exp(exp
, &val
)) {
133 case PSI_T_UINT8
: val
.u16
= val
.u8
;
134 case PSI_T_UINT16
: val
.u32
= val
.u16
;
135 case PSI_T_UINT32
: val
.u64
= val
.u32
;
136 case PSI_T_UINT64
: return val
.u64
;
137 case PSI_T_INT8
: val
.i16
= val
.i8
;
138 case PSI_T_INT16
: val
.i32
= val
.i16
;
139 case PSI_T_INT32
: val
.i64
= val
.i32
;
140 case PSI_T_INT64
: return val
.i64
;
141 case PSI_T_FLOAT
: val
.dval
= val
.fval
;
142 case PSI_T_DOUBLE
: return val
.dval
;
143 EMPTY_SWITCH_DEFAULT_CASE();
147 ZEND_BEGIN_MODULE_GLOBALS(psi
)
151 ZEND_END_MODULE_GLOBALS(psi
);
153 #define PSI_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(psi, v)
155 #if defined(ZTS) && defined(COMPILE_DL_PSI)
156 ZEND_TSRMLS_CACHE_EXTERN();
159 #endif /* PHP_PSI_H */
167 * vim600: noet sw=4 ts=4 fdm=marker
168 * vim<600: noet sw=4 ts=4