num_exp: RPN calculator
[m6w6/ext-psi] / src / types / num_exp.h
index 8666cb8c2e334b7ab6500e6143ccb015151169a8..ba44807020a44edbcf28febacc2648bd927cba2a 100644 (file)
@@ -23,8 +23,8 @@
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
 
  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"
 
 #include "token.h"
 #include "Zend/zend_types.h"
@@ -40,24 +40,27 @@ struct psi_call_frame;
 
 struct psi_num_exp {
        struct psi_token *token;
 
 struct psi_num_exp {
        struct psi_token *token;
-       token_t type;
+       token_t op;
        union {
        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 psi_num_exp *u;
+               struct psi_number *n;
        } data;
        } 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);
 };
 
        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_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);
+void psi_num_exp_free(struct psi_num_exp **c_ptr);
+
 struct psi_num_exp *psi_num_exp_copy(struct psi_num_exp *exp);
 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_dump(int fd, 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,
 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,
@@ -87,4 +90,5 @@ static inline zend_long psi_long_num_exp(struct psi_num_exp *exp, struct psi_cal
        return 0;
 }
 
        return 0;
 }
 
+
 #endif
 #endif