calc: generate calculators
[m6w6/ext-psi] / src / types / num_exp.c
index 3d73207ad68f3a1b4350a0e9050bd987f17629fe..20a09c6900c6cdc09dfc7899d3dd257b2dd7bb02 100644 (file)
@@ -175,57 +175,57 @@ void psi_num_exp_free(struct psi_num_exp **c_ptr)
        }
 }
 
-static inline wint_t psi_num_exp_op_tok(token_t op)
+static inline const char *psi_num_exp_op_tok(token_t op)
 {
        switch (op) {
        case PSI_T_NOT:
-               return L'!';
+               return "!";
        case PSI_T_TILDE:
-               return L'~';
+               return "~";
        case PSI_T_LPAREN:
-               return L'(';
+               return "(";
 
        case PSI_T_PIPE:
-               return L'|';
+               return "|";
        case PSI_T_CARET:
-               return L'^';
+               return "^";
        case PSI_T_AMPERSAND:
-               return L'&';
+               return "&";
 
        case PSI_T_LSHIFT:
-               return L'«';
+               return "<<";
        case PSI_T_RSHIFT:
-               return L'»';
+               return ">>";
 
        case PSI_T_PLUS:
-               return L'+';
+               return "+";
        case PSI_T_MINUS:
-               return L'-';
+               return "-";
 
        case PSI_T_ASTERISK:
-               return L'*';
+               return "*";
        case PSI_T_SLASH:
-               return L'/';
+               return "/";
        case PSI_T_MODULO:
-               return L'%';
+               return "%";
 
        case PSI_T_OR:
-               return L'∨';
+               return "||";
        case PSI_T_AND:
-               return L'∧';
+               return "&&";
 
        case PSI_T_CMP_EQ:
-               return L'≣';
+               return "==";
        case PSI_T_CMP_NE:
-               return L'≠';
+               return "!=";
        case PSI_T_CMP_LE:
-               return L'≤';
+               return "<=";
        case PSI_T_CMP_GE:
-               return L'≥';
+               return ">=";
        case PSI_T_RCHEVR:
-               return L'>';
+               return ">";
        case PSI_T_LCHEVR:
-               return L'<';
+               return "<";
 
        default:
                assert(0);
@@ -242,7 +242,7 @@ void psi_num_exp_dump(int fd, struct psi_num_exp *exp)
 
        case PSI_T_NOT:
        case PSI_T_TILDE:
-               dprintf(fd, "%lc", psi_num_exp_op_tok(exp->op));
+               dprintf(fd, "%s", psi_num_exp_op_tok(exp->op));
                psi_num_exp_dump(fd, exp->data.u);
                break;
 
@@ -273,7 +273,7 @@ void psi_num_exp_dump(int fd, struct psi_num_exp *exp)
        case PSI_T_ASTERISK:
        case PSI_T_SLASH:
                psi_num_exp_dump(fd, exp->data.b.lhs);
-               dprintf(fd, " %lc ", psi_num_exp_op_tok(exp->op));
+               dprintf(fd, " %s ", psi_num_exp_op_tok(exp->op));
                psi_num_exp_dump(fd, exp->data.b.rhs);
                break;
 
@@ -290,17 +290,17 @@ bool psi_num_exp_validate(struct psi_data *data, struct psi_num_exp *exp,
        if (exp->op) {
                switch (exp->op) {
                case PSI_T_NOT:
-                       exp->calc = psi_calc_not;
+                       exp->calc = psi_calc_bool_not;
                        break;
                case PSI_T_TILDE:
                        exp->calc = psi_calc_bin_not;
                        break;
 
                case PSI_T_OR:
-                       exp->calc = psi_calc_or;
+                       exp->calc = psi_calc_bool_or;
                        break;
                case PSI_T_AND:
-                       exp->calc = psi_calc_and;
+                       exp->calc = psi_calc_bool_and;
                        break;
                case PSI_T_CMP_EQ:
                        exp->calc = psi_calc_cmp_eq;
@@ -438,23 +438,6 @@ static inline void psi_num_exp_verify_result(token_t t, impl_val *res, struct ps
        if (frame) PSI_DEBUG_PRINT(frame->context, "%s", "\n");
 }
 
-static inline int psi_num_exp_op_cmp(token_t op1, token_t op2)
-{
-       if (PSI_T_LPAREN == op2) {
-               return -1;
-       } else if (PSI_T_LPAREN == op1) {
-               return 1;
-       } else if (op1 == op2) {
-               return 0;
-       } else if (!op1) {
-               return 1;
-       } else if (!op2) {
-               return -1;
-       }
-
-       return psi_token_oper_cmp(op1, op2);
-}
-
 static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **output_ptr,
                struct psi_plist **input_ptr, struct psi_call_frame *frame)
 {
@@ -481,7 +464,7 @@ static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **outpu
                        if (entry.type == PSI_T_LPAREN) {
                                break;
                        }
-                       if (frame) PSI_DEBUG_PRINT(frame->context, " %lc", psi_num_exp_op_tok(entry.type));
+                       if (frame) PSI_DEBUG_PRINT(frame->context, " %s", psi_num_exp_op_tok(entry.type));
                        output = psi_plist_add(output, &entry);
                }
                break;
@@ -490,11 +473,11 @@ static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **outpu
        case PSI_T_TILDE:
                while (psi_plist_top(input, &entry)) {
                        /* bail out if exp->op >= entry.type */
-                       if (psi_num_exp_op_cmp(exp->op, entry.type) != 1) {
+                       if (psi_calc_oper(exp->op, entry.type) != 1) {
                                break;
                        }
                        psi_plist_pop(input, NULL);
-                       if (frame) PSI_DEBUG_PRINT(frame->context, " %lc", psi_num_exp_op_tok(entry.type));
+                       if (frame) PSI_DEBUG_PRINT(frame->context, " %s", psi_num_exp_op_tok(entry.type));
                        output = psi_plist_add(output, &entry);
                }
                entry.type = exp->op;
@@ -507,11 +490,11 @@ static void psi_num_exp_reduce(struct psi_num_exp *exp, struct psi_plist **outpu
                psi_num_exp_reduce(exp->data.b.lhs, &output, &input, frame);
                while (psi_plist_top(input, &entry)) {
                        /* bail out if exp->op > entry.type */
-                       if (psi_num_exp_op_cmp(exp->op, entry.type) == -1) {
+                       if (psi_calc_oper(exp->op, entry.type) == -1) {
                                break;
                        }
                        psi_plist_pop(input, NULL);
-                       if (frame) PSI_DEBUG_PRINT(frame->context, " %lc", psi_num_exp_op_tok(entry.type));
+                       if (frame) PSI_DEBUG_PRINT(frame->context, " %s", psi_num_exp_op_tok(entry.type));
                        output = psi_plist_add(output, &entry);
                }
                entry.type = exp->op;
@@ -543,7 +526,7 @@ token_t psi_num_exp_exec(struct psi_num_exp *exp, impl_val *res,
        psi_num_exp_reduce(exp, &output, &input, frame);
 
        while (psi_plist_pop(input, &entry)) {
-               if (frame) PSI_DEBUG_PRINT(frame->context, " %lc", psi_num_exp_op_tok(entry.type));
+               if (frame) PSI_DEBUG_PRINT(frame->context, " %s", psi_num_exp_op_tok(entry.type));
                output = psi_plist_add(output, &entry);
        }
        if (frame) PSI_DEBUG_PRINT(frame->context, "%s", "\n");
@@ -557,7 +540,7 @@ token_t psi_num_exp_exec(struct psi_num_exp *exp, impl_val *res,
                case PSI_T_NOT:
                case PSI_T_TILDE:
                        psi_plist_pop(input, &rhs);
-                       if (frame) PSI_DEBUG_PRINT(frame->context, " %lc", psi_num_exp_op_tok(entry.type));
+                       if (frame) PSI_DEBUG_PRINT(frame->context, " %s", psi_num_exp_op_tok(entry.type));
                        psi_impl_val_dump(rhs.type, &rhs.data.value, frame);
 
                        entry.type = entry.data.calc(rhs.type, &rhs.data.value, 0, NULL, &entry.data.value);
@@ -589,7 +572,7 @@ token_t psi_num_exp_exec(struct psi_num_exp *exp, impl_val *res,
                        psi_plist_pop(input, &lhs);
 
                        psi_impl_val_dump(lhs.type, &lhs.data.value, frame);
-                       if (frame) PSI_DEBUG_PRINT(frame->context, " %lc", psi_num_exp_op_tok(entry.type));
+                       if (frame) PSI_DEBUG_PRINT(frame->context, " %s", psi_num_exp_op_tok(entry.type));
                        psi_impl_val_dump(rhs.type, &rhs.data.value, frame);
 
                        entry.type = entry.data.calc(