Changeset ecb6ac32 in mainline for uspace/app/sbi/src/rdata.c


Ignore:
Timestamp:
2010-04-04T22:32:39Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0a72efc
Parents:
73060801 (diff), 23de644 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jsvoboda/helenos/sysel.

File:
1 edited

Legend:

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

    r73060801 recb6ac32  
    2727 */
    2828
    29 /** @file Run-time data representation. */
     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 */
    3047
    3148#include <stdlib.h>
    3249#include <assert.h>
     50#include "bigint.h"
    3351#include "mytypes.h"
    3452#include "stree.h"
     
    5068static void rdata_var_print(rdata_var_t *var);
    5169
    52 
     70/** Allocate new data item.
     71 *
     72 * @param ic    Item class.
     73 * @return      New item.
     74 */
    5375rdata_item_t *rdata_item_new(item_class_t ic)
    5476{
     
    6587}
    6688
     89/** Allocate new address.
     90 *
     91 * @return      New address.
     92 */
    6793rdata_addr_var_t *rdata_addr_var_new(void)
    6894{
     
    78104}
    79105
     106/** Allocate new named property address.
     107 *
     108 * @return      New named property address.
     109 */
    80110rdata_aprop_named_t *rdata_aprop_named_new(void)
    81111{
     
    91121}
    92122
     123/** Allocate new indexed property address.
     124 *
     125 * @return      New indexed property address.
     126 */
    93127rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
    94128{
     
    104138}
    105139
     140/** Allocate new property address.
     141 *
     142 * @param apc   Property address class.
     143 * @return      New property address.
     144 */
    106145rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
    107146{
     
    118157}
    119158
     159/** Allocate new address.
     160 *
     161 * @param ac    Address class.
     162 * @return      New address.
     163 */
    120164rdata_address_t *rdata_address_new(address_class_t ac)
    121165{
     
    132176}
    133177
     178/** Allocate new value.
     179 *
     180 * @return      New value.
     181 */
    134182rdata_value_t *rdata_value_new(void)
    135183{
     
    145193}
    146194
     195/** Allocate new var node.
     196 *
     197 * @param vc    Var node class (varclass).
     198 * @return      New var node.
     199 */
    147200rdata_var_t *rdata_var_new(var_class_t vc)
    148201{
     
    159212}
    160213
     214/** Allocate new reference.
     215 *
     216 * @return      New reference.
     217 */
    161218rdata_ref_t *rdata_ref_new(void)
    162219{
     
    172229}
    173230
     231/** Allocate new delegate.
     232 *
     233 * @return      New delegate.
     234 */
    174235rdata_deleg_t *rdata_deleg_new(void)
    175236{
     
    185246}
    186247
     248/** Allocate new array.
     249 *
     250 * @return      New array.
     251 */
    187252rdata_array_t *rdata_array_new(int rank)
    188253{
     
    205270}
    206271
     272/** Allocate new object.
     273 *
     274 * @return      New object.
     275 */
    207276rdata_object_t *rdata_object_new(void)
    208277{
     
    218287}
    219288
     289/** Allocate new integer.
     290 *
     291 * @return      New integer.
     292 */
    220293rdata_int_t *rdata_int_new(void)
    221294{
     
    231304}
    232305
     306/** Allocate new string.
     307 *
     308 * @return      New string.
     309 */
    233310rdata_string_t *rdata_string_new(void)
    234311{
     
    244321}
    245322
     323/** Allocate new resource.
     324 *
     325 * @return      New resource.
     326 */
    246327rdata_resource_t *rdata_resource_new(void)
    247328{
     
    257338}
    258339
     340/** Allocate array elements.
     341 *
     342 * Allocates var nodes for elements of @a array.
     343 *
     344 * @param array         Array.
     345 */
    259346void rdata_array_alloc_element(rdata_array_t *array)
    260347{
     
    282369 * Dimension is the total number of elements in an array, in other words,
    283370 * the product of all extents.
     371 *
     372 * @param array         Array.
    284373 */
    285374static int rdata_array_get_dim(rdata_array_t *array)
     
    294383}
    295384
    296 /** Make copy of a variable. */
     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 */
    297393void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest)
    298394{
     
    328424}
    329425
     426/** Copy integer.
     427 *
     428 * @param src           Source integer.
     429 * @param dest          Place to store pointer to new integer.
     430 */
    330431static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
    331432{
    332433        *dest = rdata_int_new();
    333         (*dest)->value = src->value;
    334 }
    335 
     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 */
    336442static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest)
    337443{
     
    340446}
    341447
     448/** Copy reference.
     449 *
     450 * @param src           Source reference.
     451 * @param dest          Place to store pointer to new reference.
     452 */
    342453static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest)
    343454{
     
    346457}
    347458
     459/** Copy delegate.
     460 *
     461 * @param src           Source delegate.
     462 * @param dest          Place to store pointer to new delegate.
     463 */
    348464static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest)
    349465{
     
    353469}
    354470
     471/** Copy array.
     472 *
     473 * @param src           Source array.
     474 * @param dest          Place to store pointer to new array.
     475 */
    355476static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
    356477{
     
    360481}
    361482
     483/** Copy object.
     484 *
     485 * @param src           Source object.
     486 * @param dest          Place to store pointer to new object.
     487 */
    362488static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest)
    363489{
     
    367493}
    368494
     495/** Copy resource.
     496 *
     497 * @param src           Source resource.
     498 * @param dest          Place to store pointer to new resource.
     499 */
    369500static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest)
    370501{
     
    375506/** Read data from a variable.
    376507 *
    377  * Return value stored in variable @a var.
     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.
    378516 */
    379517void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
     
    393531/** Write data to a variable.
    394532 *
    395  * Store @a value to variable @a var.
     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.
    396540 */
    397541void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
     
    418562}
    419563
     564/** Print data item in human-readable form.
     565 *
     566 * @param item          Item to print.
     567 */
    420568void rdata_item_print(rdata_item_t *item)
    421569{
     
    437585}
    438586
     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 */
    439596static void rdata_address_print(rdata_address_t *address)
    440597{
     
    449606}
    450607
     608/** Print value in human-readable form.
     609 *
     610 * @param value         Value to print.
     611 */
    451612void rdata_value_print(rdata_value_t *value)
    452613{
     
    454615}
    455616
     617/** Print contents of var node in human-readable form.
     618 *
     619 * @param item          Var node to print.
     620 */
    456621static void rdata_var_print(rdata_var_t *var)
    457622{
    458623        switch (var->vc) {
    459624        case vc_int:
    460                 printf("int(%d)", var->u.int_v->value);
     625                printf("int(");
     626                bigint_print(&var->u.int_v->value);
     627                printf(")");
    461628                break;
    462629        case vc_string:
Note: See TracChangeset for help on using the changeset viewer.