Changeset 23de644 in mainline for uspace/app/sbi/src/run.c
- Timestamp:
- 2010-04-04T22:31:01Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 074444f, ecb6ac32
- Parents:
- 3aae4e8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r3aae4e8 r23de644 32 32 #include <stdlib.h> 33 33 #include <assert.h> 34 #include "bigint.h" 34 35 #include "builtin.h" 35 36 #include "debug.h" … … 57 58 58 59 static bool_t run_exc_match(run_t *run, stree_except_t *except_c); 60 static stree_csi_t *run_exc_payload_get_csi(run_t *run); 61 59 62 static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *aprop); 60 63 … … 113 116 run_proc(run, proc_ar, &res); 114 117 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); 121 119 } 122 120 … … 302 300 303 301 var->u.int_v = int_v; 304 int_v->value = 0;302 bigint_init(&int_v->value, 0); 305 303 306 304 block_ar = run_get_current_block_ar(run); … … 329 327 #endif 330 328 run_expr(run, if_s->cond, &rcond); 329 if (run_is_bo(run)) 330 return; 331 331 332 332 if (run_item_boolean_value(run, rcond) == b_true) { … … 357 357 #endif 358 358 run_expr(run, while_s->cond, &rcond); 359 if (run_is_bo(run)) 360 return; 359 361 360 362 while (run_item_boolean_value(run, rcond) == b_true) { 361 363 run_block(run, while_s->body); 362 364 run_expr(run, while_s->cond, &rcond); 365 if (run_is_bo(run)) 366 return; 363 367 364 368 if (run->thread_ar->bo_mode != bm_none) … … 381 385 #endif 382 386 run_expr(run, raise_s->expr, &rexpr); 387 if (run_is_bo(run)) 388 return; 389 383 390 run_cvt_value_item(run, rexpr, &rexpr_vi); 384 391 … … 401 408 #endif 402 409 run_expr(run, return_s->expr, &rexpr); 410 if (run_is_bo(run)) 411 return; 412 403 413 run_cvt_value_item(run, rexpr, &rexpr_vi); 404 414 … … 477 487 * 478 488 * 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. 481 490 * 482 491 * @param run Runner object. … … 486 495 static bool_t run_exc_match(run_t *run, stree_except_t *except_c) 487 496 { 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 */ 516 static stree_csi_t *run_exc_payload_get_csi(run_t *run) 517 { 488 518 rdata_value_t *payload; 489 519 rdata_var_t *payload_v; 490 520 rdata_object_t *payload_o; 491 tdata_item_t *etype;492 521 493 522 payload = run->thread_ar->exc_payload; … … 495 524 496 525 if (payload->var->vc != vc_ref) { 526 /* XXX Prevent this via static type checking. */ 497 527 printf("Error: Exception payload must be an object " 498 528 "(found type %d).\n", payload->var->vc); … … 502 532 payload_v = payload->var->u.ref_v->vref; 503 533 if (payload_v->vc != vc_object) { 534 /* XXX Prevent this via static type checking. */ 504 535 printf("Error: Exception payload must be an object " 505 536 "(found type %d).\n", payload_v->vc); … … 517 548 assert(payload_o->class_sym->sc == sc_csi); 518 549 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 */ 561 void 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 } 525 576 } 526 577 … … 620 671 621 672 (*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); 623 675 break; 624 676 case vc_string: … … 1171 1223 1172 1224 if (addr_var->vref == NULL) { 1225 #ifdef DEBUG_RUN_TRACE 1173 1226 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); 1175 1230 *ritem = run_recovery_item(run); 1176 1231 return; … … 1181 1236 #endif 1182 1237 *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 */ 1248 void 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. */ 1264 bool_t run_is_bo(run_t *run) 1265 { 1266 return run->thread_ar->bo_mode != bm_none; 1183 1267 } 1184 1268
Note:
See TracChangeset
for help on using the changeset viewer.