+ return;
+
+// for (i = 0; i < s->args->count; ++i) {
+// decl_arg *darg = s->args->args[i];
+// impl_val tmp, tmp_ptr;
+// zval ztmp;
+// char *ptr = (char *) ret_val->ptr + darg->layout->pos;
+//
+// tmp_ptr.ptr = &tmp;
+// memset(&tmp, 0, sizeof(tmp));
+// memcpy(&tmp, ptr, darg->layout->len);
+// switch (real_decl_type(darg->type)->type) {
+// case PSI_T_FLOAT:
+// case PSI_T_DOUBLE:
+// psi_to_double(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var);
+// break;
+// case PSI_T_INT8:
+// case PSI_T_UINT8:
+// if (darg->var->pointer_level) {
+// psi_to_string(&ztmp, real_decl_type(darg->type)->type, &tmp_ptr, darg->var);
+// break;
+// }
+// /* no break */
+// case PSI_T_INT16:
+// case PSI_T_UINT16:
+// case PSI_T_INT32:
+// case PSI_T_UINT32:
+// case PSI_T_INT64:
+// case PSI_T_UINT64:
+// psi_to_int(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var);
+// break;
+// case PSI_T_STRUCT:
+// psi_to_array(&ztmp, real_decl_type(darg->type)->type, &tmp_ptr, darg->var);
+// break;
+// default:
+// printf("t=%d\n", real_decl_type(darg->type)->type);
+// abort();
+// }
+// add_assoc_zval(return_value, darg->var->name, &ztmp);
+// }
+ return;
+ }
+ ret_val = deref_impl_val(ret_val, var);
+ for (i = 0; i < var->arg->var->array_size; ++i) {
+ impl_val *ptr = iterate(ret_val, t, i, &tmp);
+
+ switch (t) {
+ case PSI_T_FLOAT:
+ ZVAL_DOUBLE(&ele, (double) ptr->fval);
+ break;
+ case PSI_T_DOUBLE:
+ ZVAL_DOUBLE(&ele, ptr->dval);
+ break;
+ default:
+ ZVAL_LONG(&ele, ptr->lval);
+ break;
+ }
+
+ add_next_index_zval(return_value, &ele);
+ }
+}
+
+static inline ZEND_RESULT_CODE psi_parse_args(zend_execute_data *execute_data, impl *impl)
+{
+ impl_arg *iarg;
+
+ if (!impl->func->args->count) {
+ return zend_parse_parameters_none();
+ }
+
+ ZEND_PARSE_PARAMETERS_START(psi_num_min_args(impl), impl->func->args->count)
+ nextarg:
+ iarg = impl->func->args->args[_i];
+ if (iarg->def) {
+ Z_PARAM_OPTIONAL;
+ }
+ if (PSI_T_BOOL == iarg->type->type) {
+ if (iarg->def) {
+ iarg->val.zend.bval = iarg->def->type == PSI_T_TRUE ? 1 : 0;
+ }
+ Z_PARAM_BOOL(iarg->val.zend.bval);
+ } else if (PSI_T_INT == iarg->type->type) {
+ if (iarg->def) {
+ iarg->val.zend.lval = zend_atol(iarg->def->text, strlen(iarg->def->text));
+ }
+ Z_PARAM_LONG(iarg->val.zend.lval);
+ } else if (PSI_T_FLOAT == iarg->type->type || PSI_T_DOUBLE == iarg->type->type) {
+ if (iarg->def) {
+ iarg->val.dval = zend_strtod(iarg->def->text, NULL);
+ }
+ Z_PARAM_DOUBLE(iarg->val.dval);
+ } else if (PSI_T_STRING == iarg->type->type) {
+ struct {char *val; size_t len;} str;
+ if (iarg->def) {
+ /* FIXME */
+ str.len = strlen(iarg->def->text) - 2;
+ str.val = &iarg->def->text[1];
+ }
+ Z_PARAM_STR_EX(iarg->val.zend.str, 1, 0);
+ if (iarg->val.zend.str) {
+ zend_string_addref(iarg->val.zend.str);
+ } else if (iarg->def) {
+ iarg->val.zend.str = zend_string_init(str.val, str.len, 0);
+ }
+ } else if (PSI_T_ARRAY == iarg->type->type) {
+ /* handled as _zv in let or set */
+ Z_PARAM_PROLOGUE(0);
+ } else {
+ error_code = ZPP_ERROR_FAILURE;
+ break;
+ }
+ iarg->_zv = _arg;
+ if (_i < _max_num_args) {
+ goto nextarg;
+ }
+ ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
+
+ return SUCCESS;
+}
+
+static inline void *psi_do_calloc(let_calloc *alloc)
+{
+ decl_type *type = real_decl_type(alloc->type);
+ size_t size;
+
+ if (type->type == PSI_T_STRUCT) {
+ /* psi_do_clean expects at least one NULL pointer after the struct */
+ size = type->strct->size + sizeof(void *);
+ } else {
+ size = psi_t_size(type->type);
+ }
+
+ return ecalloc(alloc->n, size);
+}
+
+static inline void *psi_do_let(decl_arg *darg)
+{
+ impl_arg *iarg = darg->let->arg;
+ impl_val *arg_val;
+
+ darg->let->ptr = &darg->let->out;
+ arg_val = darg->let->ptr;
+
+ if (!iarg) {
+ /* let foo = calloc(1, long);
+ * let foo = NULL;
+ * let foo;
+ */
+ if (darg->let->val->func && darg->let->val->func->type == PSI_T_CALLOC) {
+ arg_val->ptr = psi_do_calloc(darg->let->val->func->alloc);
+ darg->let->mem = arg_val->ptr;
+ } else if (darg->var->array_size) {
+ arg_val->ptr = ecalloc(darg->var->array_size, sizeof(*arg_val));
+ darg->let->mem = arg_val->ptr;
+ } else {
+ memset(arg_val, 0, sizeof(*arg_val));
+ }
+ } else {
+
+ switch (darg->let->val->func->type) {
+ case PSI_T_BOOLVAL:
+ if (iarg->type->type == PSI_T_BOOL) {
+ arg_val->cval = iarg->val.zend.bval;
+ } else {
+ arg_val->cval = zend_is_true(iarg->_zv);
+ }
+ break;
+ case PSI_T_INTVAL:
+ if (iarg->type->type == PSI_T_INT) {
+ arg_val->lval = iarg->val.zend.lval;
+ } else {
+ arg_val->lval = zval_get_long(iarg->_zv);
+ }
+ break;
+ case PSI_T_STRVAL:
+ if (iarg->type->type == PSI_T_STRING) {
+ arg_val->ptr = estrdup(iarg->val.zend.str->val);
+ darg->let->mem = arg_val->ptr;
+ zend_string_release(iarg->val.zend.str);
+ } else {
+ zend_string *zs = zval_get_string(iarg->_zv);
+ arg_val->ptr = estrdup(zs->val);
+ darg->let->mem = arg_val->ptr;
+ zend_string_release(zs);
+ }
+ break;
+ case PSI_T_STRLEN:
+ if (iarg->type->type == PSI_T_STRING) {
+ arg_val->lval = iarg->val.zend.str->len;
+ zend_string_release(iarg->val.zend.str);
+ } else {
+ zend_string *zs = zval_get_string(iarg->_zv);
+ arg_val->lval = zs->len;
+ zend_string_release(zs);
+ }
+ break;
+ case PSI_T_ARRVAL:
+ if (iarg->type->type == PSI_T_ARRAY) {
+ decl_type *type = real_decl_type(darg->type);
+
+ switch (type->type) {
+ case PSI_T_STRUCT:
+ arg_val->ptr = psi_array_to_struct(type->strct, HASH_OF(iarg->_zv));
+ darg->let->mem = arg_val->ptr;
+ break;
+ }
+ }
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+ }
+
+ if (darg->let->val && darg->let->val->is_reference) {
+ return &darg->let->ptr;
+ } else {
+ return darg->let->ptr;