tinyexpr: Move enums together and stop explicit numbering

We should _not_ be doing bit-fiddling with these, so there's no reason
to care about the number.

This also removes the unused "TE_VARIABLE" symbol.
This commit is contained in:
Fabian Homborg 2018-11-02 13:56:11 +01:00
parent 3bbec871e4
commit b193df8b42

View File

@ -38,8 +38,10 @@ typedef double (*te_fun1)(double);
typedef double (*te_fun0)(); typedef double (*te_fun0)();
enum { enum {
TE_VARIABLE = 0, TE_CONSTANT, TE_CONSTANT = 0,
TE_FUNCTION0 = 8, TE_FUNCTION1, TE_FUNCTION2, TE_FUNCTION3 TE_FUNCTION0, TE_FUNCTION1, TE_FUNCTION2, TE_FUNCTION3,
TOK_NULL, TOK_ERROR, TOK_END, TOK_SEP,
TOK_OPEN, TOK_CLOSE, TOK_NUMBER, TOK_INFIX
}; };
int get_arity(const int type) { int get_arity(const int type) {
@ -49,12 +51,6 @@ int get_arity(const int type) {
return 0; return 0;
} }
// TODO: Is it actually used that these share a space?
enum {
TOK_NULL = TE_FUNCTION0+16, TOK_ERROR, TOK_END, TOK_SEP,
TOK_OPEN, TOK_CLOSE, TOK_NUMBER, TOK_INFIX
};
typedef struct te_expr { typedef struct te_expr {
int type; int type;
union {double value; const void *function;}; union {double value; const void *function;};
@ -465,7 +461,6 @@ double te_eval(const te_expr *n) {
static void optimize(te_expr *n) { static void optimize(te_expr *n) {
/* Evaluates as much as possible. */ /* Evaluates as much as possible. */
if (n->type == TE_CONSTANT) return; if (n->type == TE_CONSTANT) return;
if (n->type == TE_VARIABLE) return;
const int arity = get_arity(n->type); const int arity = get_arity(n->type);
bool known = true; bool known = true;