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


Ignore:
Timestamp:
2010-04-04T22:32:39Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0a72efc
Parents:
73060801 (diff), 23de644 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jsvoboda/helenos/sysel.

File:
1 edited

Legend:

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

    r73060801 recb6ac32  
    3232#include <stdlib.h>
    3333#include <assert.h>
     34#include "bigint.h"
    3435#include "builtin.h"
    3536#include "debug.h"
     
    5758
    5859static bool_t run_exc_match(run_t *run, stree_except_t *except_c);
     60static stree_csi_t *run_exc_payload_get_csi(run_t *run);
     61
    5962static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *aprop);
    6063
     
    113116        run_proc(run, proc_ar, &res);
    114117
    115         /* Check for unhandled exceptions. */
    116         if (run->thread_ar->bo_mode != bm_none) {
    117                 assert(run->thread_ar->bo_mode == bm_exc);
    118                 printf("Error: Unhandled exception.\n");
    119                 exit(1);
    120         }
     118        run_exc_check_unhandled(run);
    121119}
    122120
     
    302300
    303301        var->u.int_v = int_v;
    304         int_v->value = 0;
     302        bigint_init(&int_v->value, 0);
    305303
    306304        block_ar = run_get_current_block_ar(run);
     
    329327#endif
    330328        run_expr(run, if_s->cond, &rcond);
     329        if (run_is_bo(run))
     330                return;
    331331
    332332        if (run_item_boolean_value(run, rcond) == b_true) {
     
    357357#endif
    358358        run_expr(run, while_s->cond, &rcond);
     359        if (run_is_bo(run))
     360                return;
    359361
    360362        while (run_item_boolean_value(run, rcond) == b_true) {
    361363                run_block(run, while_s->body);
    362364                run_expr(run, while_s->cond, &rcond);
     365                if (run_is_bo(run))
     366                        return;
    363367
    364368                if (run->thread_ar->bo_mode != bm_none)
     
    381385#endif
    382386        run_expr(run, raise_s->expr, &rexpr);
     387        if (run_is_bo(run))
     388                return;
     389
    383390        run_cvt_value_item(run, rexpr, &rexpr_vi);
    384391
     
    401408#endif
    402409        run_expr(run, return_s->expr, &rexpr);
     410        if (run_is_bo(run))
     411                return;
     412
    403413        run_cvt_value_item(run, rexpr, &rexpr_vi);
    404414
     
    477487 *
    478488 * Checks if the currently active exception in the runner object @c run
    479  * matches except clause @c except_c. Generates an error if the exception
    480  * payload has invalid type (i.e. not an object).
     489 * matches except clause @c except_c.
    481490 *
    482491 * @param run           Runner object.
     
    486495static bool_t run_exc_match(run_t *run, stree_except_t *except_c)
    487496{
     497        stree_csi_t *exc_csi;
     498        tdata_item_t *etype;
     499
     500        /* Get CSI of active exception. */
     501        exc_csi = run_exc_payload_get_csi(run);
     502
     503        /* Evaluate type expression in except clause. */
     504        run_texpr(run->program, run_get_current_csi(run), except_c->etype,
     505            &etype);
     506
     507        /* Determine if active exc. is derived from type in exc. clause. */
     508        return tdata_is_csi_derived_from_ti(exc_csi, etype);
     509}
     510
     511/** Return CSI of the active exception.
     512 *
     513 * @param run           Runner object.
     514 * @return              CSI of the active exception.
     515 */
     516static stree_csi_t *run_exc_payload_get_csi(run_t *run)
     517{
    488518        rdata_value_t *payload;
    489519        rdata_var_t *payload_v;
    490520        rdata_object_t *payload_o;
    491         tdata_item_t *etype;
    492521
    493522        payload = run->thread_ar->exc_payload;
     
    495524
    496525        if (payload->var->vc != vc_ref) {
     526                /* XXX Prevent this via static type checking. */
    497527                printf("Error: Exception payload must be an object "
    498528                    "(found type %d).\n", payload->var->vc);
     
    502532        payload_v = payload->var->u.ref_v->vref;
    503533        if (payload_v->vc != vc_object) {
     534                /* XXX Prevent this via static type checking. */
    504535                printf("Error: Exception payload must be an object "
    505536                    "(found type %d).\n", payload_v->vc);
     
    517548        assert(payload_o->class_sym->sc == sc_csi);
    518549
    519         /* Evaluate type expression in except clause. */
    520         run_texpr(run->program, run_get_current_csi(run), except_c->etype,
    521             &etype);
    522 
    523         return tdata_is_csi_derived_from_ti(payload_o->class_sym->u.csi,
    524             etype);
     550        return payload_o->class_sym->u.csi;
     551}
     552
     553
     554/** Check for unhandled exception.
     555 *
     556 * Checks whether there is an active exception. If so, it prints an
     557 * error message and raises a run-time error.
     558 *
     559 * @param run           Runner object.
     560 */
     561void run_exc_check_unhandled(run_t *run)
     562{
     563        stree_csi_t *exc_csi;
     564
     565        if (run->thread_ar->bo_mode != bm_none) {
     566                assert(run->thread_ar->bo_mode == bm_exc);
     567
     568                exc_csi = run_exc_payload_get_csi(run);
     569
     570                printf("Error: Unhandled exception '");
     571                symbol_print_fqn(csi_to_symbol(exc_csi));
     572                printf("'.\n");
     573
     574                run_raise_error(run);
     575        }
    525576}
    526577
     
    620671
    621672                (*var)->u.int_v = int_v;
    622                 int_v->value = item->u.value->var->u.int_v->value;
     673                bigint_clone(&item->u.value->var->u.int_v->value,
     674                    &int_v->value);
    623675                break;
    624676        case vc_string:
     
    11711223
    11721224        if (addr_var->vref == NULL) {
     1225#ifdef DEBUG_RUN_TRACE
    11731226                printf("Error: Accessing null reference.\n");
    1174                 run_raise_error(run);
     1227#endif
     1228                /* Raise Error.NilReference */
     1229                run_raise_exc(run, run->program->builtin->error_nilreference);
    11751230                *ritem = run_recovery_item(run);
    11761231                return;
     
    11811236#endif
    11821237        *ritem = item;
     1238}
     1239
     1240/** Raise an exception of the given class.
     1241 *
     1242 * Used when the interpreter generates an exception due to a run-time
     1243 * error (not for the @c raise statement).
     1244 *
     1245 * @param run           Runner object.
     1246 * @param csi           Exception class.
     1247 */
     1248void run_raise_exc(run_t *run, stree_csi_t *csi)
     1249{
     1250        rdata_item_t *exc_vi;
     1251
     1252        /* Create exception object. */
     1253        run_new_csi_inst(run, csi, &exc_vi);
     1254        assert(exc_vi->ic == ic_value);
     1255
     1256        /* Store exception object in thread AR. */
     1257        run->thread_ar->exc_payload = exc_vi->u.value;
     1258
     1259        /* Start exception bailout. */
     1260        run->thread_ar->bo_mode = bm_exc;
     1261}
     1262
     1263/** Determine if we are bailing out. */
     1264bool_t run_is_bo(run_t *run)
     1265{
     1266        return run->thread_ar->bo_mode != bm_none;
    11831267}
    11841268
Note: See TracChangeset for help on using the changeset viewer.