functor types
[m6w6/ext-psi] / src / marshal.c
index f204753bfbf9190c13a0eb96f5bea4769a46f5b1..622db12bd817ce05ea02573c65fafe370541c934 100644 (file)
@@ -13,6 +13,10 @@ void psi_to_void(zval *return_value, set_value *set, impl_val *ret_val)
        RETVAL_NULL();
 }
 
+impl_val *psi_let_void(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free) {
+       return tmp;
+}
+
 void psi_to_zval(zval *return_value, set_value *set, impl_val *ret_val) {
        RETVAL_ZVAL(ret_val->ptr, 1, 0);
 }
@@ -106,9 +110,10 @@ static inline impl_val *psi_val_intval(impl_val *tmp, token_t real_type, zend_lo
        case PSI_T_UINT16:              tmp->u16 = intval;              break;
        case PSI_T_INT32:               tmp->i32 = intval;              break;
        case PSI_T_UINT32:              tmp->u32 = intval;              break;
-       case PSI_T_INT:                 tmp->ival = intval;             break;
        case PSI_T_INT64:               tmp->i64 = intval;              break;
        case PSI_T_UINT64:              tmp->u64 = intval;              break;
+       case PSI_T_INT:                 tmp->ival = intval;             break;
+       case PSI_T_LONG:                tmp->lval = intval;             break;
        case PSI_T_FLOAT:               tmp->fval = intval;             break;
        case PSI_T_DOUBLE:              tmp->dval = intval;             break;
 #ifdef HAVE_LONG_DOUBLE
@@ -123,7 +128,7 @@ static inline impl_val *psi_val_intval(impl_val *tmp, token_t real_type, zend_lo
 impl_val *psi_let_intval(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free)
 {
        zend_long intval;
-       token_t real_type = type ? real_decl_type(type)->type : PSI_T_INT;
+       token_t real_type = type ? real_decl_type(type)->type : PSI_T_LONG;
 
        if (iarg->type->type == PSI_T_INT) {
                intval = iarg->val.zend.lval;
@@ -333,7 +338,7 @@ void psi_from_zval_ex(impl_val **ptr, decl_arg *spec, token_t cast, zval *zv, vo
                val->ival = zval_get_long(zv);
                break;
        case PSI_T_STRUCT:
-               *tmp = *ptr = psi_array_to_struct(real->strct, HASH_OF(zv));
+               *tmp = *ptr = psi_array_to_struct(real->real.strct, HASH_OF(zv));
                break;
        }
 }
@@ -343,6 +348,8 @@ void psi_from_zval(impl_val *mem, decl_arg *spec, zval *zv, void **tmp)
        decl_type *type = real_decl_type(spec->type);
 
        switch (type->type) {
+       case PSI_T_FUNCTION:
+               break;
        case PSI_T_FLOAT:
                mem->fval = (float) zval_get_double(zv);
                break;
@@ -389,6 +396,32 @@ void *psi_array_to_struct(decl_struct *s, HashTable *arr)
        return mem;
 }
 
+void *psi_array_to_union(decl_union *u, HashTable *arr) {
+       size_t i;
+       char *mem = ecalloc(1, u->size + sizeof(void *));
+
+       if (arr) for (i = 0; i < u->args->count; ++i) {
+               decl_arg *darg = u->args->args[i];
+               zval *entry = zend_hash_str_find_ind(arr, darg->var->name, strlen(darg->var->name));
+
+               if (entry) {
+                       impl_val val;
+                       void *tmp = NULL;
+
+                       memset(&tmp, 0, sizeof(tmp));
+                       psi_from_zval(&val, darg, entry, &tmp);
+                       memcpy(mem, &val, darg->layout->len);
+                       if (tmp) {
+                               ((void **)(mem + u->size))[0] = tmp;
+                       }
+                       /* first found entry wins */
+                       break;
+               }
+       }
+
+       return mem;
+}
+
 void psi_to_recursive(zval *return_value, set_value *set, impl_val *r_val)
 {
        set->outer.set->func->handler(return_value, set, r_val);
@@ -500,7 +533,10 @@ impl_val *psi_let_arrval(impl_val *tmp, decl_type *type, impl_arg *iarg, void **
 
        switch (real->type) {
        case PSI_T_STRUCT:
-               *to_free = tmp = psi_array_to_struct(real->strct, arr);
+               *to_free = tmp = psi_array_to_struct(real->real.strct, arr);
+               break;
+       case PSI_T_UNION:
+               *to_free = tmp = psi_array_to_union(real->real.unn, arr);
                break;
        EMPTY_SWITCH_DEFAULT_CASE();
        }