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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #ifndef DMEVAL_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #define DMEVAL_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 typedef double DMValue;
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
8 #define DMCONVTYPE (int)
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
9 #define DM_MAX_ARGS 8
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
747
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
11
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 {
674
a25d30714cfe Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 670
diff changeset
14 // No-op
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 OP_NONE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 OP_ADD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 OP_SUB,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 OP_MUL,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 OP_DIV,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 OP_MOD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
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
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
26 OP_BIT_LSHIFT,
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
27 OP_BIT_RSHIFT,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
747
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
29 OP_BIT_AND,
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
30 OP_BIT_OR,
faf43d8aa841 Rename some constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 742
diff changeset
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
a25d30714cfe Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 670
diff changeset
38 // Special ops
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 OP_FUNC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 OP_VAR,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 OP_SUBEXPR,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 OP_CONST,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
674
a25d30714cfe Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 670
diff changeset
44 // Total number of operators
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 } DMOperType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
685
f4005431de35 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
56
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 ID_FUNC,
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
60 ID_VAR,
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
61 ID_CVAR,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 } DMEvalIdType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 char *name;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 int type;
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
69 int nargs;
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
70 DMValue (*func)(DMValue arg[DM_MAX_ARGS]);
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
71 DMValue *var, cvalue;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 } DMEvalId;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 typedef struct DMEvalNode
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 {
693
837ad9dcc348 More work on evaluator reordering pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 685
diff changeset
77 BOOL ok;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 int op;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 DMValue val;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 DMEvalId *id;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
82 struct DMEvalNode *args[DM_MAX_ARGS];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 struct DMEvalNode *subexpr, *next, *prev;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 } DMEvalNode;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 BOOL err;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 char *errStr;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 int nids;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 DMEvalId *ids;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 int mode, prev, expect;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 } DMEvalContext;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 DMEvalId *dm_eval_find_id(DMEvalContext *ev, const char *name);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 DMEvalId *dm_eval_add_var(DMEvalContext *ev, const char *name, DMValue *var);
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
101 DMEvalId *dm_eval_add_const(DMEvalContext *ev, const char *name, DMValue value);
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
102 DMEvalId *dm_eval_add_func(DMEvalContext *ev, const char *name, DMValue (*func)(DMValue *), int nargs);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 DMEvalContext *dm_eval_new(void);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 void dm_eval_close(DMEvalContext *ev);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 void dm_eval_free(DMEvalNode *node);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 void dm_eval_clear_err(DMEvalContext *ev);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 int dm_eval_parse_expr(DMEvalContext *ev, char *expr, DMEvalNode **result);
680
4422a1880859 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 679
diff changeset
110 int dm_eval_reorder(DMEvalContext *ev, DMEvalNode *node, DMEvalNode **result);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 int dm_eval_exec(DMEvalContext *ev, DMEvalNode *tree, DMValue *presult);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 #endif // DMEVAL_H