Mercurial > hg > dmlib
annotate dmeval.h @ 740:48c48e94d87f
More work on the evaluator. Still broken, of course.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 22 Apr 2013 09:37:34 +0300 |
parents | f3cab48c6746 |
children | aba7dde79a04 |
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 |
11 enum | |
12 { | |
674 | 13 // No-op |
0 | 14 OP_NONE, |
15 | |
16 OP_ADD, | |
17 OP_SUB, | |
18 OP_MUL, | |
19 OP_DIV, | |
20 OP_MOD, | |
21 | |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
22 OP_SUB_UNARY, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
23 OP_COMPLEMENT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
24 |
0 | 25 OP_LSHIFT, |
26 OP_RSHIFT, | |
27 | |
28 OP_AND, | |
29 OP_OR, | |
30 OP_XOR, | |
740
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
31 |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
32 OP_GT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
33 OP_LT, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
34 OP_GT_EQ, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
35 OP_LT_EQ, |
48c48e94d87f
More work on the evaluator. Still broken, of course.
Matti Hamalainen <ccr@tnsp.org>
parents:
725
diff
changeset
|
36 |
674 | 37 // Special ops |
0 | 38 OP_FUNC, |
39 OP_VAR, | |
40 OP_SUBEXPR, | |
41 OP_CONST, | |
42 | |
674 | 43 // Total number of operators |
0 | 44 OP_NOPERS |
45 } DMOperType; | |
46 | |
685 | 47 |
0 | 48 enum |
49 { | |
50 ID_FUNC, | |
670 | 51 ID_VAR, |
52 ID_CVAR, | |
0 | 53 } DMEvalIdType; |
54 | |
55 | |
56 typedef struct | |
57 { | |
58 char *name; | |
59 int type; | |
670 | 60 int nargs; |
61 DMValue (*func)(DMValue arg[DM_MAX_ARGS]); | |
62 DMValue *var, cvalue; | |
0 | 63 } DMEvalId; |
64 | |
65 | |
66 typedef struct DMEvalNode | |
67 { | |
693
837ad9dcc348
More work on evaluator reordering pass.
Matti Hamalainen <ccr@tnsp.org>
parents:
685
diff
changeset
|
68 BOOL ok; |
0 | 69 int op; |
70 DMValue val; | |
71 DMEvalId *id; | |
72 | |
670 | 73 struct DMEvalNode *args[DM_MAX_ARGS]; |
0 | 74 struct DMEvalNode *subexpr, *next, *prev; |
75 } DMEvalNode; | |
76 | |
77 | |
78 typedef struct | |
79 { | |
80 BOOL err; | |
81 char *errStr; | |
82 | |
83 int nids; | |
84 DMEvalId *ids; | |
85 | |
86 int mode, prev, expect; | |
87 } DMEvalContext; | |
88 | |
89 | |
90 DMEvalId *dm_eval_find_id(DMEvalContext *ev, const char *name); | |
91 DMEvalId *dm_eval_add_var(DMEvalContext *ev, const char *name, DMValue *var); | |
670 | 92 DMEvalId *dm_eval_add_const(DMEvalContext *ev, const char *name, DMValue value); |
93 DMEvalId *dm_eval_add_func(DMEvalContext *ev, const char *name, DMValue (*func)(DMValue *), int nargs); | |
0 | 94 |
95 DMEvalContext *dm_eval_new(void); | |
96 void dm_eval_close(DMEvalContext *ev); | |
97 void dm_eval_free(DMEvalNode *node); | |
98 void dm_eval_clear_err(DMEvalContext *ev); | |
99 | |
100 int dm_eval_parse_expr(DMEvalContext *ev, char *expr, DMEvalNode **result); | |
680 | 101 int dm_eval_reorder(DMEvalContext *ev, DMEvalNode *node, DMEvalNode **result); |
0 | 102 int dm_eval_exec(DMEvalContext *ev, DMEvalNode *tree, DMValue *presult); |
103 | |
104 | |
105 #endif // DMEVAL_H |