Changes in uspace/app/sbi/src/run.c [38aaacc2:074444f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r38aaacc2 r074444f 67 67 rdata_value_t *value); 68 68 69 static void run_var_new_tprimitive(run_t *run, tdata_primitive_t *tprimitive, 70 rdata_var_t **rvar); 71 static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar); 72 static void run_var_new_deleg(run_t *run, rdata_var_t **rvar); 73 74 75 /** Initialize runner instance. 76 * 77 * @param run Runner object 78 */ 69 /** Initialize runner instance. */ 79 70 void run_init(run_t *run) 80 71 { … … 82 73 } 83 74 84 /** Run program. 85 * 86 * Associates the program @a prog with the runner object and executes 87 * it. If a run-time error occurs during the execution (e.g. an unhandled 88 * exception), @a run->error will be set to @c b_true when this function 89 * returns. 90 * 91 * @param run Runner object 92 * @param prog Program to run 93 */ 75 /** Run program */ 94 76 void run_program(run_t *run, stree_program_t *prog) 95 77 { … … 137 119 } 138 120 139 /** Run procedure. 140 * 141 * Inserts the provided procedure AR @a proc_ar on the execution stack 142 * (in the thread AR) and executes the procedure. The return value 143 * of the procedure is stored to *(@a res). @c NULL is stored if the 144 * procedure returns no value. 145 * 146 * If the procedure execution bails out due to an exception, this 147 * can be determined by looking at @c bo_mode in thread AR. Also, 148 * in this case @c NULL is stored into *(@a res). 149 * 150 * @param run Runner object 151 * @param proc_ar Procedure activation record 152 * @param res Place to store procedure return value 153 */ 121 /** Run procedure. */ 154 122 void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res) 155 123 { … … 203 171 } 204 172 205 /** Run code block. 206 * 207 * @param run Runner object 208 * @param block Block to run 209 */ 173 /** Run code block */ 210 174 static void run_block(run_t *run, stree_block_t *block) 211 175 { … … 254 218 * @a res. 255 219 * 256 * @param run Runner object 257 * @param stat Statement to run 258 * @param res Place to store exps result or NULL if not interested 220 * @param run Runner object. 221 * @param stat Statement to run. 222 * @param res Place to store exps result or NULL if not interested. 259 223 */ 260 224 void run_stat(run_t *run, stree_stat_t *stat, rdata_item_t **res) … … 302 266 * of the expression (or NULL if it has no value) will be stored to @a res. 303 267 * 304 * @param run Runner object 305 * @param exps Expression statement to run 306 * @param res Place to store exps result or NULL if not interested 268 * @param run Runner object. 269 * @param exps Expression statement to run. 270 * @param res Place to store exps result or NULL if not interested. 307 271 */ 308 272 static void run_exps(run_t *run, stree_exps_t *exps, rdata_item_t **res) … … 319 283 } 320 284 321 /** Run variable declaration statement. 322 * 323 * @param run Runner object 324 * @param vdecl Variable declaration statement to run 325 */ 285 /** Run variable declaration statement. */ 326 286 static void run_vdecl(run_t *run, stree_vdecl_t *vdecl) 327 287 { 328 288 run_block_ar_t *block_ar; 329 289 rdata_var_t *var, *old_var; 330 tdata_item_t *var_ti;290 rdata_int_t *int_v; 331 291 332 292 #ifdef DEBUG_RUN_TRACE 333 293 printf("Executing variable declaration statement.\n"); 334 294 #endif 335 /* Compute variable type. XXX Memoize. */ 336 run_texpr(run->program, run_get_current_csi(run), vdecl->type, 337 &var_ti); 338 339 /* Create variable and initialize with default value. */ 340 run_var_new(run, var_ti, &var); 295 296 /* XXX Need to support other variables than int. */ 297 298 var = rdata_var_new(vc_int); 299 int_v = rdata_int_new(); 300 301 var->u.int_v = int_v; 302 bigint_init(&int_v->value, 0); 341 303 342 304 block_ar = run_get_current_block_ar(run); … … 356 318 } 357 319 358 /** Run @c if statement. 359 * 360 * @param run Runner object 361 * @param if_s If statement to run 362 */ 320 /** Run @c if statement. */ 363 321 static void run_if(run_t *run, stree_if_t *if_s) 364 322 { … … 390 348 } 391 349 392 /** Run @c while statement. 393 * 394 * @param run Runner object 395 * @param while_s While statement to run 396 */ 350 /** Run @c while statement. */ 397 351 static void run_while(run_t *run, stree_while_t *while_s) 398 352 { … … 421 375 } 422 376 423 /** Run @c raise statement. 424 * 425 * @param run Runner object 426 * @param raise_s Raise statement to run 427 */ 377 /** Run @c raise statement. */ 428 378 static void run_raise(run_t *run, stree_raise_t *raise_s) 429 379 { … … 447 397 } 448 398 449 /** Run @c return statement. 450 * 451 * Sets the return value in procedure AR and forces control to return 452 * from the function by setting bailout mode to @c bm_proc. 453 * 454 * @param run Runner object 455 * @param raise_s Return statement to run 456 */ 399 /** Run @c return statement. */ 457 400 static void run_return(run_t *run, stree_return_t *return_s) 458 401 { … … 470 413 run_cvt_value_item(run, rexpr, &rexpr_vi); 471 414 472 /* Store expression result in procedureAR. */415 /* Store expression result in function AR. */ 473 416 proc_ar = run_get_current_proc_ar(run); 474 417 proc_ar->retval = rexpr_vi; … … 479 422 } 480 423 481 /** Run @c with-except-finally statement. 482 * 483 * Note: 'With' clause is not implemented. 484 * 485 * @param run Runner object 486 * @param wef_s With-except-finally statement to run 487 */ 424 /** Run @c with-except-finally statement. */ 488 425 static void run_wef(run_t *run, stree_wef_t *wef_s) 489 426 { … … 552 489 * matches except clause @c except_c. 553 490 * 554 * @param run Runner object 555 * @param except_c @c except clause 556 * @return @c b_true if there is a match, @c b_false otherwise 491 * @param run Runner object. 492 * @param except_c @c except clause. 493 * @return @c b_true if there is a match, @c b_false otherwise. 557 494 */ 558 495 static bool_t run_exc_match(run_t *run, stree_except_t *except_c) … … 569 506 570 507 /* Determine if active exc. is derived from type in exc. clause. */ 571 /* XXX This is wrong, it does not work with generics. */572 508 return tdata_is_csi_derived_from_ti(exc_csi, etype); 573 509 } … … 575 511 /** Return CSI of the active exception. 576 512 * 577 * @param run Runner object 578 * @return CSI of the active exception 513 * @param run Runner object. 514 * @return CSI of the active exception. 579 515 */ 580 516 static stree_csi_t *run_exc_payload_get_csi(run_t *run) … … 621 557 * error message and raises a run-time error. 622 558 * 623 * @param run Runner object 559 * @param run Runner object. 624 560 */ 625 561 void run_exc_check_unhandled(run_t *run) … … 643 579 * 644 580 * Raises an error that cannot be handled by the user program. 645 *646 * @param run Runner object647 581 */ 648 582 void run_raise_error(run_t *run) … … 652 586 } 653 587 654 /** Construct a special recovery item. 655 * 656 * @param run Runner object 657 */ 588 /** Construct a special recovery item. */ 658 589 rdata_item_t *run_recovery_item(run_t *run) 659 590 { … … 662 593 } 663 594 664 /** Find a local variable in the currently active function. 665 * 666 * @param run Runner object 667 * @param name Name SID of the local variable 668 * @return Pointer to var node or @c NULL if not found 669 */ 595 /** Find a local variable in the currently active function. */ 670 596 rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name) 671 597 { … … 692 618 } 693 619 694 /** Get current procedure activation record. 695 * 696 * @param run Runner object 697 * @return Active procedure AR 698 */ 620 /** Get current function activation record. */ 699 621 run_proc_ar_t *run_get_current_proc_ar(run_t *run) 700 622 { … … 705 627 } 706 628 707 /** Get current block activation record. 708 * 709 * @param run Runner object 710 * @return Active block AR 711 */ 629 /** Get current block activation record. */ 712 630 run_block_ar_t *run_get_current_block_ar(run_t *run) 713 631 { … … 721 639 } 722 640 723 /** Get current CSI. 724 * 725 * @param run Runner object 726 * @return Active CSI 727 */ 641 /** Get current CSI. */ 728 642 stree_csi_t *run_get_current_csi(run_t *run) 729 643 { … … 740 654 * (1) Create a variable of the desired type. 741 655 * (2) Initialize the variable with the provided value. 742 *743 * @param item Value item (initial value for variable).744 * @param var Place to store new var node.745 656 */ 746 657 void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var) 747 658 { 748 rdata_bool_t *bool_v;749 659 rdata_char_t *char_v; 750 rdata_deleg_t *deleg_v;751 660 rdata_int_t *int_v; 752 661 rdata_string_t *string_v; … … 758 667 759 668 switch (in_var->vc) { 760 case vc_bool:761 *var = rdata_var_new(vc_bool);762 bool_v = rdata_bool_new();763 764 (*var)->u.bool_v = bool_v;765 bool_v->value = item->u.value->var->u.bool_v->value;766 break;767 669 case vc_char: 768 670 *var = rdata_var_new(vc_char); … … 773 675 &char_v->value); 774 676 break; 775 case vc_deleg:776 *var = rdata_var_new(vc_deleg);777 deleg_v = rdata_deleg_new();778 779 (*var)->u.deleg_v = deleg_v;780 deleg_v->obj = item->u.value->var->u.deleg_v->obj;781 deleg_v->sym = item->u.value->var->u.deleg_v->sym;782 break;783 677 case vc_int: 784 678 *var = rdata_var_new(vc_int); … … 810 704 } 811 705 812 /** Construct a procedure AR. 813 * 814 * @param run Runner object 815 * @param obj Object whose procedure is being activated 816 * @param proc Procedure that is being activated 817 * @param rproc_ar Place to store pointer to new activation record 818 */ 706 /** Construct a function AR. */ 819 707 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc, 820 708 run_proc_ar_t **rproc_ar) … … 845 733 * When invoking a procedure this is used to store the argument values 846 734 * in the activation record. 847 *848 * @param run Runner object849 * @param proc_ar Existing procedure activation record where to store850 * the values851 * @param arg_vals List of value items (rdata_item_t *) -- real852 * argument values853 735 */ 854 736 void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals) … … 885 767 case sc_fun: 886 768 fun = symbol_to_fun(outer_symbol); 887 args = &fun-> sig->args;888 varg = fun-> sig->varg;769 args = &fun->args; 770 varg = fun->varg; 889 771 break; 890 772 case sc_prop: … … 983 865 * When invoking a setter this is used to store its argument value in its 984 866 * procedure activation record. 985 *986 * @param run Runner object987 * @param proc_ar Existing procedure activation record where to store988 * the setter argument989 * @param arg_val Value items (rdata_item_t *) -- real argument value990 867 */ 991 868 void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar, … … 1021 898 } 1022 899 1023 /** Print function activation backtrace. 1024 * 1025 * Prints a backtrace of activated functions for debugging purposes. 1026 * 1027 * @param run Runner object 1028 */ 900 /** Print function activation backtrace. */ 1029 901 void run_print_fun_bt(run_t *run) 1030 902 { … … 1048 920 * If @a item is a value, we just return a copy. If @a item is an address, 1049 921 * we read from the address. 1050 *1051 * @param run Runner object1052 * @param item Input item (value or address)1053 * @param ritem Place to store pointer to new value item1054 922 */ 1055 923 void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem) … … 1083 951 * Get var-class of @a item, regardless whether it is a value or address. 1084 952 * (I.e. the var class of the value or variable at the given address). 1085 *1086 * @param run Runner object1087 * @param item Value or address item1088 * @return Varclass of @a item1089 953 */ 1090 954 var_class_t run_item_get_vc(run_t *run, rdata_item_t *item) … … 1128 992 * copy. 1129 993 * 1130 * @param run Runner object 1131 * @param addr Address of class @c ac_prop 1132 * @ return Pointer to var node994 * @param run Runner object. 995 * @param addr Address of class @c ac_prop. 996 * @param Pointer to var node. 1133 997 */ 1134 998 static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *addr) … … 1151 1015 /** Read data from an address. 1152 1016 * 1153 * Read value from the specified address. 1154 * 1155 * @param run Runner object 1156 * @param address Address to read 1157 * @param ritem Place to store pointer to the value that was read 1017 * Return value stored in a variable at the specified address. 1158 1018 */ 1159 1019 void run_address_read(run_t *run, rdata_address_t *address, … … 1176 1036 /** Write data to an address. 1177 1037 * 1178 * Store value @a value at address @a address. 1179 * 1180 * @param run Runner object 1181 * @param address Address to write 1182 * @param value Value to store at the address 1038 * Store @a value to the variable at @a address. 1183 1039 */ 1184 1040 void run_address_write(run_t *run, rdata_address_t *address, … … 1197 1053 } 1198 1054 1199 /** Read data from a property address.1200 *1201 * This involves invoking the property getter procedure.1202 *1203 * @param run Runner object.1204 * @param addr_prop Property address to read.1205 * @param ritem Place to store pointer to the value that was read.1206 */1207 1055 static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop, 1208 1056 rdata_item_t **ritem) … … 1268 1116 } 1269 1117 1270 /** Write data to a property address.1271 *1272 * This involves invoking the property setter procedure.1273 *1274 * @param run Runner object1275 * @param addr_prop Property address to write1276 * @param value Value to store at the address1277 */1278 1118 static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop, 1279 1119 rdata_value_t *value) … … 1341 1181 * 1342 1182 * Constructs a reference (value item) pointing to @a var. 1343 *1344 * @param run Runner object1345 * @param var Variable node that is being referenced1346 * @param res Place to store pointer to new reference.1347 1183 */ 1348 1184 void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res) … … 1374 1210 * Takes a reference (address or value) and returns the address (item) of 1375 1211 * the target of the reference. 1376 *1377 * @param run Runner object1378 * @param ref Reference1379 * @param rtitem Place to store pointer to the resulting address.1380 1212 */ 1381 1213 void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem) … … 1420 1252 * error (not for the @c raise statement). 1421 1253 * 1422 * @param run Runner object 1423 * @param csi Exception class 1254 * @param run Runner object. 1255 * @param csi Exception class. 1424 1256 */ 1425 1257 void run_raise_exc(run_t *run, stree_csi_t *csi) … … 1438 1270 } 1439 1271 1440 /** Determine if we are bailing out. 1441 * 1442 * @param run Runner object 1443 * @return @c b_true if we are bailing out, @c b_false otherwise 1444 */ 1272 /** Determine if we are bailing out. */ 1445 1273 bool_t run_is_bo(run_t *run) 1446 1274 { … … 1448 1276 } 1449 1277 1450 /** Construct a new variable of the given type.1451 *1452 * The variable is allocated and initialized with a default value1453 * based on type item @a ti. For reference types the default value1454 * is a null reference. At this point this does not work for generic1455 * types (we need RTTI).1456 *1457 * @param run Runner object1458 * @param ti Type of variable to create (type item)1459 * @param rvar Place to store pointer to new variable1460 */1461 void run_var_new(run_t *run, tdata_item_t *ti, rdata_var_t **rvar)1462 {1463 rdata_var_t *var;1464 1465 switch (ti->tic) {1466 case tic_tprimitive:1467 run_var_new_tprimitive(run, ti->u.tprimitive, rvar);1468 break;1469 case tic_tobject:1470 case tic_tarray:1471 run_var_new_null_ref(run, rvar);1472 break;1473 case tic_tdeleg:1474 case tic_tfun:1475 run_var_new_deleg(run, rvar);1476 break;1477 case tic_tvref:1478 /*1479 * XXX Need to obtain run-time value of type argument to1480 * initialize variable properly.1481 */1482 var = rdata_var_new(vc_int);1483 var->u.int_v = rdata_int_new();1484 bigint_init(&var->u.int_v->value, 0);1485 *rvar = var;1486 break;1487 case tic_ignore:1488 assert(b_false);1489 }1490 }1491 1492 /** Construct a new variable of primitive type.1493 *1494 * The variable is allocated and initialized with a default value1495 * based on primitive type item @a tprimitive.1496 *1497 * @param run Runner object1498 * @param ti Primitive type of variable to create1499 * @param rvar Place to store pointer to new variable1500 */1501 static void run_var_new_tprimitive(run_t *run, tdata_primitive_t *tprimitive,1502 rdata_var_t **rvar)1503 {1504 rdata_var_t *var;1505 1506 (void) run;1507 1508 switch (tprimitive->tpc) {1509 case tpc_bool:1510 var = rdata_var_new(vc_bool);1511 var->u.bool_v = rdata_bool_new();1512 var->u.bool_v->value = b_false;1513 break;1514 case tpc_char:1515 var = rdata_var_new(vc_char);1516 var->u.char_v = rdata_char_new();1517 bigint_init(&var->u.char_v->value, 0);1518 break;1519 case tpc_int:1520 var = rdata_var_new(vc_int);1521 var->u.int_v = rdata_int_new();1522 bigint_init(&var->u.int_v->value, 0);1523 break;1524 case tpc_nil:1525 assert(b_false);1526 case tpc_string:1527 var = rdata_var_new(vc_string);1528 var->u.string_v = rdata_string_new();1529 var->u.string_v->value = "";1530 break;1531 case tpc_resource:1532 var = rdata_var_new(vc_resource);1533 var->u.resource_v = rdata_resource_new();1534 var->u.resource_v->data = NULL;1535 break;1536 }1537 1538 *rvar = var;1539 }1540 1541 /** Construct a new variable containing null reference.1542 *1543 * @param run Runner object1544 * @param rvar Place to store pointer to new variable1545 */1546 static void run_var_new_null_ref(run_t *run, rdata_var_t **rvar)1547 {1548 rdata_var_t *var;1549 1550 (void) run;1551 1552 /* Return null reference. */1553 var = rdata_var_new(vc_ref);1554 var->u.ref_v = rdata_ref_new();1555 1556 *rvar = var;1557 }1558 1559 /** Construct a new variable containing invalid delegate.1560 *1561 * @param run Runner object1562 * @param rvar Place to store pointer to new variable1563 */1564 static void run_var_new_deleg(run_t *run, rdata_var_t **rvar)1565 {1566 rdata_var_t *var;1567 1568 (void) run;1569 1570 /* Return null reference. */1571 var = rdata_var_new(vc_deleg);1572 var->u.deleg_v = rdata_deleg_new();1573 1574 *rvar = var;1575 }1576 1577 /** Construct a new thread activation record.1578 *1579 * @param run Runner object1580 * @return New thread AR.1581 */1582 1278 run_thread_ar_t *run_thread_ar_new(void) 1583 1279 { … … 1593 1289 } 1594 1290 1595 /** Construct a new procedure activation record.1596 *1597 * @param run Runner object1598 * @return New procedure AR.1599 */1600 1291 run_proc_ar_t *run_proc_ar_new(void) 1601 1292 { … … 1611 1302 } 1612 1303 1613 /** Construct a new block activation record.1614 *1615 * @param run Runner object1616 * @return New block AR.1617 */1618 1304 run_block_ar_t *run_block_ar_new(void) 1619 1305 {
Note:
See TracChangeset
for help on using the changeset viewer.