Changes in uspace/app/sbi/src/run.c [051bc69a:6c39a907] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r051bc69a r6c39a907 34 34 #include "bigint.h" 35 35 #include "builtin.h" 36 #include "cspan.h"37 36 #include "debug.h" 38 37 #include "intmap.h" … … 55 54 static void run_while(run_t *run, stree_while_t *while_s); 56 55 static void run_raise(run_t *run, stree_raise_t *raise_s); 57 static void run_break(run_t *run, stree_break_t *break_s);58 56 static void run_return(run_t *run, stree_return_t *return_s); 59 57 static void run_wef(run_t *run, stree_wef_t *wef_s); … … 73 71 static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar); 74 72 static 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 77 74 78 75 /** Initialize runner instance. … … 180 177 switch (run->thread_ar->bo_mode) { 181 178 case bm_stat: 182 /* Break bailout was not caught. */183 assert(b_false);179 printf("Error: Misplaced 'break' statement.\n"); 180 exit(1); 184 181 case bm_proc: 185 182 run->thread_ar->bo_mode = bm_none; … … 286 283 run_raise(run, stat->u.raise_s); 287 284 break; 288 case st_break:289 run_break(run, stat->u.break_s);290 break;291 285 case st_return: 292 286 run_return(run, stat->u.return_s); … … 298 292 printf("Ignoring unimplemented statement type %d.\n", stat->sc); 299 293 break; 294 default: 295 assert(b_false); 300 296 } 301 297 } … … 368 364 { 369 365 rdata_item_t *rcond; 370 list_node_t *ifc_node;371 stree_if_clause_t *ifc;372 bool_t clause_fired;373 366 374 367 #ifdef DEBUG_RUN_TRACE 375 368 printf("Executing if statement.\n"); 376 369 #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); 408 385 } 409 386 … … 433 410 run_expr(run, while_s->cond, &rcond); 434 411 if (run_is_bo(run)) 412 return; 413 414 if (run->thread_ar->bo_mode != bm_none) 435 415 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;441 416 } 442 417 … … 465 440 run_cvt_value_item(run, rexpr, &rexpr_vi); 466 441 467 /* Store expression cspan in thread AR. */468 run->thread_ar->exc_cspan = raise_s->expr->cspan;469 470 442 /* Store expression result in thread AR. */ 471 443 run->thread_ar->exc_payload = rexpr_vi->u.value; … … 475 447 } 476 448 477 /** Run @c break statement.478 *479 * Forces control to return from the active breakable statement by setting480 * bailout mode to @c bm_stat.481 *482 * @param run Runner object483 * @param break_s Break statement to run484 */485 static void run_break(run_t *run, stree_break_t *break_s)486 {487 #ifdef DEBUG_RUN_TRACE488 printf("Executing 'break' statement.\n");489 #endif490 (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 497 449 /** Run @c return statement. 498 450 * … … 501 453 * 502 454 * @param run Runner object 503 * @param r eturn_s Return statement to run455 * @param raise_s Return statement to run 504 456 */ 505 457 static void run_return(run_t *run, stree_return_t *return_s) … … 512 464 printf("Executing return statement.\n"); 513 465 #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; 525 475 526 476 /* Force control to ascend and leave the procedure. */ … … 682 632 exc_csi = run_exc_payload_get_csi(run); 683 633 684 if (run->thread_ar->exc_cspan != NULL) {685 cspan_print(run->thread_ar->exc_cspan);686 putchar(' ');687 }688 689 634 printf("Error: Unhandled exception '"); 690 635 symbol_print_fqn(csi_to_symbol(exc_csi)); … … 804 749 rdata_char_t *char_v; 805 750 rdata_deleg_t *deleg_v; 806 rdata_enum_t *enum_v;807 751 rdata_int_t *int_v; 808 752 rdata_string_t *string_v; … … 836 780 deleg_v->obj = item->u.value->var->u.deleg_v->obj; 837 781 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;845 782 break; 846 783 case vc_int: … … 917 854 void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals) 918 855 { 919 stree_ctor_t *ctor;920 856 stree_fun_t *fun; 921 857 stree_prop_t *prop; … … 942 878 outer_symbol = proc_ar->proc->outer_symbol; 943 879 944 /* Make compiler happy. */945 args = NULL;946 varg = NULL;947 948 880 /* 949 881 * The procedure being activated should belong to a member function or … … 951 883 */ 952 884 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;958 885 case sc_fun: 959 886 fun = symbol_to_fun(outer_symbol); … … 966 893 varg = prop->varg; 967 894 break; 968 case sc_csi: 969 case sc_deleg: 970 case sc_enum: 971 case sc_var: 895 default: 972 896 assert(b_false); 973 897 } … … 1453 1377 * @param run Runner object 1454 1378 * @param ref Reference 1455 * @param cspan Cspan to put into exception if reference is nil1456 * or @c NULL if no cspan is provided.1457 1379 * @param rtitem Place to store pointer to the resulting address. 1458 1380 */ 1459 void run_dereference(run_t *run, rdata_item_t *ref, cspan_t *cspan, 1460 rdata_item_t **ritem) 1381 void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem) 1461 1382 { 1462 1383 rdata_item_t *ref_val; … … 1483 1404 #endif 1484 1405 /* 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); 1487 1407 *ritem = run_recovery_item(run); 1488 1408 return; … … 1502 1422 * @param run Runner object 1503 1423 * @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 */ 1425 void run_raise_exc(run_t *run, stree_csi_t *csi) 1507 1426 { 1508 1427 rdata_item_t *exc_vi; 1509 1510 /* Store exception cspan in thread AR. */1511 run->thread_ar->exc_cspan = cspan;1512 1428 1513 1429 /* Create exception object. */ … … 1556 1472 break; 1557 1473 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 just1563 * 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;1569 1474 case tic_tfun: 1570 1475 run_var_new_deleg(run, rvar); … … 1673 1578 } 1674 1579 1675 /** Construct a new variable containing default value of an enum type.1676 *1677 * @param run Runner object1678 * @param rvar Place to store pointer to new variable1679 */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 1703 1580 /** Construct a new thread activation record. 1704 1581 *
Note:
See TracChangeset
for help on using the changeset viewer.