7673d4ee292669aa315ce8283e7ce3a2270a7d25
[m6w6/ext-psi] / php_psi.h
1 #ifndef PHP_PSI_H
2 #define PHP_PSI_H
3
4 extern zend_module_entry psi_module_entry;
5 #define phpext_psi_ptr &psi_module_entry
6
7 #define PHP_PSI_VERSION "0.1.0"
8
9 #ifdef PHP_WIN32
10 # define PHP_PSI_API __declspec(dllexport)
11 #elif defined(__GNUC__) && __GNUC__ >= 4
12 # define PHP_PSI_API __attribute__ ((visibility("default")))
13 #else
14 # define PHP_PSI_API
15 #endif
16
17 #ifdef ZTS
18 #include "TSRM.h"
19 #endif
20
21 #include "context.h"
22
23 void psi_error_wrapper(PSI_Token *t, int type, const char *msg, ...);
24 void psi_error(int type, const char *fn, unsigned ln, const char *msg, ...);
25 void psi_verror(int type, const char *fn, unsigned ln, const char *msg, va_list argv);
26
27 static inline int psi_check_env(const char *var) {
28 char *set = getenv(var);
29 return (set && *set && '0' != *set);
30 }
31
32 typedef struct psi_object {
33 void *data;
34 size_t size;
35 zend_object std;
36 } psi_object;
37
38 static inline psi_object *PSI_OBJ(zval *zv, zend_object *zo) {
39 if (zv) {
40 zo = Z_OBJ_P(zv);
41 }
42 return (void *) (((char *) zo) - zo->handlers->offset);
43 }
44
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);
48
49 size_t psi_offset_padding(size_t diff, size_t alignment);
50 int psi_internal_type(impl_type *type);
51 zend_internal_arg_info *psi_internal_arginfo(impl *impl);
52 size_t psi_num_min_args(impl *impl);
53
54 void psi_to_void(zval *return_value, set_value *set, impl_val *ret_val);
55 void psi_to_bool(zval *return_value, set_value *set, impl_val *ret_val);
56 void psi_to_int(zval *return_value, set_value *set, impl_val *ret_val);
57 void psi_to_double(zval *return_value, set_value *set, impl_val *ret_val);
58 void psi_to_string(zval *return_value, set_value *set, impl_val *ret_val);
59 void psi_to_recursive(zval *return_value, set_value *set, impl_val *r_val);
60 void psi_to_array(zval *return_value, set_value *set, impl_val *ret_val);
61 void psi_to_object(zval *return_value, set_value *set, impl_val *ret_val);
62
63 void psi_call(zend_execute_data *execute_data, zval *return_value, impl *impl);
64
65 int psi_calc_num_exp(num_exp *exp, impl_val *strct, impl_val *res);
66
67 static inline zend_long psi_long_num_exp(num_exp *exp, impl_val *strct) {
68 impl_val val = {0};
69
70 switch (psi_calc_num_exp(exp, strct, &val)) {
71 case PSI_T_UINT8: return val.u8;
72 case PSI_T_UINT16: return val.u16;
73 case PSI_T_UINT32: return val.u32;
74 case PSI_T_UINT64: return val.u64; /* FIXME */
75 case PSI_T_INT8: return val.i8;
76 case PSI_T_INT16: return val.i16;
77 case PSI_T_INT32: return val.i32;
78 case PSI_T_INT64: return val.i64;
79 case PSI_T_FLOAT: return val.fval;
80 case PSI_T_DOUBLE: return val.dval;
81 EMPTY_SWITCH_DEFAULT_CASE();
82 }
83 return 0;
84 }
85
86 int psi_calc_add(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res);
87 int psi_calc_sub(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res);
88 int psi_calc_mul(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res);
89 int psi_calc_div(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res);
90
91 ZEND_BEGIN_MODULE_GLOBALS(psi)
92 char *engine;
93 char *directory;
94 PSI_Context context;
95 ZEND_END_MODULE_GLOBALS(psi);
96
97 #define PSI_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(psi, v)
98
99 #if defined(ZTS) && defined(COMPILE_DL_PSI)
100 ZEND_TSRMLS_CACHE_EXTERN();
101 #endif
102
103 #endif /* PHP_PSI_H */
104
105
106 /*
107 * Local variables:
108 * tab-width: 4
109 * c-basic-offset: 4
110 * End:
111 * vim600: noet sw=4 ts=4 fdm=marker
112 * vim<600: noet sw=4 ts=4
113 */