Changes in uspace/app/sbi/src/run_expr.c [23de644:1ebc1a62] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run_expr.c
r23de644 r1ebc1a62 32 32 #include <stdlib.h> 33 33 #include <assert.h> 34 #include "bigint.h"35 34 #include "debug.h" 36 35 #include "intmap.h" … … 72 71 73 72 static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res); 74 static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val,75 rdata_item_t **res);76 77 73 static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res); 78 74 static void run_new_array(run_t *run, stree_new_t *new_op, … … 353 349 value->var = var; 354 350 var->u.int_v = int_v; 355 bigint_clone(&lit_int->value, &int_v->value);351 int_v->value = lit_int->value; 356 352 357 353 *res = item; … … 440 436 #endif 441 437 run_expr(run, binop->arg1, &rarg1_i); 442 if (run_is_bo(run)) {443 *res = NULL;444 return;445 }446 447 438 run_expr(run, binop->arg2, &rarg2_i); 448 if (run_is_bo(run)) {449 *res = NULL;450 return;451 }452 439 453 440 switch (binop->bc) { 454 441 case bo_plus: 455 case bo_minus:456 case bo_mult:457 442 case bo_equal: 458 443 case bo_notequal: … … 511 496 rdata_int_t *int_v; 512 497 513 bigint_t *i1, *i2; 514 bigint_t diff; 515 bool_t done; 516 bool_t zf, nf; 498 int i1, i2; 517 499 518 500 (void) run; … … 527 509 var->u.int_v = int_v; 528 510 529 i1 = &v1->var->u.int_v->value; 530 i2 = &v2->var->u.int_v->value; 531 532 done = b_true; 511 i1 = v1->var->u.int_v->value; 512 i2 = v2->var->u.int_v->value; 533 513 534 514 switch (binop->bc) { 535 515 case bo_plus: 536 bigint_add(i1, i2, &int_v->value); 537 break; 538 case bo_minus: 539 bigint_sub(i1, i2, &int_v->value); 540 break; 541 case bo_mult: 542 bigint_mul(i1, i2, &int_v->value); 543 break; 544 default: 545 done = b_false; 546 break; 547 } 548 549 if (done) { 550 *res = item; 551 return; 552 } 553 554 /* Relational operation. */ 555 556 bigint_sub(i1, i2, &diff); 557 zf = bigint_is_zero(&diff); 558 nf = bigint_is_negative(&diff); 516 int_v->value = i1 + i2; 517 break; 559 518 560 519 /* XXX We should have a real boolean type. */ 561 switch (binop->bc) {562 520 case bo_equal: 563 bigint_init(&int_v->value, zf ? 1 : 0);521 int_v->value = (i1 == i2) ? 1 : 0; 564 522 break; 565 523 case bo_notequal: 566 bigint_init(&int_v->value, !zf ? 1 : 0);524 int_v->value = (i1 != i2) ? 1 : 0; 567 525 break; 568 526 case bo_lt: 569 bigint_init(&int_v->value, (!zf && nf) ? 1 : 0);527 int_v->value = (i1 < i2) ? 1 : 0; 570 528 break; 571 529 case bo_gt: 572 bigint_init(&int_v->value, (!zf && !nf) ? 1 : 0);530 int_v->value = (i1 > i2) ? 1 : 0; 573 531 break; 574 532 case bo_lt_equal: 575 bigint_init(&int_v->value, (zf || nf) ? 1 : 0);533 int_v->value = (i1 <= i2) ? 1 : 0; 576 534 break; 577 535 case bo_gt_equal: 578 bigint_init(&int_v->value, !nf ? 1 : 0);536 int_v->value = (i1 >= i2) ? 1 : 0; 579 537 break; 580 538 default: … … 652 610 /* XXX We should have a real boolean type. */ 653 611 case bo_equal: 654 bigint_init(&int_v->value, (ref1 == ref2) ? 1 : 0);612 int_v->value = (ref1 == ref2) ? 1 : 0; 655 613 break; 656 614 case bo_notequal: 657 bigint_init(&int_v->value, (ref1 != ref2) ? 1 : 0);615 int_v->value = (ref1 != ref2) ? 1 : 0; 658 616 break; 659 617 default: … … 670 628 static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res) 671 629 { 672 rdata_item_t *rarg_i; 673 rdata_item_t *rarg_vi; 674 rdata_value_t *val; 630 rdata_item_t *rarg; 675 631 676 632 #ifdef DEBUG_RUN_TRACE 677 633 printf("Run unary operation.\n"); 678 634 #endif 679 run_expr(run, unop->arg, &rarg_i); 680 if (run_is_bo(run)) { 681 *res = NULL; 682 return; 683 } 684 685 #ifdef DEBUG_RUN_TRACE 686 printf("Check unop argument result.\n"); 687 #endif 688 run_cvt_value_item(run, rarg_i, &rarg_vi); 689 690 val = rarg_vi->u.value; 691 692 switch (val->var->vc) { 693 case vc_int: 694 run_unop_int(run, unop, val, res); 695 break; 696 default: 697 printf("Unimplemented: Unrary operation argument of " 698 "type %d.\n", val->var->vc); 699 run_raise_error(run); 700 *res = NULL; 701 break; 702 } 703 } 704 705 /** Evaluate unary operation on int argument. */ 706 static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val, 707 rdata_item_t **res) 708 { 709 rdata_item_t *item; 710 rdata_value_t *value; 711 rdata_var_t *var; 712 rdata_int_t *int_v; 713 714 (void) run; 715 716 item = rdata_item_new(ic_value); 717 value = rdata_value_new(); 718 var = rdata_var_new(vc_int); 719 int_v = rdata_int_new(); 720 721 item->u.value = value; 722 value->var = var; 723 var->u.int_v = int_v; 724 725 switch (unop->uc) { 726 case uo_plus: 727 bigint_clone(&val->var->u.int_v->value, &int_v->value); 728 break; 729 case uo_minus: 730 bigint_reverse_sign(&val->var->u.int_v->value, 731 &int_v->value); 732 break; 733 } 734 735 *res = item; 736 } 737 635 run_expr(run, unop->arg, &rarg); 636 *res = NULL; 637 } 738 638 739 639 /** Evaluate @c new operation. */ … … 780 680 int length; 781 681 int i; 782 int rc;783 int iextent;784 682 785 683 #ifdef DEBUG_RUN_TRACE … … 810 708 /* Evaluate extent argument. */ 811 709 run_expr(run, expr, &rexpr); 812 if (run_is_bo(run)) {813 *res = NULL;814 return;815 }816 817 710 run_cvt_value_item(run, rexpr, &rexpr_vi); 818 711 assert(rexpr_vi->ic == ic_value); … … 825 718 826 719 #ifdef DEBUG_RUN_TRACE 827 printf("Array extent: "); 828 bigint_print(&rexpr_var->u.int_v->value); 829 printf(".\n"); 830 #endif 831 rc = bigint_get_value_int(&rexpr_var->u.int_v->value, 832 &iextent); 833 if (rc != EOK) { 834 printf("Memory allocation failed (big int used).\n"); 835 exit(1); 836 } 837 838 array->extent[i] = iextent; 720 printf("Array extent: %d.\n", rexpr_var->u.int_v->value); 721 #endif 722 array->extent[i] = rexpr_var->u.int_v->value; 839 723 length = length * array->extent[i]; 840 724 … … 854 738 elem_var = rdata_var_new(vc_int); 855 739 elem_var->u.int_v = rdata_int_new(); 856 bigint_init(&elem_var->u.int_v->value, 0);740 elem_var->u.int_v->value = 0; 857 741 858 742 array->element[i] = elem_var; … … 871 755 tdata_item_t *titem, rdata_item_t **res) 872 756 { 757 rdata_object_t *obj; 758 rdata_var_t *obj_var; 759 760 stree_symbol_t *csi_sym; 873 761 stree_csi_t *csi; 762 stree_csimbr_t *csimbr; 763 764 rdata_var_t *mbr_var; 765 766 list_node_t *node; 874 767 875 768 #ifdef DEBUG_RUN_TRACE 876 769 printf("Create new object.\n"); 877 770 #endif 771 (void) run; 878 772 (void) new_op; 879 773 … … 881 775 assert(titem->tic == tic_tobject); 882 776 csi = titem->u.tobject->csi; 883 884 /* Create CSI instance. */ 885 run_new_csi_inst(run, csi, res); 777 csi_sym = csi_to_symbol(csi); 778 779 /* Create the object. */ 780 obj = rdata_object_new(); 781 obj->class_sym = csi_sym; 782 intmap_init(&obj->fields); 783 784 obj_var = rdata_var_new(vc_object); 785 obj_var->u.object_v = obj; 786 787 /* Create object fields. */ 788 node = list_first(&csi->members); 789 while (node != NULL) { 790 csimbr = list_node_data(node, stree_csimbr_t *); 791 if (csimbr->cc == csimbr_var) { 792 /* XXX Depends on member variable type. */ 793 mbr_var = rdata_var_new(vc_int); 794 mbr_var->u.int_v = rdata_int_new(); 795 mbr_var->u.int_v->value = 0; 796 797 intmap_set(&obj->fields, csimbr->u.var->name->sid, 798 mbr_var); 799 } 800 801 node = list_next(&csi->members, node); 802 } 803 804 /* Create reference to the new object. */ 805 run_reference(run, obj_var, res); 886 806 } 887 807 … … 895 815 #endif 896 816 run_expr(run, access->arg, &rarg); 897 if (run_is_bo(run)) {898 *res = NULL;899 return;900 }901 902 817 if (rarg == NULL) { 903 818 printf("Error: Sub-expression has no value.\n"); … … 1113 1028 #endif 1114 1029 run_expr(run, call->fun, &rfun); 1115 if (run_is_bo(run)) {1116 *res = NULL;1117 return;1118 }1119 1030 1120 1031 if (run->thread_ar->bo_mode != bm_none) { … … 1147 1058 arg = list_node_data(node, stree_expr_t *); 1148 1059 run_expr(run, arg, &rarg_i); 1149 if (run_is_bo(run)) {1150 *res = NULL;1151 return;1152 }1153 1154 1060 run_cvt_value_item(run, rarg_i, &rarg_vi); 1155 1061 … … 1190 1096 #endif 1191 1097 run_expr(run, index->base, &rbase); 1192 if (run_is_bo(run)) {1193 *res = NULL;1194 return;1195 }1196 1098 1197 1099 vc = run_item_get_vc(run, rbase); … … 1213 1115 arg = list_node_data(node, stree_expr_t *); 1214 1116 run_expr(run, arg, &rarg_i); 1215 if (run_is_bo(run)) {1216 *res = NULL;1217 return;1218 }1219 1220 1117 run_cvt_value_item(run, rarg_i, &rarg_vi); 1221 1118 … … 1252 1149 int elem_index; 1253 1150 int arg_val; 1254 int rc;1255 1151 1256 1152 rdata_item_t *ritem; … … 1293 1189 } 1294 1190 1295 rc = bigint_get_value_int( 1296 &arg->u.value->var->u.int_v->value, 1297 &arg_val); 1298 1299 if (rc != EOK || arg_val < 0 || arg_val >= array->extent[i]) { 1300 #ifdef DEBUG_RUN_TRACE 1191 arg_val = arg->u.value->var->u.int_v->value; 1192 1193 if (arg_val < 0 || arg_val >= array->extent[i]) { 1301 1194 printf("Error: Array index (value: %d) is out of range.\n", 1302 1195 arg_val); 1303 #endif 1304 /* Raise Error.OutOfBounds */ 1305 run_raise_exc(run, 1306 run->program->builtin->error_outofbounds); 1196 run_raise_error(run); 1307 1197 *res = run_recovery_item(run); 1308 1198 return; … … 1417 1307 int elem_index; 1418 1308 int arg_val; 1419 int rc 1, rc2;1309 int rc; 1420 1310 1421 1311 rdata_value_t *value; … … 1432 1322 run_cvt_value_item(run, base, &base_vi); 1433 1323 assert(base_vi->u.value->var->vc == vc_string); 1434 string = base _vi->u.value->var->u.string_v;1324 string = base->u.value->var->u.string_v; 1435 1325 1436 1326 /* … … 1456 1346 } 1457 1347 1458 rc1 = bigint_get_value_int( 1459 &arg->u.value->var->u.int_v->value, 1460 &arg_val); 1461 1348 arg_val = arg->u.value->var->u.int_v->value; 1462 1349 elem_index = arg_val; 1463 1350 … … 1471 1358 } 1472 1359 1473 if (rc1 == EOK) 1474 rc2 = os_str_get_char(string->value, elem_index, &cval); 1475 1476 if (rc1 != EOK || rc2 != EOK) { 1360 rc = os_str_get_char(string->value, elem_index, &cval); 1361 if (rc != EOK) { 1477 1362 printf("Error: String index (value: %d) is out of range.\n", 1478 1363 arg_val); … … 1487 1372 cvar = rdata_var_new(vc_int); 1488 1373 cvar->u.int_v = rdata_int_new(); 1489 bigint_init(&cvar->u.int_v->value, cval);1374 cvar->u.int_v->value = cval; 1490 1375 value->var = cvar; 1491 1376 … … 1504 1389 #endif 1505 1390 run_expr(run, assign->dest, &rdest_i); 1506 if (run_is_bo(run)) {1507 *res = NULL;1508 return;1509 }1510 1511 1391 run_expr(run, assign->src, &rsrc_i); 1512 if (run_is_bo(run)) {1513 *res = NULL;1514 return;1515 }1516 1392 1517 1393 run_cvt_value_item(run, rsrc_i, &rsrc_vi); … … 1547 1423 #endif 1548 1424 run_expr(run, as_op->arg, &rarg_i); 1549 if (run_is_bo(run)) {1550 *res = NULL;1551 return;1552 }1553 1425 1554 1426 /* … … 1595 1467 1596 1468 *res = rarg_vi; 1597 }1598 1599 /** Create new CSI instance. */1600 void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res)1601 {1602 rdata_object_t *obj;1603 rdata_var_t *obj_var;1604 1605 stree_symbol_t *csi_sym;1606 stree_csimbr_t *csimbr;1607 1608 rdata_var_t *mbr_var;1609 1610 list_node_t *node;1611 1612 csi_sym = csi_to_symbol(csi);1613 1614 #ifdef DEBUG_RUN_TRACE1615 printf("Create new instance of CSI '");1616 symbol_print_fqn(csi_sym);1617 printf("'.\n");1618 #endif1619 1620 /* Create the object. */1621 obj = rdata_object_new();1622 obj->class_sym = csi_sym;1623 intmap_init(&obj->fields);1624 1625 obj_var = rdata_var_new(vc_object);1626 obj_var->u.object_v = obj;1627 1628 /* Create object fields. */1629 node = list_first(&csi->members);1630 while (node != NULL) {1631 csimbr = list_node_data(node, stree_csimbr_t *);1632 if (csimbr->cc == csimbr_var) {1633 /* XXX Depends on member variable type. */1634 mbr_var = rdata_var_new(vc_int);1635 mbr_var->u.int_v = rdata_int_new();1636 bigint_init(&mbr_var->u.int_v->value, 0);1637 1638 intmap_set(&obj->fields, csimbr->u.var->name->sid,1639 mbr_var);1640 }1641 1642 node = list_next(&csi->members, node);1643 }1644 1645 /* Create reference to the new object. */1646 run_reference(run, obj_var, res);1647 1469 } 1648 1470 … … 1670 1492 } 1671 1493 1672 return !bigint_is_zero(&var->u.int_v->value);1673 } 1494 return (var->u.int_v->value != 0); 1495 }
Note:
See TracChangeset
for help on using the changeset viewer.