0c5fcb5e63d35a5b3675774c56b84ea617928b4b
6 #include <Zend/Zend_API.h>
10 PSI_Compiler
*PSI_CompilerInit(PSI_Compiler
*C
, PSI_Validator
*V
, void *context
)
13 C
= malloc(sizeof(*C
));
15 memset(C
, 0, sizeof(*C
));
17 PSI_DataExchange((PSI_Data
*) C
, (PSI_Data
*) V
);
24 typedef struct PSI_ClosureData
{
29 static inline PSI_ClosureData
*PSI_ClosureDataAlloc(void *context
, impl
*impl
) {
30 PSI_ClosureData
*data
= malloc(sizeof(*data
));
32 data
->context
= context
;
38 static inline size_t impl_num_min_args(impl
*impl
) {
39 size_t i
, n
= impl
->func
->args
->count
;
41 for (i
= 0; i
< impl
->func
->args
->count
; ++i
) {
42 if (impl
->func
->args
->args
[i
]->def
) {
49 void jit_closure_handler(jit_type_t signature
, void *result
, void **args
, void *user_data
)
51 zend_execute_data
*execute_data
= args
[0];
52 zval
*return_value
= args
[1];
53 PSI_ClosureData
*data
= user_data
;
56 if (!data
->impl
->func
->args
->count
) {
57 if (SUCCESS
!= zend_parse_parameters_none()) {
61 ZEND_PARSE_PARAMETERS_START(impl_num_min_args(data
->impl
), data
->impl
->func
->args
->count
)
63 iarg
= data
->impl
->func
->args
->args
[_i
];
67 if (PSI_T_BOOL
== iarg
->type
->type
) {
69 iarg
->val
.bval
= iarg
->def
->type
== PSI_T_TRUE
? 1 : 0;
71 Z_PARAM_BOOL(iarg
->val
.bval
);
72 } else if (PSI_T_INT
== iarg
->type
->type
) {
74 iarg
->val
.lval
= atol(iarg
->def
->text
);
76 Z_PARAM_LONG(iarg
->val
.lval
);
77 } else if (PSI_T_FLOAT
== iarg
->type
->type
) {
79 iarg
->val
.dval
= strtod(iarg
->def
->text
, NULL
);
81 Z_PARAM_DOUBLE(iarg
->val
.dval
);
82 } else if (PSI_T_STRING
== iarg
->type
->type
) {
85 iarg
->val
.str
.len
= strlen(iarg
->def
->text
) - 2;
86 iarg
->val
.str
.val
= &iarg
->def
->text
[1];
88 Z_PARAM_STRING(iarg
->val
.str
.val
, iarg
->val
.str
.len
);
90 error_code
= ZPP_ERROR_FAILURE
;
94 ZEND_PARSE_PARAMETERS_END();
97 zend_function_entry
*PSI_CompilerCompile(PSI_Compiler
*C
)
100 jit_type_t signature
, params
[] = {
104 zend_function_entry
*zfe
= calloc(C
->impls
->count
+ 1, sizeof(*zfe
));
106 for (i
= 0; i
< C
->impls
->count
; ++i
) {
107 zend_function_entry
*zf
;
108 PSI_ClosureData
*data
;
110 if (!C
->impls
->list
[i
]->decl
) {
113 signature
= jit_type_create_signature(jit_abi_cdecl
, jit_type_void
, params
, 2, 1);
116 data
= PSI_ClosureDataAlloc(C
->context
, C
->impls
->list
[i
]);
117 zf
->fname
= C
->impls
->list
[i
]->func
->name
;
118 zf
->handler
= jit_closure_create(C
->context
, signature
, jit_closure_handler
, data
);