Mercurial > audlegacy
annotate src/audacious/tuple_compiler.c @ 3471:95d8ceb5e1d7 trunk
Automated merge with ssh://hg.atheme.org//hg/audacious
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 09 Sep 2007 22:59:36 +0300 |
parents | 86dafe2300f7 |
children | 9580bb3e58fa |
rev | line source |
---|---|
3409
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * Audacious - Tuplez compiler |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Copyright (c) 2007 Matti 'ccr' Hämäläinen |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 * the Free Software Foundation; under version 3 of the License. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful, |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 * GNU General Public License for more details. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 * along with this program. If not, see <http://www.gnu.org/licenses>. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 * The Audacious team does not consider modular code linking to |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 * Audacious or using our public API to be a derived work. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 /* |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 * What's this? |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 * ------------ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 * Nothing really. A prototype / pseudo-C for an improved Tuple formatting |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 * system, where the format string is "compiled" into a tree structure, |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 * which can then be traversed fast while "evaluating". This file does |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 * not represent anything but some of my (ccr) ideas for the concept. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 * The basic ideas are: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 * 1) compiled structure for faster traversing |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 * 2) sub-expression removal / constant elimination |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 * 3) indexes and/or hashes for tuple entries for faster access |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 * 4) avoid expensive memory re-allocation |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 * and possibly 5) caching of certain things |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 * |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 * TODO: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 * - implement definitions (${=foo,"baz"} ${=foo,1234}) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 * - implement functions |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 * - implement handling of external expressions |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 * - error handling issues? |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 * - evaluation context: how local variables should REALLY work? |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 #include "config.h" |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 #include <assert.h> |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 #include <stdarg.h> |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 #include "tuple_compiler.h" |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 void tuple_error(const char *fmt, ...) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 va_list ap; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 fprintf(stderr, "compiler: "); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 va_start(ap, fmt); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 vfprintf(stderr, fmt, ap); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 va_end(ap); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 exit(5); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 static void tuple_evalctx_free_var(TupleEvalVar *var) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 assert(var != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 g_free(var->defval); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 g_free(var->name); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 g_free(var); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 static void tuple_evalctx_free_function(TupleEvalFunc *func) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 assert(func != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 g_free(func->name); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 g_free(func); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 /* Initialize an evaluation context |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 TupleEvalContext * tuple_evalctx_new(void) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 return g_new0(TupleEvalContext, 1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 /* "Reset" the evaluation context, clean up locally set variables, |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 * but leave globals. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 void tuple_evalctx_reset(TupleEvalContext *ctx) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 gint i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 /* Free local variables */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 for (i = 0; i < ctx->nvariables; i++) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 if (ctx->variables[i]) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 ctx->variables[i]->dictref = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 if (ctx->variables[i]->islocal) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 tuple_evalctx_free_var(ctx->variables[i]); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 /* Free an evaluation context and associated data |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 void tuple_evalctx_free(TupleEvalContext *ctx) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 gint i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 if (!ctx) return; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 /* Deallocate variables */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 for (i = 0; i < ctx->nvariables; i++) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 if (ctx->variables[i]) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 tuple_evalctx_free_var(ctx->variables[i]); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 g_free(ctx->variables); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 /* Deallocate functions */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 for (i = 0; i < ctx->nfunctions; i++) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 if (ctx->functions[i]) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 tuple_evalctx_free_function(ctx->functions[i]); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 g_free(ctx->functions); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 /* Zero context */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 memset(ctx, 0, sizeof(TupleEvalContext)); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 gint tuple_evalctx_add_var(TupleEvalContext *ctx, gchar *name, gboolean islocal, gint type) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 gint i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 TupleEvalVar * tmp = g_new0(TupleEvalVar, 1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 tmp->name = g_strdup(name); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 tmp->islocal = islocal; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 tmp->type = type; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 /* Find a free slot */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 for (i = 0; i < ctx->nvariables; i++) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 if (!ctx->variables[i]) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 ctx->variables[i] = tmp; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 return i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 i = ctx->nvariables; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 ctx->variables = g_renew(TupleEvalVar *, ctx->variables, ctx->nvariables + MIN_ALLOC_NODES); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 memset(&(ctx->variables[ctx->nvariables]), 0, MIN_ALLOC_NODES * sizeof(TupleEvalVar *)); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 ctx->nvariables += MIN_ALLOC_NODES; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 ctx->variables[i] = tmp; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 return i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 gint tuple_evalctx_add_function(TupleEvalContext *ctx, gchar *name) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 assert(ctx != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 assert(name != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 return -1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 static void tuple_evalnode_insert(TupleEvalNode **nodes, TupleEvalNode *node) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 assert(nodes != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 assert(node != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 if (*nodes) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 node->prev = (*nodes)->prev; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 (*nodes)->prev->next = node; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 (*nodes)->prev = node; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 node->next = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 *nodes = node; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 node->prev = node; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 node->next = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 static TupleEvalNode *tuple_evalnode_new(void) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 return g_new0(TupleEvalNode, 1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 void tuple_evalnode_free(TupleEvalNode *expr) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 TupleEvalNode *curr = expr, *next; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 while (curr) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 next = curr->next; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 g_free(curr->text); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 if (curr->children) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 tuple_evalnode_free(curr->children); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 g_free(curr); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 curr = next; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 static TupleEvalNode *tuple_compiler_pass1(gint *level, TupleEvalContext *ctx, gchar **expression); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 static gboolean tc_get_item(gchar **str, gchar *buf, size_t max, gchar endch, gboolean *literal, gchar *errstr, gchar *item) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 size_t i = 0; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 gchar *s = *str, tmpendch; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 assert(str != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 assert(buf != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 if (*s == '"') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 if (*literal == FALSE) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 tuple_error("Literal string value not allowed in '%s'.\n", item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
228 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 s++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 *literal = TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 tmpendch = '"'; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 *literal = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 tmpendch = endch; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 if (*literal == FALSE) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 while (*s != '\0' && *s != tmpendch && (isalnum(*s) || *s == '-') && i < (max - 1)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 buf[i++] = *(s++); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
241 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 if (*s != tmpendch && *s != '}' && !isalnum(*s) && *s != '-') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 tuple_error("Invalid field '%s' in '%s'.\n", *str, item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 } else if (*s != tmpendch) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 tuple_error("Expected '%c' in '%s'.\n", tmpendch, item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
247 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
248 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
249 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 while (*s != '\0' && *s != tmpendch && i < (max - 1)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 if (*s == '\\') s++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 buf[i++] = *(s++); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 buf[i] = '\0'; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
256 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 if (*literal) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 if (*s == tmpendch) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 s++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 tuple_error("Expected literal string end ('%c') in '%s'.\n", tmpendch, item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 if (*s != endch) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 tuple_error("Expected '%c' after %s in '%s'\n", endch, errstr, item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 *str = s; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 return TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 static gint tc_get_variable(TupleEvalContext *ctx, gchar *name, gint type) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 gint i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 if (*name == '\0') return -1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 for (i = 0; i < ctx->nvariables; i++) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 if (ctx->variables[i] && !strcmp(ctx->variables[i]->name, name)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 return i; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 return tuple_evalctx_add_var(ctx, name, FALSE, type); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 static gboolean tc_parse_construct1(TupleEvalContext *ctx, TupleEvalNode **res, gchar *item, gchar **c, gint *level, gint opcode) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 gchar tmps1[MAX_STR], tmps2[MAX_STR]; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 gboolean literal1 = TRUE, literal2 = TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 (*c)++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 if (tc_get_item(c, tmps1, MAX_STR, ',', &literal1, "tag1", item)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 (*c)++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 if (tc_get_item(c, tmps2, MAX_STR, ':', &literal2, "tag2", item)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 TupleEvalNode *tmp = tuple_evalnode_new(); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 (*c)++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 tmp->opcode = opcode; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 if ((tmp->var[0] = tc_get_variable(ctx, tmps1, literal1 ? VAR_CONST : VAR_FIELD)) < 0) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 tuple_evalnode_free(tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 tuple_error("Invalid variable '%s' in '%s'.\n", tmps1, item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
307 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 if ((tmp->var[1] = tc_get_variable(ctx, tmps2, literal2 ? VAR_CONST : VAR_FIELD)) < 0) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 tuple_evalnode_free(tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 tuple_error("Invalid variable '%s' in '%s'.\n", tmps2, item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 tmp->children = tuple_compiler_pass1(level, ctx, c); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 tuple_evalnode_insert(res, tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
318 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
319 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 return TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 /* Compile format expression into TupleEvalNode tree. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 * A "simple" straight compilation is sufficient in first pass, later |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 * passes can perform subexpression removal and other optimizations. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 static TupleEvalNode *tuple_compiler_pass1(gint *level, TupleEvalContext *ctx, gchar **expression) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 TupleEvalNode *res = NULL, *tmp = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 gchar *c = *expression, *item, tmps1[MAX_STR]; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 gboolean literal, end = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
333 assert(ctx != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
334 assert(expression != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 (*level)++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
337 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
338 while (*c != '\0' && !end) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 tmp = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 if (*c == '}') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 (*level)--; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 end = TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 } else if (*c == '$') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 /* Expression? */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 item = c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 if (*c == '{') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 gint opcode; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 gchar *expr = ++c; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
351 switch (*c) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 case '?': c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
353 /* Exists? */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 literal = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 if (tc_get_item(&c, tmps1, MAX_STR, ':', &literal, "tag", item)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
357 tmp = tuple_evalnode_new(); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 tmp->opcode = OP_EXISTS; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 if ((tmp->var[0] = tc_get_variable(ctx, tmps1, VAR_FIELD)) < 0) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 tuple_error("Invalid variable '%s' in '%s'.\n", tmps1, expr); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 tmp->children = tuple_compiler_pass1(level, ctx, &c); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 tuple_evalnode_insert(&res, tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 case '=': c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
370 if (*c != '=') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 /* Definition */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
372 literal = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
373 if (tc_get_item(&c, tmps1, MAX_STR, ',', &literal, "variable", item)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
374 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 if (*c == '"') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 /* String */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
378 } else if (isdigit(*c)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
379 /* Integer */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
380 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 tuple_error("definitions not yet supported!\n"); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 /* Equals? */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 if (!tc_parse_construct1(ctx, &res, item, &c, level, OP_EQUALS)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
389 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
390 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 case '!': c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 if (*c != '=') goto ext_expression; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 if (!tc_parse_construct1(ctx, &res, item, &c, level, OP_NOT_EQUALS)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 case '<': c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 if (*c == '=') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 opcode = OP_LTEQ; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
404 opcode = OP_LT; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
406 if (!tc_parse_construct1(ctx, &res, item, &c, level, opcode)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
407 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
409 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
410 case '>': c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
411 if (*c == '=') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
412 opcode = OP_GTEQ; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
413 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
415 opcode = OP_GT; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
416 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
417 if (!tc_parse_construct1(ctx, &res, item, &c, level, opcode)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
420 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
421 case '(': c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
422 if (!strncmp(c, "empty)?", 7)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
423 c += 7; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
424 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
425 goto ext_expression; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
426 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
427 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
428 default: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 ext_expression: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 /* Get expression content */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 c = expr; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 literal = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
433 if (tc_get_item(&c, tmps1, MAX_STR, '}', &literal, "field", item)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 /* FIXME!! FIX ME! Check for external expressions */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 /* I HAS A FIELD - A field. You has it. */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 tmp = tuple_evalnode_new(); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 tmp->opcode = OP_FIELD; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 if ((tmp->var[0] = tc_get_variable(ctx, tmps1, VAR_FIELD)) < 0) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 tuple_error("Invalid variable '%s' in '%s'.\n", tmps1, expr); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
442 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 tuple_evalnode_insert(&res, tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
444 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
445 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 } else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
447 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
448 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
450 tuple_error("Expected '{', got '%c' in '%s'.\n", *c, c); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
451 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
454 } else if (*c == '%') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
455 /* Function? */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
456 item = c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
457 if (*c == '{') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
458 size_t i = 0; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 while (*c != '\0' && (isalnum(*c) || *c == '-') && *c != '}' && *c != ':' && i < (MAX_STR - 1)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
462 tmps1[i++] = *(c++); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 tmps1[i] = '\0'; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
465 if (*c == ':') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
466 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
467 } else if (*c == '}') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
468 c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
469 } else if (*c == '\0') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 tuple_error("Expected '}' or function arguments in '%s'\n", item); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 tuple_error("Expected '{', got '%c' in '%s'.\n", *c, c); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 /* Parse raw/literal text */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
479 size_t i = 0; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
480 while (*c != '\0' && *c != '$' && *c != '%' && *c != '}' && i < (MAX_STR - 1)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
481 if (*c == '\\') c++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
482 tmps1[i++] = *(c++); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
483 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
484 tmps1[i] = '\0'; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
485 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
486 tmp = tuple_evalnode_new(); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
487 tmp->opcode = OP_RAW; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
488 tmp->text = g_strdup(tmps1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 tuple_evalnode_insert(&res, tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
490 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
491 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
492 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
493 if (*level <= 0) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
494 tuple_error("Syntax error! Uneven/unmatched nesting of elements in '%s'!\n", c); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
495 goto ret_error; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
496 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
497 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
498 *expression = c; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
499 return res; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
500 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
501 ret_error: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
502 tuple_evalnode_free(tmp); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
503 tuple_evalnode_free(res); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
504 return NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
505 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
506 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
507 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
508 static TupleEvalNode *tuple_compiler_pass2(gboolean *changed, TupleEvalContext *ctx, TupleEvalNode *expr) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
509 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
510 TupleEvalNode *curr = expr, *res = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
511 *changed = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
512 assert(ctx != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 assert(expr != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
515 return res; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
516 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
517 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
518 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
519 TupleEvalNode *tuple_formatter_compile(TupleEvalContext *ctx, gchar *expr) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
521 gint level = 0; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
522 gboolean changed = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
523 gchar *tmpexpr = expr; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
524 TupleEvalNode *res1, *res2; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
525 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
526 res1 = tuple_compiler_pass1(&level, ctx, &tmpexpr); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
527 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
528 if (level != 1) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
529 tuple_error("Syntax error! Uneven/unmatched nesting of elements! (%d)\n", level); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 tuple_evalnode_free(res1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 return NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
532 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
533 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
534 res2 = tuple_compiler_pass2(&changed, ctx, res1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
536 if (changed) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
537 tuple_evalnode_free(res1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 return res2; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
539 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 tuple_evalnode_free(res2); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
541 return res1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
542 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
543 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
546 /* Evaluate tuple in given TupleEval expression in given |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 * context and return resulting string. |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
548 */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 static TupleValue * tf_get_dictref(TupleEvalVar *var, Tuple *tuple) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
551 if (var->type == VAR_FIELD && var->dictref == NULL) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
552 var->dictref = mowgli_dictionary_retrieve(tuple->dict, var->name); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
553 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
554 return var->dictref; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
555 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
556 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
557 static TupleValueType tf_get_var(gchar **tmps, gint *tmpi, TupleEvalVar *var, Tuple *tuple) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
558 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
559 TupleValueType type = TUPLE_UNKNOWN; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
560 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
561 switch (var->type) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
562 case VAR_DEF: *tmps = var->defval; type = TUPLE_STRING; break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
563 case VAR_CONST: *tmps = var->name; type = TUPLE_STRING; break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
564 case VAR_FIELD: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
565 if (tf_get_dictref(var, tuple)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
566 if (var->dictref->type == TUPLE_STRING) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
567 *tmps = var->dictref->value.string; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
568 else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
569 *tmpi = var->dictref->value.integer; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
570 type = var->dictref->type; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
571 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
572 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
573 default: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
574 tmps = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
575 tmpi = 0; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
576 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
577 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
578 return type; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
579 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
580 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
581 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
582 static gboolean tuple_formatter_eval_do(TupleEvalContext *ctx, TupleEvalNode *expr, Tuple *tuple, gchar **res, size_t *resmax, size_t *reslen) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
583 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
584 TupleEvalNode *curr = expr; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
585 gchar tmps[MAX_STR], *tmps2; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
586 gboolean result; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
587 gint resulti; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
588 TupleEvalVar *var0, *var1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
589 gint tmpi0, tmpi1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
590 gchar *tmps0, *tmps1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
591 TupleValueType type0, type1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
592 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
593 if (!expr) return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
594 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
595 while (curr) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
596 const gchar *str = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
597 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
598 switch (curr->opcode) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
599 case OP_RAW: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
600 str = curr->text; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
601 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
602 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
603 case OP_FIELD: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
604 var0 = ctx->variables[curr->var[0]]; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
605 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
606 switch (var0->type) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
607 case VAR_DEF: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
608 str = var0->defval; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
609 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
610 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
611 case VAR_FIELD: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
612 if (tf_get_dictref(var0, tuple)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
613 switch (var0->dictref->type) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
614 case TUPLE_STRING: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
615 str = var0->dictref->value.string; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
616 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
617 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
618 case TUPLE_INT: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
619 snprintf(tmps, sizeof(tmps), "%d", var0->dictref->value.integer); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
620 str = tmps; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
621 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
622 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
623 default: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
624 str = NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
625 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
626 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
627 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
628 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
629 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
630 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
631 case OP_EXISTS: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
632 if (mowgli_dictionary_retrieve(tuple->dict, ctx->variables[curr->var[0]]->name)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
633 if (!tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
634 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
635 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
636 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
637 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
638 case OP_EQUALS: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
639 case OP_NOT_EQUALS: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
640 case OP_LT: case OP_LTEQ: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
641 case OP_GT: case OP_GTEQ: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
642 var0 = ctx->variables[curr->var[0]]; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
643 var1 = ctx->variables[curr->var[1]]; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
644 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
645 type0 = tf_get_var(&tmps0, &tmpi0, var0, tuple); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
646 type1 = tf_get_var(&tmps1, &tmpi1, var1, tuple); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
647 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
648 if (type0 == type1) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
649 if (type0 == TUPLE_STRING) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
650 resulti = strcmp(tmps0, tmps1); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
651 else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
652 resulti = tmpi0 - tmpi1; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
653 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
654 switch (curr->opcode) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
655 case OP_EQUALS: result = (resulti == 0); break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
656 case OP_NOT_EQUALS: result = (resulti != 0); break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
657 case OP_LT: result = (resulti < 0); break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
658 case OP_LTEQ: result = (resulti <= 0); break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
659 case OP_GT: result = (resulti > 0); break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
660 case OP_GTEQ: result = (resulti >= 0); break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
661 default: result = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
662 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
663 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
664 if (result && !tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
665 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
666 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
667 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
668 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
669 case OP_IS_EMPTY: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
670 var0 = ctx->variables[curr->var[0]]; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
671 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
672 if (var0->dictref == NULL) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
673 var0->dictref = mowgli_dictionary_retrieve(tuple->dict, var0->name); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
674 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
675 switch (var0->dictref->type) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
676 case TUPLE_INT: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
677 result = (var0->dictref->value.integer == 0); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
678 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
679 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
680 case TUPLE_STRING: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
681 result = TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
682 tmps2 = var0->dictref->value.string; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
683 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
684 while (result && *tmps2 != '\0') { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
685 if (*tmps2 == ' ') |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
686 tmps2++; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
687 else |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
688 result = FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
689 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
690 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
691 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
692 default: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
693 result = TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
694 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
696 if (result) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
697 if (!tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen)) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
698 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
699 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
700 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
701 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
702 default: |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
703 tuple_error("Unimplemented opcode %d!\n", curr->opcode); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
704 return FALSE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
705 break; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
706 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
708 if (str) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
709 /* (Re)allocate res for more space, if needed. */ |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
710 *reslen += strlen(str); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
711 if (*res) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
712 if (*reslen >= *resmax) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
713 *resmax += MIN_ALLOC_BUF; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
714 *res = g_realloc(*res, *resmax); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
715 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
716 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 strcat(*res, str); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
718 } else { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
719 *resmax = *reslen + MIN_ALLOC_BUF; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
720 *res = g_malloc(*resmax); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
721 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
722 strcpy(*res, str); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
723 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
724 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
725 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 curr = curr->next; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
727 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
729 return TRUE; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
730 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
731 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
732 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
733 gchar *tuple_formatter_eval(TupleEvalContext *ctx, TupleEvalNode *expr, Tuple *tuple) |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
734 { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
735 gchar *res = g_strdup(""); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 size_t resmax = 0, reslen = 0; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 assert(ctx != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 assert(tuple != NULL); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
739 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
740 if (!expr) return NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
741 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
742 if (!tuple_formatter_eval_do(ctx, expr, tuple, &res, &resmax, &reslen)) { |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
743 g_free(res); |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
744 return NULL; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
745 } |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
746 |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
747 return res; |
86dafe2300f7
Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
748 } |