From: Michael Wallner Date: Thu, 5 Nov 2015 11:44:39 +0000 (+0100) Subject: fixes X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a7a2bb568d3ac79ce398941ab9231f0f9555bb22;p=m6w6%2Fext-psi fixes --- diff --git a/src/module.c b/src/module.c index e3658a7..3e222b0 100644 --- a/src/module.c +++ b/src/module.c @@ -131,11 +131,11 @@ void psi_to_string(zval *return_value, token_t t, impl_val *ret_val, decl_var *v case PSI_T_CHAR: case PSI_T_SINT8: case PSI_T_UINT8: - if (var->pointer_level == var->arg->var->pointer_level) { + if (!var->arg->var->pointer_level) { RETVAL_STRINGL(&ret_val->cval, 1); } else { ret_val = deref_impl_val(ret_val, var); - if (ret_val->ptr) { + if (ret_val) { RETVAL_STRING(ret_val->ptr); } else { RETVAL_EMPTY_STRING(); @@ -365,7 +365,7 @@ void psi_to_array(zval *return_value, token_t t, impl_val *ret_val, decl_var *va decl_struct_layout layout = s->layout[i]; impl_val tmp; zval ztmp; - char *ptr = (char *) ret_val->ptr + layout.pos; + char *ptr = (char *) ret_val + layout.pos; memset(&tmp, 0, sizeof(tmp)); memcpy(&tmp, ptr, layout.len); @@ -578,15 +578,17 @@ void psi_do_set(zval *return_value, set_func *func, decl_vars *vars) void psi_do_return(impl *impl, impl_val *ret_val, zval *return_value) { - switch (impl->stmts->ret.list[0]->func->type) { + return_stmt *ret = impl->stmts->ret.list[0]; + + switch (ret->func->type) { case PSI_T_TO_STRING: - psi_to_string(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, impl->decl->func->var); + psi_to_string(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, ret->decl); break; case PSI_T_TO_INT: - psi_to_int(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, impl->decl->func->var); + psi_to_int(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, ret->decl); break; case PSI_T_TO_ARRAY: - psi_to_array(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, impl->decl->func->var); + psi_to_array(return_value, real_decl_type(impl->decl->func->type)->type, ret_val, ret->decl); break; EMPTY_SWITCH_DEFAULT_CASE(); } diff --git a/src/parser.h b/src/parser.h index 28913f6..7424414 100644 --- a/src/parser.h +++ b/src/parser.h @@ -336,7 +336,7 @@ typedef union impl_val { static inline impl_val *deref_impl_val(impl_val *ret_val, decl_var *var) { unsigned i; - for (i = 0; i < var->arg->var->pointer_level; ++i) { + if (var->arg->var != var) for (i = 0; i < var->pointer_level; ++i) { ret_val = *(void **) ret_val; } return ret_val; diff --git a/src/validator.c b/src/validator.c index 7bc2f70..510bba1 100644 --- a/src/validator.c +++ b/src/validator.c @@ -266,11 +266,13 @@ static inline int validate_impl_func(PSI_Validator *V, impl *impl, impl_func *fu } return 1; } + static inline decl *locate_impl_decl(decls *decls, return_stmt *ret) { size_t i; for (i = 0; i < decls->count; ++i) { if (!strcmp(decls->list[i]->func->var->name, ret->decl->name)) { + ret->decl->arg = decls->list[i]->func; return decls->list[i]; } } diff --git a/tests/pipe/pipe.psi b/tests/pipe/pipe.psi index 5bc3cd6..deb11d0 100644 --- a/tests/pipe/pipe.psi +++ b/tests/pipe/pipe.psi @@ -4,5 +4,5 @@ extern int pipe(int fds[2]); function \pipe(array &$fds = null) : int { return to_int(pipe); let fds = calloc(2, int); - set $fds = to_array(fds); + set $fds = to_array(fds[2]); }