Mercurial > hg > dmlib
annotate dmeval.h @ 747:faf43d8aa841
Rename some constants.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 04 May 2013 05:32:52 +0300 |
parents | aba7dde79a04 |
children | 7be7c7c5deaa |
rev | line source |
---|---|
0 | 1 #ifndef DMEVAL_H |
2 #define DMEVAL_H | |
3 | |
4 #include "dmlib.h" | |
5 | |
6 | |
7 typedef double DMValue; | |
670 | 8 #define DMCONVTYPE (int) |
9 #define DM_MAX_ARGS 8 | |
0 | 10 |
747 | 11 |
0 | 12 enum |
13 { | |
674 | 14 // No-op |
0 | 15 OP_NONE, |
16 | |
17 OP_ADD, | |
18 OP_SUB, | |
19 OP_MUL, | |
20 OP_DIV, | |
21 OP_MOD, | |
22 | |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
23 OP_SUB_UNARY, |
747 | 24 OP_BIT_COMPLEMENT, |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
25 |
747 | 26 OP_BIT_LSHIFT, |
27 OP_BIT_RSHIFT, | |
0 | 28 |
747 | 29 OP_BIT_AND, |
30 OP_BIT_OR, | |
31 OP_BIT_XOR, | |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
32 |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
33 OP_GT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
34 OP_LT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
35 OP_GT_EQ, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
36 OP_LT_EQ, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
37 |
674 | 38 // Special ops |
0 | 39 OP_FUNC, |
40 OP_VAR, | |
41 OP_SUBEXPR, | |
42 OP_CONST, | |
43 | |
674 | 44 // Total number of operators |
0 | 45 OP_NOPERS |
742
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
46 } DMOper; |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
47 |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
48 |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
49 enum |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
50 { |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
51 OT_LEFT, // Left-associative |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
52 OT_RIGHT, // Right-associative |
aba7dde79a04
Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents:
740
diff
changeset
|
53 OT_UNARY, |
0 | 54 } DMOperType; |
55 | |
685 | 56 |
0 | 57 enum |
58 { | |
59 ID_FUNC, | |
670 | 60 ID_VAR, |
61 ID_CVAR, | |
0 | 62 } DMEvalIdType; |
63 | |
64 | |
65 typedef struct | |
66 { | |
67 char *name; | |
68 int type; | |
670 | 69 int nargs; |
70 DMValue (*func)(DMValue arg[DM_MAX_ARGS]); | |
71 DMValue *var, cvalue; | |
0 | 72 } DMEvalId; |
73 | |
74 | |
75 typedef struct DMEvalNode | |
76 { | |
693
837ad9dcc348
More work on evaluator reordering pass.
Matti Hamalainen <ccr@tnsp.org>
parents:
685
diff
changeset
|
77 BOOL ok; |
0 | 78 int op; |
79 DMValue val; | |
80 DMEvalId *id; | |
81 | |
670 | 82 struct DMEvalNode *args[DM_MAX_ARGS]; |
0 | 83 struct DMEvalNode *subexpr, *next, *prev; |
84 } DMEvalNode; | |
85 | |
86 | |
87 typedef struct | |
88 { | |
89 BOOL err; | |
90 char *errStr; | |
91 | |
92 int nids; | |
93 DMEvalId *ids; | |
94 | |
95 int mode, prev, expect; | |
96 } DMEvalContext; | |
97 | |
98 | |
99 DMEvalId *dm_eval_find_id(DMEvalContext *ev, const char *name); | |
100 DMEvalId *dm_eval_add_var(DMEvalContext *ev, const char *name, DMValue *var); | |
670 | 101 DMEvalId *dm_eval_add_const(DMEvalContext *ev, const char *name, DMValue value); |
102 DMEvalId *dm_eval_add_func(DMEvalContext *ev, const char *name, DMValue (*func)(DMValue *), int nargs); | |
0 | 103 |
104 DMEvalContext *dm_eval_new(void); | |
105 void dm_eval_close(DMEvalContext *ev); | |
106 void dm_eval_free(DMEvalNode *node); | |
107 void dm_eval_clear_err(DMEvalContext *ev); | |
108 | |
109 int dm_eval_parse_expr(DMEvalContext *ev, char *expr, DMEvalNode **result); | |
680 | 110 int dm_eval_reorder(DMEvalContext *ev, DMEvalNode *node, DMEvalNode **result); |
0 | 111 int dm_eval_exec(DMEvalContext *ev, DMEvalNode *tree, DMValue *presult); |
112 | |
113 | |
114 #endif // DMEVAL_H |