source: mainline/uspace/app/sbi/src/rdata_t.h@ 75e0f15

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 75e0f15 was 051b3db8, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Update SBI to rev. 344 from upstream. What's new:

  • Builtin.WriteLine() renamed to Console.WriteLine()
  • Implemented 'switch' statement
  • Significantly reduced memory consumption (also increases execution speed in some cases)
  • Properties can be accessed via unqualified names
  • Exceptions raised during property accesses are now handled correctly
  • Some missing checks against expressions returning no value added
  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file Run-time data representation. */
30
31
32#ifndef RDATA_T_H_
33#define RDATA_T_H_
34
35#include "intmap_t.h"
36
37/** Boolean variable. */
38typedef struct {
39 bool_t value;
40} rdata_bool_t;
41
42/** Character variable.
43 *
44 * Sysel character type should be able to store arbitrarily (or at least
45 * very) large character sets.
46 */
47typedef struct {
48 bigint_t value;
49} rdata_char_t;
50
51/** Integer variable.
52 *
53 * Sysel int type should be able to store arbitrarily (or at least
54 * very) large numbers.
55 */
56typedef struct {
57 bigint_t value;
58} rdata_int_t;
59
60/** String variable */
61typedef struct {
62 const char *value;
63} rdata_string_t;
64
65/** Reference variable */
66typedef struct {
67 struct rdata_var *vref;
68} rdata_ref_t;
69
70/** Delegate variable
71 *
72 * A delegate variable points to a static or non-static symbol. If the
73 * symbol is non static, @c obj points to the object the symbol
74 * belongs to.
75 */
76typedef struct {
77 /** Object or @c NULL if deleg. points to a static function. */
78 struct rdata_var *obj;
79
80 /** Member symbol. */
81 struct stree_symbol *sym;
82} rdata_deleg_t;
83
84/** Enumerated type value. */
85typedef struct {
86 /** Enum member declaration */
87 struct stree_embr *value;
88} rdata_enum_t;
89
90/** Array variable */
91typedef struct {
92 /** Rank */
93 int rank;
94
95 /** Extents (@c rank entries) */
96 int *extent;
97
98 /**
99 * Elements (extent[0] * extent[1] * ... extent[rank - 1] entries)
100 * stored in lexicographical order. Each element is (rdata_var_t *).
101 */
102 struct rdata_var **element;
103} rdata_array_t;
104
105/** Object variable */
106typedef struct {
107 /** Class of this object (symbol) */
108 struct stree_symbol *class_sym;
109
110 /** @c sn_static if this is a static object (i.e. class object) */
111 statns_t static_obj;
112
113 /** Map field name SID to field data */
114 intmap_t fields; /* of (rdata_var_t *) */
115} rdata_object_t;
116
117/** Resource handle
118 *
119 * Binding to external data. This type can be used to refer to data used
120 * by builtin functions (such as files).
121 */
122typedef struct {
123 /** Only understood by the right builtin function. */
124 void *data;
125} rdata_resource_t;
126
127/** Symbol reference variable
128 *
129 * A symbol reference points to a program symbol.
130 */
131typedef struct {
132 /** Program symbol. */
133 struct stree_symbol *sym;
134} rdata_symbol_t;
135
136typedef enum var_class {
137 /** Boolean */
138 vc_bool,
139
140 /** Character **/
141 vc_char,
142
143 /** Integer */
144 vc_int,
145
146 /** String */
147 vc_string,
148
149 /** Reference */
150 vc_ref,
151
152 /** Delegate */
153 vc_deleg,
154
155 /** Enumerated type value */
156 vc_enum,
157
158 /** Array */
159 vc_array,
160
161 /** Object */
162 vc_object,
163
164 /** Interpreter builtin resource */
165 vc_resource,
166
167 /** Symbol reference */
168 vc_symbol
169} var_class_t;
170
171/** Variable.
172 *
173 * A piece of memory holding one of the basic types of data element.
174 * It is addressable (via rdata_var_t *) and mutable, at least from
175 * internal point of view of the interpreter.
176 */
177typedef struct rdata_var {
178 var_class_t vc;
179
180 union {
181 rdata_bool_t *bool_v;
182 rdata_char_t *char_v;
183 rdata_int_t *int_v;
184 rdata_string_t *string_v;
185 rdata_ref_t *ref_v;
186 rdata_deleg_t *deleg_v;
187 rdata_enum_t *enum_v;
188 rdata_array_t *array_v;
189 rdata_object_t *object_v;
190 rdata_resource_t *resource_v;
191 rdata_symbol_t *symbol_v;
192 } u;
193} rdata_var_t;
194
195/** Address class */
196typedef enum {
197 /** Variable address */
198 ac_var,
199
200 /** Property address */
201 ac_prop
202} address_class_t;
203
204/** Variable address */
205typedef struct {
206 /** Targeted variable */
207 rdata_var_t *vref;
208} rdata_addr_var_t;
209
210/** Named property address */
211typedef struct {
212 /** Delegate to the property */
213 rdata_deleg_t *prop_d;
214} rdata_aprop_named_t;
215
216/** Indexed property address */
217typedef struct {
218 /** Delegate to the object (or CSI) which is being indexed. */
219 rdata_deleg_t *object_d;
220
221 /** Arguments (indices) */
222 list_t args; /* of rdata_item_t */
223} rdata_aprop_indexed_t;
224
225typedef enum {
226 /* Named property address */
227 apc_named,
228
229 /* Indexed property address */
230 apc_indexed
231} aprop_class_t;
232
233/** Property address.
234 *
235 * When an access or index operation is performed on a property, the getter
236 * is run and the prefetched value is stored in @c tvalue. If the property
237 * is a non-scalar value type (a struct), then we might want to point to
238 * the proper @c var node inside it. @c tpos is used for this purpose.
239 *
240 * The assignment operator will modify @c tvalue and at the end the setter
241 * is called to store @c tvalue back into the property.
242 */
243typedef struct {
244 aprop_class_t apc;
245
246 /** Temporary copy of property value or @c NULL when not used. */
247 struct rdata_value *tvalue;
248
249 /**
250 * Points to the specific var node within @c tvalue that is addressed
251 * or @c NULL when @c tvalue is not used.
252 */
253 rdata_var_t *tpos;
254
255 union {
256 rdata_aprop_named_t *named;
257 rdata_aprop_indexed_t *indexed;
258 } u;
259} rdata_addr_prop_t;
260
261/** Address item */
262typedef struct rdata_address {
263 address_class_t ac;
264
265 union {
266 rdata_addr_var_t *var_a;
267 rdata_addr_prop_t *prop_a;
268 } u;
269} rdata_address_t;
270
271/** Value item. */
272typedef struct rdata_value {
273 /**
274 * Read-only Variable holding a copy of the data. Currently we don't
275 * allow sharing the same @c var node between different value nodes
276 * so that when destroying the value we can destroy the var.
277 *
278 * We could share this, but would need to reference-count it.
279 */
280 rdata_var_t *var;
281} rdata_value_t;
282
283typedef enum {
284 /** Address of a variable. */
285 ic_address,
286 /** Value */
287 ic_value
288} item_class_t;
289
290/** Data item.
291 *
292 * Data item is the result of evaluating an expression. An address expression
293 * yields an address item (a.k.a. L-value), a value expression yields a data
294 * item (a.k.a. R-value). This model is used to accomodate semantics of the
295 * assignment operator.
296 */
297typedef struct rdata_item {
298 item_class_t ic;
299
300 union {
301 rdata_address_t *address;
302 rdata_value_t *value;
303 } u;
304} rdata_item_t;
305
306#endif
Note: See TracBrowser for help on using the repository browser.