X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Flet_func.h;h=63ebe323ef4f727ad480bd4deb58cd2eb1a3fad6;hp=526265b9cbf0c9ec44c8e91b59e7f864b1b1d627;hb=cffcbdd1df9f6d5dcf78f49a3d1b44cefe21b2f5;hpb=5359ad5c181e5772f350fe1cba060cbed3a05b91 diff --git a/src/types/let_func.h b/src/types/let_func.h index 526265b..63ebe32 100644 --- a/src/types/let_func.h +++ b/src/types/let_func.h @@ -1,27 +1,74 @@ -#ifndef _PSI_TYPES_LET_FUNC_H -#define _PSI_TYPES_LET_FUNC_H +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. -typedef impl_val *(*let_func_handler)(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free); + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: -typedef struct let_func { + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*******************************************************************************/ + +#ifndef PSI_TYPES_LET_FUNC_H +#define PSI_TYPES_LET_FUNC_H + +#include "token.h" + +struct psi_data; +struct psi_impl; +struct psi_decl_arg; +struct psi_impl_var; +struct psi_let_exp; +struct psi_call_frame; + +struct psi_let_func { + struct psi_token *token; token_t type; char *name; - impl_var *var; - let_func_handler handler; -} let_func; - -static inline let_func *init_let_func(token_t type, const char *name, impl_var *var) { - let_func *func = calloc(1, sizeof(*func)); - func->type = type; - func->name = strdup(name); - func->var = var; - return func; -} + struct psi_impl_var *var; + struct psi_plist *inner; +}; + +struct psi_let_func *psi_let_func_init(token_t type, const char *name, struct psi_impl_var *var); +void psi_let_func_free(struct psi_let_func **func_ptr); +void psi_let_func_dump(int fd, struct psi_let_func *func, unsigned level); + +void *psi_let_func_exec(struct psi_let_exp *func_val, struct psi_let_func *func, struct psi_decl_arg *darg, struct psi_call_frame *frame); +bool psi_let_func_validate(struct psi_data *data, struct psi_let_exp *exp, struct psi_let_func *func, struct psi_impl *impl); + +#include "marshal.h" + +static inline psi_marshal_let locate_let_func_fn(token_t type) { + psi_marshal_let let_fn; -static inline void free_let_func(let_func *func) { - free_impl_var(func->var); - free(func->name); - free(func); + switch (type) { + case PSI_T_BOOLVAL: let_fn = psi_let_boolval; break; + case PSI_T_INTVAL: let_fn = psi_let_intval; break; + case PSI_T_FLOATVAL: let_fn = psi_let_floatval; break; + case PSI_T_STRVAL: let_fn = psi_let_strval; break; + case PSI_T_STRLEN: let_fn = psi_let_strlen; break; + case PSI_T_PATHVAL: let_fn = psi_let_pathval; break; + case PSI_T_OBJVAL: let_fn = psi_let_objval; break; + case PSI_T_ZVAL: let_fn = psi_let_zval; break; + case PSI_T_VOID: let_fn = psi_let_void; break; + case PSI_T_COUNT: let_fn = psi_let_count; break; + default: let_fn = NULL; break; + } + return let_fn; } #endif