annotate dmeval.h @ 742:aba7dde79a04

Add associativity types enum.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 22 Apr 2013 17:00:01 +0300
parents 48c48e94d87f
children faf43d8aa841
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
674
a25d30714cfe Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 670
diff changeset
13 // No-op
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 OP_NONE,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 OP_ADD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 OP_SUB,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 OP_MUL,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 OP_DIV,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 OP_MOD,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 OP_LSHIFT,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 OP_RSHIFT,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 OP_AND,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 OP_OR,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
a25d30714cfe Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 670
diff changeset
37 // Special ops
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 OP_FUNC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 OP_VAR,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 OP_SUBEXPR,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 OP_CONST,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
674
a25d30714cfe Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 670
diff changeset
43 // Total number of operators
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 OP_NOPERS
742
aba7dde79a04 Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents: 740
diff changeset
45 } DMOper;
aba7dde79a04 Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents: 740
diff changeset
46
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 enum
aba7dde79a04 Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents: 740
diff changeset
49 {
aba7dde79a04 Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents: 740
diff changeset
50 OT_LEFT, // Left-associative
aba7dde79a04 Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents: 740
diff changeset
51 OT_RIGHT, // Right-associative
aba7dde79a04 Add associativity types enum.
Matti Hamalainen <ccr@tnsp.org>
parents: 740
diff changeset
52 OT_UNARY,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 } DMOperType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
685
f4005431de35 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 680
diff changeset
55
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 ID_FUNC,
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
59 ID_VAR,
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
60 ID_CVAR,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 } DMEvalIdType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
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 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 char *name;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 int type;
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
68 int nargs;
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
69 DMValue (*func)(DMValue arg[DM_MAX_ARGS]);
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
70 DMValue *var, cvalue;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 } DMEvalId;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
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 typedef struct DMEvalNode
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 {
693
837ad9dcc348 More work on evaluator reordering pass.
Matti Hamalainen <ccr@tnsp.org>
parents: 685
diff changeset
76 BOOL ok;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 int op;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 DMValue val;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 DMEvalId *id;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
670
0d37fe455b86 More work on evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
81 struct DMEvalNode *args[DM_MAX_ARGS];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 struct DMEvalNode *subexpr, *next, *prev;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 } DMEvalNode;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
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 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 BOOL err;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 char *errStr;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 int nids;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 DMEvalId *ids;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 int mode, prev, expect;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 } DMEvalContext;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
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 DMEvalId *dm_eval_find_id(DMEvalContext *ev, const char *name);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 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
100 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
101 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
102
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 DMEvalContext *dm_eval_new(void);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 void dm_eval_close(DMEvalContext *ev);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 void dm_eval_free(DMEvalNode *node);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 void dm_eval_clear_err(DMEvalContext *ev);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 int dm_eval_parse_expr(DMEvalContext *ev, char *expr, DMEvalNode **result);
680
4422a1880859 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 679
diff changeset
109 int dm_eval_reorder(DMEvalContext *ev, DMEvalNode *node, DMEvalNode **result);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 int dm_eval_exec(DMEvalContext *ev, DMEvalNode *tree, DMValue *presult);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
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 #endif // DMEVAL_H