annotate src/audlegacy/tuple_compiler.c @ 4862:7ec3621a9f9b

We only need the results of the stat once, do not bother with a variable at all. From code analysis, unique ID uYRsrf.
author Tony Vroon <chainsaw@gentoo.org>
date Sun, 19 Apr 2009 23:26:48 +0100
parents 7bf7f83a217e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3837
047bf3ed21b2 Use UTF-8 for my name. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 3825
diff changeset
3 * Copyright (c) 2007 Matti 'ccr' Hämäläinen
3409
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 * TODO:
3822
c597262d6d50 Add a TODO note about the UTF-8/Unicode problems with within Tuplez
Matti Hamalainen <ccr@tnsp.org>
parents: 3818
diff changeset
23 * - Unicode/UTF-8 support in format strings. using any non-ASCII
c597262d6d50 Add a TODO note about the UTF-8/Unicode problems with within Tuplez
Matti Hamalainen <ccr@tnsp.org>
parents: 3818
diff changeset
24 * characters in Tuplez format strings WILL cause things go boom
c597262d6d50 Add a TODO note about the UTF-8/Unicode problems with within Tuplez
Matti Hamalainen <ccr@tnsp.org>
parents: 3818
diff changeset
25 * at the moment!
c597262d6d50 Add a TODO note about the UTF-8/Unicode problems with within Tuplez
Matti Hamalainen <ccr@tnsp.org>
parents: 3818
diff changeset
26 *
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 * - 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
28 * - implement functions
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 * - 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
30 * - evaluation context: how local variables should REALLY work?
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
31 * currently there is just a single context, is a "global" context needed?
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #include "config.h"
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #include <assert.h>
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 #include <stdarg.h>
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #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
38
3792
f31e93cd8f2f Make some #defines private.
Matti Hamalainen <ccr@tnsp.org>
parents: 3789
diff changeset
39 #define MAX_STR (256)
f31e93cd8f2f Make some #defines private.
Matti Hamalainen <ccr@tnsp.org>
parents: 3789
diff changeset
40 #define MIN_ALLOC_NODES (8)
f31e93cd8f2f Make some #defines private.
Matti Hamalainen <ccr@tnsp.org>
parents: 3789
diff changeset
41 #define MIN_ALLOC_BUF (64)
f31e93cd8f2f Make some #defines private.
Matti Hamalainen <ccr@tnsp.org>
parents: 3789
diff changeset
42
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
3812
80996bb4213f Use gchar.
Matti Hamalainen <ccr@tnsp.org>
parents: 3811
diff changeset
44 void tuple_error(TupleEvalContext *ctx, const gchar *fmt, ...)
3409
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 va_list ap;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
47 g_free(ctx->errmsg);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 va_start(ap, fmt);
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
49 ctx->errmsg = g_strdup_vprintf(fmt, ap);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 va_end(ap);
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
51 ctx->iserror = TRUE;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 }
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 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
56 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 assert(var != NULL);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
58 var->fieldidx = -1;
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
59 g_free(var->defvals);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 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
61 g_free(var);
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
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 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
66 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 assert(func != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 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
70 g_free(func);
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 /* 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
75 */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 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
77 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 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
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
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
82 /* "Reset" the evaluation context, clean up temporary variables.
3409
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 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
85 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 gint i;
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 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
89 if (ctx->variables[i]) {
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
90 ctx->variables[i]->fieldref = NULL;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
92 if (ctx->variables[i]->istemp)
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 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
94 }
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
95
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
96 ctx->iserror = FALSE;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 /* 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
101 */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 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
103 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 gint i;
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 if (!ctx) return;
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 /* Deallocate variables */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 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
110 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
111 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
112
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 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
114
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 /* Deallocate functions */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 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
117 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
118 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
119
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 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
121
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 /* Zero context */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 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
124 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
127 gint tuple_evalctx_add_var(TupleEvalContext *ctx, const gchar *name, const gboolean istemp, const gint type, const TupleValueType ctype)
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
129 gint i, ref = -1;
3811
61b2da934f95 Assert that new data is not NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 3810
diff changeset
130 TupleEvalVar *tmp = g_new0(TupleEvalVar, 1);
61b2da934f95 Assert that new data is not NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 3810
diff changeset
131 assert(tmp != NULL);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 tmp->name = g_strdup(name);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
134 tmp->istemp = istemp;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 tmp->type = type;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
136 tmp->fieldidx = ref;
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
137 tmp->ctype = ctype;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
138
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
139 /* Find fieldidx, if any */
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
140 switch (type) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
141 case VAR_FIELD:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
142 for (i = 0; i < FIELD_LAST && ref < 0; i++)
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
143 if (strcmp(tuple_fields[i].name, name) == 0) ref = i;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
144
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
145 tmp->fieldidx = ref;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
146 break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
147
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
148 case VAR_CONST:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
149 if (ctype == TUPLE_INT)
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
150 tmp->defvali = atoi(name);
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
151 break;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
152 }
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
153
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 /* 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
155 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
156 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
157 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
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 i = ctx->nvariables;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 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
163 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
164 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
165 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
166
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 return i;
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 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
172 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 assert(ctx != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 assert(name != 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 return -1;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 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
181 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 assert(nodes != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 assert(node != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 if (*nodes) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 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
187 (*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
188 (*nodes)->prev = node;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 node->next = NULL;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 *nodes = node;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 node->prev = node;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 node->next = NULL;
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 }
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 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
199 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 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
201 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
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 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
205 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 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
207
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 while (curr) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 next = 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 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
212
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 if (curr->children)
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 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
215
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 g_free(curr);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 curr = next;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 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
224
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
226 static gboolean tc_get_item(TupleEvalContext *ctx,
3813
a8950cdd2041 Use gssize instead of size_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 3812
diff changeset
227 gchar **str, gchar *buf, gssize max,
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
228 gchar endch, gboolean *literal, gchar *errstr, gchar *item)
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 {
3813
a8950cdd2041 Use gssize instead of size_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 3812
diff changeset
230 gssize i = 0;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 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
232 assert(str != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 assert(buf != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 if (*s == '"') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 if (*literal == FALSE) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
237 tuple_error(ctx, "Literal string value not allowed in '%s'.\n", item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 s++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 *literal = TRUE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 tmpendch = '"';
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 *literal = FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 tmpendch = endch;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 if (*literal == FALSE) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 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
250 buf[i++] = *(s++);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 if (*s != tmpendch && *s != '}' && !isalnum(*s) && *s != '-') {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
254 tuple_error(ctx, "Invalid field '%s' in '%s'.\n", *str, item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 } else if (*s != tmpendch) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
257 tuple_error(ctx, "Expected '%c' in '%s'.\n", tmpendch, item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 }
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 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
262 if (*s == '\\') s++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 buf[i++] = *(s++);
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 buf[i] = '\0';
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 if (*literal) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 if (*s == tmpendch)
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 s++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 else {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
272 tuple_error(ctx, "Expected literal string end ('%c') in '%s'.\n", tmpendch, item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 return FALSE;
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 if (*s != endch) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
278 tuple_error(ctx, "Expected '%c' after %s in '%s'\n", endch, errstr, item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 *str = s;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 return TRUE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 }
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 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
288 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 gint i;
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
290 TupleValueType ctype = TUPLE_UNKNOWN;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
292 if (name == '\0') return -1;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
293
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
294 if (isdigit(name[0])) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
295 ctype = TUPLE_INT;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
296 type = VAR_CONST;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
297 } else
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
298 ctype = TUPLE_STRING;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
300 if (type != VAR_CONST) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
301 for (i = 0; i < ctx->nvariables; i++)
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
302 if (ctx->variables[i] && !strcmp(ctx->variables[i]->name, name))
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
303 return i;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
304 }
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
305
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
306 return tuple_evalctx_add_var(ctx, name, FALSE, type, ctype);
3409
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
310 static gboolean tc_parse_construct(TupleEvalContext *ctx, TupleEvalNode **res, gchar *item, gchar **c, gint *level, gint opcode)
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 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
313 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
314
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 (*c)++;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
316 if (tc_get_item(ctx, c, tmps1, MAX_STR, ',', &literal1, "tag1", item)) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 (*c)++;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
318 if (tc_get_item(ctx, c, tmps2, MAX_STR, ':', &literal2, "tag2", item)) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 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
320 (*c)++;
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 tmp->opcode = opcode;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 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
324 tuple_evalnode_free(tmp);
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
325 tuple_error(ctx, "Invalid variable '%s' in '%s'.\n", tmps1, item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 return FALSE;
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 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
329 tuple_evalnode_free(tmp);
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
330 tuple_error(ctx, "Invalid variable '%s' in '%s'.\n", tmps2, item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 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
334 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
335 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 return TRUE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 /* 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
345 * 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
346 * 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
347 */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 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
349 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 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
351 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
352 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
353 assert(ctx != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 assert(expression != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 (*level)++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 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
359 tmp = NULL;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 if (*c == '}') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 (*level)--;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 end = TRUE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 } else if (*c == '$') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 /* Expression? */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 item = c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 if (*c == '{') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 gint opcode;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 gchar *expr = ++c;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 switch (*c) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 case '?': c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 /* Exists? */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 literal = FALSE;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
375 if (tc_get_item(ctx, &c, tmps1, MAX_STR, ':', &literal, "tag", item)) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 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
378 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
379 if ((tmp->var[0] = tc_get_variable(ctx, tmps1, VAR_FIELD)) < 0) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
380 tuple_error(ctx, "Invalid variable '%s' in '%s'.\n", tmps1, expr);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 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
384 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
385 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 case '=': c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 if (*c != '=') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 /* Definition */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 literal = FALSE;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
393 if (tc_get_item(ctx, &c, tmps1, MAX_STR, ',', &literal, "variable", item)) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 if (*c == '"') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 /* String */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 } 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
399 /* Integer */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
402 tuple_error(ctx, "Definitions are not yet supported!\n");
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 /* Equals? */
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
408 if (!tc_parse_construct(ctx, &res, item, &c, level, OP_EQUALS))
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 case '!': c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 if (*c != '=') goto ext_expression;
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
415 if (!tc_parse_construct(ctx, &res, item, &c, level, OP_NOT_EQUALS))
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 case '<': c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 if (*c == '=') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 opcode = OP_LTEQ;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 opcode = OP_LT;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
426 if (!tc_parse_construct(ctx, &res, item, &c, level, opcode))
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 case '>': c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 if (*c == '=') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 opcode = OP_GTEQ;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 opcode = OP_GT;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
437 if (!tc_parse_construct(ctx, &res, item, &c, level, opcode))
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 case '(': c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 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
443 c += 7;
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
444 literal = FALSE;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
445 if (tc_get_item(ctx, &c, tmps1, MAX_STR, ':', &literal, "tag", item)) {
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
446 c++;
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
447 tmp = tuple_evalnode_new();
3983
c4295265f61d Ooooops, another stupid bug - accidentally ${(empty)?..} was compiled into
Matti Hamalainen <ccr@tnsp.org>
parents: 3954
diff changeset
448 tmp->opcode = OP_IS_EMPTY;
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
449 if ((tmp->var[0] = tc_get_variable(ctx, tmps1, VAR_FIELD)) < 0) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
450 tuple_error(ctx, "Invalid variable '%s' in '%s'.\n", tmps1, expr);
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
451 goto ret_error;
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
452 }
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
453 tmp->children = tuple_compiler_pass1(level, ctx, &c);
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
454 tuple_evalnode_insert(&res, tmp);
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
455 } else
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
456 goto ret_error;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 goto ext_expression;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 break;
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 default:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 ext_expression:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 /* Get expression content */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 c = expr;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 literal = FALSE;
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
466 if (tc_get_item(ctx, &c, tmps1, MAX_STR, '}', &literal, "field", item)) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 /* 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
468
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 /* 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
470 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
471 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
472 if ((tmp->var[0] = tc_get_variable(ctx, tmps1, VAR_FIELD)) < 0) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
473 tuple_error(ctx, "Invalid variable '%s' in '%s'.\n", tmps1, expr);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 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
477 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 } else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 } else {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
483 tuple_error(ctx, "Expected '{', got '%c' in '%s'.\n", *c, c);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 goto ret_error;
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
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 } else if (*c == '%') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 /* Function? */
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 item = c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 if (*c == '{') {
3813
a8950cdd2041 Use gssize instead of size_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 3812
diff changeset
491 gssize i = 0;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 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
495 tmps1[i++] = *(c++);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 tmps1[i] = '\0';
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 if (*c == ':') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 } else if (*c == '}') {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 } else if (*c == '\0') {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
503 tuple_error(ctx, "Expected '}' or function arguments in '%s'\n", item);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 goto ret_error;
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 } else {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
507 tuple_error(ctx, "Expected '{', got '%c' in '%s'.\n", *c, c);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 goto ret_error;
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 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 /* Parse raw/literal text */
3813
a8950cdd2041 Use gssize instead of size_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 3812
diff changeset
512 gssize i = 0;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 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
514 if (*c == '\\') c++;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 tmps1[i++] = *(c++);
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 tmps1[i] = '\0';
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 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
520 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
521 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
522 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
523 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 }
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 if (*level <= 0) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
527 tuple_error(ctx, "Syntax error! Uneven/unmatched nesting of elements in '%s'!\n", c);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 goto ret_error;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 *expression = c;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 return res;
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 ret_error:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 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
536 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
537 return NULL;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 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
542 {
3693
13bd2580ec18 Fix two gcc warnings.
Jonathan Schleifer <js@h3c.de>
parents: 3498
diff changeset
543 /* TupleEvalNode *curr = expr; */
13bd2580ec18 Fix two gcc warnings.
Jonathan Schleifer <js@h3c.de>
parents: 3498
diff changeset
544 TupleEvalNode *res = NULL;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 assert(ctx != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 return res;
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
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 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
552 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 gint level = 0;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 gboolean changed = FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 gchar *tmpexpr = expr;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 TupleEvalNode *res1, *res2;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 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
559
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 if (level != 1) {
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
561 tuple_error(ctx, "Syntax error! Uneven/unmatched nesting of elements! (%d)\n", level);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 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
563 return NULL;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 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
567
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 if (changed) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 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
570 return res2;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 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
573 return res1;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 }
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
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
578 /* Fetch a reference to a tuple field for given variable by fieldidx or dict.
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
579 * Return pointer to field, NULL if not available.
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 */
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
581 static TupleValue * tf_get_fieldref(TupleEvalVar *var, Tuple *tuple)
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 {
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
583 if (var->type == VAR_FIELD && var->fieldref == NULL) {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
584 if (var->fieldidx < 0)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
585 var->fieldref = mowgli_dictionary_retrieve(tuple->dict, var->name);
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
586 else
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
587 var->fieldref = tuple->values[var->fieldidx];
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
588 }
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
590 return var->fieldref;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
593
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
594 /* Fetch string or int value of given variable, whatever type it might be.
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
595 * Return VAR_* type for the variable.
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
596 */
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 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
598 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 TupleValueType type = TUPLE_UNKNOWN;
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
600 *tmps = NULL;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
601 *tmpi = 0;
3409
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 switch (var->type) {
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
604 case VAR_DEF:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
605 switch (var->ctype) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
606 case TUPLE_STRING: *tmps = var->defvals; break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
607 case TUPLE_INT: *tmpi = var->defvali; break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
608 default: /* Possible, but should be prevented elsewhere */ break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
609 }
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
610 type = var->ctype;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
611 break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
612
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
613 case VAR_CONST:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
614 switch (var->ctype) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
615 case TUPLE_STRING: *tmps = var->name; break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
616 case TUPLE_INT: *tmpi = var->defvali; break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
617 default: /* Cannot happen */ break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
618 }
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
619 type = var->ctype;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
620 break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
621
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 case VAR_FIELD:
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
623 if (tf_get_fieldref(var, tuple)) {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
624 if (var->fieldref->type == TUPLE_STRING)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
625 *tmps = var->fieldref->value.string;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 else
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
627 *tmpi = var->fieldref->value.integer;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
628 type = var->fieldref->type;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 return type;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 }
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
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
637 /* Evaluate tuple in given TupleEval expression in given
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
638 * context and return resulting string.
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
639 */
3813
a8950cdd2041 Use gssize instead of size_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 3812
diff changeset
640 static gboolean tuple_formatter_eval_do(TupleEvalContext *ctx, TupleEvalNode *expr, Tuple *tuple, gchar **res, gssize *resmax, gssize *reslen)
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 TupleEvalNode *curr = expr;
3815
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
643 TupleEvalVar *var0, *var1;
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
644 TupleValueType type0, type1;
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
645 gint tmpi0, tmpi1;
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
646 gchar tmps[MAX_STR], *tmps0, *tmps1, *tmps2;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 gboolean result;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 gint resulti;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 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
651
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 while (curr) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 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
654
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 switch (curr->opcode) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656 case OP_RAW:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 str = curr->text;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 case OP_FIELD:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 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
662
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 switch (var0->type) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 case VAR_DEF:
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
665 switch (var0->ctype) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
666 case TUPLE_STRING:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
667 str = var0->defvals;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
668 break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
669
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
670 case TUPLE_INT:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
671 g_snprintf(tmps, sizeof(tmps), "%d", var0->defvali);
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
672 str = tmps;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
673 break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
674
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
675 default:
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
676 break;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
677 }
3409
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 VAR_FIELD:
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
681 if (tf_get_fieldref(var0, tuple)) {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
682 switch (var0->fieldref->type) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 case TUPLE_STRING:
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
684 str = var0->fieldref->value.string;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 case TUPLE_INT:
3816
aad4dc862bc7 Use g_snprintf()
Matti Hamalainen <ccr@tnsp.org>
parents: 3815
diff changeset
688 g_snprintf(tmps, sizeof(tmps), "%d", var0->fieldref->value.integer);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 str = tmps;
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 str = NULL;
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 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 break;
3825
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
699
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 case OP_EQUALS:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 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
702 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
703 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
704 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
705 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
706
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 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
708 type1 = tf_get_var(&tmps1, &tmpi1, var1, tuple);
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
709 result = FALSE;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
711 if (type0 != TUPLE_UNKNOWN && type1 != TUPLE_UNKNOWN) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
712 if (type0 == type1) {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
713 if (type0 == TUPLE_STRING)
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
714 resulti = strcmp(tmps0, tmps1);
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
715 else
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
716 resulti = tmpi0 - tmpi1;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
717 } else {
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
718 if (type0 == TUPLE_INT)
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
719 resulti = tmpi0 - atoi(tmps1);
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
720 else
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
721 resulti = atoi(tmps0) - tmpi1;
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
722 }
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
723
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 switch (curr->opcode) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 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
726 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
727 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
728 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
729 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
730 case OP_GTEQ: result = (resulti >= 0); break;
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
731 default: result = FALSE;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 }
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
733 }
3815
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
734
3954
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
735 if (result && !tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
7afbcd87cd65 The compiler should now correctly recognize integer constants, thanks to
Matti Hamalainen <ccr@tnsp.org>
parents: 3837
diff changeset
736 return FALSE;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738
3825
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
739 case OP_EXISTS:
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
740 #ifdef NO_EXISTS_HACK
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
741 if (tf_get_fieldref(ctx->variables[curr->var[0]], tuple)) {
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
742 if (!tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
743 return FALSE;
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
744 }
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
745 break;
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
746 #endif
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
747
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 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
749 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
750
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
751 if (tf_get_fieldref(var0, tuple)) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
753 switch (var0->fieldref->type) {
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 case TUPLE_INT:
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
755 result = (var0->fieldref->value.integer == 0);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 case TUPLE_STRING:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759 result = TRUE;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
760 tmps2 = var0->fieldref->value.string;
3815
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
761
3824
9ecd41c7f348 Check for NULL strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 3823
diff changeset
762 while (result && tmps2 && *tmps2 != '\0') {
3817
5ea2431c12bf Handle Unicode/UTF-8 in tuple data.
Matti Hamalainen <ccr@tnsp.org>
parents: 3816
diff changeset
763 gunichar uc = g_utf8_get_char(tmps2);
5ea2431c12bf Handle Unicode/UTF-8 in tuple data.
Matti Hamalainen <ccr@tnsp.org>
parents: 3816
diff changeset
764 if (g_unichar_isspace(uc))
3823
860392c82b29 Fix the UTF-8 handling of tuple (empty)? check.
Matti Hamalainen <ccr@tnsp.org>
parents: 3822
diff changeset
765 tmps2 = g_utf8_next_char(tmps2);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766 else
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 result = FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 break;
3815
e17726ffadbb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 3813
diff changeset
770
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 default:
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 result = TRUE;
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
773 }
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
774 } else
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
775 result = TRUE;
3825
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
776
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
777 #ifdef NO_EXISTS_HACK
3495
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
778 if (result && !tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
174e9c75bb24 Miscellaneous code cleanups; Support "(empty)?" expression.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
779 return FALSE;
3825
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
780 #else
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
781 if ((curr->opcode == OP_EXISTS && !result) || (curr->opcode == OP_IS_EMPTY && result)) {
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
782 if (!tuple_formatter_eval_do(ctx, curr->children, tuple, res, resmax, reslen))
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
783 return FALSE;
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
784 }
2fa6737082ae Made ${?..:} (OP_EXISTS) work as reverse of as ${(empty)?..} (OP_IS_EMPTY),
Matti Hamalainen <ccr@tnsp.org>
parents: 3824
diff changeset
785 #endif
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 default:
3810
e307e455aca0 Improved error handling. Now the error status and message are saved into evaluation context.
Matti Hamalainen <ccr@tnsp.org>
parents: 3809
diff changeset
789 tuple_error(ctx, "Unimplemented opcode %d!\n", curr->opcode);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 return FALSE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 break;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 if (str) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 /* (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
796 *reslen += strlen(str);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 if (*res) {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 if (*reslen >= *resmax) {
3818
10a72af488d9 Fix a stupid bug in memory reallocation of the evaluator.
Matti Hamalainen <ccr@tnsp.org>
parents: 3817
diff changeset
799 *resmax += *reslen + MIN_ALLOC_BUF;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 *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
801 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
803 strcat(*res, str);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 } else {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 *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
806 *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
807
4103
7b9d5718a6dc strncpy() -> g_strlcpy()
Jonathan Schleifer <js-audacious@webkeks.org>
parents: 4102
diff changeset
808 g_strlcpy(*res, str, *resmax);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 curr = curr->next;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 return TRUE;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 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
820 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821 gchar *res = g_strdup("");
3813
a8950cdd2041 Use gssize instead of size_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 3812
diff changeset
822 gssize resmax = 0, reslen = 0;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 assert(ctx != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 assert(tuple != NULL);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825
3793
db6cb4048a74 Return empty string if expr is NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 3792
diff changeset
826 if (!expr) return res;
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
828 tuple_formatter_eval_do(ctx, expr, tuple, &res, &resmax, &reslen);
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 return res;
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 }
4381
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
832
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
833
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
834 static void print_vars(FILE *f, TupleEvalContext *ctx, TupleEvalNode *node, gint start, gint end)
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
835 {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
836 gint i;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
837
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
838 for (i = start; i <= end; i++) {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
839 TupleEvalVar *v = NULL;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
840 gchar *s = NULL;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
841 gint n = node->var[i];
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
842
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
843 if (n >= 0) {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
844 v = ctx->variables[n];
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
845 if (v) {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
846 s = v->name;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
847
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
848 if (v->type == VAR_CONST)
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
849 fprintf(f, "(const)");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
850 else if (v->type == VAR_DEF)
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
851 fprintf(f, "(def)");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
852 }
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
853 }
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
854
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
855 fprintf(f, "var[%d]=(%d),\"%s\" ", i, n, s);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
856 }
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
857 }
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
858
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
859
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
860 gint tuple_formatter_print(FILE *f, gint *level, TupleEvalContext *ctx, TupleEvalNode *expr)
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
861 {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
862 TupleEvalNode *curr = expr;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
863
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
864 if (!expr) return -1;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
865
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
866 (*level)++;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
867
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
868 while (curr) {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
869 gint i;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
870 for (i = 0; i < *level; i++)
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
871 fprintf(f, " ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
872
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
873 switch (curr->opcode) {
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
874 case OP_RAW:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
875 fprintf(f, "OP_RAW text=\"%s\"\n", curr->text);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
876 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
877
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
878 case OP_FIELD:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
879 fprintf(f, "OP_FIELD ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
880 print_vars(f, ctx, curr, 0, 0);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
881 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
882 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
883
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
884 case OP_EXISTS:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
885 fprintf(f, "OP_EXISTS ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
886 print_vars(f, ctx, curr, 0, 0);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
887 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
888 tuple_formatter_print(f, level, ctx, curr->children);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
889 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
890
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
891 case OP_DEF_STRING:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
892 fprintf(f, "OP_DEF_STRING ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
893 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
894 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
895
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
896 case OP_DEF_INT:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
897 fprintf(f, "OP_DEF_INT ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
898 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
899 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
900
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
901 case OP_EQUALS:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
902 fprintf(f, "OP_EQUALS ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
903 print_vars(f, ctx, curr, 0, 1);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
904 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
905 tuple_formatter_print(f, level, ctx, curr->children);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
906 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
907
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
908 case OP_NOT_EQUALS:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
909 fprintf(f, "OP_NOT_EQUALS ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
910 print_vars(f, ctx, curr, 0, 1);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
911 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
912 tuple_formatter_print(f, level, ctx, curr->children);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
913 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
914
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
915 case OP_IS_EMPTY:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
916 fprintf(f, "OP_IS_EMPTY ");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
917 print_vars(f, ctx, curr, 0, 0);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
918 fprintf(f, "\n");
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
919 tuple_formatter_print(f, level, ctx, curr->children);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
920 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
921
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
922 default:
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
923 fprintf(f, "Unimplemented opcode %d!\n", curr->opcode);
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
924 break;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
925 }
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
926
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
927 curr = curr->next;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
928 }
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
929
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
930 (*level)--;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
931
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
932 return 0;
ce3f2d2455cf Moved debugging functions to tuple_compiler.c
Matti Hamalainen <ccr@tnsp.org>
parents: 4103
diff changeset
933 }