Ignore:
File:
1 edited

Legend:

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

    r38aaacc2 r074444f  
    6767    rdata_value_t *value);
    6868
    69 static void run_var_new_tprimitive(run_t *run, tdata_primitive_t *tprimitive,
    70     rdata_var_t **rvar);
    71 static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar);
    72 static 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  */
     69/** Initialize runner instance. */
    7970void run_init(run_t *run)
    8071{
     
    8273}
    8374
    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  */
     75/** Run program */
    9476void run_program(run_t *run, stree_program_t *prog)
    9577{
     
    137119}
    138120
    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  */
     121/** Run procedure. */
    154122void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res)
    155123{
     
    203171}
    204172
    205 /** Run code block.
    206  *
    207  * @param run           Runner object
    208  * @param block         Block to run
    209  */
     173/** Run code block */
    210174static void run_block(run_t *run, stree_block_t *block)
    211175{
     
    254218 * @a res.
    255219 *
    256  * @param run   Runner object
    257  * @param stat  Statement to run
    258  * @param res   Place to store exps result or NULL if not interested
     220 * @param run   Runner object.
     221 * @param stat  Statement to run.
     222 * @param res   Place to store exps result or NULL if not interested.
    259223 */
    260224void run_stat(run_t *run, stree_stat_t *stat, rdata_item_t **res)
     
    302266 * of the expression (or NULL if it has no value) will be stored to @a res.
    303267 *
    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
     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.
    307271 */
    308272static void run_exps(run_t *run, stree_exps_t *exps, rdata_item_t **res)
     
    319283}
    320284
    321 /** Run variable declaration statement.
    322  *
    323  * @param run   Runner object
    324  * @param vdecl Variable declaration statement to run
    325  */
     285/** Run variable declaration statement. */
    326286static void run_vdecl(run_t *run, stree_vdecl_t *vdecl)
    327287{
    328288        run_block_ar_t *block_ar;
    329289        rdata_var_t *var, *old_var;
    330         tdata_item_t *var_ti;
     290        rdata_int_t *int_v;
    331291
    332292#ifdef DEBUG_RUN_TRACE
    333293        printf("Executing variable declaration statement.\n");
    334294#endif
    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);
     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);
    341303
    342304        block_ar = run_get_current_block_ar(run);
     
    356318}
    357319
    358 /** Run @c if statement.
    359  *
    360  * @param run   Runner object
    361  * @param if_s  If statement to run
    362  */
     320/** Run @c if statement. */
    363321static void run_if(run_t *run, stree_if_t *if_s)
    364322{
     
    390348}
    391349
    392 /** Run @c while statement.
    393  *
    394  * @param run           Runner object
    395  * @param while_s       While statement to run
    396  */
     350/** Run @c while statement. */
    397351static void run_while(run_t *run, stree_while_t *while_s)
    398352{
     
    421375}
    422376
    423 /** Run @c raise statement.
    424  *
    425  * @param run           Runner object
    426  * @param raise_s       Raise statement to run
    427  */
     377/** Run @c raise statement. */
    428378static void run_raise(run_t *run, stree_raise_t *raise_s)
    429379{
     
    447397}
    448398
    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  */
     399/** Run @c return statement. */
    457400static void run_return(run_t *run, stree_return_t *return_s)
    458401{
     
    470413        run_cvt_value_item(run, rexpr, &rexpr_vi);
    471414
    472         /* Store expression result in procedure AR. */
     415        /* Store expression result in function AR. */
    473416        proc_ar = run_get_current_proc_ar(run);
    474417        proc_ar->retval = rexpr_vi;
     
    479422}
    480423
    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  */
     424/** Run @c with-except-finally statement. */
    488425static void run_wef(run_t *run, stree_wef_t *wef_s)
    489426{
     
    552489 * matches except clause @c except_c.
    553490 *
    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
     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.
    557494 */
    558495static bool_t run_exc_match(run_t *run, stree_except_t *except_c)
     
    569506
    570507        /* Determine if active exc. is derived from type in exc. clause. */
    571         /* XXX This is wrong, it does not work with generics. */
    572508        return tdata_is_csi_derived_from_ti(exc_csi, etype);
    573509}
     
    575511/** Return CSI of the active exception.
    576512 *
    577  * @param run           Runner object
    578  * @return              CSI of the active exception
     513 * @param run           Runner object.
     514 * @return              CSI of the active exception.
    579515 */
    580516static stree_csi_t *run_exc_payload_get_csi(run_t *run)
     
    621557 * error message and raises a run-time error.
    622558 *
    623  * @param run           Runner object
     559 * @param run           Runner object.
    624560 */
    625561void run_exc_check_unhandled(run_t *run)
     
    643579 *
    644580 * Raises an error that cannot be handled by the user program.
    645  *
    646  * @param run           Runner object
    647581 */
    648582void run_raise_error(run_t *run)
     
    652586}
    653587
    654 /** Construct a special recovery item.
    655  *
    656  * @param run           Runner object
    657  */
     588/** Construct a special recovery item. */
    658589rdata_item_t *run_recovery_item(run_t *run)
    659590{
     
    662593}
    663594
    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  */
     595/** Find a local variable in the currently active function. */
    670596rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name)
    671597{
     
    692618}
    693619
    694 /** Get current procedure activation record.
    695  *
    696  * @param run           Runner object
    697  * @return              Active procedure AR
    698  */
     620/** Get current function activation record. */
    699621run_proc_ar_t *run_get_current_proc_ar(run_t *run)
    700622{
     
    705627}
    706628
    707 /** Get current block activation record.
    708  *
    709  * @param run           Runner object
    710  * @return              Active block AR
    711  */
     629/** Get current block activation record. */
    712630run_block_ar_t *run_get_current_block_ar(run_t *run)
    713631{
     
    721639}
    722640
    723 /** Get current CSI.
    724  *
    725  * @param run           Runner object
    726  * @return              Active CSI
    727  */
     641/** Get current CSI. */
    728642stree_csi_t *run_get_current_csi(run_t *run)
    729643{
     
    740654 * (1) Create a variable of the desired type.
    741655 * (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.
    745656 */
    746657void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var)
    747658{
    748         rdata_bool_t *bool_v;
    749659        rdata_char_t *char_v;
    750         rdata_deleg_t *deleg_v;
    751660        rdata_int_t *int_v;
    752661        rdata_string_t *string_v;
     
    758667
    759668        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;
    767669        case vc_char:
    768670                *var = rdata_var_new(vc_char);
     
    773675                    &char_v->value);
    774676                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;
    783677        case vc_int:
    784678                *var = rdata_var_new(vc_int);
     
    810704}
    811705
    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  */
     706/** Construct a function AR. */
    819707void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc,
    820708    run_proc_ar_t **rproc_ar)
     
    845733 * When invoking a procedure this is used to store the argument values
    846734 * 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
    853735 */
    854736void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals)
     
    885767        case sc_fun:
    886768                fun = symbol_to_fun(outer_symbol);
    887                 args = &fun->sig->args;
    888                 varg = fun->sig->varg;
     769                args = &fun->args;
     770                varg = fun->varg;
    889771                break;
    890772        case sc_prop:
     
    983865 * When invoking a setter this is used to store its argument value in its
    984866 * 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
    990867 */
    991868void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
     
    1021898}
    1022899
    1023 /** Print function activation backtrace.
    1024  *
    1025  * Prints a backtrace of activated functions for debugging purposes.
    1026  *
    1027  * @param run           Runner object
    1028  */
     900/** Print function activation backtrace. */
    1029901void run_print_fun_bt(run_t *run)
    1030902{
     
    1048920 * If @a item is a value, we just return a copy. If @a item is an address,
    1049921 * 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
    1054922 */
    1055923void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem)
     
    1083951 * Get var-class of @a item, regardless whether it is a value or address.
    1084952 * (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
    1089953 */
    1090954var_class_t run_item_get_vc(run_t *run, rdata_item_t *item)
     
    1128992 * copy.
    1129993 *
    1130  * @param run   Runner object
    1131  * @param addr  Address of class @c ac_prop
    1132  * @return      Pointer to var node
     994 * @param run   Runner object.
     995 * @param addr  Address of class @c ac_prop.
     996 * @param       Pointer to var node.
    1133997 */
    1134998static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *addr)
     
    11511015/** Read data from an address.
    11521016 *
    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
     1017 * Return value stored in a variable at the specified address.
    11581018 */
    11591019void run_address_read(run_t *run, rdata_address_t *address,
     
    11761036/** Write data to an address.
    11771037 *
    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
     1038 * Store @a value to the variable at @a address.
    11831039 */
    11841040void run_address_write(run_t *run, rdata_address_t *address,
     
    11971053}
    11981054
    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  */
    12071055static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
    12081056    rdata_item_t **ritem)
     
    12681116}
    12691117
    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  */
    12781118static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
    12791119    rdata_value_t *value)
     
    13411181 *
    13421182 * 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.
    13471183 */
    13481184void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res)
     
    13741210 * Takes a reference (address or value) and returns the address (item) of
    13751211 * 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.
    13801212 */
    13811213void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem)
     
    14201252 * error (not for the @c raise statement).
    14211253 *
    1422  * @param run           Runner object
    1423  * @param csi           Exception class
     1254 * @param run           Runner object.
     1255 * @param csi           Exception class.
    14241256 */
    14251257void run_raise_exc(run_t *run, stree_csi_t *csi)
     
    14381270}
    14391271
    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  */
     1272/** Determine if we are bailing out. */
    14451273bool_t run_is_bo(run_t *run)
    14461274{
     
    14481276}
    14491277
    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  */
    1461 void 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  */
    1501 static 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  */
    1546 static 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  */
    1564 static 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  */
    15821278run_thread_ar_t *run_thread_ar_new(void)
    15831279{
     
    15931289}
    15941290
    1595 /** Construct a new procedure activation record.
    1596  *
    1597  * @param run   Runner object
    1598  * @return      New procedure AR.
    1599  */
    16001291run_proc_ar_t *run_proc_ar_new(void)
    16011292{
     
    16111302}
    16121303
    1613 /** Construct a new block activation record.
    1614  *
    1615  * @param run   Runner object
    1616  * @return      New block AR.
    1617  */
    16181304run_block_ar_t *run_block_ar_new(void)
    16191305{
Note: See TracChangeset for help on using the changeset viewer.