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


Ignore:
Timestamp:
2010-04-23T21:41:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4f866c
Parents:
074444f
Message:

Update SBI to rev. 207.

File:
1 edited

Legend:

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

    r074444f r38aaacc2  
    6767    rdata_value_t *value);
    6868
    69 /** Initialize runner instance. */
     69static void run_var_new_tprimitive(run_t *run, tdata_primitive_t *tprimitive,
     70    rdata_var_t **rvar);
     71static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar);
     72static void run_var_new_deleg(run_t *run, rdata_var_t **rvar);
     73
     74
     75/** Initialize runner instance.
     76 *
     77 * @param run           Runner object
     78 */
    7079void run_init(run_t *run)
    7180{
     
    7382}
    7483
    75 /** Run program */
     84/** Run program.
     85 *
     86 * Associates the program @a prog with the runner object and executes
     87 * it. If a run-time error occurs during the execution (e.g. an unhandled
     88 * exception), @a run->error will be set to @c b_true when this function
     89 * returns.
     90 *
     91 * @param run           Runner object
     92 * @param prog          Program to run
     93 */
    7694void run_program(run_t *run, stree_program_t *prog)
    7795{
     
    119137}
    120138
    121 /** Run procedure. */
     139/** Run procedure.
     140 *
     141 * Inserts the provided procedure AR @a proc_ar on the execution stack
     142 * (in the thread AR) and executes the procedure. The return value
     143 * of the procedure is stored to *(@a res). @c NULL is stored if the
     144 * procedure returns no value.
     145 *
     146 * If the procedure execution bails out due to an exception, this
     147 * can be determined by looking at @c bo_mode in thread AR. Also,
     148 * in this case @c NULL is stored into *(@a res).
     149 *
     150 * @param run           Runner object
     151 * @param proc_ar       Procedure activation record
     152 * @param res           Place to store procedure return value
     153 */
    122154void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res)
    123155{
     
    171203}
    172204
    173 /** Run code block */
     205/** Run code block.
     206 *
     207 * @param run           Runner object
     208 * @param block         Block to run
     209 */
    174210static void run_block(run_t *run, stree_block_t *block)
    175211{
     
    218254 * @a res.
    219255 *
    220  * @param run   Runner object.
    221  * @param stat  Statement to run.
    222  * @param res   Place to store exps result or NULL if not interested.
     256 * @param run   Runner object
     257 * @param stat  Statement to run
     258 * @param res   Place to store exps result or NULL if not interested
    223259 */
    224260void run_stat(run_t *run, stree_stat_t *stat, rdata_item_t **res)
     
    266302 * of the expression (or NULL if it has no value) will be stored to @a res.
    267303 *
    268  * @param run   Runner object.
    269  * @param exps  Expression statement to run.
    270  * @param res   Place to store exps result or NULL if not interested.
     304 * @param run   Runner object
     305 * @param exps  Expression statement to run
     306 * @param res   Place to store exps result or NULL if not interested
    271307 */
    272308static void run_exps(run_t *run, stree_exps_t *exps, rdata_item_t **res)
     
    283319}
    284320
    285 /** Run variable declaration statement. */
     321/** Run variable declaration statement.
     322 *
     323 * @param run   Runner object
     324 * @param vdecl Variable declaration statement to run
     325 */
    286326static void run_vdecl(run_t *run, stree_vdecl_t *vdecl)
    287327{
    288328        run_block_ar_t *block_ar;
    289329        rdata_var_t *var, *old_var;
    290         rdata_int_t *int_v;
     330        tdata_item_t *var_ti;
    291331
    292332#ifdef DEBUG_RUN_TRACE
    293333        printf("Executing variable declaration statement.\n");
    294334#endif
    295 
    296         /* XXX Need to support other variables than int. */
    297 
    298         var = rdata_var_new(vc_int);
    299         int_v = rdata_int_new();
    300 
    301         var->u.int_v = int_v;
    302         bigint_init(&int_v->value, 0);
     335        /* Compute variable type. XXX Memoize. */
     336        run_texpr(run->program, run_get_current_csi(run), vdecl->type,
     337            &var_ti);
     338
     339        /* Create variable and initialize with default value. */
     340        run_var_new(run, var_ti, &var);
    303341
    304342        block_ar = run_get_current_block_ar(run);
     
    318356}
    319357
    320 /** Run @c if statement. */
     358/** Run @c if statement.
     359 *
     360 * @param run   Runner object
     361 * @param if_s  If statement to run
     362 */
    321363static void run_if(run_t *run, stree_if_t *if_s)
    322364{
     
    348390}
    349391
    350 /** Run @c while statement. */
     392/** Run @c while statement.
     393 *
     394 * @param run           Runner object
     395 * @param while_s       While statement to run
     396 */
    351397static void run_while(run_t *run, stree_while_t *while_s)
    352398{
     
    375421}
    376422
    377 /** Run @c raise statement. */
     423/** Run @c raise statement.
     424 *
     425 * @param run           Runner object
     426 * @param raise_s       Raise statement to run
     427 */
    378428static void run_raise(run_t *run, stree_raise_t *raise_s)
    379429{
     
    397447}
    398448
    399 /** Run @c return statement. */
     449/** Run @c return statement.
     450 *
     451 * Sets the return value in procedure AR and forces control to return
     452 * from the function by setting bailout mode to @c bm_proc.
     453 *
     454 * @param run           Runner object
     455 * @param raise_s       Return statement to run
     456 */
    400457static void run_return(run_t *run, stree_return_t *return_s)
    401458{
     
    413470        run_cvt_value_item(run, rexpr, &rexpr_vi);
    414471
    415         /* Store expression result in function AR. */
     472        /* Store expression result in procedure AR. */
    416473        proc_ar = run_get_current_proc_ar(run);
    417474        proc_ar->retval = rexpr_vi;
     
    422479}
    423480
    424 /** Run @c with-except-finally statement. */
     481/** Run @c with-except-finally statement.
     482 *
     483 * Note: 'With' clause is not implemented.
     484 *
     485 * @param run           Runner object
     486 * @param wef_s         With-except-finally statement to run
     487 */
    425488static void run_wef(run_t *run, stree_wef_t *wef_s)
    426489{
     
    489552 * matches except clause @c except_c.
    490553 *
    491  * @param run           Runner object.
    492  * @param except_c      @c except clause.
    493  * @return              @c b_true if there is a match, @c b_false otherwise.
     554 * @param run           Runner object
     555 * @param except_c      @c except clause
     556 * @return              @c b_true if there is a match, @c b_false otherwise
    494557 */
    495558static bool_t run_exc_match(run_t *run, stree_except_t *except_c)
     
    506569
    507570        /* Determine if active exc. is derived from type in exc. clause. */
     571        /* XXX This is wrong, it does not work with generics. */
    508572        return tdata_is_csi_derived_from_ti(exc_csi, etype);
    509573}
     
    511575/** Return CSI of the active exception.
    512576 *
    513  * @param run           Runner object.
    514  * @return              CSI of the active exception.
     577 * @param run           Runner object
     578 * @return              CSI of the active exception
    515579 */
    516580static stree_csi_t *run_exc_payload_get_csi(run_t *run)
     
    557621 * error message and raises a run-time error.
    558622 *
    559  * @param run           Runner object.
     623 * @param run           Runner object
    560624 */
    561625void run_exc_check_unhandled(run_t *run)
     
    579643 *
    580644 * Raises an error that cannot be handled by the user program.
     645 *
     646 * @param run           Runner object
    581647 */
    582648void run_raise_error(run_t *run)
     
    586652}
    587653
    588 /** Construct a special recovery item. */
     654/** Construct a special recovery item.
     655 *
     656 * @param run           Runner object
     657 */
    589658rdata_item_t *run_recovery_item(run_t *run)
    590659{
     
    593662}
    594663
    595 /** Find a local variable in the currently active function. */
     664/** Find a local variable in the currently active function.
     665 *
     666 * @param run           Runner object
     667 * @param name          Name SID of the local variable
     668 * @return              Pointer to var node or @c NULL if not found
     669 */
    596670rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name)
    597671{
     
    618692}
    619693
    620 /** Get current function activation record. */
     694/** Get current procedure activation record.
     695 *
     696 * @param run           Runner object
     697 * @return              Active procedure AR
     698 */
    621699run_proc_ar_t *run_get_current_proc_ar(run_t *run)
    622700{
     
    627705}
    628706
    629 /** Get current block activation record. */
     707/** Get current block activation record.
     708 *
     709 * @param run           Runner object
     710 * @return              Active block AR
     711 */
    630712run_block_ar_t *run_get_current_block_ar(run_t *run)
    631713{
     
    639721}
    640722
    641 /** Get current CSI. */
     723/** Get current CSI.
     724 *
     725 * @param run           Runner object
     726 * @return              Active CSI
     727 */
    642728stree_csi_t *run_get_current_csi(run_t *run)
    643729{
     
    654740 * (1) Create a variable of the desired type.
    655741 * (2) Initialize the variable with the provided value.
     742 *
     743 * @param item          Value item (initial value for variable).
     744 * @param var           Place to store new var node.
    656745 */
    657746void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var)
    658747{
     748        rdata_bool_t *bool_v;
    659749        rdata_char_t *char_v;
     750        rdata_deleg_t *deleg_v;
    660751        rdata_int_t *int_v;
    661752        rdata_string_t *string_v;
     
    667758
    668759        switch (in_var->vc) {
     760        case vc_bool:
     761                *var = rdata_var_new(vc_bool);
     762                bool_v = rdata_bool_new();
     763
     764                (*var)->u.bool_v = bool_v;
     765                bool_v->value = item->u.value->var->u.bool_v->value;
     766                break;
    669767        case vc_char:
    670768                *var = rdata_var_new(vc_char);
     
    675773                    &char_v->value);
    676774                break;
     775        case vc_deleg:
     776                *var = rdata_var_new(vc_deleg);
     777                deleg_v = rdata_deleg_new();
     778
     779                (*var)->u.deleg_v = deleg_v;
     780                deleg_v->obj = item->u.value->var->u.deleg_v->obj;
     781                deleg_v->sym = item->u.value->var->u.deleg_v->sym;
     782                break;
    677783        case vc_int:
    678784                *var = rdata_var_new(vc_int);
     
    704810}
    705811
    706 /** Construct a function AR. */
     812/** Construct a procedure AR.
     813 *
     814 * @param run           Runner object
     815 * @param obj           Object whose procedure is being activated
     816 * @param proc          Procedure that is being activated
     817 * @param rproc_ar      Place to store pointer to new activation record
     818 */
    707819void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc,
    708820    run_proc_ar_t **rproc_ar)
     
    733845 * When invoking a procedure this is used to store the argument values
    734846 * in the activation record.
     847 *
     848 * @param run           Runner object
     849 * @param proc_ar       Existing procedure activation record where to store
     850 *                      the values
     851 * @param arg_vals      List of value items (rdata_item_t *) -- real
     852 *                      argument values
    735853 */
    736854void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals)
     
    767885        case sc_fun:
    768886                fun = symbol_to_fun(outer_symbol);
    769                 args = &fun->args;
    770                 varg = fun->varg;
     887                args = &fun->sig->args;
     888                varg = fun->sig->varg;
    771889                break;
    772890        case sc_prop:
     
    865983 * When invoking a setter this is used to store its argument value in its
    866984 * procedure activation record.
     985 *
     986 * @param run           Runner object
     987 * @param proc_ar       Existing procedure activation record where to store
     988 *                      the setter argument
     989 * @param arg_val       Value items (rdata_item_t *) -- real argument value
    867990 */
    868991void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
     
    8981021}
    8991022
    900 /** Print function activation backtrace. */
     1023/** Print function activation backtrace.
     1024 *
     1025 * Prints a backtrace of activated functions for debugging purposes.
     1026 *
     1027 * @param run           Runner object
     1028 */
    9011029void run_print_fun_bt(run_t *run)
    9021030{
     
    9201048 * If @a item is a value, we just return a copy. If @a item is an address,
    9211049 * we read from the address.
     1050 *
     1051 * @param run           Runner object
     1052 * @param item          Input item (value or address)
     1053 * @param ritem         Place to store pointer to new value item
    9221054 */
    9231055void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem)
     
    9511083 * Get var-class of @a item, regardless whether it is a value or address.
    9521084 * (I.e. the var class of the value or variable at the given address).
     1085 *
     1086 * @param run           Runner object
     1087 * @param item          Value or address item
     1088 * @return              Varclass of @a item
    9531089 */
    9541090var_class_t run_item_get_vc(run_t *run, rdata_item_t *item)
     
    9921128 * copy.
    9931129 *
    994  * @param run   Runner object.
    995  * @param addr  Address of class @c ac_prop.
    996  * @param       Pointer to var node.
     1130 * @param run   Runner object
     1131 * @param addr  Address of class @c ac_prop
     1132 * @return      Pointer to var node
    9971133 */
    9981134static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *addr)
     
    10151151/** Read data from an address.
    10161152 *
    1017  * Return value stored in a variable at the specified address.
     1153 * Read value from the specified address.
     1154 *
     1155 * @param run           Runner object
     1156 * @param address       Address to read
     1157 * @param ritem         Place to store pointer to the value that was read
    10181158 */
    10191159void run_address_read(run_t *run, rdata_address_t *address,
     
    10361176/** Write data to an address.
    10371177 *
    1038  * Store @a value to the variable at @a address.
     1178 * Store value @a value at address @a address.
     1179 *
     1180 * @param run           Runner object
     1181 * @param address       Address to write
     1182 * @param value         Value to store at the address
    10391183 */
    10401184void run_address_write(run_t *run, rdata_address_t *address,
     
    10531197}
    10541198
     1199/** Read data from a property address.
     1200 *
     1201 * This involves invoking the property getter procedure.
     1202 *
     1203 * @param run           Runner object.
     1204 * @param addr_prop     Property address to read.
     1205 * @param ritem         Place to store pointer to the value that was read.
     1206 */
    10551207static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
    10561208    rdata_item_t **ritem)
     
    11161268}
    11171269
     1270/** Write data to a property address.
     1271 *
     1272 * This involves invoking the property setter procedure.
     1273 *
     1274 * @param run           Runner object
     1275 * @param addr_prop     Property address to write
     1276 * @param value         Value to store at the address
     1277 */
    11181278static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
    11191279    rdata_value_t *value)
     
    11811341 *
    11821342 * Constructs a reference (value item) pointing to @a var.
     1343 *
     1344 * @param run           Runner object
     1345 * @param var           Variable node that is being referenced
     1346 * @param res           Place to store pointer to new reference.
    11831347 */
    11841348void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res)
     
    12101374 * Takes a reference (address or value) and returns the address (item) of
    12111375 * the target of the reference.
     1376 *
     1377 * @param run           Runner object
     1378 * @param ref           Reference
     1379 * @param rtitem        Place to store pointer to the resulting address.
    12121380 */
    12131381void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem)
     
    12521420 * error (not for the @c raise statement).
    12531421 *
    1254  * @param run           Runner object.
    1255  * @param csi           Exception class.
     1422 * @param run           Runner object
     1423 * @param csi           Exception class
    12561424 */
    12571425void run_raise_exc(run_t *run, stree_csi_t *csi)
     
    12701438}
    12711439
    1272 /** Determine if we are bailing out. */
     1440/** Determine if we are bailing out.
     1441 *
     1442 * @param run           Runner object
     1443 * @return              @c b_true if we are bailing out, @c b_false otherwise
     1444 */
    12731445bool_t run_is_bo(run_t *run)
    12741446{
     
    12761448}
    12771449
     1450/** Construct a new variable of the given type.
     1451 *
     1452 * The variable is allocated and initialized with a default value
     1453 * based on type item @a ti. For reference types the default value
     1454 * is a null reference. At this point this does not work for generic
     1455 * types (we need RTTI).
     1456 *
     1457 * @param run           Runner object
     1458 * @param ti            Type of variable to create (type item)
     1459 * @param rvar          Place to store pointer to new variable
     1460 */
     1461void run_var_new(run_t *run, tdata_item_t *ti, rdata_var_t **rvar)
     1462{
     1463        rdata_var_t *var;
     1464
     1465        switch (ti->tic) {
     1466        case tic_tprimitive:
     1467                run_var_new_tprimitive(run, ti->u.tprimitive, rvar);
     1468                break;
     1469        case tic_tobject:
     1470        case tic_tarray:
     1471                run_var_new_null_ref(run, rvar);
     1472                break;
     1473        case tic_tdeleg:
     1474        case tic_tfun:
     1475                run_var_new_deleg(run, rvar);
     1476                break;
     1477        case tic_tvref:
     1478                /*
     1479                 * XXX Need to obtain run-time value of type argument to
     1480                 * initialize variable properly.
     1481                 */
     1482                var = rdata_var_new(vc_int);
     1483                var->u.int_v = rdata_int_new();
     1484                bigint_init(&var->u.int_v->value, 0);
     1485                *rvar = var;
     1486                break;
     1487        case tic_ignore:
     1488                assert(b_false);
     1489        }
     1490}
     1491
     1492/** Construct a new variable of primitive type.
     1493 *
     1494 * The variable is allocated and initialized with a default value
     1495 * based on primitive type item @a tprimitive.
     1496 *
     1497 * @param run           Runner object
     1498 * @param ti            Primitive type of variable to create
     1499 * @param rvar          Place to store pointer to new variable
     1500 */
     1501static void run_var_new_tprimitive(run_t *run, tdata_primitive_t *tprimitive,
     1502    rdata_var_t **rvar)
     1503{
     1504        rdata_var_t *var;
     1505
     1506        (void) run;
     1507
     1508        switch (tprimitive->tpc) {
     1509        case tpc_bool:
     1510                var = rdata_var_new(vc_bool);
     1511                var->u.bool_v = rdata_bool_new();
     1512                var->u.bool_v->value = b_false;
     1513                break;
     1514        case tpc_char:
     1515                var = rdata_var_new(vc_char);
     1516                var->u.char_v = rdata_char_new();
     1517                bigint_init(&var->u.char_v->value, 0);
     1518                break;
     1519        case tpc_int:
     1520                var = rdata_var_new(vc_int);
     1521                var->u.int_v = rdata_int_new();
     1522                bigint_init(&var->u.int_v->value, 0);
     1523                break;
     1524        case tpc_nil:
     1525                assert(b_false);
     1526        case tpc_string:
     1527                var = rdata_var_new(vc_string);
     1528                var->u.string_v = rdata_string_new();
     1529                var->u.string_v->value = "";
     1530                break;
     1531        case tpc_resource:
     1532                var = rdata_var_new(vc_resource);
     1533                var->u.resource_v = rdata_resource_new();
     1534                var->u.resource_v->data = NULL;
     1535                break;
     1536        }
     1537
     1538        *rvar = var;
     1539}
     1540
     1541/** Construct a new variable containing null reference.
     1542 *
     1543 * @param run           Runner object
     1544 * @param rvar          Place to store pointer to new variable
     1545 */
     1546static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar)
     1547{
     1548        rdata_var_t *var;
     1549
     1550        (void) run;
     1551
     1552        /* Return null reference. */
     1553        var = rdata_var_new(vc_ref);
     1554        var->u.ref_v = rdata_ref_new();
     1555
     1556        *rvar = var;
     1557}
     1558
     1559/** Construct a new variable containing invalid delegate.
     1560 *
     1561 * @param run           Runner object
     1562 * @param rvar          Place to store pointer to new variable
     1563 */
     1564static void run_var_new_deleg(run_t *run, rdata_var_t **rvar)
     1565{
     1566        rdata_var_t *var;
     1567
     1568        (void) run;
     1569
     1570        /* Return null reference. */
     1571        var = rdata_var_new(vc_deleg);
     1572        var->u.deleg_v = rdata_deleg_new();
     1573
     1574        *rvar = var;
     1575}
     1576
     1577/** Construct a new thread activation record.
     1578 *
     1579 * @param run   Runner object
     1580 * @return      New thread AR.
     1581 */
    12781582run_thread_ar_t *run_thread_ar_new(void)
    12791583{
     
    12891593}
    12901594
     1595/** Construct a new procedure activation record.
     1596 *
     1597 * @param run   Runner object
     1598 * @return      New procedure AR.
     1599 */
    12911600run_proc_ar_t *run_proc_ar_new(void)
    12921601{
     
    13021611}
    13031612
     1613/** Construct a new block activation record.
     1614 *
     1615 * @param run   Runner object
     1616 * @return      New block AR.
     1617 */
    13041618run_block_ar_t *run_block_ar_new(void)
    13051619{
Note: See TracChangeset for help on using the changeset viewer.