Changeset 73751c0 in mainline for uspace/app/sbi/src/run.c
- Timestamp:
- 2011-03-18T12:16:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b495a93
- Parents:
- 42a3a57 (diff), b64eac6 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r42a3a57 r73751c0 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 53 53 static void run_vdecl(run_t *run, stree_vdecl_t *vdecl); 54 54 static void run_if(run_t *run, stree_if_t *if_s); 55 static void run_switch(run_t *run, stree_switch_t *switch_s); 55 56 static void run_while(run_t *run, stree_while_t *while_s); 56 57 static void run_raise(run_t *run, stree_raise_t *raise_s); … … 142 143 run_proc_ar_set_args(run, proc_ar, &main_args); 143 144 run_proc(run, proc_ar, &res); 145 run_proc_ar_destroy(run, proc_ar); 144 146 145 147 run_exc_check_unhandled(run); … … 272 274 assert(list_node_data(node, run_block_ar_t *) == block_ar); 273 275 list_remove(&proc_ar->block_ar, node); 276 277 /* Deallocate block activation record. */ 278 run_block_ar_destroy(run, block_ar); 274 279 } 275 280 … … 303 308 run_if(run, stat->u.if_s); 304 309 break; 310 case st_switch: 311 run_switch(run, stat->u.switch_s); 312 break; 305 313 case st_while: 306 314 run_while(run, stat->u.while_s); … … 342 350 run_expr(run, exps->expr, &rexpr); 343 351 352 /* 353 * If the expression has a value, the caller should have asked for it. 354 */ 355 assert(res != NULL || rexpr == NULL); 356 344 357 if (res != NULL) 345 358 *res = rexpr; … … 355 368 run_block_ar_t *block_ar; 356 369 rdata_var_t *var, *old_var; 357 tdata_item_t *var_ti;358 370 359 371 #ifdef DEBUG_RUN_TRACE 360 372 printf("Executing variable declaration statement.\n"); 361 373 #endif 362 /* Compute variable type. XXX Memoize. */363 run_texpr(run->program, run_get_current_csi(run), vdecl->type,364 &var_ti);365 366 374 /* Create variable and initialize with default value. */ 367 run_var_new(run, v ar_ti, &var);375 run_var_new(run, vdecl->titem, &var); 368 376 369 377 block_ar = run_get_current_block_ar(run); … … 393 401 list_node_t *ifc_node; 394 402 stree_if_clause_t *ifc; 395 bool_t clause_fired;403 bool_t rcond_b, clause_fired; 396 404 397 405 #ifdef DEBUG_RUN_TRACE … … 411 419 return; 412 420 413 if (run_item_boolean_value(run, rcond) == b_true) { 421 rcond_b = run_item_boolean_value(run, rcond); 422 rdata_item_destroy(rcond); 423 424 if (rcond_b == b_true) { 414 425 #ifdef DEBUG_RUN_TRACE 415 426 printf("Taking non-default path.\n"); … … 436 447 } 437 448 449 /** Run @c switch statement. 450 * 451 * @param run Runner object 452 * @param switch_s Switch statement to run 453 */ 454 static void run_switch(run_t *run, stree_switch_t *switch_s) 455 { 456 rdata_item_t *rsexpr, *rsexpr_vi; 457 rdata_item_t *rwexpr, *rwexpr_vi; 458 list_node_t *whenc_node; 459 stree_when_t *whenc; 460 list_node_t *expr_node; 461 stree_expr_t *expr; 462 bool_t clause_fired; 463 bool_t equal; 464 465 #ifdef DEBUG_RUN_TRACE 466 printf("Executing switch statement.\n"); 467 #endif 468 rsexpr_vi = NULL; 469 470 /* Evaluate switch expression */ 471 run_expr(run, switch_s->expr, &rsexpr); 472 if (run_is_bo(run)) 473 goto cleanup; 474 475 /* Convert to value item */ 476 run_cvt_value_item(run, rsexpr, &rsexpr_vi); 477 rdata_item_destroy(rsexpr); 478 if (run_is_bo(run)) 479 goto cleanup; 480 481 clause_fired = b_false; 482 whenc_node = list_first(&switch_s->when_clauses); 483 484 /* Walk through all when clauses and see if they fire. */ 485 486 while (whenc_node != NULL) { 487 /* Get when clause */ 488 whenc = list_node_data(whenc_node, stree_when_t *); 489 490 expr_node = list_first(&whenc->exprs); 491 492 /* Walk through all expressions in the when clause */ 493 while (expr_node != NULL) { 494 /* Get expression */ 495 expr = list_node_data(expr_node, stree_expr_t *); 496 497 /* Evaluate expression */ 498 run_expr(run, expr, &rwexpr); 499 if (run_is_bo(run)) 500 goto cleanup; 501 502 /* Convert to value item */ 503 run_cvt_value_item(run, rwexpr, &rwexpr_vi); 504 rdata_item_destroy(rwexpr); 505 if (run_is_bo(run)) { 506 rdata_item_destroy(rwexpr_vi); 507 goto cleanup; 508 } 509 510 /* Check if values are equal ('==') */ 511 run_equal(run, rsexpr_vi->u.value, 512 rwexpr_vi->u.value, &equal); 513 rdata_item_destroy(rwexpr_vi); 514 if (run_is_bo(run)) 515 goto cleanup; 516 517 if (equal) { 518 #ifdef DEBUG_RUN_TRACE 519 printf("Taking non-default path.\n"); 520 #endif 521 run_block(run, whenc->block); 522 clause_fired = b_true; 523 break; 524 } 525 526 expr_node = list_next(&whenc->exprs, expr_node); 527 } 528 529 if (clause_fired) 530 break; 531 532 whenc_node = list_next(&switch_s->when_clauses, whenc_node); 533 } 534 535 /* If no when clause fired, invoke the else clause. */ 536 if (clause_fired == b_false && switch_s->else_block != NULL) { 537 #ifdef DEBUG_RUN_TRACE 538 printf("Taking default path.\n"); 539 #endif 540 run_block(run, switch_s->else_block); 541 } 542 cleanup: 543 if (rsexpr_vi != NULL) 544 rdata_item_destroy(rsexpr_vi); 545 546 #ifdef DEBUG_RUN_TRACE 547 printf("Switch statement terminated.\n"); 548 #endif 549 } 550 438 551 /** Run @c while statement. 439 552 * … … 453 566 454 567 while (run_item_boolean_value(run, rcond) == b_true) { 568 rdata_item_destroy(rcond); 455 569 run_block(run, while_s->body); 456 570 run_expr(run, while_s->cond, &rcond); … … 459 573 } 460 574 575 if (rcond != NULL) 576 rdata_item_destroy(rcond); 577 461 578 if (run->thread_ar->bo_mode == bm_stat) { 462 579 /* Bailout due to break statement */ … … 487 604 488 605 run_cvt_value_item(run, rexpr, &rexpr_vi); 606 rdata_item_destroy(rexpr); 607 if (run_is_bo(run)) 608 return; 489 609 490 610 /* Store expression cspan in thread AR. */ … … 492 612 493 613 /* Store expression result in thread AR. */ 614 /* XXX rexpr_vi is leaked here, we only return ->u.value */ 494 615 run->thread_ar->exc_payload = rexpr_vi->u.value; 495 616 … … 541 662 542 663 run_cvt_value_item(run, rexpr, &rexpr_vi); 664 rdata_item_destroy(rexpr); 665 if (run_is_bo(run)) 666 return; 543 667 544 668 /* Store expression result in procedure AR. */ … … 632 756 { 633 757 stree_csi_t *exc_csi; 634 tdata_item_t *etype;635 758 636 759 /* Get CSI of active exception. */ 637 760 exc_csi = run_exc_payload_get_csi(run); 638 761 639 /* Evaluate type expression in except clause. */640 run_texpr(run->program, run_get_current_csi(run), except_c->etype,641 &etype);642 643 762 /* Determine if active exc. is derived from type in exc. clause. */ 644 763 /* XXX This is wrong, it does not work with generics. */ 645 return tdata_is_csi_derived_from_ti(exc_csi, e type);764 return tdata_is_csi_derived_from_ti(exc_csi, except_c->titem); 646 765 } 647 766 … … 1009 1128 (void) run; 1010 1129 1011 /* Create functionactivation record. */1130 /* Create procedure activation record. */ 1012 1131 proc_ar = run_proc_ar_new(); 1013 1132 proc_ar->obj = obj; … … 1024 1143 *rproc_ar = proc_ar; 1025 1144 } 1145 1146 /** Destroy a procedure AR. 1147 * 1148 * @param run Runner object 1149 * @param proc_ar Pointer to procedure activation record 1150 */ 1151 void run_proc_ar_destroy(run_t *run, run_proc_ar_t *proc_ar) 1152 { 1153 list_node_t *ar_node; 1154 run_block_ar_t *block_ar; 1155 1156 (void) run; 1157 1158 /* Destroy special block activation record. */ 1159 ar_node = list_first(&proc_ar->block_ar); 1160 block_ar = list_node_data(ar_node, run_block_ar_t *); 1161 list_remove(&proc_ar->block_ar, ar_node); 1162 run_block_ar_destroy(run, block_ar); 1163 1164 /* Destroy procedure activation record. */ 1165 proc_ar->obj = NULL; 1166 proc_ar->proc = NULL; 1167 list_fini(&proc_ar->block_ar); 1168 proc_ar->retval = NULL; 1169 run_proc_ar_delete(proc_ar); 1170 } 1171 1026 1172 1027 1173 /** Fill arguments in a procedure AR. … … 1055 1201 rdata_ref_t *ref; 1056 1202 rdata_array_t *array; 1203 rdata_var_t *elem_var; 1057 1204 int n_vargs, idx; 1058 1205 … … 1147 1294 assert(rarg->ic == ic_value); 1148 1295 1149 rdata_var_write(array->element[idx], rarg->u.value); 1296 run_value_item_to_var(rarg, &elem_var); 1297 array->element[idx] = elem_var; 1150 1298 1151 1299 rarg_n = list_next(arg_vals, rarg_n); … … 1241 1389 } 1242 1390 1391 /** Destroy a block AR. 1392 * 1393 * @param run Runner object 1394 * @param proc_ar Pointer to block activation record 1395 */ 1396 void run_block_ar_destroy(run_t *run, run_block_ar_t *block_ar) 1397 { 1398 map_elem_t *elem; 1399 rdata_var_t *var; 1400 int key; 1401 1402 (void) run; 1403 1404 elem = intmap_first(&block_ar->vars); 1405 while (elem != NULL) { 1406 /* Destroy the variable */ 1407 var = intmap_elem_get_value(elem); 1408 rdata_var_destroy(var); 1409 1410 /* Remove the map element */ 1411 key = intmap_elem_get_key(elem); 1412 intmap_set(&block_ar->vars, key, NULL); 1413 1414 elem = intmap_first(&block_ar->vars); 1415 } 1416 1417 intmap_fini(&block_ar->vars); 1418 run_block_ar_delete(block_ar); 1419 } 1420 1243 1421 /** Convert item to value item. 1244 1422 * … … 1269 1447 } 1270 1448 1271 /* It already is a value, we can share the @c var. */1449 /* Make a copy of the var node within. */ 1272 1450 value = rdata_value_new(); 1273 value->var = item->u.value->var;1451 rdata_var_copy(item->u.value->var, &value->var); 1274 1452 *ritem = rdata_item_new(ic_value); 1275 1453 (*ritem)->u.value = value; … … 1358 1536 { 1359 1537 (void) run; 1538 assert(ritem != NULL); 1360 1539 1361 1540 switch (address->ac) { … … 1368 1547 } 1369 1548 1370 assert( (*ritem)->ic == ic_value);1549 assert(*ritem == NULL || (*ritem)->ic == ic_value); 1371 1550 } 1372 1551 … … 1457 1636 run_proc(run, proc_ar, ritem); 1458 1637 1638 /* Destroy procedure activation record. */ 1639 run_proc_ar_destroy(run, proc_ar); 1640 1459 1641 #ifdef DEBUG_RUN_TRACE 1460 1642 printf("Getter returns "); … … 1529 1711 /* Setter should not return a value. */ 1530 1712 assert(ritem == NULL); 1713 1714 /* Destroy procedure activation record. */ 1715 run_proc_ar_destroy(run, proc_ar); 1531 1716 1532 1717 #ifdef DEBUG_RUN_TRACE … … 1590 1775 #endif 1591 1776 run_cvt_value_item(run, ref, &ref_val); 1777 if (run_is_bo(run)) { 1778 *ritem = run_recovery_item(run); 1779 return; 1780 } 1781 1592 1782 assert(ref_val->u.value->var->vc == vc_ref); 1593 1783 … … 1598 1788 address->u.var_a = addr_var; 1599 1789 addr_var->vref = ref_val->u.value->var->u.ref_v->vref; 1790 1791 rdata_item_destroy(ref_val); 1600 1792 1601 1793 if (addr_var->vref == NULL) { … … 1840 2032 } 1841 2033 1842 /** Construct a new procedure activation record. 1843 * 1844 * @param run Runner object 2034 /** Allocate a new procedure activation record. 2035 * 1845 2036 * @return New procedure AR. 1846 2037 */ … … 1858 2049 } 1859 2050 1860 /** Construct a new block activation record. 2051 /** Deallocate a procedure activation record. 2052 * 2053 * @return New procedure AR. 2054 */ 2055 void run_proc_ar_delete(run_proc_ar_t *proc_ar) 2056 { 2057 assert(proc_ar != NULL); 2058 free(proc_ar); 2059 } 2060 2061 /** Allocate a new block activation record. 1861 2062 * 1862 2063 * @param run Runner object … … 1875 2076 return block_ar; 1876 2077 } 2078 2079 /** Deallocate a new block activation record. 2080 * 2081 * @param run Runner object 2082 * @return New block AR. 2083 */ 2084 void run_block_ar_delete(run_block_ar_t *block_ar) 2085 { 2086 assert(block_ar != NULL); 2087 free(block_ar); 2088 }
Note:
See TracChangeset
for help on using the changeset viewer.