Changeset d0febca in mainline for uspace/app/sbi/src/run.c


Ignore:
Timestamp:
2010-03-13T12:04:37Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7715994
Parents:
94d484a
Message:

Update SBI to rev. 100.

File:
1 edited

Legend:

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

    r94d484a rd0febca  
    5858static bool_t run_exc_match(run_t *run, stree_except_t *except_c);
    5959
     60static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
     61    rdata_item_t **ritem);
     62static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
     63    rdata_value_t *value);
     64
    6065/** Initialize runner instance. */
    6166void run_init(run_t *run)
     
    7176        stree_ident_t *fake_ident;
    7277        list_t main_args;
    73         run_fun_ar_t *fun_ar;
     78        run_proc_ar_t *proc_ar;
    7479        rdata_item_t *res;
    7580
     
    7984        /* Initialize thread activation record. */
    8085        run->thread_ar = run_thread_ar_new();
    81         list_init(&run->thread_ar->fun_ar);
     86        list_init(&run->thread_ar->proc_ar);
    8287        run->thread_ar->bo_mode = bm_none;
    8388
     
    103108        /* Run function @c main. */
    104109        list_init(&main_args);
    105         run_fun_ar_create(run, NULL, main_fun, &fun_ar);
    106         run_fun_ar_set_args(run, fun_ar, &main_args);
    107         run_fun(run, fun_ar, &res);
     110        run_proc_ar_create(run, NULL, main_fun_sym, main_fun->body, &proc_ar);
     111        run_proc_ar_set_args(run, proc_ar, &main_args);
     112        run_proc(run, proc_ar, &res);
    108113
    109114        /* Check for unhandled exceptions. */
     
    115120}
    116121
    117 /** Run member function */
    118 void run_fun(run_t *run, run_fun_ar_t *fun_ar, rdata_item_t **res)
    119 {
    120         stree_symbol_t *fun_sym;
    121         stree_fun_t *fun;
     122/** Run procedure. */
     123void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res)
     124{
     125        stree_symbol_t *proc_sym;
    122126        list_node_t *node;
    123127
    124         fun_sym = fun_ar->fun_sym;
    125         fun = symbol_to_fun(fun_sym);
    126         assert(fun != NULL);
     128        proc_sym = proc_ar->proc_sym;
    127129
    128130#ifdef DEBUG_RUN_TRACE
    129131        printf("Start executing function '");
    130         symbol_print_fqn(run->program, fun_sym);
     132        symbol_print_fqn(run->program, proc_sym);
    131133        printf("'.\n");
    132134#endif
    133         /* Add function AR to the stack. */
    134         list_append(&run->thread_ar->fun_ar, fun_ar);
    135 
    136         /* Run main function block. */
    137         if (fun->body != NULL) {
    138                 run_block(run, fun->body);
     135        /* Add procedure AR to the stack. */
     136        list_append(&run->thread_ar->proc_ar, proc_ar);
     137
     138        /* Run main procedure block. */
     139        if (proc_ar->proc_block != NULL) {
     140                run_block(run, proc_ar->proc_block);
    139141        } else {
    140                 builtin_run_fun(run, fun_sym);
     142                builtin_run_proc(run, proc_sym);
    141143        }
    142144
     
    146148                printf("Error: Misplaced 'break' statement.\n");
    147149                exit(1);
    148         case bm_fun:
     150        case bm_proc:
    149151                run->thread_ar->bo_mode = bm_none;
    150152                break;
     
    154156
    155157#ifdef DEBUG_RUN_TRACE
    156         printf("Done executing function '");
    157         symbol_print_fqn(run->program, fun_sym);
     158        printf("Done executing procedure '");
     159        symbol_print_fqn(run->program, proc_sym);
    158160        printf("'.\n");
    159161
    160162        run_print_fun_bt(run);
    161163#endif
    162         /* Remove function activation record from the stack. */
    163         node = list_last(&run->thread_ar->fun_ar);
    164         assert(list_node_data(node, run_fun_ar_t *) == fun_ar);
    165         list_remove(&run->thread_ar->fun_ar, node);
    166 
    167         *res = fun_ar->retval;
     164        /* Remove procedure activation record from the stack. */
     165        node = list_last(&run->thread_ar->proc_ar);
     166        assert(list_node_data(node, run_proc_ar_t *) == proc_ar);
     167        list_remove(&run->thread_ar->proc_ar, node);
     168
     169        /* Procedure should not return an address. */
     170        assert(proc_ar->retval == NULL || proc_ar->retval->ic == ic_value);
     171        *res = proc_ar->retval;
    168172}
    169173
     
    171175static void run_block(run_t *run, stree_block_t *block)
    172176{
    173         run_fun_ar_t *fun_ar;
     177        run_proc_ar_t *proc_ar;
    174178        run_block_ar_t *block_ar;
    175179        list_node_t *node;
     
    185189
    186190        /* Add block activation record to the stack. */
    187         fun_ar = run_get_current_fun_ar(run);
    188         list_append(&fun_ar->block_ar, block_ar);
     191        proc_ar = run_get_current_proc_ar(run);
     192        list_append(&proc_ar->block_ar, block_ar);
    189193
    190194        node = list_first(&block->stats);
     
    204208
    205209        /* Remove block activation record from the stack. */
    206         node = list_last(&fun_ar->block_ar);
     210        node = list_last(&proc_ar->block_ar);
    207211        assert(list_node_data(node, run_block_ar_t *) == block_ar);
    208         list_remove(&fun_ar->block_ar, node);
     212        list_remove(&proc_ar->block_ar, node);
    209213}
    210214
     
    357361#endif
    358362        run_expr(run, raise_s->expr, &rexpr);
    359         rdata_cvt_value_item(rexpr, &rexpr_vi);
     363        run_cvt_value_item(run, rexpr, &rexpr_vi);
    360364
    361365        /* Store expression result in thread AR. */
     
    370374{
    371375        rdata_item_t *rexpr;
    372         run_fun_ar_t *fun_ar;
     376        rdata_item_t *rexpr_vi;
     377        run_proc_ar_t *proc_ar;
    373378
    374379#ifdef DEBUG_RUN_TRACE
     
    376381#endif
    377382        run_expr(run, return_s->expr, &rexpr);
     383        run_cvt_value_item(run, rexpr, &rexpr_vi);
    378384
    379385        /* Store expression result in function AR. */
    380         fun_ar = run_get_current_fun_ar(run);
    381         fun_ar->retval = rexpr;
    382 
    383         /* Force control to ascend and leave the function. */
     386        proc_ar = run_get_current_proc_ar(run);
     387        proc_ar->retval = rexpr_vi;
     388
     389        /* Force control to ascend and leave the procedure. */
    384390        if (run->thread_ar->bo_mode == bm_none)
    385                 run->thread_ar->bo_mode = bm_fun;
     391                run->thread_ar->bo_mode = bm_proc;
    386392}
    387393
     
    501507rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name)
    502508{
    503         run_fun_ar_t *fun_ar;
     509        run_proc_ar_t *proc_ar;
    504510        run_block_ar_t *block_ar;
    505511        rdata_var_t *var;
    506512        list_node_t *node;
    507513
    508         fun_ar = run_get_current_fun_ar(run);
    509         node = list_last(&fun_ar->block_ar);
     514        proc_ar = run_get_current_proc_ar(run);
     515        node = list_last(&proc_ar->block_ar);
    510516
    511517        /* Walk through all block activation records. */
     
    516522                        return var;
    517523
    518                 node = list_prev(&fun_ar->block_ar, node);
     524                node = list_prev(&proc_ar->block_ar, node);
    519525        }
    520526
     
    524530
    525531/** Get current function activation record. */
    526 run_fun_ar_t *run_get_current_fun_ar(run_t *run)
     532run_proc_ar_t *run_get_current_proc_ar(run_t *run)
    527533{
    528534        list_node_t *node;
    529535
    530         node = list_last(&run->thread_ar->fun_ar);
    531         return list_node_data(node, run_fun_ar_t *);
     536        node = list_last(&run->thread_ar->proc_ar);
     537        return list_node_data(node, run_proc_ar_t *);
    532538}
    533539
     
    535541run_block_ar_t *run_get_current_block_ar(run_t *run)
    536542{
    537         run_fun_ar_t *fun_ar;
     543        run_proc_ar_t *proc_ar;
    538544        list_node_t *node;
    539545
    540         fun_ar = run_get_current_fun_ar(run);
    541 
    542         node = list_last(&fun_ar->block_ar);
     546        proc_ar = run_get_current_proc_ar(run);
     547
     548        node = list_last(&proc_ar->block_ar);
    543549        return list_node_data(node, run_block_ar_t *);
    544550}
     
    547553stree_csi_t *run_get_current_csi(run_t *run)
    548554{
    549         run_fun_ar_t *fun_ar;
    550 
    551         fun_ar = run_get_current_fun_ar(run);
    552         return fun_ar->fun_sym->outer_csi;
     555        run_proc_ar_t *proc_ar;
     556
     557        proc_ar = run_get_current_proc_ar(run);
     558        return proc_ar->proc_sym->outer_csi;
    553559}
    554560
     
    600606
    601607/** Construct a function AR. */
    602 void run_fun_ar_create(run_t *run, rdata_var_t *obj, stree_fun_t *fun,
    603     run_fun_ar_t **rfun_ar)
    604 {
    605         run_fun_ar_t *fun_ar;
     608void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_symbol_t *proc_sym,
     609    stree_block_t *proc_block, run_proc_ar_t **rproc_ar)
     610{
     611        run_proc_ar_t *proc_ar;
     612        run_block_ar_t *block_ar;
    606613
    607614        (void) run;
    608615
    609616        /* Create function activation record. */
    610         fun_ar = run_fun_ar_new();
    611         fun_ar->obj = obj;
    612         fun_ar->fun_sym = fun_to_symbol(fun);
    613         list_init(&fun_ar->block_ar);
    614 
    615         fun_ar->retval = NULL;
    616 
    617         *rfun_ar = fun_ar;
    618 }
    619 
    620 /** Fill arguments in a function AR. */
    621 void run_fun_ar_set_args(run_t *run, run_fun_ar_t *fun_ar, list_t *args)
     617        proc_ar = run_proc_ar_new();
     618        proc_ar->obj = obj;
     619        proc_ar->proc_sym = proc_sym;
     620        proc_ar->proc_block = proc_block;
     621        list_init(&proc_ar->block_ar);
     622
     623        proc_ar->retval = NULL;
     624
     625        /* Create special block activation record to hold function arguments. */
     626        block_ar = run_block_ar_new();
     627        intmap_init(&block_ar->vars);
     628        list_append(&proc_ar->block_ar, block_ar);
     629
     630        *rproc_ar = proc_ar;
     631}
     632
     633/** Fill arguments in a procedure AR.
     634 *
     635 * When invoking a procedure this is used to store the argument values
     636 * in the activation record.
     637 */
     638void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals)
    622639{
    623640        stree_fun_t *fun;
     641        stree_prop_t *prop;
     642        list_t *args;
     643        stree_proc_arg_t *varg;
     644
    624645        run_block_ar_t *block_ar;
    625         list_node_t *rarg_n, *farg_n;
     646        list_node_t *block_ar_n;
     647        list_node_t *rarg_n, *parg_n;
    626648        list_node_t *cn;
    627649        rdata_item_t *rarg;
    628         stree_fun_arg_t *farg;
     650        stree_proc_arg_t *parg;
    629651        rdata_var_t *var;
    630652        rdata_var_t *ref_var;
     
    633655        int n_vargs, idx;
    634656
    635         /* AR should have been created with run_fun_ar_create(). */
    636         assert(fun_ar->fun_sym != NULL);
    637         assert(list_is_empty(&fun_ar->block_ar));
    638 
    639         fun = symbol_to_fun(fun_ar->fun_sym);
    640         assert(fun != NULL);
    641 
    642         /* Create special block activation record to hold function arguments. */
    643         block_ar = run_block_ar_new();
    644         intmap_init(&block_ar->vars);
    645         list_append(&fun_ar->block_ar, block_ar);
     657        /* AR should have been created with run_proc_ar_create(). */
     658        assert(proc_ar->proc_sym != NULL);
     659
     660        /*
     661         * The procedure being activated should be a member function or
     662         * property getter/setter.
     663         */
     664        switch (proc_ar->proc_sym->sc) {
     665        case sc_fun:
     666                fun = symbol_to_fun(proc_ar->proc_sym);
     667                args = &fun->args;
     668                varg = fun->varg;
     669                break;
     670        case sc_prop:
     671                prop = symbol_to_prop(proc_ar->proc_sym);
     672                args = &prop->args;
     673                varg = prop->varg;
     674                break;
     675        default:
     676                assert(b_false);
     677        }
     678
     679        /* Fetch first block activation record. */
     680        block_ar_n = list_first(&proc_ar->block_ar);
     681        assert(block_ar_n != NULL);
     682        block_ar = list_node_data(block_ar_n, run_block_ar_t *);
    646683
    647684        /* Declare local variables to hold argument values. */
    648         rarg_n = list_first(args);
    649         farg_n = list_first(&fun->args);
    650 
    651         while (farg_n != NULL) {
     685        rarg_n = list_first(arg_vals);
     686        parg_n = list_first(args);
     687
     688        while (parg_n != NULL) {
    652689                if (rarg_n == NULL) {
    653690                        printf("Error: Too few arguments to function '");
    654                         symbol_print_fqn(run->program, fun_ar->fun_sym);
     691                        symbol_print_fqn(run->program, proc_ar->proc_sym);
    655692                        printf("'.\n");
    656693                        exit(1);
     
    658695
    659696                rarg = list_node_data(rarg_n, rdata_item_t *);
    660                 farg = list_node_data(farg_n, stree_fun_arg_t *);
     697                parg = list_node_data(parg_n, stree_proc_arg_t *);
    661698
    662699                assert(rarg->ic == ic_value);
     
    666703
    667704                /* Declare variable using name of formal argument. */
    668                 intmap_set(&block_ar->vars, farg->name->sid, var);
    669 
    670                 rarg_n = list_next(args, rarg_n);
    671                 farg_n = list_next(&fun->args, farg_n);
    672         }
    673 
    674         if (fun->varg != NULL) {
     705                intmap_set(&block_ar->vars, parg->name->sid, var);
     706
     707                rarg_n = list_next(arg_vals, rarg_n);
     708                parg_n = list_next(args, parg_n);
     709        }
     710
     711        if (varg != NULL) {
    675712                /* Function is variadic. Count number of variadic arguments. */
    676713                cn = rarg_n;
     
    678715                while (cn != NULL) {
    679716                        n_vargs += 1;
    680                         cn = list_next(args, cn);
     717                        cn = list_next(arg_vals, cn);
    681718                }
    682719
     
    695732                        rdata_var_write(array->element[idx], rarg->u.value);
    696733
    697                         rarg_n = list_next(args, rarg_n);
     734                        rarg_n = list_next(arg_vals, rarg_n);
    698735                        idx += 1;
    699736                }
     
    709746
    710747                /* Declare variable using name of formal argument. */
    711                 intmap_set(&block_ar->vars, fun->varg->name->sid,
     748                intmap_set(&block_ar->vars, varg->name->sid,
    712749                    ref_var);
    713750        }
     
    716753        if (rarg_n != NULL) {
    717754                printf("Error: Too many arguments to function '");
    718                 symbol_print_fqn(run->program, fun_ar->fun_sym);
     755                symbol_print_fqn(run->program, proc_ar->proc_sym);
    719756                printf("'.\n");
    720757                exit(1);
    721758        }
     759}
     760
     761/** Fill setter argument in a procedure AR.
     762 *
     763 * When invoking a setter this is used to store its argument value in its
     764 * procedure activation record.
     765 */
     766void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
     767    rdata_item_t *arg_val)
     768{
     769        stree_prop_t *prop;
     770        run_block_ar_t *block_ar;
     771        list_node_t *block_ar_n;
     772        rdata_var_t *var;
     773
     774        (void) run;
     775
     776        /* AR should have been created with run_proc_ar_create(). */
     777        assert(proc_ar->proc_sym != NULL);
     778
     779        /* The procedure being activated should be a property setter. */
     780        prop = symbol_to_prop(proc_ar->proc_sym);
     781        assert(prop != NULL);
     782
     783        /* Fetch first block activation record. */
     784        block_ar_n = list_first(&proc_ar->block_ar);
     785        assert(block_ar_n != NULL);
     786        block_ar = list_node_data(block_ar_n, run_block_ar_t *);
     787
     788        assert(arg_val->ic == ic_value);
     789
     790        /* Construct a variable from the argument value. */
     791        run_value_item_to_var(arg_val, &var);
     792
     793        /* Declare variable using name of formal argument. */
     794        intmap_set(&block_ar->vars, prop->setter_arg_name->sid, var);
    722795}
    723796
     
    726799{
    727800        list_node_t *node;
    728         run_fun_ar_t *fun_ar;
     801        run_proc_ar_t *proc_ar;
    729802
    730803        printf("Backtrace:\n");
    731         node = list_last(&run->thread_ar->fun_ar);
     804        node = list_last(&run->thread_ar->proc_ar);
    732805        while (node != NULL) {
    733806                printf(" * ");
    734                 fun_ar = list_node_data(node, run_fun_ar_t *);
    735                 symbol_print_fqn(run->program, fun_ar->fun_sym);
     807                proc_ar = list_node_data(node, run_proc_ar_t *);
     808                symbol_print_fqn(run->program, proc_ar->proc_sym);
    736809                printf("\n");
    737810
    738                 node = list_prev(&run->thread_ar->fun_ar, node);
    739         }
    740 }
     811                node = list_prev(&run->thread_ar->proc_ar, node);
     812        }
     813}
     814
     815/** Convert item to value item.
     816 *
     817 * If @a item is a value, we just return a copy. If @a item is an address,
     818 * we read from the address.
     819 */
     820void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem)
     821{
     822        rdata_value_t *value;
     823
     824        /*
     825         * This can happen when trying to use output of a function which
     826         * does not return a value.
     827         */
     828        if (item == NULL) {
     829                printf("Error: Sub-expression has no value.\n");
     830                exit(1);
     831        }
     832
     833        /* Address item. Perform read operation. */
     834        if (item->ic == ic_address) {
     835                run_address_read(run, item->u.address, ritem);
     836                return;
     837        }
     838
     839        /* It already is a value, we can share the @c var. */
     840        value = rdata_value_new();
     841        value->var = item->u.value->var;
     842        *ritem = rdata_item_new(ic_value);
     843        (*ritem)->u.value = value;
     844}
     845
     846
     847/** Read data from an address.
     848 *
     849 * Return value stored in a variable at the specified address.
     850 */
     851void run_address_read(run_t *run, rdata_address_t *address,
     852    rdata_item_t **ritem)
     853{
     854        (void) run;
     855
     856        switch (address->ac) {
     857        case ac_var:
     858                rdata_var_read(address->u.var_a->vref, ritem);
     859                break;
     860        case ac_prop:
     861                run_aprop_read(run, address->u.prop_a, ritem);
     862                break;
     863        }
     864
     865        assert((*ritem)->ic == ic_value);
     866}
     867
     868/** Write data to an address.
     869 *
     870 * Store @a value to the variable at @a address.
     871 */
     872void run_address_write(run_t *run, rdata_address_t *address,
     873    rdata_value_t *value)
     874{
     875        (void) run;
     876
     877        switch (address->ac) {
     878        case ac_var:
     879                rdata_var_write(address->u.var_a->vref, value);
     880                break;
     881        case ac_prop:
     882                run_aprop_write(run, address->u.prop_a, value);
     883                break;
     884        }
     885}
     886
     887static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
     888    rdata_item_t **ritem)
     889{
     890        rdata_deleg_t *deleg;
     891        rdata_var_t *obj;
     892        stree_symbol_t *prop_sym;
     893        stree_prop_t *prop;
     894
     895        run_proc_ar_t *proc_ar;
     896
     897#ifdef DEBUG_RUN_TRACE
     898        printf("Read from property.\n");
     899#endif
     900        /*
     901         * If @c tvalue is present, we need to use the relevant part from that
     902         * instead of re-reading the whole thing.
     903         */
     904        if (addr_prop->tvalue != NULL) {
     905                printf("Unimplemented: Property field access.\n");
     906                exit(1);
     907        }
     908
     909        if (addr_prop->apc == apc_named)
     910                deleg = addr_prop->u.named->prop_d;
     911        else
     912                deleg = addr_prop->u.indexed->object_d;
     913
     914        obj = deleg->obj;
     915        prop_sym = deleg->sym;
     916        prop = symbol_to_prop(prop_sym);
     917        assert(prop != NULL);
     918
     919        if (prop->getter_body == NULL) {
     920                printf("Error: Property is not readable.\n");
     921                exit(1);
     922        }
     923
     924        /* Create procedure activation record. */
     925        run_proc_ar_create(run, obj, prop_sym, prop->getter_body, &proc_ar);
     926
     927        /* Fill in arguments (indices). */
     928        if (addr_prop->apc == apc_indexed) {
     929                run_proc_ar_set_args(run, proc_ar,
     930                    &addr_prop->u.indexed->args);
     931        }
     932
     933        /* Run getter. */
     934        run_proc(run, proc_ar, ritem);
     935
     936#ifdef DEBUG_RUN_TRACE
     937        printf("Getter returns ");
     938        rdata_item_print(*ritem);
     939        printf(".\n");
     940        printf("Done reading from property.\n");
     941#endif
     942}
     943
     944static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
     945    rdata_value_t *value)
     946{
     947        rdata_deleg_t *deleg;
     948        rdata_var_t *obj;
     949        stree_symbol_t *prop_sym;
     950        stree_prop_t *prop;
     951
     952        run_proc_ar_t *proc_ar;
     953        rdata_item_t *vitem;
     954        rdata_item_t *ritem;
     955
     956#ifdef DEBUG_RUN_TRACE
     957        printf("Write to property.\n");
     958#endif
     959        /* If @c tvalue is present, we need to modify it and write it back. */
     960        if (addr_prop->tvalue != NULL) {
     961                printf("Unimplemented: Read-modify-write property access.\n");
     962                exit(1);
     963        }
     964
     965        if (addr_prop->apc == apc_named)
     966                deleg = addr_prop->u.named->prop_d;
     967        else
     968                deleg = addr_prop->u.indexed->object_d;
     969
     970        obj = deleg->obj;
     971        prop_sym = deleg->sym;
     972        prop = symbol_to_prop(prop_sym);
     973        assert(prop != NULL);
     974
     975        if (prop->setter_body == NULL) {
     976                printf("Error: Property is not writable.\n");
     977                exit(1);
     978        }
     979
     980        vitem = rdata_item_new(ic_value);
     981        vitem->u.value = value;
     982
     983        /* Create procedure activation record. */
     984        run_proc_ar_create(run, obj, prop_sym, prop->setter_body, &proc_ar);
     985
     986        /* Fill in arguments (indices). */
     987        if (addr_prop->apc == apc_indexed) {
     988                run_proc_ar_set_args(run, proc_ar,
     989                    &addr_prop->u.indexed->args);
     990        }
     991
     992        /* Fill in value argument for setter. */
     993        run_proc_ar_set_setter_arg(run, proc_ar, vitem);
     994
     995        /* Run setter. */
     996        run_proc(run, proc_ar, &ritem);
     997
     998        /* Setter should not return a value. */
     999        assert(ritem == NULL);
     1000
     1001#ifdef DEBUG_RUN_TRACE
     1002        printf("Done writing to property.\n");
     1003#endif
     1004}
     1005
     1006/** Return reference to a variable.
     1007 *
     1008 * Constructs a reference (value item) pointing to @a var.
     1009 */
     1010void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res)
     1011{
     1012        rdata_ref_t *ref;
     1013        rdata_var_t *ref_var;
     1014        rdata_value_t *ref_value;
     1015        rdata_item_t *ref_item;
     1016
     1017        (void) run;
     1018
     1019        /* Create reference to the variable. */
     1020        ref = rdata_ref_new();
     1021        ref_var = rdata_var_new(vc_ref);
     1022        ref->vref = var;
     1023        ref_var->u.ref_v = ref;
     1024
     1025        /* Construct value of the reference to return. */
     1026        ref_item = rdata_item_new(ic_value);
     1027        ref_value = rdata_value_new();
     1028        ref_item->u.value = ref_value;
     1029        ref_value->var = ref_var;
     1030
     1031        *res = ref_item;
     1032}
     1033
     1034/** Return address of reference target.
     1035 *
     1036 * Takes a reference (address or value) and returns the address (item) of
     1037 * the target of the reference.
     1038 */
     1039void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem)
     1040{
     1041        rdata_item_t *ref_val;
     1042        rdata_item_t *item;
     1043        rdata_address_t *address;
     1044        rdata_addr_var_t *addr_var;
     1045
     1046#ifdef DEBUG_RUN_TRACE
     1047        printf("run_dereference()\n");
     1048#endif
     1049        run_cvt_value_item(run, ref, &ref_val);
     1050        assert(ref_val->u.value->var->vc == vc_ref);
     1051
     1052        item = rdata_item_new(ic_address);
     1053        address = rdata_address_new(ac_var);
     1054        addr_var = rdata_addr_var_new();
     1055        item->u.address = address;
     1056        address->u.var_a = addr_var;
     1057        addr_var->vref = ref_val->u.value->var->u.ref_v->vref;
     1058
     1059        if (addr_var->vref == NULL) {
     1060                printf("Error: Accessing null reference.\n");
     1061                exit(1);
     1062        }
     1063
     1064#ifdef DEBUG_RUN_TRACE
     1065        printf("vref set to %p\n", addr_var->vref);
     1066#endif
     1067        *ritem = item;
     1068}
     1069
    7411070
    7421071run_thread_ar_t *run_thread_ar_new(void)
     
    7531082}
    7541083
    755 run_fun_ar_t *run_fun_ar_new(void)
    756 {
    757         run_fun_ar_t *fun_ar;
    758 
    759         fun_ar = calloc(1, sizeof(run_fun_ar_t));
    760         if (fun_ar == NULL) {
     1084run_proc_ar_t *run_proc_ar_new(void)
     1085{
     1086        run_proc_ar_t *proc_ar;
     1087
     1088        proc_ar = calloc(1, sizeof(run_proc_ar_t));
     1089        if (proc_ar == NULL) {
    7611090                printf("Memory allocation failed.\n");
    7621091                exit(1);
    7631092        }
    7641093
    765         return fun_ar;
     1094        return proc_ar;
    7661095}
    7671096
Note: See TracChangeset for help on using the changeset viewer.