Changes in uspace/app/sbi/src/run.c [051b3db8:c5cb943d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r051b3db8 rc5cb943d 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);56 55 static void run_while(run_t *run, stree_while_t *while_s); 57 56 static void run_raise(run_t *run, stree_raise_t *raise_s); … … 143 142 run_proc_ar_set_args(run, proc_ar, &main_args); 144 143 run_proc(run, proc_ar, &res); 145 run_proc_ar_destroy(run, proc_ar);146 144 147 145 run_exc_check_unhandled(run); … … 274 272 assert(list_node_data(node, run_block_ar_t *) == block_ar); 275 273 list_remove(&proc_ar->block_ar, node); 276 277 /* Deallocate block activation record. */278 run_block_ar_destroy(run, block_ar);279 274 } 280 275 … … 308 303 run_if(run, stat->u.if_s); 309 304 break; 310 case st_switch:311 run_switch(run, stat->u.switch_s);312 break;313 305 case st_while: 314 306 run_while(run, stat->u.while_s); … … 350 342 run_expr(run, exps->expr, &rexpr); 351 343 352 /*353 * If the expression has a value, the caller should have asked for it.354 */355 assert(res != NULL || rexpr == NULL);356 357 344 if (res != NULL) 358 345 *res = rexpr; … … 368 355 run_block_ar_t *block_ar; 369 356 rdata_var_t *var, *old_var; 357 tdata_item_t *var_ti; 370 358 371 359 #ifdef DEBUG_RUN_TRACE 372 360 printf("Executing variable declaration statement.\n"); 373 361 #endif 362 /* Compute variable type. XXX Memoize. */ 363 run_texpr(run->program, run_get_current_csi(run), vdecl->type, 364 &var_ti); 365 374 366 /* Create variable and initialize with default value. */ 375 run_var_new(run, v decl->titem, &var);367 run_var_new(run, var_ti, &var); 376 368 377 369 block_ar = run_get_current_block_ar(run); … … 401 393 list_node_t *ifc_node; 402 394 stree_if_clause_t *ifc; 403 bool_t rcond_b,clause_fired;395 bool_t clause_fired; 404 396 405 397 #ifdef DEBUG_RUN_TRACE … … 419 411 return; 420 412 421 rcond_b = run_item_boolean_value(run, rcond); 422 rdata_item_destroy(rcond); 423 424 if (rcond_b == b_true) { 413 if (run_item_boolean_value(run, rcond) == b_true) { 425 414 #ifdef DEBUG_RUN_TRACE 426 415 printf("Taking non-default path.\n"); … … 447 436 } 448 437 449 /** Run @c switch statement.450 *451 * @param run Runner object452 * @param switch_s Switch statement to run453 */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_TRACE466 printf("Executing switch statement.\n");467 #endif468 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_TRACE519 printf("Taking non-default path.\n");520 #endif521 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_TRACE538 printf("Taking default path.\n");539 #endif540 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_TRACE547 printf("Switch statement terminated.\n");548 #endif549 }550 551 438 /** Run @c while statement. 552 439 * … … 566 453 567 454 while (run_item_boolean_value(run, rcond) == b_true) { 568 rdata_item_destroy(rcond);569 455 run_block(run, while_s->body); 570 456 run_expr(run, while_s->cond, &rcond); … … 573 459 } 574 460 575 if (rcond != NULL)576 rdata_item_destroy(rcond);577 578 461 if (run->thread_ar->bo_mode == bm_stat) { 579 462 /* Bailout due to break statement */ … … 604 487 605 488 run_cvt_value_item(run, rexpr, &rexpr_vi); 606 rdata_item_destroy(rexpr);607 if (run_is_bo(run))608 return;609 489 610 490 /* Store expression cspan in thread AR. */ … … 612 492 613 493 /* Store expression result in thread AR. */ 614 /* XXX rexpr_vi is leaked here, we only return ->u.value */615 494 run->thread_ar->exc_payload = rexpr_vi->u.value; 616 495 … … 662 541 663 542 run_cvt_value_item(run, rexpr, &rexpr_vi); 664 rdata_item_destroy(rexpr);665 if (run_is_bo(run))666 return;667 543 668 544 /* Store expression result in procedure AR. */ … … 756 632 { 757 633 stree_csi_t *exc_csi; 634 tdata_item_t *etype; 758 635 759 636 /* Get CSI of active exception. */ 760 637 exc_csi = run_exc_payload_get_csi(run); 761 638 639 /* Evaluate type expression in except clause. */ 640 run_texpr(run->program, run_get_current_csi(run), except_c->etype, 641 &etype); 642 762 643 /* Determine if active exc. is derived from type in exc. clause. */ 763 644 /* XXX This is wrong, it does not work with generics. */ 764 return tdata_is_csi_derived_from_ti(exc_csi, e xcept_c->titem);645 return tdata_is_csi_derived_from_ti(exc_csi, etype); 765 646 } 766 647 … … 1128 1009 (void) run; 1129 1010 1130 /* Create procedureactivation record. */1011 /* Create function activation record. */ 1131 1012 proc_ar = run_proc_ar_new(); 1132 1013 proc_ar->obj = obj; … … 1143 1024 *rproc_ar = proc_ar; 1144 1025 } 1145 1146 /** Destroy a procedure AR.1147 *1148 * @param run Runner object1149 * @param proc_ar Pointer to procedure activation record1150 */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 1172 1026 1173 1027 /** Fill arguments in a procedure AR. … … 1201 1055 rdata_ref_t *ref; 1202 1056 rdata_array_t *array; 1203 rdata_var_t *elem_var;1204 1057 int n_vargs, idx; 1205 1058 … … 1294 1147 assert(rarg->ic == ic_value); 1295 1148 1296 run_value_item_to_var(rarg, &elem_var); 1297 array->element[idx] = elem_var; 1149 rdata_var_write(array->element[idx], rarg->u.value); 1298 1150 1299 1151 rarg_n = list_next(arg_vals, rarg_n); … … 1389 1241 } 1390 1242 1391 /** Destroy a block AR.1392 *1393 * @param run Runner object1394 * @param proc_ar Pointer to block activation record1395 */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 1421 1243 /** Convert item to value item. 1422 1244 * … … 1447 1269 } 1448 1270 1449 /* Make a copy of the var node within. */1271 /* It already is a value, we can share the @c var. */ 1450 1272 value = rdata_value_new(); 1451 rdata_var_copy(item->u.value->var, &value->var);1273 value->var = item->u.value->var; 1452 1274 *ritem = rdata_item_new(ic_value); 1453 1275 (*ritem)->u.value = value; … … 1536 1358 { 1537 1359 (void) run; 1538 assert(ritem != NULL);1539 1360 1540 1361 switch (address->ac) { … … 1547 1368 } 1548 1369 1549 assert( *ritem == NULL ||(*ritem)->ic == ic_value);1370 assert((*ritem)->ic == ic_value); 1550 1371 } 1551 1372 … … 1636 1457 run_proc(run, proc_ar, ritem); 1637 1458 1638 /* Destroy procedure activation record. */1639 run_proc_ar_destroy(run, proc_ar);1640 1641 1459 #ifdef DEBUG_RUN_TRACE 1642 1460 printf("Getter returns "); … … 1711 1529 /* Setter should not return a value. */ 1712 1530 assert(ritem == NULL); 1713 1714 /* Destroy procedure activation record. */1715 run_proc_ar_destroy(run, proc_ar);1716 1531 1717 1532 #ifdef DEBUG_RUN_TRACE … … 1775 1590 #endif 1776 1591 run_cvt_value_item(run, ref, &ref_val); 1777 if (run_is_bo(run)) {1778 *ritem = run_recovery_item(run);1779 return;1780 }1781 1782 1592 assert(ref_val->u.value->var->vc == vc_ref); 1783 1593 … … 1788 1598 address->u.var_a = addr_var; 1789 1599 addr_var->vref = ref_val->u.value->var->u.ref_v->vref; 1790 1791 rdata_item_destroy(ref_val);1792 1600 1793 1601 if (addr_var->vref == NULL) { … … 2032 1840 } 2033 1841 2034 /** Allocate a new procedure activation record. 2035 * 1842 /** Construct a new procedure activation record. 1843 * 1844 * @param run Runner object 2036 1845 * @return New procedure AR. 2037 1846 */ … … 2049 1858 } 2050 1859 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. 1860 /** Construct a new block activation record. 2062 1861 * 2063 1862 * @param run Runner object … … 2076 1875 return block_ar; 2077 1876 } 2078 2079 /** Deallocate a new block activation record.2080 *2081 * @param run Runner object2082 * @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.