Changes in uspace/app/sbi/src/rdata.c [23de644:1ebc1a62] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/rdata.c
r23de644 r1ebc1a62 27 27 */ 28 28 29 /** @file Run-time data representation. 30 * 31 * At run time SBI represents all data as a graph of interconnected @c var 32 * nodes (variable nodes). Any piece of memory addressable by the program 33 * (i.e. all variables) are stored in var nodes. However, var nodes are also 34 * used internally to implement value items. (I.e. values in value items 35 * have exactly the same structure as program variables). 36 * 37 * Unlike byte- or word-oriented memory on a real machine, var nodes provide 38 * structured and typed storage. (This typing is dynamic, however and has 39 * nothing to do with the static type system). 40 * 41 * There are several types of var nodes, one for each primitive type, 42 * reference, delegate, array, and object. A reference var node contains 43 * a pointer to another var node. Delegate var node points to some stree 44 * declaration. Array and object var nodes refer to a collection of child 45 * nodes (fields, elements). 46 */ 29 /** @file Run-time data representation. */ 47 30 48 31 #include <stdlib.h> 49 32 #include <assert.h> 50 #include "bigint.h"51 33 #include "mytypes.h" 52 34 #include "stree.h" … … 68 50 static void rdata_var_print(rdata_var_t *var); 69 51 70 /** Allocate new data item. 71 * 72 * @param ic Item class. 73 * @return New item. 74 */ 52 75 53 rdata_item_t *rdata_item_new(item_class_t ic) 76 54 { … … 87 65 } 88 66 89 /** Allocate new address.90 *91 * @return New address.92 */93 67 rdata_addr_var_t *rdata_addr_var_new(void) 94 68 { … … 104 78 } 105 79 106 /** Allocate new named property address.107 *108 * @return New named property address.109 */110 80 rdata_aprop_named_t *rdata_aprop_named_new(void) 111 81 { … … 121 91 } 122 92 123 /** Allocate new indexed property address.124 *125 * @return New indexed property address.126 */127 93 rdata_aprop_indexed_t *rdata_aprop_indexed_new(void) 128 94 { … … 138 104 } 139 105 140 /** Allocate new property address.141 *142 * @param apc Property address class.143 * @return New property address.144 */145 106 rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc) 146 107 { … … 157 118 } 158 119 159 /** Allocate new address.160 *161 * @param ac Address class.162 * @return New address.163 */164 120 rdata_address_t *rdata_address_new(address_class_t ac) 165 121 { … … 176 132 } 177 133 178 /** Allocate new value.179 *180 * @return New value.181 */182 134 rdata_value_t *rdata_value_new(void) 183 135 { … … 193 145 } 194 146 195 /** Allocate new var node.196 *197 * @param vc Var node class (varclass).198 * @return New var node.199 */200 147 rdata_var_t *rdata_var_new(var_class_t vc) 201 148 { … … 212 159 } 213 160 214 /** Allocate new reference.215 *216 * @return New reference.217 */218 161 rdata_ref_t *rdata_ref_new(void) 219 162 { … … 229 172 } 230 173 231 /** Allocate new delegate.232 *233 * @return New delegate.234 */235 174 rdata_deleg_t *rdata_deleg_new(void) 236 175 { … … 246 185 } 247 186 248 /** Allocate new array.249 *250 * @return New array.251 */252 187 rdata_array_t *rdata_array_new(int rank) 253 188 { … … 270 205 } 271 206 272 /** Allocate new object.273 *274 * @return New object.275 */276 207 rdata_object_t *rdata_object_new(void) 277 208 { … … 287 218 } 288 219 289 /** Allocate new integer.290 *291 * @return New integer.292 */293 220 rdata_int_t *rdata_int_new(void) 294 221 { … … 304 231 } 305 232 306 /** Allocate new string.307 *308 * @return New string.309 */310 233 rdata_string_t *rdata_string_new(void) 311 234 { … … 321 244 } 322 245 323 /** Allocate new resource.324 *325 * @return New resource.326 */327 246 rdata_resource_t *rdata_resource_new(void) 328 247 { … … 338 257 } 339 258 340 /** Allocate array elements.341 *342 * Allocates var nodes for elements of @a array.343 *344 * @param array Array.345 */346 259 void rdata_array_alloc_element(rdata_array_t *array) 347 260 { … … 369 282 * Dimension is the total number of elements in an array, in other words, 370 283 * the product of all extents. 371 *372 * @param array Array.373 284 */ 374 285 static int rdata_array_get_dim(rdata_array_t *array) … … 383 294 } 384 295 385 /** Make copy of a variable. 386 * 387 * Creates a new var node that is an exact copy of an existing var node. 388 * This can be thought of as a shallow copy. 389 * 390 * @param src Source var node. 391 * @param dest Place to store pointer to new var node. 392 */ 296 /** Make copy of a variable. */ 393 297 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest) 394 298 { … … 424 328 } 425 329 426 /** Copy integer.427 *428 * @param src Source integer.429 * @param dest Place to store pointer to new integer.430 */431 330 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest) 432 331 { 433 332 *dest = rdata_int_new(); 434 bigint_clone(&src->value, &(*dest)->value); 435 } 436 437 /** Copy string. 438 * 439 * @param src Source string. 440 * @param dest Place to store pointer to new string. 441 */ 333 (*dest)->value = src->value; 334 } 335 442 336 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest) 443 337 { … … 446 340 } 447 341 448 /** Copy reference.449 *450 * @param src Source reference.451 * @param dest Place to store pointer to new reference.452 */453 342 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest) 454 343 { … … 457 346 } 458 347 459 /** Copy delegate.460 *461 * @param src Source delegate.462 * @param dest Place to store pointer to new delegate.463 */464 348 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest) 465 349 { … … 469 353 } 470 354 471 /** Copy array.472 *473 * @param src Source array.474 * @param dest Place to store pointer to new array.475 */476 355 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest) 477 356 { … … 481 360 } 482 361 483 /** Copy object.484 *485 * @param src Source object.486 * @param dest Place to store pointer to new object.487 */488 362 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest) 489 363 { … … 493 367 } 494 368 495 /** Copy resource.496 *497 * @param src Source resource.498 * @param dest Place to store pointer to new resource.499 */500 369 static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest) 501 370 { … … 506 375 /** Read data from a variable. 507 376 * 508 * This copies data from the variable to a value item. Ideally any read access 509 * to a program variable should go through this function. (Keep in mind 510 * that although values are composed of var nodes internally, but are not 511 * variables per se. Therefore this function is not used to read from values) 512 * 513 * @param var Variable to read from (var node where it is stored). 514 * @param ritem Place to store pointer to new value item read from 515 * the variable. 377 * Return value stored in variable @a var. 516 378 */ 517 379 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem) … … 531 393 /** Write data to a variable. 532 394 * 533 * This copies data to the variable from a value. Ideally any write access 534 * to a program variable should go through this function. (Keep in mind 535 * that even though values are composed of var nodes internally, but are not 536 * variables per se. Therefore this function is not used to write to values) 537 * 538 * @param var Variable to write to (var node where it is stored). 539 * @param value The value to write. 395 * Store @a value to variable @a var. 540 396 */ 541 397 void rdata_var_write(rdata_var_t *var, rdata_value_t *value) … … 562 418 } 563 419 564 /** Print data item in human-readable form.565 *566 * @param item Item to print.567 */568 420 void rdata_item_print(rdata_item_t *item) 569 421 { … … 585 437 } 586 438 587 /** Print address in human-readable form.588 *589 * Actually this displays contents of the var node that is being addressed.590 *591 * XXX Maybe we should really rather print the address and not the data592 * it is pointing to?593 *594 * @param item Address to print.595 */596 439 static void rdata_address_print(rdata_address_t *address) 597 440 { … … 606 449 } 607 450 608 /** Print value in human-readable form.609 *610 * @param value Value to print.611 */612 451 void rdata_value_print(rdata_value_t *value) 613 452 { … … 615 454 } 616 455 617 /** Print contents of var node in human-readable form.618 *619 * @param item Var node to print.620 */621 456 static void rdata_var_print(rdata_var_t *var) 622 457 { 623 458 switch (var->vc) { 624 459 case vc_int: 625 printf("int("); 626 bigint_print(&var->u.int_v->value); 627 printf(")"); 460 printf("int(%d)", var->u.int_v->value); 628 461 break; 629 462 case vc_string:
Note:
See TracChangeset
for help on using the changeset viewer.