Changeset fa36f29 in mainline for uspace/app/sbi/src/run_expr.c


Ignore:
Timestamp:
2010-02-27T17:59:14Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
94d484a
Parents:
09ababb7
Message:

Update SBI to rev. 75.

File:
1 edited

Legend:

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

    r09ababb7 rfa36f29  
    3333#include <assert.h>
    3434#include "debug.h"
     35#include "intmap.h"
    3536#include "list.h"
    3637#include "mytypes.h"
     
    4445static void run_nameref(run_t *run, stree_nameref_t *nameref,
    4546    rdata_item_t **res);
     47
    4648static void run_literal(run_t *run, stree_literal_t *literal,
    4749    rdata_item_t **res);
    4850static void run_lit_int(run_t *run, stree_lit_int_t *lit_int,
    4951    rdata_item_t **res);
     52static void run_lit_ref(run_t *run, stree_lit_ref_t *lit_ref,
     53    rdata_item_t **res);
    5054static void run_lit_string(run_t *run, stree_lit_string_t *lit_string,
    5155    rdata_item_t **res);
     56
     57static void run_self_ref(run_t *run, stree_self_ref_t *self_ref,
     58    rdata_item_t **res);
     59
    5260static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res);
     61static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
     62    rdata_value_t *v2, rdata_item_t **res);
     63static void run_binop_ref(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
     64    rdata_value_t *v2, rdata_item_t **res);
     65
    5366static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res);
     67static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res);
     68
    5469static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res);
     70static void run_access_item(run_t *run, stree_access_t *access,
     71    rdata_item_t *arg, rdata_item_t **res);
     72static void run_access_ref(run_t *run, stree_access_t *access,
     73    rdata_item_t *arg, rdata_item_t **res);
     74static void run_access_deleg(run_t *run, stree_access_t *access,
     75    rdata_item_t *arg, rdata_item_t **res);
     76static void run_access_object(run_t *run, stree_access_t *access,
     77    rdata_item_t *arg, rdata_item_t **res);
     78
    5579static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res);
    5680static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res);
    57 
    58 static void run_address_read(run_t *run, rdata_address_t *address,
    59     rdata_item_t **ritem);
    60 static void run_address_write(run_t *run, rdata_address_t *address,
    61     rdata_value_t *value);
    6281
    6382/** Evaluate expression. */
     
    7594                run_literal(run, expr->u.literal, res);
    7695                break;
     96        case ec_self_ref:
     97                run_self_ref(run, expr->u.self_ref, res);
     98                break;
    7799        case ec_binop:
    78100                run_binop(run, expr->u.binop, res);
     
    80102        case ec_unop:
    81103                run_unop(run, expr->u.unop, res);
     104                break;
     105        case ec_new:
     106                run_new(run, expr->u.new_op, res);
    82107                break;
    83108        case ec_access:
     
    106131        rdata_item_t *item;
    107132        rdata_address_t *address;
    108         rdata_value_t *val;
     133        rdata_value_t *value;
    109134        rdata_var_t *var;
    110135        rdata_deleg_t *deleg_v;
     136
     137        run_fun_ar_t *fun_ar;
     138        stree_symbol_t *csi_sym;
     139        stree_csi_t *csi;
     140        rdata_object_t *obj;
     141        rdata_var_t *member_var;
    111142
    112143#ifdef DEBUG_RUN_TRACE
     
    137168         */
    138169
    139         /* XXX Start lookup in currently active CSI. */
    140         sym = symbol_lookup_in_csi(run->program, NULL, nameref->name);
     170        /* Determine currently active object or CSI. */
     171        fun_ar = run_get_current_fun_ar(run);
     172        if (fun_ar->obj != NULL) {
     173                assert(fun_ar->obj->vc == vc_object);
     174                obj = fun_ar->obj->u.object_v;
     175                csi_sym = obj->class_sym;
     176                csi = symbol_to_csi(csi_sym);
     177                assert(csi != NULL);
     178        } else {
     179                csi = fun_ar->fun_sym->outer_csi;
     180                obj = NULL;
     181        }
     182
     183        sym = symbol_lookup_in_csi(run->program, csi, nameref->name);
    141184
    142185        switch (sym->sc) {
     
    146189#endif
    147190                item = rdata_item_new(ic_value);
    148                 val = rdata_value_new();
     191                value = rdata_value_new();
    149192                var = rdata_var_new(vc_deleg);
    150193                deleg_v = rdata_deleg_new();
    151194
    152                 item->u.value = val;
    153                 val->var = var;
     195                item->u.value = value;
     196                value->var = var;
    154197                var->u.deleg_v = deleg_v;
    155198
     
    158201                *res = item;
    159202                break;
     203        case sc_fun:
     204                /* There should be no global functions. */
     205                assert(csi != NULL);
     206
     207                if (sym->outer_csi != csi) {
     208                        /* Function is not in the current object. */
     209                        printf("Error: Cannot access non-static member "
     210                            "function '");
     211                        symbol_print_fqn(run->program, sym);
     212                        printf("' from nested CSI '");
     213                        symbol_print_fqn(run->program, csi_sym);
     214                        printf("'.\n");
     215                        exit(1);
     216                }
     217
     218                /* Construct delegate. */
     219                item = rdata_item_new(ic_value);
     220                value = rdata_value_new();
     221                item->u.value = value;
     222
     223                var = rdata_var_new(vc_deleg);
     224                deleg_v = rdata_deleg_new();
     225                value->var = var;
     226                var->u.deleg_v = deleg_v;
     227
     228                deleg_v->obj = fun_ar->obj;
     229                deleg_v->sym = sym;
     230
     231                *res = item;
     232                break;
     233        case sc_var:
     234#ifdef DEBUG_RUN_TRACE
     235                printf("Referencing member variable.\n");
     236#endif
     237                /* There should be no global variables. */
     238                assert(csi != NULL);
     239
     240                /* XXX Assume variable is not static for now. */
     241                assert(obj != NULL);
     242
     243                if (sym->outer_csi != csi) {
     244                        /* Variable is not in the current object. */
     245                        printf("Error: Cannot access non-static member "
     246                            "variable '");
     247                        symbol_print_fqn(run->program, sym);
     248                        printf("' from nested CSI '");
     249                        symbol_print_fqn(run->program, csi_sym);
     250                        printf("'.\n");
     251                        exit(1);
     252                }
     253
     254                /* Find member variable in object. */
     255                member_var = intmap_get(&obj->fields, nameref->name->sid);
     256                assert(member_var != NULL);
     257
     258                /* Return address of the variable. */
     259                item = rdata_item_new(ic_address);
     260                address = rdata_address_new();
     261
     262                item->u.address = address;
     263                address->vref = member_var;
     264
     265                *res = item;
     266                break;
    160267        default:
    161268                printf("Referencing symbol class %d unimplemented.\n", sym->sc);
     
    176283        case ltc_int:
    177284                run_lit_int(run, &literal->u.lit_int, res);
     285                break;
     286        case ltc_ref:
     287                run_lit_ref(run, &literal->u.lit_ref, res);
    178288                break;
    179289        case ltc_string:
     
    197307        printf("Run integer literal.\n");
    198308#endif
     309        (void) run;
    199310
    200311        item = rdata_item_new(ic_value);
     
    211322}
    212323
     324/** Evaluate reference literal (@c nil). */
     325static void run_lit_ref(run_t *run, stree_lit_ref_t *lit_ref,
     326    rdata_item_t **res)
     327{
     328        rdata_item_t *item;
     329        rdata_value_t *value;
     330        rdata_var_t *var;
     331        rdata_ref_t *ref_v;
     332
     333#ifdef DEBUG_RUN_TRACE
     334        printf("Run reference literal (nil).\n");
     335#endif
     336        (void) run;
     337        (void) lit_ref;
     338
     339        item = rdata_item_new(ic_value);
     340        value = rdata_value_new();
     341        var = rdata_var_new(vc_ref);
     342        ref_v = rdata_ref_new();
     343
     344        item->u.value = value;
     345        value->var = var;
     346        var->u.ref_v = ref_v;
     347        ref_v->vref = NULL;
     348
     349        *res = item;
     350}
     351
    213352/** Evaluate string literal. */
    214353static void run_lit_string(run_t *run, stree_lit_string_t *lit_string,
     
    223362        printf("Run integer literal.\n");
    224363#endif
     364        (void) run;
     365
    225366        item = rdata_item_new(ic_value);
    226367        value = rdata_value_new();
     
    236377}
    237378
     379/** Evaluate @c self reference. */
     380static void run_self_ref(run_t *run, stree_self_ref_t *self_ref,
     381    rdata_item_t **res)
     382{
     383        run_fun_ar_t *fun_ar;
     384
     385#ifdef DEBUG_RUN_TRACE
     386        printf("Run self reference.\n");
     387#endif
     388        (void) self_ref;
     389        fun_ar = run_get_current_fun_ar(run);
     390
     391        /* Return reference to the currently active object. */
     392        rdata_reference(fun_ar->obj, res);
     393}
    238394
    239395/** Evaluate binary operation. */
     
    243399        rdata_item_t *rarg1_vi, *rarg2_vi;
    244400        rdata_value_t *v1, *v2;
    245         int i1, i2;
    246 
    247         rdata_item_t *item;
    248         rdata_value_t *value;
    249         rdata_var_t *var;
    250         rdata_int_t *int_v;
    251401
    252402#ifdef DEBUG_RUN_TRACE
     
    276426#endif
    277427
    278         run_cvt_value_item(run, rarg1_i, &rarg1_vi);
    279         run_cvt_value_item(run, rarg2_i, &rarg2_vi);
     428        rdata_cvt_value_item(rarg1_i, &rarg1_vi);
     429        rdata_cvt_value_item(rarg2_i, &rarg2_vi);
    280430
    281431        v1 = rarg1_vi->u.value;
    282432        v2 = rarg2_vi->u.value;
    283433
    284         if (v1->var->vc != vc_int || v2->var->vc != vc_int) {
    285                 printf("Unimplemented: Binary operation arguments are not "
    286                     "integer values.\n");
    287                 exit(1);
    288         }
     434        if (v1->var->vc != v2->var->vc) {
     435                printf("Unimplemented: Binary operation arguments have "
     436                    "different type.\n");
     437                exit(1);
     438        }
     439
     440        switch (v1->var->vc) {
     441        case vc_int:
     442                run_binop_int(run, binop, v1, v2, res);
     443                break;
     444        case vc_ref:
     445                run_binop_ref(run, binop, v1, v2, res);
     446                break;
     447        default:
     448                printf("Unimplemented: Binary operation arguments of "
     449                    "type %d.\n", v1->var->vc);
     450                exit(1);
     451        }
     452}
     453
     454/** Evaluate binary operation on int arguments. */
     455static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
     456    rdata_value_t *v2, rdata_item_t **res)
     457{
     458        rdata_item_t *item;
     459        rdata_value_t *value;
     460        rdata_var_t *var;
     461        rdata_int_t *int_v;
     462
     463        int i1, i2;
     464
     465        (void) run;
    289466
    290467        item = rdata_item_new(ic_value);
     
    331508}
    332509
     510/** Evaluate binary operation on ref arguments. */
     511static void run_binop_ref(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
     512    rdata_value_t *v2, rdata_item_t **res)
     513{
     514        rdata_item_t *item;
     515        rdata_value_t *value;
     516        rdata_var_t *var;
     517        rdata_int_t *int_v;
     518
     519        rdata_var_t *ref1, *ref2;
     520
     521        (void) run;
     522
     523        item = rdata_item_new(ic_value);
     524        value = rdata_value_new();
     525        var = rdata_var_new(vc_int);
     526        int_v = rdata_int_new();
     527
     528        item->u.value = value;
     529        value->var = var;
     530        var->u.int_v = int_v;
     531
     532        ref1 = v1->var->u.ref_v->vref;
     533        ref2 = v2->var->u.ref_v->vref;
     534
     535        switch (binop->bc) {
     536        /* XXX We should have a real boolean type. */
     537        case bo_equal:
     538                int_v->value = (ref1 == ref2) ? 1 : 0;
     539                break;
     540        case bo_notequal:
     541                int_v->value = (ref1 != ref2) ? 1 : 0;
     542                break;
     543        default:
     544                printf("Error: Invalid binary operation on reference "
     545                    "arguments (%d).\n", binop->bc);
     546                assert(b_false);
     547        }
     548
     549        *res = item;
     550}
     551
     552
    333553/** Evaluate unary operation. */
    334554static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res)
     
    343563}
    344564
     565/** Evaluate @c new operation. */
     566static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res)
     567{
     568        rdata_object_t *obj;
     569        rdata_var_t *obj_var;
     570
     571        stree_symbol_t *csi_sym;
     572        stree_csi_t *csi;
     573        stree_csimbr_t *csimbr;
     574
     575        rdata_var_t *mbr_var;
     576
     577        list_node_t *node;
     578
     579#ifdef DEBUG_RUN_TRACE
     580        printf("Run 'new' operation.\n");
     581#endif
     582        /* Lookup object CSI. */
     583        /* XXX Should start in the current CSI. */
     584        csi_sym = symbol_xlookup_in_csi(run->program, NULL, new_op->texpr);
     585        csi = symbol_to_csi(csi_sym);
     586        if (csi == NULL) {
     587                printf("Error: Symbol '");
     588                symbol_print_fqn(run->program, csi_sym);
     589                printf("' is not a CSI. CSI required for 'new' operator.\n");
     590                exit(1);
     591        }
     592
     593        /* Create the object. */
     594        obj = rdata_object_new();
     595        obj->class_sym = csi_sym;
     596        intmap_init(&obj->fields);
     597
     598        obj_var = rdata_var_new(vc_object);
     599        obj_var->u.object_v = obj;
     600
     601        /* Create object fields. */
     602        node = list_first(&csi->members);
     603        while (node != NULL) {
     604                csimbr = list_node_data(node, stree_csimbr_t *);
     605                if (csimbr->cc == csimbr_var) {
     606                        /* XXX Depends on member variable type. */
     607                        mbr_var = rdata_var_new(vc_int);
     608                        mbr_var->u.int_v = rdata_int_new();
     609                        mbr_var->u.int_v->value = 0;
     610
     611                        intmap_set(&obj->fields, csimbr->u.var->name->sid,
     612                            mbr_var);
     613                }
     614
     615                node = list_next(&csi->members, node);
     616        }
     617
     618        /* Create reference to the new object. */
     619        rdata_reference(obj_var, res);
     620}
     621
    345622/** Evaluate member acccess. */
    346623static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res)
    347624{
    348625        rdata_item_t *rarg;
     626
     627#ifdef DEBUG_RUN_TRACE
     628        printf("Run access operation.\n");
     629#endif
     630        run_expr(run, access->arg, &rarg);
     631        if (rarg == NULL) {
     632                printf("Error: Sub-expression has no value.\n");
     633                exit(1);
     634        }
     635
     636        run_access_item(run, access, rarg, res);
     637}
     638
     639/** Evaluate member acccess (with base already evaluated). */
     640static void run_access_item(run_t *run, stree_access_t *access,
     641    rdata_item_t *arg, rdata_item_t **res)
     642{
     643        var_class_t vc;
     644
     645#ifdef DEBUG_RUN_TRACE
     646        printf("Run access operation on pre-evaluated base.\n");
     647#endif
     648        switch (arg->ic) {
     649        case ic_value:
     650                vc = arg->u.value->var->vc;
     651                break;
     652        case ic_address:
     653                vc = arg->u.address->vref->vc;
     654                break;
     655        default:
     656                /* Silence warning. */
     657                abort();
     658        }
     659
     660        switch (vc) {
     661        case vc_ref:
     662                run_access_ref(run, access, arg, res);
     663                break;
     664        case vc_deleg:
     665                run_access_deleg(run, access, arg, res);
     666                break;
     667        case vc_object:
     668                run_access_object(run, access, arg, res);
     669                break;
     670        default:
     671                printf("Unimplemented: Using access operator ('.') "
     672                    "with unsupported data type (value/%d).\n", vc);
     673                exit(1);
     674        }
     675}
     676
     677/** Evaluate reference acccess. */
     678static void run_access_ref(run_t *run, stree_access_t *access,
     679    rdata_item_t *arg, rdata_item_t **res)
     680{
     681        rdata_item_t *darg;
     682
     683        /* Implicitly dereference. */
     684        rdata_dereference(arg, &darg);
     685
     686        /* Try again. */
     687        run_access_item(run, access, darg, res);
     688}
     689
     690/** Evaluate delegate-member acccess. */
     691static void run_access_deleg(run_t *run, stree_access_t *access,
     692    rdata_item_t *arg, rdata_item_t **res)
     693{
     694        rdata_item_t *arg_vi;
     695        rdata_value_t *arg_val;
    349696        rdata_deleg_t *deleg_v;
    350697        stree_symbol_t *member;
    351698
    352699#ifdef DEBUG_RUN_TRACE
    353         printf("Run access operation.\n");
    354 #endif
    355         run_expr(run, access->arg, &rarg);
    356 
    357         if (rarg->ic == ic_value && rarg->u.value->var->vc == vc_deleg) {
    358 #ifdef DEBUG_RUN_TRACE
    359                 printf("Accessing delegate.\n");
    360 #endif
    361                 deleg_v = rarg->u.value->var->u.deleg_v;
    362                 if (deleg_v->obj != NULL || deleg_v->sym->sc != sc_csi) {
    363                         printf("Error: Using '.' with symbol of wrong "
    364                             "type (%d).\n", deleg_v->sym->sc);
    365                         exit(1);
    366                 }
    367 
    368                 member = symbol_search_csi(run->program, deleg_v->sym->u.csi,
    369                     access->member_name);
    370 
    371                 if (member == NULL) {
    372                         printf("Error: No such member.\n");
    373                         exit(1);
    374                 }
    375 
    376 #ifdef DEBUG_RUN_TRACE
    377                 printf("Found member '%s'.\n",
     700        printf("Run delegate access operation.\n");
     701#endif
     702        rdata_cvt_value_item(arg, &arg_vi);
     703        arg_val = arg_vi->u.value;
     704        assert(arg_val->var->vc == vc_deleg);
     705
     706        deleg_v = arg_val->var->u.deleg_v;
     707        if (deleg_v->obj != NULL || deleg_v->sym->sc != sc_csi) {
     708                printf("Error: Using '.' with delegate to different object "
     709                    "than a CSI (%d).\n", deleg_v->sym->sc);
     710                exit(1);
     711        }
     712
     713        member = symbol_search_csi(run->program, deleg_v->sym->u.csi,
     714            access->member_name);
     715
     716        if (member == NULL) {
     717                printf("Error: CSI '");
     718                symbol_print_fqn(run->program, deleg_v->sym);
     719                printf("' has no member named '%s'.\n",
    378720                    strtab_get_str(access->member_name->sid));
    379 #endif
    380 
    381                 /* Reuse existing item, value, var, deleg. */
     721                exit(1);
     722        }
     723
     724#ifdef DEBUG_RUN_TRACE
     725        printf("Found member '%s'.\n",
     726            strtab_get_str(access->member_name->sid));
     727#endif
     728
     729        /*
     730         * Reuse existing item, value, var, deleg.
     731         * XXX This is maybe not a good idea because it complicates memory
     732         * management as there is not a single owner
     733         */
     734        deleg_v->sym = member;
     735        *res = arg;
     736}
     737
     738/** Evaluate object member acccess. */
     739static void run_access_object(run_t *run, stree_access_t *access,
     740    rdata_item_t *arg, rdata_item_t **res)
     741{
     742        stree_symbol_t *member;
     743        rdata_object_t *object;
     744        rdata_item_t *ritem;
     745        rdata_address_t *address;
     746
     747        rdata_value_t *value;
     748        rdata_deleg_t *deleg_v;
     749        rdata_var_t *var;
     750
     751#ifdef DEBUG_RUN_TRACE
     752        printf("Run object access operation.\n");
     753#endif
     754        assert(arg->ic == ic_address);
     755        assert(arg->u.value->var->vc == vc_object);
     756
     757        object = arg->u.value->var->u.object_v;
     758
     759        member = symbol_search_csi(run->program, object->class_sym->u.csi,
     760            access->member_name);
     761
     762        if (member == NULL) {
     763                printf("Error: Object of class '");
     764                symbol_print_fqn(run->program, object->class_sym);
     765                printf("' has no member named '%s'.\n",
     766                    strtab_get_str(access->member_name->sid));
     767                exit(1);
     768        }
     769
     770#ifdef DEBUG_RUN_TRACE
     771        printf("Found member '%s'.\n",
     772            strtab_get_str(access->member_name->sid));
     773#endif
     774
     775        switch (member->sc) {
     776        case sc_csi:
     777                printf("Error: Accessing object member which is nested CSI.\n");
     778                exit(1);
     779        case sc_fun:
     780                /* Construct delegate. */
     781                ritem = rdata_item_new(ic_value);
     782                value = rdata_value_new();
     783                ritem->u.value = value;
     784
     785                var = rdata_var_new(vc_deleg);
     786                value->var = var;
     787                deleg_v = rdata_deleg_new();
     788                var->u.deleg_v = deleg_v;
     789
     790                deleg_v->obj = arg->u.value->var;
    382791                deleg_v->sym = member;
    383 
    384                 *res = rarg;
    385                 return;
    386         }
    387 
    388         *res = NULL;
     792                break;
     793        case sc_var:
     794                /* Construct variable address item. */
     795                ritem = rdata_item_new(ic_address);
     796                address = rdata_address_new();
     797                ritem->u.address = address;
     798
     799                address->vref = intmap_get(&object->fields,
     800                    access->member_name->sid);
     801                assert(address->vref != NULL);
     802                break;
     803        case sc_prop:
     804                printf("Unimplemented: Accessing object property.\n");
     805                exit(1);
     806        }
     807
     808        *res = ritem;
    389809}
    390810
     
    399819        rdata_item_t *rarg_i, *rarg_vi;
    400820
     821        stree_fun_t *fun;
     822        run_fun_ar_t *fun_ar;
     823
    401824#ifdef DEBUG_RUN_TRACE
    402825        printf("Run call operation.\n");
     
    422845        printf("'\n");
    423846#endif
    424 
    425847        /* Evaluate function arguments. */
    426848        list_init(&arg_vals);
     
    430852                arg = list_node_data(node, stree_expr_t *);
    431853                run_expr(run, arg, &rarg_i);
    432                 run_cvt_value_item(run, rarg_i, &rarg_vi);
     854                rdata_cvt_value_item(rarg_i, &rarg_vi);
    433855
    434856                list_append(&arg_vals, rarg_vi);
     
    436858        }
    437859
    438         run_fun(run, deleg_v->sym->u.fun, &arg_vals);
     860        fun = symbol_to_fun(deleg_v->sym);
     861        assert(fun != NULL);
     862
     863        /* Create function activation record. */
     864        run_fun_ar_create(run, deleg_v->obj, fun, &fun_ar);
     865
     866        /* Fill in argument values. */
     867        run_fun_ar_set_args(run, fun_ar, &arg_vals);
     868
     869        /* Run the function. */
     870        run_fun(run, fun_ar, res);
    439871
    440872#ifdef DEBUG_RUN_TRACE
    441873        printf("Returned from function call.\n");
    442874#endif
    443         *res = NULL;
    444875}
    445876
     
    457888        run_expr(run, assign->src, &rsrc_i);
    458889
    459         run_cvt_value_item(run, rsrc_i, &rsrc_vi);
     890        rdata_cvt_value_item(rsrc_i, &rsrc_vi);
    460891        src_val = rsrc_vi->u.value;
    461892
     
    466897        }
    467898
    468         run_address_write(run, rdest_i->u.address, rsrc_vi->u.value);
     899        rdata_address_write(rdest_i->u.address, rsrc_vi->u.value);
    469900
    470901        *res = NULL;
     
    483914        rdata_var_t *var;
    484915
    485         run_cvt_value_item(run, item, &vitem);
     916        (void) run;
     917        rdata_cvt_value_item(item, &vitem);
    486918
    487919        assert(vitem->ic == ic_value);
     
    495927        return (var->u.int_v->value != 0);
    496928}
    497 
    498 /** Convert item to value item.
    499  *
    500  * If @a item is a value, we just return a copy. If @a item is an address,
    501  * we read from the address.
    502  */
    503 void run_cvt_value_item(run_t *run, rdata_item_t *item,
    504     rdata_item_t **ritem)
    505 {
    506         rdata_value_t *value;
    507 
    508         /* Address item. Perform read operation. */
    509         if (item->ic == ic_address) {
    510                 run_address_read(run, item->u.address, ritem);
    511                 return;
    512         }
    513 
    514         /* It already is a value, we can share the @c var. */
    515         value = rdata_value_new();
    516         value->var = item->u.value->var;
    517         *ritem = rdata_item_new(ic_value);
    518         (*ritem)->u.value = value;
    519 }
    520 
    521 /** Read data from an address.
    522  *
    523  * Return value stored in a variable at the specified address.
    524  */
    525 static void run_address_read(run_t *run, rdata_address_t *address,
    526     rdata_item_t **ritem)
    527 {
    528         rdata_value_t *value;
    529         rdata_var_t *rvar;
    530         (void) run;
    531 
    532         /* Perform a shallow copy of @c var. */
    533         rdata_var_copy(address->vref, &rvar);
    534 
    535         value = rdata_value_new();
    536         value->var = rvar;
    537         *ritem = rdata_item_new(ic_value);
    538         (*ritem)->u.value = value;
    539 }
    540 
    541 /** Write data to an address.
    542  *
    543  * Store @a value to the variable at @a address.
    544  */
    545 static void run_address_write(run_t *run, rdata_address_t *address,
    546     rdata_value_t *value)
    547 {
    548         rdata_var_t *nvar;
    549         rdata_var_t *orig_var;
    550 
    551         /* Perform a shallow copy of @c value->var. */
    552         rdata_var_copy(value->var, &nvar);
    553         orig_var = address->vref;
    554 
    555         /* XXX do this in a prettier way. */
    556 
    557         orig_var->vc = nvar->vc;
    558         switch (nvar->vc) {
    559         case vc_int: orig_var->u.int_v = nvar->u.int_v; break;
    560         case vc_ref: orig_var->u.ref_v = nvar->u.ref_v; break;
    561         case vc_deleg: orig_var->u.deleg_v = nvar->u.deleg_v; break;
    562         case vc_object: orig_var->u.object_v = nvar->u.object_v; break;
    563         default: assert(b_false);
    564         }
    565 
    566         /* XXX We should free some stuff around here. */
    567 }
Note: See TracChangeset for help on using the changeset viewer.