Changes in uspace/app/sbi/src/run.c [074444f:38aaacc2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r074444f r38aaacc2 67 67 rdata_value_t *value); 68 68 69 /** Initialize runner instance. */ 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 */ 70 79 void run_init(run_t *run) 71 80 { … … 73 82 } 74 83 75 /** Run program */ 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 */ 76 94 void run_program(run_t *run, stree_program_t *prog) 77 95 { … … 119 137 } 120 138 121 /** Run procedure. */ 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 */ 122 154 void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res) 123 155 { … … 171 203 } 172 204 173 /** Run code block */ 205 /** Run code block. 206 * 207 * @param run Runner object 208 * @param block Block to run 209 */ 174 210 static void run_block(run_t *run, stree_block_t *block) 175 211 { … … 218 254 * @a res. 219 255 * 220 * @param run Runner object .221 * @param stat Statement to run .222 * @param res Place to store exps result or NULL if not interested .256 * @param run Runner object 257 * @param stat Statement to run 258 * @param res Place to store exps result or NULL if not interested 223 259 */ 224 260 void run_stat(run_t *run, stree_stat_t *stat, rdata_item_t **res) … … 266 302 * of the expression (or NULL if it has no value) will be stored to @a res. 267 303 * 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 .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 271 307 */ 272 308 static void run_exps(run_t *run, stree_exps_t *exps, rdata_item_t **res) … … 283 319 } 284 320 285 /** Run variable declaration statement. */ 321 /** Run variable declaration statement. 322 * 323 * @param run Runner object 324 * @param vdecl Variable declaration statement to run 325 */ 286 326 static void run_vdecl(run_t *run, stree_vdecl_t *vdecl) 287 327 { 288 328 run_block_ar_t *block_ar; 289 329 rdata_var_t *var, *old_var; 290 rdata_int_t *int_v;330 tdata_item_t *var_ti; 291 331 292 332 #ifdef DEBUG_RUN_TRACE 293 333 printf("Executing variable declaration statement.\n"); 294 334 #endif 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); 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); 303 341 304 342 block_ar = run_get_current_block_ar(run); … … 318 356 } 319 357 320 /** Run @c if statement. */ 358 /** Run @c if statement. 359 * 360 * @param run Runner object 361 * @param if_s If statement to run 362 */ 321 363 static void run_if(run_t *run, stree_if_t *if_s) 322 364 { … … 348 390 } 349 391 350 /** Run @c while statement. */ 392 /** Run @c while statement. 393 * 394 * @param run Runner object 395 * @param while_s While statement to run 396 */ 351 397 static void run_while(run_t *run, stree_while_t *while_s) 352 398 { … … 375 421 } 376 422 377 /** Run @c raise statement. */ 423 /** Run @c raise statement. 424 * 425 * @param run Runner object 426 * @param raise_s Raise statement to run 427 */ 378 428 static void run_raise(run_t *run, stree_raise_t *raise_s) 379 429 { … … 397 447 } 398 448 399 /** Run @c return statement. */ 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 */ 400 457 static void run_return(run_t *run, stree_return_t *return_s) 401 458 { … … 413 470 run_cvt_value_item(run, rexpr, &rexpr_vi); 414 471 415 /* Store expression result in functionAR. */472 /* Store expression result in procedure AR. */ 416 473 proc_ar = run_get_current_proc_ar(run); 417 474 proc_ar->retval = rexpr_vi; … … 422 479 } 423 480 424 /** Run @c with-except-finally statement. */ 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 */ 425 488 static void run_wef(run_t *run, stree_wef_t *wef_s) 426 489 { … … 489 552 * matches except clause @c except_c. 490 553 * 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 .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 494 557 */ 495 558 static bool_t run_exc_match(run_t *run, stree_except_t *except_c) … … 506 569 507 570 /* Determine if active exc. is derived from type in exc. clause. */ 571 /* XXX This is wrong, it does not work with generics. */ 508 572 return tdata_is_csi_derived_from_ti(exc_csi, etype); 509 573 } … … 511 575 /** Return CSI of the active exception. 512 576 * 513 * @param run Runner object .514 * @return CSI of the active exception .577 * @param run Runner object 578 * @return CSI of the active exception 515 579 */ 516 580 static stree_csi_t *run_exc_payload_get_csi(run_t *run) … … 557 621 * error message and raises a run-time error. 558 622 * 559 * @param run Runner object .623 * @param run Runner object 560 624 */ 561 625 void run_exc_check_unhandled(run_t *run) … … 579 643 * 580 644 * Raises an error that cannot be handled by the user program. 645 * 646 * @param run Runner object 581 647 */ 582 648 void run_raise_error(run_t *run) … … 586 652 } 587 653 588 /** Construct a special recovery item. */ 654 /** Construct a special recovery item. 655 * 656 * @param run Runner object 657 */ 589 658 rdata_item_t *run_recovery_item(run_t *run) 590 659 { … … 593 662 } 594 663 595 /** Find a local variable in the currently active function. */ 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 */ 596 670 rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name) 597 671 { … … 618 692 } 619 693 620 /** Get current function activation record. */ 694 /** Get current procedure activation record. 695 * 696 * @param run Runner object 697 * @return Active procedure AR 698 */ 621 699 run_proc_ar_t *run_get_current_proc_ar(run_t *run) 622 700 { … … 627 705 } 628 706 629 /** Get current block activation record. */ 707 /** Get current block activation record. 708 * 709 * @param run Runner object 710 * @return Active block AR 711 */ 630 712 run_block_ar_t *run_get_current_block_ar(run_t *run) 631 713 { … … 639 721 } 640 722 641 /** Get current CSI. */ 723 /** Get current CSI. 724 * 725 * @param run Runner object 726 * @return Active CSI 727 */ 642 728 stree_csi_t *run_get_current_csi(run_t *run) 643 729 { … … 654 740 * (1) Create a variable of the desired type. 655 741 * (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. 656 745 */ 657 746 void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var) 658 747 { 748 rdata_bool_t *bool_v; 659 749 rdata_char_t *char_v; 750 rdata_deleg_t *deleg_v; 660 751 rdata_int_t *int_v; 661 752 rdata_string_t *string_v; … … 667 758 668 759 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; 669 767 case vc_char: 670 768 *var = rdata_var_new(vc_char); … … 675 773 &char_v->value); 676 774 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; 677 783 case vc_int: 678 784 *var = rdata_var_new(vc_int); … … 704 810 } 705 811 706 /** Construct a function AR. */ 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 */ 707 819 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc, 708 820 run_proc_ar_t **rproc_ar) … … 733 845 * When invoking a procedure this is used to store the argument values 734 846 * in the activation record. 847 * 848 * @param run Runner object 849 * @param proc_ar Existing procedure activation record where to store 850 * the values 851 * @param arg_vals List of value items (rdata_item_t *) -- real 852 * argument values 735 853 */ 736 854 void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals) … … 767 885 case sc_fun: 768 886 fun = symbol_to_fun(outer_symbol); 769 args = &fun-> args;770 varg = fun-> varg;887 args = &fun->sig->args; 888 varg = fun->sig->varg; 771 889 break; 772 890 case sc_prop: … … 865 983 * When invoking a setter this is used to store its argument value in its 866 984 * procedure activation record. 985 * 986 * @param run Runner object 987 * @param proc_ar Existing procedure activation record where to store 988 * the setter argument 989 * @param arg_val Value items (rdata_item_t *) -- real argument value 867 990 */ 868 991 void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar, … … 898 1021 } 899 1022 900 /** Print function activation backtrace. */ 1023 /** Print function activation backtrace. 1024 * 1025 * Prints a backtrace of activated functions for debugging purposes. 1026 * 1027 * @param run Runner object 1028 */ 901 1029 void run_print_fun_bt(run_t *run) 902 1030 { … … 920 1048 * If @a item is a value, we just return a copy. If @a item is an address, 921 1049 * we read from the address. 1050 * 1051 * @param run Runner object 1052 * @param item Input item (value or address) 1053 * @param ritem Place to store pointer to new value item 922 1054 */ 923 1055 void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem) … … 951 1083 * Get var-class of @a item, regardless whether it is a value or address. 952 1084 * (I.e. the var class of the value or variable at the given address). 1085 * 1086 * @param run Runner object 1087 * @param item Value or address item 1088 * @return Varclass of @a item 953 1089 */ 954 1090 var_class_t run_item_get_vc(run_t *run, rdata_item_t *item) … … 992 1128 * copy. 993 1129 * 994 * @param run Runner object .995 * @param addr Address of class @c ac_prop .996 * @ param Pointer to var node.1130 * @param run Runner object 1131 * @param addr Address of class @c ac_prop 1132 * @return Pointer to var node 997 1133 */ 998 1134 static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *addr) … … 1015 1151 /** Read data from an address. 1016 1152 * 1017 * Return value stored in a variable at the specified address. 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 1018 1158 */ 1019 1159 void run_address_read(run_t *run, rdata_address_t *address, … … 1036 1176 /** Write data to an address. 1037 1177 * 1038 * Store @a value to the variable at @a address. 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 1039 1183 */ 1040 1184 void run_address_write(run_t *run, rdata_address_t *address, … … 1053 1197 } 1054 1198 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 */ 1055 1207 static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop, 1056 1208 rdata_item_t **ritem) … … 1116 1268 } 1117 1269 1270 /** Write data to a property address. 1271 * 1272 * This involves invoking the property setter procedure. 1273 * 1274 * @param run Runner object 1275 * @param addr_prop Property address to write 1276 * @param value Value to store at the address 1277 */ 1118 1278 static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop, 1119 1279 rdata_value_t *value) … … 1181 1341 * 1182 1342 * Constructs a reference (value item) pointing to @a var. 1343 * 1344 * @param run Runner object 1345 * @param var Variable node that is being referenced 1346 * @param res Place to store pointer to new reference. 1183 1347 */ 1184 1348 void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res) … … 1210 1374 * Takes a reference (address or value) and returns the address (item) of 1211 1375 * the target of the reference. 1376 * 1377 * @param run Runner object 1378 * @param ref Reference 1379 * @param rtitem Place to store pointer to the resulting address. 1212 1380 */ 1213 1381 void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem) … … 1252 1420 * error (not for the @c raise statement). 1253 1421 * 1254 * @param run Runner object .1255 * @param csi Exception class .1422 * @param run Runner object 1423 * @param csi Exception class 1256 1424 */ 1257 1425 void run_raise_exc(run_t *run, stree_csi_t *csi) … … 1270 1438 } 1271 1439 1272 /** Determine if we are bailing out. */ 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 */ 1273 1445 bool_t run_is_bo(run_t *run) 1274 1446 { … … 1276 1448 } 1277 1449 1450 /** Construct a new variable of the given type. 1451 * 1452 * The variable is allocated and initialized with a default value 1453 * based on type item @a ti. For reference types the default value 1454 * is a null reference. At this point this does not work for generic 1455 * types (we need RTTI). 1456 * 1457 * @param run Runner object 1458 * @param ti Type of variable to create (type item) 1459 * @param rvar Place to store pointer to new variable 1460 */ 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 to 1480 * 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 value 1495 * based on primitive type item @a tprimitive. 1496 * 1497 * @param run Runner object 1498 * @param ti Primitive type of variable to create 1499 * @param rvar Place to store pointer to new variable 1500 */ 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 object 1544 * @param rvar Place to store pointer to new variable 1545 */ 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 object 1562 * @param rvar Place to store pointer to new variable 1563 */ 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 object 1580 * @return New thread AR. 1581 */ 1278 1582 run_thread_ar_t *run_thread_ar_new(void) 1279 1583 { … … 1289 1593 } 1290 1594 1595 /** Construct a new procedure activation record. 1596 * 1597 * @param run Runner object 1598 * @return New procedure AR. 1599 */ 1291 1600 run_proc_ar_t *run_proc_ar_new(void) 1292 1601 { … … 1302 1611 } 1303 1612 1613 /** Construct a new block activation record. 1614 * 1615 * @param run Runner object 1616 * @return New block AR. 1617 */ 1304 1618 run_block_ar_t *run_block_ar_new(void) 1305 1619 {
Note:
See TracChangeset
for help on using the changeset viewer.