functor types
[m6w6/ext-psi] / src / engine.c
index aa4feeb87d1e0e5ef66e0cede6d1fe1c76bf2ab3..37f99766acd63dfda8817084efd173084067703c 100644 (file)
 #include "calc.h"
 #include "marshal.h"
 
-size_t psi_t_alignment(token_t t)
-{
-#define PSI_ALIGNOF(T) case PSI_T_## T: return ALIGNOF_## T ##_T;
-       switch (t) {
-       PSI_ALIGNOF(INT8);
-       PSI_ALIGNOF(UINT8);
-       PSI_ALIGNOF(INT16);
-       PSI_ALIGNOF(UINT16);
-       PSI_ALIGNOF(INT32);
-       PSI_ALIGNOF(UINT32);
-       PSI_ALIGNOF(INT64);
-       PSI_ALIGNOF(UINT64);
-       case PSI_T_FLOAT:
-               return ALIGNOF_FLOAT;
-       case PSI_T_DOUBLE:
-               return ALIGNOF_DOUBLE;
-       case PSI_T_POINTER:
-       case PSI_T_FUNCTION:
-               return ALIGNOF_VOID_P;
-       case PSI_T_ENUM:
-               return ALIGNOF_INT;
-       EMPTY_SWITCH_DEFAULT_CASE();
-       }
-       return 0;
-}
-
-size_t psi_t_size(token_t t)
-{
-#define PSI_SIZEOF(T) case PSI_T_## T : return SIZEOF_## T ##_T;
-       switch (t) {
-       PSI_SIZEOF(INT8);
-       PSI_SIZEOF(UINT8);
-       PSI_SIZEOF(INT16);
-       PSI_SIZEOF(UINT16);
-       PSI_SIZEOF(INT32);
-       PSI_SIZEOF(UINT32);
-       PSI_SIZEOF(INT64);
-       PSI_SIZEOF(UINT64);
-       case PSI_T_FLOAT:
-               return SIZEOF_FLOAT;
-       case PSI_T_DOUBLE:
-               return SIZEOF_DOUBLE;
-       case PSI_T_POINTER:
-       case PSI_T_FUNCTION:
-               return SIZEOF_VOID_P;
-       case PSI_T_ENUM:
-               return SIZEOF_INT;
-       EMPTY_SWITCH_DEFAULT_CASE();
-       }
-       return 0;
-}
 
 int psi_internal_type(impl_type *type)
 {
@@ -258,12 +207,6 @@ static inline void *psi_do_calloc(let_calloc *alloc)
        return mem;
 }
 
-static inline impl_val *psi_let_val(token_t let_func, impl_arg *iarg, impl_val *arg_val, decl_struct *strct, void **to_free)
-{
-       abort();
-       return arg_val;
-}
-
 static inline impl_val *psi_let_func(let_func *func, decl_arg *darg) {
        return darg->ptr = func->handler(darg->ptr, darg->type, func->var->arg, &darg->mem);
 }
@@ -329,7 +272,7 @@ static inline void psi_do_free(free_stmt *fre)
                }
 
                /* FIXME: check in validate_* that free functions return scalar */
-               PSI_ContextCall(&PSI_G(context), &f->decl->call, NULL);
+               psi_context_call(&PSI_G(context), &f->decl->call, NULL);
        }
 }
 
@@ -339,11 +282,17 @@ static inline void psi_clean_array_struct(let_stmt *let, decl_arg *darg) {
                decl_type *type = real_decl_type(darg->type);
 
                if (type->type == PSI_T_STRUCT) {
-                       void **ptr = (void **) ((char *) darg->mem + type->strct->size);
+                       void **ptr = (void **) ((char *) darg->mem + type->real.strct->size);
 
                        while (*ptr) {
                                efree(*ptr++);
                        }
+               } else if (type->type == PSI_T_STRUCT) {
+                       void **ptr = (void **) ((char *) darg->mem + type->real.unn->size);
+
+                       if (*ptr) {
+                               efree(*ptr);
+                       }
                }
        }
 }
@@ -427,7 +376,10 @@ static inline void psi_do_args(impl *impl) {
 
                switch (real->type) {
                case PSI_T_STRUCT:
-                       impl->decl->func->ptr = psi_array_to_struct(real->strct, NULL);
+                       impl->decl->func->ptr = psi_array_to_struct(real->real.strct, NULL);
+                       break;
+               case PSI_T_UNION:
+                       impl->decl->func->ptr = psi_array_to_union(real->real.unn, NULL);
                        break;
                }
        }
@@ -520,7 +472,7 @@ ZEND_RESULT_CODE psi_call(zend_execute_data *execute_data, zval *return_value, i
                }
        }
 
-       PSI_ContextCall(&PSI_G(context), &impl->decl->call, va);
+       psi_context_call(&PSI_G(context), &impl->decl->call, va);
        psi_do_return(return_value, impl->stmts->ret.list[0]);
 
        for (i = 0; i < impl->stmts->set.count; ++i) {