Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/rdata.c

    r23de644 r1ebc1a62  
    2727 */
    2828
    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. */
    4730
    4831#include <stdlib.h>
    4932#include <assert.h>
    50 #include "bigint.h"
    5133#include "mytypes.h"
    5234#include "stree.h"
     
    6850static void rdata_var_print(rdata_var_t *var);
    6951
    70 /** Allocate new data item.
    71  *
    72  * @param ic    Item class.
    73  * @return      New item.
    74  */
     52
    7553rdata_item_t *rdata_item_new(item_class_t ic)
    7654{
     
    8765}
    8866
    89 /** Allocate new address.
    90  *
    91  * @return      New address.
    92  */
    9367rdata_addr_var_t *rdata_addr_var_new(void)
    9468{
     
    10478}
    10579
    106 /** Allocate new named property address.
    107  *
    108  * @return      New named property address.
    109  */
    11080rdata_aprop_named_t *rdata_aprop_named_new(void)
    11181{
     
    12191}
    12292
    123 /** Allocate new indexed property address.
    124  *
    125  * @return      New indexed property address.
    126  */
    12793rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
    12894{
     
    138104}
    139105
    140 /** Allocate new property address.
    141  *
    142  * @param apc   Property address class.
    143  * @return      New property address.
    144  */
    145106rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
    146107{
     
    157118}
    158119
    159 /** Allocate new address.
    160  *
    161  * @param ac    Address class.
    162  * @return      New address.
    163  */
    164120rdata_address_t *rdata_address_new(address_class_t ac)
    165121{
     
    176132}
    177133
    178 /** Allocate new value.
    179  *
    180  * @return      New value.
    181  */
    182134rdata_value_t *rdata_value_new(void)
    183135{
     
    193145}
    194146
    195 /** Allocate new var node.
    196  *
    197  * @param vc    Var node class (varclass).
    198  * @return      New var node.
    199  */
    200147rdata_var_t *rdata_var_new(var_class_t vc)
    201148{
     
    212159}
    213160
    214 /** Allocate new reference.
    215  *
    216  * @return      New reference.
    217  */
    218161rdata_ref_t *rdata_ref_new(void)
    219162{
     
    229172}
    230173
    231 /** Allocate new delegate.
    232  *
    233  * @return      New delegate.
    234  */
    235174rdata_deleg_t *rdata_deleg_new(void)
    236175{
     
    246185}
    247186
    248 /** Allocate new array.
    249  *
    250  * @return      New array.
    251  */
    252187rdata_array_t *rdata_array_new(int rank)
    253188{
     
    270205}
    271206
    272 /** Allocate new object.
    273  *
    274  * @return      New object.
    275  */
    276207rdata_object_t *rdata_object_new(void)
    277208{
     
    287218}
    288219
    289 /** Allocate new integer.
    290  *
    291  * @return      New integer.
    292  */
    293220rdata_int_t *rdata_int_new(void)
    294221{
     
    304231}
    305232
    306 /** Allocate new string.
    307  *
    308  * @return      New string.
    309  */
    310233rdata_string_t *rdata_string_new(void)
    311234{
     
    321244}
    322245
    323 /** Allocate new resource.
    324  *
    325  * @return      New resource.
    326  */
    327246rdata_resource_t *rdata_resource_new(void)
    328247{
     
    338257}
    339258
    340 /** Allocate array elements.
    341  *
    342  * Allocates var nodes for elements of @a array.
    343  *
    344  * @param array         Array.
    345  */
    346259void rdata_array_alloc_element(rdata_array_t *array)
    347260{
     
    369282 * Dimension is the total number of elements in an array, in other words,
    370283 * the product of all extents.
    371  *
    372  * @param array         Array.
    373284 */
    374285static int rdata_array_get_dim(rdata_array_t *array)
     
    383294}
    384295
    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. */
    393297void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest)
    394298{
     
    424328}
    425329
    426 /** Copy integer.
    427  *
    428  * @param src           Source integer.
    429  * @param dest          Place to store pointer to new integer.
    430  */
    431330static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
    432331{
    433332        *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
    442336static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest)
    443337{
     
    446340}
    447341
    448 /** Copy reference.
    449  *
    450  * @param src           Source reference.
    451  * @param dest          Place to store pointer to new reference.
    452  */
    453342static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest)
    454343{
     
    457346}
    458347
    459 /** Copy delegate.
    460  *
    461  * @param src           Source delegate.
    462  * @param dest          Place to store pointer to new delegate.
    463  */
    464348static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest)
    465349{
     
    469353}
    470354
    471 /** Copy array.
    472  *
    473  * @param src           Source array.
    474  * @param dest          Place to store pointer to new array.
    475  */
    476355static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
    477356{
     
    481360}
    482361
    483 /** Copy object.
    484  *
    485  * @param src           Source object.
    486  * @param dest          Place to store pointer to new object.
    487  */
    488362static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest)
    489363{
     
    493367}
    494368
    495 /** Copy resource.
    496  *
    497  * @param src           Source resource.
    498  * @param dest          Place to store pointer to new resource.
    499  */
    500369static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest)
    501370{
     
    506375/** Read data from a variable.
    507376 *
    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.
    516378 */
    517379void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
     
    531393/** Write data to a variable.
    532394 *
    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.
    540396 */
    541397void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
     
    562418}
    563419
    564 /** Print data item in human-readable form.
    565  *
    566  * @param item          Item to print.
    567  */
    568420void rdata_item_print(rdata_item_t *item)
    569421{
     
    585437}
    586438
    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 data
    592  * it is pointing to?
    593  *
    594  * @param item          Address to print.
    595  */
    596439static void rdata_address_print(rdata_address_t *address)
    597440{
     
    606449}
    607450
    608 /** Print value in human-readable form.
    609  *
    610  * @param value         Value to print.
    611  */
    612451void rdata_value_print(rdata_value_t *value)
    613452{
     
    615454}
    616455
    617 /** Print contents of var node in human-readable form.
    618  *
    619  * @param item          Var node to print.
    620  */
    621456static void rdata_var_print(rdata_var_t *var)
    622457{
    623458        switch (var->vc) {
    624459        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);
    628461                break;
    629462        case vc_string:
Note: See TracChangeset for help on using the changeset viewer.