Ignore:
File:
1 edited

Legend:

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

    r051bc69a r6c39a907  
    3434#include "bigint.h"
    3535#include "builtin.h"
    36 #include "cspan.h"
    3736#include "debug.h"
    3837#include "intmap.h"
     
    5554static void run_while(run_t *run, stree_while_t *while_s);
    5655static void run_raise(run_t *run, stree_raise_t *raise_s);
    57 static void run_break(run_t *run, stree_break_t *break_s);
    5856static void run_return(run_t *run, stree_return_t *return_s);
    5957static void run_wef(run_t *run, stree_wef_t *wef_s);
     
    7371static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar);
    7472static void run_var_new_deleg(run_t *run, rdata_var_t **rvar);
    75 static void run_var_new_enum(run_t *run, tdata_enum_t *tenum,
    76     rdata_var_t **rvar);
     73
    7774
    7875/** Initialize runner instance.
     
    180177        switch (run->thread_ar->bo_mode) {
    181178        case bm_stat:
    182                 /* Break bailout was not caught. */
    183                 assert(b_false);
     179                printf("Error: Misplaced 'break' statement.\n");
     180                exit(1);
    184181        case bm_proc:
    185182                run->thread_ar->bo_mode = bm_none;
     
    286283                run_raise(run, stat->u.raise_s);
    287284                break;
    288         case st_break:
    289                 run_break(run, stat->u.break_s);
    290                 break;
    291285        case st_return:
    292286                run_return(run, stat->u.return_s);
     
    298292                printf("Ignoring unimplemented statement type %d.\n", stat->sc);
    299293                break;
     294        default:
     295                assert(b_false);
    300296        }
    301297}
     
    368364{
    369365        rdata_item_t *rcond;
    370         list_node_t *ifc_node;
    371         stree_if_clause_t *ifc;
    372         bool_t clause_fired;
    373366
    374367#ifdef DEBUG_RUN_TRACE
    375368        printf("Executing if statement.\n");
    376369#endif
    377         clause_fired = b_false;
    378         ifc_node = list_first(&if_s->if_clauses);
    379 
    380         /* Walk through all if/elif clauses and see if they fire. */
    381 
    382         while (ifc_node != NULL) {
    383                 /* Get if/elif clause */
    384                 ifc = list_node_data(ifc_node, stree_if_clause_t *);
    385 
    386                 run_expr(run, ifc->cond, &rcond);
    387                 if (run_is_bo(run))
    388                         return;
    389 
    390                 if (run_item_boolean_value(run, rcond) == b_true) {
    391 #ifdef DEBUG_RUN_TRACE
    392                         printf("Taking non-default path.\n");
    393 #endif
    394                         run_block(run, ifc->block);
    395                         clause_fired = b_true;
    396                         break;
    397                 }
    398 
    399                 ifc_node = list_next(&if_s->if_clauses, ifc_node);
    400         }
    401 
    402         /* If no if/elif clause fired, invoke the else clause. */
    403         if (clause_fired == b_false && if_s->else_block != NULL) {
    404 #ifdef DEBUG_RUN_TRACE
    405                 printf("Taking default path.\n");
    406 #endif
    407                 run_block(run, if_s->else_block);
     370        run_expr(run, if_s->cond, &rcond);
     371        if (run_is_bo(run))
     372                return;
     373
     374        if (run_item_boolean_value(run, rcond) == b_true) {
     375#ifdef DEBUG_RUN_TRACE
     376                printf("Taking true path.\n");
     377#endif
     378                run_block(run, if_s->if_block);
     379        } else {
     380#ifdef DEBUG_RUN_TRACE
     381                printf("Taking false path.\n");
     382#endif
     383                if (if_s->else_block != NULL)
     384                        run_block(run, if_s->else_block);
    408385        }
    409386
     
    433410                run_expr(run, while_s->cond, &rcond);
    434411                if (run_is_bo(run))
     412                        return;
     413
     414                if (run->thread_ar->bo_mode != bm_none)
    435415                        break;
    436         }
    437 
    438         if (run->thread_ar->bo_mode == bm_stat) {
    439                 /* Bailout due to break statement */
    440                 run->thread_ar->bo_mode = bm_none;
    441416        }
    442417
     
    465440        run_cvt_value_item(run, rexpr, &rexpr_vi);
    466441
    467         /* Store expression cspan in thread AR. */
    468         run->thread_ar->exc_cspan = raise_s->expr->cspan;
    469 
    470442        /* Store expression result in thread AR. */
    471443        run->thread_ar->exc_payload = rexpr_vi->u.value;
     
    475447}
    476448
    477 /** Run @c break statement.
    478  *
    479  * Forces control to return from the active breakable statement by setting
    480  * bailout mode to @c bm_stat.
    481  *
    482  * @param run           Runner object
    483  * @param break_s       Break statement to run
    484  */
    485 static void run_break(run_t *run, stree_break_t *break_s)
    486 {
    487 #ifdef DEBUG_RUN_TRACE
    488         printf("Executing 'break' statement.\n");
    489 #endif
    490         (void) break_s;
    491 
    492         /* Force control to ascend and leave the procedure. */
    493         if (run->thread_ar->bo_mode == bm_none)
    494                 run->thread_ar->bo_mode = bm_stat;
    495 }
    496 
    497449/** Run @c return statement.
    498450 *
     
    501453 *
    502454 * @param run           Runner object
    503  * @param return_s      Return statement to run
     455 * @param raise_s       Return statement to run
    504456 */
    505457static void run_return(run_t *run, stree_return_t *return_s)
     
    512464        printf("Executing return statement.\n");
    513465#endif
    514         if (return_s->expr != NULL) {
    515                 run_expr(run, return_s->expr, &rexpr);
    516                 if (run_is_bo(run))
    517                         return;
    518 
    519                 run_cvt_value_item(run, rexpr, &rexpr_vi);
    520 
    521                 /* Store expression result in procedure AR. */
    522                 proc_ar = run_get_current_proc_ar(run);
    523                 proc_ar->retval = rexpr_vi;
    524         }
     466        run_expr(run, return_s->expr, &rexpr);
     467        if (run_is_bo(run))
     468                return;
     469
     470        run_cvt_value_item(run, rexpr, &rexpr_vi);
     471
     472        /* Store expression result in procedure AR. */
     473        proc_ar = run_get_current_proc_ar(run);
     474        proc_ar->retval = rexpr_vi;
    525475
    526476        /* Force control to ascend and leave the procedure. */
     
    682632                exc_csi = run_exc_payload_get_csi(run);
    683633
    684                 if (run->thread_ar->exc_cspan != NULL) {
    685                         cspan_print(run->thread_ar->exc_cspan);
    686                         putchar(' ');
    687                 }
    688 
    689634                printf("Error: Unhandled exception '");
    690635                symbol_print_fqn(csi_to_symbol(exc_csi));
     
    804749        rdata_char_t *char_v;
    805750        rdata_deleg_t *deleg_v;
    806         rdata_enum_t *enum_v;
    807751        rdata_int_t *int_v;
    808752        rdata_string_t *string_v;
     
    836780                deleg_v->obj = item->u.value->var->u.deleg_v->obj;
    837781                deleg_v->sym = item->u.value->var->u.deleg_v->sym;
    838                 break;
    839         case vc_enum:
    840                 *var = rdata_var_new(vc_enum);
    841                 enum_v = rdata_enum_new();
    842 
    843                 (*var)->u.enum_v = enum_v;
    844                 enum_v->value = item->u.value->var->u.enum_v->value;
    845782                break;
    846783        case vc_int:
     
    917854void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals)
    918855{
    919         stree_ctor_t *ctor;
    920856        stree_fun_t *fun;
    921857        stree_prop_t *prop;
     
    942878        outer_symbol = proc_ar->proc->outer_symbol;
    943879
    944         /* Make compiler happy. */
    945         args = NULL;
    946         varg = NULL;
    947 
    948880        /*
    949881         * The procedure being activated should belong to a member function or
     
    951883         */
    952884        switch (outer_symbol->sc) {
    953         case sc_ctor:
    954                 ctor = symbol_to_ctor(outer_symbol);
    955                 args = &ctor->sig->args;
    956                 varg = ctor->sig->varg;
    957                 break;
    958885        case sc_fun:
    959886                fun = symbol_to_fun(outer_symbol);
     
    966893                varg = prop->varg;
    967894                break;
    968         case sc_csi:
    969         case sc_deleg:
    970         case sc_enum:
    971         case sc_var:
     895        default:
    972896                assert(b_false);
    973897        }
     
    14531377 * @param run           Runner object
    14541378 * @param ref           Reference
    1455  * @param cspan         Cspan to put into exception if reference is nil
    1456  *                      or @c NULL if no cspan is provided.
    14571379 * @param rtitem        Place to store pointer to the resulting address.
    14581380 */
    1459 void run_dereference(run_t *run, rdata_item_t *ref, cspan_t *cspan,
    1460     rdata_item_t **ritem)
     1381void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem)
    14611382{
    14621383        rdata_item_t *ref_val;
     
    14831404#endif
    14841405                /* Raise Error.NilReference */
    1485                 run_raise_exc(run, run->program->builtin->error_nilreference,
    1486                     cspan);
     1406                run_raise_exc(run, run->program->builtin->error_nilreference);
    14871407                *ritem = run_recovery_item(run);
    14881408                return;
     
    15021422 * @param run           Runner object
    15031423 * @param csi           Exception class
    1504  * @param cspan         Cspan of code that caused exception (for debugging)
    1505  */
    1506 void run_raise_exc(run_t *run, stree_csi_t *csi, cspan_t *cspan)
     1424 */
     1425void run_raise_exc(run_t *run, stree_csi_t *csi)
    15071426{
    15081427        rdata_item_t *exc_vi;
    1509 
    1510         /* Store exception cspan in thread AR. */
    1511         run->thread_ar->exc_cspan = cspan;
    15121428
    15131429        /* Create exception object. */
     
    15561472                break;
    15571473        case tic_tdeleg:
    1558                 run_var_new_deleg(run, rvar);
    1559                 break;
    1560         case tic_tebase:
    1561                 /*
    1562                  * One cannot declare variable of ebase type. It is just
    1563                  * type of expressions referring to enum types.
    1564                  */
    1565                 assert(b_false);
    1566         case tic_tenum:
    1567                 run_var_new_enum(run, ti->u.tenum, rvar);
    1568                 break;
    15691474        case tic_tfun:
    15701475                run_var_new_deleg(run, rvar);
     
    16731578}
    16741579
    1675 /** Construct a new variable containing default value of an enum type.
    1676  *
    1677  * @param run           Runner object
    1678  * @param rvar          Place to store pointer to new variable
    1679  */
    1680 static void run_var_new_enum(run_t *run, tdata_enum_t *tenum,
    1681     rdata_var_t **rvar)
    1682 {
    1683         rdata_var_t *var;
    1684         list_node_t *embr_n;
    1685         stree_embr_t *embr;
    1686 
    1687         (void) run;
    1688 
    1689         /* Get first member of enum which will serve as default value. */
    1690         embr_n = list_first(&tenum->enum_d->members);
    1691         assert(embr_n != NULL);
    1692 
    1693         embr = list_node_data(embr_n, stree_embr_t *);
    1694 
    1695         /* Return null reference. */
    1696         var = rdata_var_new(vc_enum);
    1697         var->u.enum_v = rdata_enum_new();
    1698         var->u.enum_v->value = embr;
    1699 
    1700         *rvar = var;
    1701 }
    1702 
    17031580/** Construct a new thread activation record.
    17041581 *
Note: See TracChangeset for help on using the changeset viewer.