X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fnum_exp.h;h=db3aaf0174e97737f45425af6e19d1bb9d9cc409;hp=8666cb8c2e334b7ab6500e6143ccb015151169a8;hb=a0f437f26cd0f121ee911a55327a68a3544bf15f;hpb=9bcb1df0786a8193d65949c857baaba2f4296e84 diff --git a/src/types/num_exp.h b/src/types/num_exp.h index 8666cb8..db3aaf0 100644 --- a/src/types/num_exp.h +++ b/src/types/num_exp.h @@ -23,8 +23,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -#ifndef PSI_TYPES_NUM_EXP -#define PSI_TYPES_NUM_EXP +#ifndef PSI_TYPES_NUM_EXP_H +#define PSI_TYPES_NUM_EXP_H #include "token.h" #include "Zend/zend_types.h" @@ -37,54 +37,75 @@ struct psi_decl_enum_item; struct psi_let_exp; struct psi_set_exp; struct psi_call_frame; +struct psi_validate_scope; struct psi_num_exp { struct psi_token *token; - token_t type; + token_t op; union { - char *numb; - impl_val ival; - struct psi_const *cnst; - struct psi_decl_var *dvar; - struct psi_decl_enum_item *enm; + struct { + struct psi_num_exp *lhs; + struct psi_num_exp *rhs; + } b; + struct { + struct psi_decl_type *typ; + struct psi_num_exp *num; + } c; + struct { + struct psi_num_exp *cond; + struct psi_num_exp *truthy; + struct psi_num_exp *falsy; + } t; + struct psi_num_exp *u; + struct psi_number *n; } data; - token_t op; - struct psi_num_exp *operand; token_t (*calc)(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); }; -struct psi_num_exp *psi_num_exp_init(token_t t, void *num); +struct psi_num_exp *psi_num_exp_init_ternary(token_t op, + struct psi_num_exp *cond, struct psi_num_exp *truthy, + struct psi_num_exp *falsy); +struct psi_num_exp *psi_num_exp_init_binary(token_t op, + struct psi_num_exp *lhs, struct psi_num_exp *rhs); +struct psi_num_exp *psi_num_exp_init_unary(token_t op, + struct psi_num_exp *u); +struct psi_num_exp *psi_num_exp_init_num(struct psi_number *n); +struct psi_num_exp *psi_num_exp_init_cast(struct psi_decl_type *typ, + struct psi_num_exp *num); +void psi_num_exp_free(struct psi_num_exp **c_ptr); + struct psi_num_exp *psi_num_exp_copy(struct psi_num_exp *exp); -void psi_num_exp_free(struct psi_num_exp **exp_ptr); -void psi_num_exp_dump(int fd, struct psi_num_exp *exp); +void psi_num_exp_copy_ctor(struct psi_num_exp **exp_ptr); +void psi_num_exp_dump(struct psi_dump *dump, struct psi_num_exp *exp); bool psi_num_exp_validate(struct psi_data *data, struct psi_num_exp *exp, - struct psi_impl *impl, struct psi_decl *cb_decl, - struct psi_let_exp *current_let, struct psi_set_exp *current_set, - struct psi_decl_enum *current_enum); - -token_t psi_num_exp_exec(struct psi_num_exp *exp, impl_val *res, struct psi_call_frame *frame); - -#include - -static inline zend_long psi_long_num_exp(struct psi_num_exp *exp, struct psi_call_frame *frame) { - impl_val val = {0}; - - switch (psi_num_exp_exec(exp, &val, frame)) { - case PSI_T_UINT8: return val.u8; - case PSI_T_UINT16: return val.u16; - case PSI_T_UINT32: return val.u32; - case PSI_T_UINT64: return val.u64; /* FIXME */ - case PSI_T_INT8: return val.i8; - case PSI_T_INT16: return val.i16; - case PSI_T_INT32: return val.i32; - case PSI_T_INT64: return val.i64; - case PSI_T_FLOAT: return val.fval; - case PSI_T_DOUBLE: return val.dval; - default: - assert(0); - } - return 0; + struct psi_validate_scope *scope); + +token_t psi_num_exp_exec(struct psi_num_exp *exp, impl_val *res, + struct psi_call_frame *frame, struct psi_cpp *cpp); + +struct psi_plist *psi_num_exp_tokens(struct psi_num_exp *exp, + struct psi_plist *list); + + +#include "calc.h" +static inline zend_long psi_num_exp_get_long(struct psi_num_exp *exp, + struct psi_call_frame *frame, struct psi_cpp *cpp) { + impl_val res = {0}; + + psi_calc_cast(psi_num_exp_exec(exp, &res, frame, cpp), &res, + PSI_T_INT64, &res); + + return res.i64; +} +static inline double psi_num_exp_get_double(struct psi_num_exp *exp, + struct psi_call_frame *frame, struct psi_cpp *cpp) { + impl_val res = {0}; + + psi_calc_cast(psi_num_exp_exec(exp, &res, frame, cpp), &res, + PSI_T_DOUBLE, &res); + + return res.dval; } #endif