Changeset 1ef0fc3 in mainline for uspace/app/sbi/src/run_expr.c
- Timestamp:
- 2010-04-10T11:19:18Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d7e45c8
- Parents:
- 2721a75 (diff), 074444f (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_expr.c
r2721a75 r1ef0fc3 53 53 static void run_literal(run_t *run, stree_literal_t *literal, 54 54 rdata_item_t **res); 55 static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool, 56 rdata_item_t **res); 57 static void run_lit_char(run_t *run, stree_lit_char_t *lit_char, 58 rdata_item_t **res); 55 59 static void run_lit_int(run_t *run, stree_lit_int_t *lit_int, 56 60 rdata_item_t **res); … … 64 68 65 69 static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res); 70 static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 71 rdata_value_t *v2, rdata_item_t **res); 72 static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 73 rdata_value_t *v2, rdata_item_t **res); 66 74 static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 67 75 rdata_value_t *v2, rdata_item_t **res); … … 315 323 printf("Run literal.\n"); 316 324 #endif 317 318 325 switch (literal->ltc) { 326 case ltc_bool: 327 run_lit_bool(run, &literal->u.lit_bool, res); 328 break; 329 case ltc_char: 330 run_lit_char(run, &literal->u.lit_char, res); 331 break; 319 332 case ltc_int: 320 333 run_lit_int(run, &literal->u.lit_int, res); … … 326 339 run_lit_string(run, &literal->u.lit_string, res); 327 340 break; 328 default: 329 assert(b_false); 330 } 341 } 342 } 343 344 /** Evaluate Boolean literal. */ 345 static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool, 346 rdata_item_t **res) 347 { 348 rdata_item_t *item; 349 rdata_value_t *value; 350 rdata_var_t *var; 351 rdata_bool_t *bool_v; 352 353 #ifdef DEBUG_RUN_TRACE 354 printf("Run Boolean literal.\n"); 355 #endif 356 (void) run; 357 358 item = rdata_item_new(ic_value); 359 value = rdata_value_new(); 360 var = rdata_var_new(vc_bool); 361 bool_v = rdata_bool_new(); 362 363 item->u.value = value; 364 value->var = var; 365 var->u.bool_v = bool_v; 366 bool_v->value = lit_bool->value; 367 368 *res = item; 369 } 370 371 /** Evaluate character literal. */ 372 static void run_lit_char(run_t *run, stree_lit_char_t *lit_char, 373 rdata_item_t **res) 374 { 375 rdata_item_t *item; 376 rdata_value_t *value; 377 rdata_var_t *var; 378 rdata_char_t *char_v; 379 380 #ifdef DEBUG_RUN_TRACE 381 printf("Run character literal.\n"); 382 #endif 383 (void) run; 384 385 item = rdata_item_new(ic_value); 386 value = rdata_value_new(); 387 var = rdata_var_new(vc_char); 388 char_v = rdata_char_new(); 389 390 item->u.value = value; 391 value->var = var; 392 var->u.char_v = char_v; 393 bigint_clone(&lit_char->value, &char_v->value); 394 395 *res = item; 331 396 } 332 397 … … 486 551 487 552 switch (v1->var->vc) { 553 case vc_bool: 554 run_binop_bool(run, binop, v1, v2, res); 555 break; 556 case vc_char: 557 run_binop_char(run, binop, v1, v2, res); 558 break; 488 559 case vc_int: 489 560 run_binop_int(run, binop, v1, v2, res); … … 495 566 run_binop_ref(run, binop, v1, v2, res); 496 567 break; 568 case vc_deleg: 569 case vc_array: 570 case vc_object: 571 case vc_resource: 572 assert(b_false); 573 } 574 } 575 576 /** Evaluate binary operation on bool arguments. */ 577 static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 578 rdata_value_t *v2, rdata_item_t **res) 579 { 580 rdata_item_t *item; 581 rdata_value_t *value; 582 rdata_var_t *var; 583 rdata_bool_t *bool_v; 584 585 bool_t b1, b2; 586 587 (void) run; 588 589 item = rdata_item_new(ic_value); 590 value = rdata_value_new(); 591 var = rdata_var_new(vc_bool); 592 bool_v = rdata_bool_new(); 593 594 item->u.value = value; 595 value->var = var; 596 var->u.bool_v = bool_v; 597 598 b1 = v1->var->u.bool_v->value; 599 b2 = v2->var->u.bool_v->value; 600 601 switch (binop->bc) { 602 case bo_plus: 603 case bo_minus: 604 case bo_mult: 605 assert(b_false); 606 607 case bo_equal: 608 bool_v->value = (b1 == b2); 609 break; 610 case bo_notequal: 611 bool_v->value = (b1 != b2); 612 break; 613 case bo_lt: 614 bool_v->value = (b1 == b_false) && (b2 == b_true); 615 break; 616 case bo_gt: 617 bool_v->value = (b1 == b_true) && (b2 == b_false); 618 break; 619 case bo_lt_equal: 620 bool_v->value = (b1 == b_false) || (b2 == b_true); 621 break; 622 case bo_gt_equal: 623 bool_v->value = (b1 == b_true) || (b2 == b_false); 624 break; 625 } 626 627 *res = item; 628 } 629 630 /** Evaluate binary operation on char arguments. */ 631 static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 632 rdata_value_t *v2, rdata_item_t **res) 633 { 634 rdata_item_t *item; 635 rdata_value_t *value; 636 rdata_var_t *var; 637 rdata_bool_t *bool_v; 638 639 bigint_t *c1, *c2; 640 bigint_t diff; 641 bool_t zf, nf; 642 643 (void) run; 644 645 item = rdata_item_new(ic_value); 646 value = rdata_value_new(); 647 648 item->u.value = value; 649 650 c1 = &v1->var->u.char_v->value; 651 c2 = &v2->var->u.char_v->value; 652 653 var = rdata_var_new(vc_bool); 654 bool_v = rdata_bool_new(); 655 var->u.bool_v = bool_v; 656 value->var = var; 657 658 bigint_sub(c1, c2, &diff); 659 zf = bigint_is_zero(&diff); 660 nf = bigint_is_negative(&diff); 661 662 switch (binop->bc) { 663 case bo_plus: 664 case bo_minus: 665 case bo_mult: 666 assert(b_false); 667 668 case bo_equal: 669 bool_v->value = zf; 670 break; 671 case bo_notequal: 672 bool_v->value = !zf; 673 break; 674 case bo_lt: 675 bool_v->value = (!zf && nf); 676 break; 677 case bo_gt: 678 bool_v->value = (!zf && !nf); 679 break; 680 case bo_lt_equal: 681 bool_v->value = (zf || nf); 682 break; 683 case bo_gt_equal: 684 bool_v->value = !nf; 685 break; 497 686 default: 498 printf("Unimplemented: Binary operation arguments of "499 "type %d.\n", v1->var->vc);500 exit(1); 501 }687 assert(b_false); 688 } 689 690 *res = item; 502 691 } 503 692 … … 510 699 rdata_var_t *var; 511 700 rdata_int_t *int_v; 701 rdata_bool_t *bool_v; 512 702 513 703 bigint_t *i1, *i2; … … 520 710 item = rdata_item_new(ic_value); 521 711 value = rdata_value_new(); 522 var = rdata_var_new(vc_int);523 int_v = rdata_int_new();524 712 525 713 item->u.value = value; 526 value->var = var;527 var->u.int_v = int_v;528 714 529 715 i1 = &v1->var->u.int_v->value; … … 534 720 switch (binop->bc) { 535 721 case bo_plus: 722 int_v = rdata_int_new(); 536 723 bigint_add(i1, i2, &int_v->value); 537 724 break; 538 725 case bo_minus: 726 int_v = rdata_int_new(); 539 727 bigint_sub(i1, i2, &int_v->value); 540 728 break; 541 729 case bo_mult: 730 int_v = rdata_int_new(); 542 731 bigint_mul(i1, i2, &int_v->value); 543 732 break; … … 548 737 549 738 if (done) { 739 var = rdata_var_new(vc_int); 740 var->u.int_v = int_v; 741 value->var = var; 550 742 *res = item; 551 743 return; 552 744 } 745 746 var = rdata_var_new(vc_bool); 747 bool_v = rdata_bool_new(); 748 var->u.bool_v = bool_v; 749 value->var = var; 553 750 554 751 /* Relational operation. */ … … 558 755 nf = bigint_is_negative(&diff); 559 756 560 /* XXX We should have a real boolean type. */561 757 switch (binop->bc) { 562 758 case bo_equal: 563 b igint_init(&int_v->value, zf ? 1 : 0);759 bool_v->value = zf; 564 760 break; 565 761 case bo_notequal: 566 b igint_init(&int_v->value, !zf ? 1 : 0);762 bool_v->value = !zf; 567 763 break; 568 764 case bo_lt: 569 b igint_init(&int_v->value, (!zf && nf) ? 1 : 0);765 bool_v->value = (!zf && nf); 570 766 break; 571 767 case bo_gt: 572 b igint_init(&int_v->value, (!zf && !nf) ? 1 : 0);768 bool_v->value = (!zf && !nf); 573 769 break; 574 770 case bo_lt_equal: 575 b igint_init(&int_v->value, (zf || nf) ? 1 : 0);771 bool_v->value = (zf || nf); 576 772 break; 577 773 case bo_gt_equal: 578 b igint_init(&int_v->value, !nf ? 1 : 0);774 bool_v->value = !nf; 579 775 break; 580 776 default: … … 631 827 rdata_value_t *value; 632 828 rdata_var_t *var; 633 rdata_ int_t *int_v;829 rdata_bool_t *bool_v; 634 830 635 831 rdata_var_t *ref1, *ref2; … … 639 835 item = rdata_item_new(ic_value); 640 836 value = rdata_value_new(); 641 var = rdata_var_new(vc_ int);642 int_v = rdata_int_new();837 var = rdata_var_new(vc_bool); 838 bool_v = rdata_bool_new(); 643 839 644 840 item->u.value = value; 645 841 value->var = var; 646 var->u. int_v = int_v;842 var->u.bool_v = bool_v; 647 843 648 844 ref1 = v1->var->u.ref_v->vref; … … 650 846 651 847 switch (binop->bc) { 652 /* XXX We should have a real boolean type. */653 848 case bo_equal: 654 b igint_init(&int_v->value, (ref1 == ref2) ? 1 : 0);849 bool_v->value = (ref1 == ref2); 655 850 break; 656 851 case bo_notequal: 657 b igint_init(&int_v->value, (ref1 != ref2) ? 1 : 0);852 bool_v->value = (ref1 != ref2); 658 853 break; 659 854 default: … … 980 1175 access->member_name); 981 1176 982 if (member == NULL) { 983 printf("Error: CSI '"); 984 symbol_print_fqn(deleg_v->sym); 985 printf("' has no member named '%s'.\n", 986 strtab_get_str(access->member_name->sid)); 987 exit(1); 988 } 1177 /* Member existence should be ensured by static type checking. */ 1178 assert(member != NULL); 989 1179 990 1180 #ifdef DEBUG_RUN_TRACE … … 1475 1665 1476 1666 if (rc1 != EOK || rc2 != EOK) { 1667 #ifdef DEBUG_RUN_TRACE 1477 1668 printf("Error: String index (value: %d) is out of range.\n", 1478 1669 arg_val); 1479 exit(1); 1670 #endif 1671 /* Raise Error.OutOfBounds */ 1672 run_raise_exc(run, run->program->builtin->error_outofbounds); 1673 *res = run_recovery_item(run); 1674 return; 1480 1675 } 1481 1676 … … 1485 1680 ritem->u.value = value; 1486 1681 1487 cvar = rdata_var_new(vc_ int);1488 cvar->u. int_v = rdata_int_new();1489 bigint_init(&cvar->u. int_v->value, cval);1682 cvar = rdata_var_new(vc_char); 1683 cvar->u.char_v = rdata_char_new(); 1684 bigint_init(&cvar->u.char_v->value, cval); 1490 1685 value->var = cvar; 1491 1686 … … 1651 1846 * Tries to interpret @a item as a boolean value. If it is not a boolean 1652 1847 * value, this generates an error. 1653 *1654 * XXX Currently int supplants the role of a true boolean type.1655 1848 */ 1656 1849 bool_t run_item_boolean_value(run_t *run, rdata_item_t *item) … … 1665 1858 var = vitem->u.value->var; 1666 1859 1667 if (var->vc != vc_int) { 1668 printf("Error: Boolean (int) expression expected.\n"); 1669 exit(1); 1670 } 1671 1672 return !bigint_is_zero(&var->u.int_v->value); 1673 } 1860 assert(var->vc == vc_bool); 1861 return var->u.bool_v->value; 1862 }
Note:
See TracChangeset
for help on using the changeset viewer.