Changeset fa36f29 in mainline for uspace/app/sbi/src/run_expr.c
- Timestamp:
- 2010-02-27T17:59:14Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 94d484a
- Parents:
- 09ababb7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run_expr.c
r09ababb7 rfa36f29 33 33 #include <assert.h> 34 34 #include "debug.h" 35 #include "intmap.h" 35 36 #include "list.h" 36 37 #include "mytypes.h" … … 44 45 static void run_nameref(run_t *run, stree_nameref_t *nameref, 45 46 rdata_item_t **res); 47 46 48 static void run_literal(run_t *run, stree_literal_t *literal, 47 49 rdata_item_t **res); 48 50 static void run_lit_int(run_t *run, stree_lit_int_t *lit_int, 49 51 rdata_item_t **res); 52 static void run_lit_ref(run_t *run, stree_lit_ref_t *lit_ref, 53 rdata_item_t **res); 50 54 static void run_lit_string(run_t *run, stree_lit_string_t *lit_string, 51 55 rdata_item_t **res); 56 57 static void run_self_ref(run_t *run, stree_self_ref_t *self_ref, 58 rdata_item_t **res); 59 52 60 static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res); 61 static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 62 rdata_value_t *v2, rdata_item_t **res); 63 static void run_binop_ref(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 64 rdata_value_t *v2, rdata_item_t **res); 65 53 66 static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res); 67 static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res); 68 54 69 static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res); 70 static void run_access_item(run_t *run, stree_access_t *access, 71 rdata_item_t *arg, rdata_item_t **res); 72 static void run_access_ref(run_t *run, stree_access_t *access, 73 rdata_item_t *arg, rdata_item_t **res); 74 static void run_access_deleg(run_t *run, stree_access_t *access, 75 rdata_item_t *arg, rdata_item_t **res); 76 static void run_access_object(run_t *run, stree_access_t *access, 77 rdata_item_t *arg, rdata_item_t **res); 78 55 79 static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res); 56 80 static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res); 57 58 static void run_address_read(run_t *run, rdata_address_t *address,59 rdata_item_t **ritem);60 static void run_address_write(run_t *run, rdata_address_t *address,61 rdata_value_t *value);62 81 63 82 /** Evaluate expression. */ … … 75 94 run_literal(run, expr->u.literal, res); 76 95 break; 96 case ec_self_ref: 97 run_self_ref(run, expr->u.self_ref, res); 98 break; 77 99 case ec_binop: 78 100 run_binop(run, expr->u.binop, res); … … 80 102 case ec_unop: 81 103 run_unop(run, expr->u.unop, res); 104 break; 105 case ec_new: 106 run_new(run, expr->u.new_op, res); 82 107 break; 83 108 case ec_access: … … 106 131 rdata_item_t *item; 107 132 rdata_address_t *address; 108 rdata_value_t *val ;133 rdata_value_t *value; 109 134 rdata_var_t *var; 110 135 rdata_deleg_t *deleg_v; 136 137 run_fun_ar_t *fun_ar; 138 stree_symbol_t *csi_sym; 139 stree_csi_t *csi; 140 rdata_object_t *obj; 141 rdata_var_t *member_var; 111 142 112 143 #ifdef DEBUG_RUN_TRACE … … 137 168 */ 138 169 139 /* XXX Start lookup in currently active CSI. */ 140 sym = symbol_lookup_in_csi(run->program, NULL, nameref->name); 170 /* Determine currently active object or CSI. */ 171 fun_ar = run_get_current_fun_ar(run); 172 if (fun_ar->obj != NULL) { 173 assert(fun_ar->obj->vc == vc_object); 174 obj = fun_ar->obj->u.object_v; 175 csi_sym = obj->class_sym; 176 csi = symbol_to_csi(csi_sym); 177 assert(csi != NULL); 178 } else { 179 csi = fun_ar->fun_sym->outer_csi; 180 obj = NULL; 181 } 182 183 sym = symbol_lookup_in_csi(run->program, csi, nameref->name); 141 184 142 185 switch (sym->sc) { … … 146 189 #endif 147 190 item = rdata_item_new(ic_value); 148 val = rdata_value_new();191 value = rdata_value_new(); 149 192 var = rdata_var_new(vc_deleg); 150 193 deleg_v = rdata_deleg_new(); 151 194 152 item->u.value = val ;153 val ->var = var;195 item->u.value = value; 196 value->var = var; 154 197 var->u.deleg_v = deleg_v; 155 198 … … 158 201 *res = item; 159 202 break; 203 case sc_fun: 204 /* There should be no global functions. */ 205 assert(csi != NULL); 206 207 if (sym->outer_csi != csi) { 208 /* Function is not in the current object. */ 209 printf("Error: Cannot access non-static member " 210 "function '"); 211 symbol_print_fqn(run->program, sym); 212 printf("' from nested CSI '"); 213 symbol_print_fqn(run->program, csi_sym); 214 printf("'.\n"); 215 exit(1); 216 } 217 218 /* Construct delegate. */ 219 item = rdata_item_new(ic_value); 220 value = rdata_value_new(); 221 item->u.value = value; 222 223 var = rdata_var_new(vc_deleg); 224 deleg_v = rdata_deleg_new(); 225 value->var = var; 226 var->u.deleg_v = deleg_v; 227 228 deleg_v->obj = fun_ar->obj; 229 deleg_v->sym = sym; 230 231 *res = item; 232 break; 233 case sc_var: 234 #ifdef DEBUG_RUN_TRACE 235 printf("Referencing member variable.\n"); 236 #endif 237 /* There should be no global variables. */ 238 assert(csi != NULL); 239 240 /* XXX Assume variable is not static for now. */ 241 assert(obj != NULL); 242 243 if (sym->outer_csi != csi) { 244 /* Variable is not in the current object. */ 245 printf("Error: Cannot access non-static member " 246 "variable '"); 247 symbol_print_fqn(run->program, sym); 248 printf("' from nested CSI '"); 249 symbol_print_fqn(run->program, csi_sym); 250 printf("'.\n"); 251 exit(1); 252 } 253 254 /* Find member variable in object. */ 255 member_var = intmap_get(&obj->fields, nameref->name->sid); 256 assert(member_var != NULL); 257 258 /* Return address of the variable. */ 259 item = rdata_item_new(ic_address); 260 address = rdata_address_new(); 261 262 item->u.address = address; 263 address->vref = member_var; 264 265 *res = item; 266 break; 160 267 default: 161 268 printf("Referencing symbol class %d unimplemented.\n", sym->sc); … … 176 283 case ltc_int: 177 284 run_lit_int(run, &literal->u.lit_int, res); 285 break; 286 case ltc_ref: 287 run_lit_ref(run, &literal->u.lit_ref, res); 178 288 break; 179 289 case ltc_string: … … 197 307 printf("Run integer literal.\n"); 198 308 #endif 309 (void) run; 199 310 200 311 item = rdata_item_new(ic_value); … … 211 322 } 212 323 324 /** Evaluate reference literal (@c nil). */ 325 static void run_lit_ref(run_t *run, stree_lit_ref_t *lit_ref, 326 rdata_item_t **res) 327 { 328 rdata_item_t *item; 329 rdata_value_t *value; 330 rdata_var_t *var; 331 rdata_ref_t *ref_v; 332 333 #ifdef DEBUG_RUN_TRACE 334 printf("Run reference literal (nil).\n"); 335 #endif 336 (void) run; 337 (void) lit_ref; 338 339 item = rdata_item_new(ic_value); 340 value = rdata_value_new(); 341 var = rdata_var_new(vc_ref); 342 ref_v = rdata_ref_new(); 343 344 item->u.value = value; 345 value->var = var; 346 var->u.ref_v = ref_v; 347 ref_v->vref = NULL; 348 349 *res = item; 350 } 351 213 352 /** Evaluate string literal. */ 214 353 static void run_lit_string(run_t *run, stree_lit_string_t *lit_string, … … 223 362 printf("Run integer literal.\n"); 224 363 #endif 364 (void) run; 365 225 366 item = rdata_item_new(ic_value); 226 367 value = rdata_value_new(); … … 236 377 } 237 378 379 /** Evaluate @c self reference. */ 380 static void run_self_ref(run_t *run, stree_self_ref_t *self_ref, 381 rdata_item_t **res) 382 { 383 run_fun_ar_t *fun_ar; 384 385 #ifdef DEBUG_RUN_TRACE 386 printf("Run self reference.\n"); 387 #endif 388 (void) self_ref; 389 fun_ar = run_get_current_fun_ar(run); 390 391 /* Return reference to the currently active object. */ 392 rdata_reference(fun_ar->obj, res); 393 } 238 394 239 395 /** Evaluate binary operation. */ … … 243 399 rdata_item_t *rarg1_vi, *rarg2_vi; 244 400 rdata_value_t *v1, *v2; 245 int i1, i2;246 247 rdata_item_t *item;248 rdata_value_t *value;249 rdata_var_t *var;250 rdata_int_t *int_v;251 401 252 402 #ifdef DEBUG_RUN_TRACE … … 276 426 #endif 277 427 278 r un_cvt_value_item(run,rarg1_i, &rarg1_vi);279 r un_cvt_value_item(run,rarg2_i, &rarg2_vi);428 rdata_cvt_value_item(rarg1_i, &rarg1_vi); 429 rdata_cvt_value_item(rarg2_i, &rarg2_vi); 280 430 281 431 v1 = rarg1_vi->u.value; 282 432 v2 = rarg2_vi->u.value; 283 433 284 if (v1->var->vc != vc_int || v2->var->vc != vc_int) { 285 printf("Unimplemented: Binary operation arguments are not " 286 "integer values.\n"); 287 exit(1); 288 } 434 if (v1->var->vc != v2->var->vc) { 435 printf("Unimplemented: Binary operation arguments have " 436 "different type.\n"); 437 exit(1); 438 } 439 440 switch (v1->var->vc) { 441 case vc_int: 442 run_binop_int(run, binop, v1, v2, res); 443 break; 444 case vc_ref: 445 run_binop_ref(run, binop, v1, v2, res); 446 break; 447 default: 448 printf("Unimplemented: Binary operation arguments of " 449 "type %d.\n", v1->var->vc); 450 exit(1); 451 } 452 } 453 454 /** Evaluate binary operation on int arguments. */ 455 static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 456 rdata_value_t *v2, rdata_item_t **res) 457 { 458 rdata_item_t *item; 459 rdata_value_t *value; 460 rdata_var_t *var; 461 rdata_int_t *int_v; 462 463 int i1, i2; 464 465 (void) run; 289 466 290 467 item = rdata_item_new(ic_value); … … 331 508 } 332 509 510 /** Evaluate binary operation on ref arguments. */ 511 static void run_binop_ref(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 512 rdata_value_t *v2, rdata_item_t **res) 513 { 514 rdata_item_t *item; 515 rdata_value_t *value; 516 rdata_var_t *var; 517 rdata_int_t *int_v; 518 519 rdata_var_t *ref1, *ref2; 520 521 (void) run; 522 523 item = rdata_item_new(ic_value); 524 value = rdata_value_new(); 525 var = rdata_var_new(vc_int); 526 int_v = rdata_int_new(); 527 528 item->u.value = value; 529 value->var = var; 530 var->u.int_v = int_v; 531 532 ref1 = v1->var->u.ref_v->vref; 533 ref2 = v2->var->u.ref_v->vref; 534 535 switch (binop->bc) { 536 /* XXX We should have a real boolean type. */ 537 case bo_equal: 538 int_v->value = (ref1 == ref2) ? 1 : 0; 539 break; 540 case bo_notequal: 541 int_v->value = (ref1 != ref2) ? 1 : 0; 542 break; 543 default: 544 printf("Error: Invalid binary operation on reference " 545 "arguments (%d).\n", binop->bc); 546 assert(b_false); 547 } 548 549 *res = item; 550 } 551 552 333 553 /** Evaluate unary operation. */ 334 554 static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res) … … 343 563 } 344 564 565 /** Evaluate @c new operation. */ 566 static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res) 567 { 568 rdata_object_t *obj; 569 rdata_var_t *obj_var; 570 571 stree_symbol_t *csi_sym; 572 stree_csi_t *csi; 573 stree_csimbr_t *csimbr; 574 575 rdata_var_t *mbr_var; 576 577 list_node_t *node; 578 579 #ifdef DEBUG_RUN_TRACE 580 printf("Run 'new' operation.\n"); 581 #endif 582 /* Lookup object CSI. */ 583 /* XXX Should start in the current CSI. */ 584 csi_sym = symbol_xlookup_in_csi(run->program, NULL, new_op->texpr); 585 csi = symbol_to_csi(csi_sym); 586 if (csi == NULL) { 587 printf("Error: Symbol '"); 588 symbol_print_fqn(run->program, csi_sym); 589 printf("' is not a CSI. CSI required for 'new' operator.\n"); 590 exit(1); 591 } 592 593 /* Create the object. */ 594 obj = rdata_object_new(); 595 obj->class_sym = csi_sym; 596 intmap_init(&obj->fields); 597 598 obj_var = rdata_var_new(vc_object); 599 obj_var->u.object_v = obj; 600 601 /* Create object fields. */ 602 node = list_first(&csi->members); 603 while (node != NULL) { 604 csimbr = list_node_data(node, stree_csimbr_t *); 605 if (csimbr->cc == csimbr_var) { 606 /* XXX Depends on member variable type. */ 607 mbr_var = rdata_var_new(vc_int); 608 mbr_var->u.int_v = rdata_int_new(); 609 mbr_var->u.int_v->value = 0; 610 611 intmap_set(&obj->fields, csimbr->u.var->name->sid, 612 mbr_var); 613 } 614 615 node = list_next(&csi->members, node); 616 } 617 618 /* Create reference to the new object. */ 619 rdata_reference(obj_var, res); 620 } 621 345 622 /** Evaluate member acccess. */ 346 623 static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res) 347 624 { 348 625 rdata_item_t *rarg; 626 627 #ifdef DEBUG_RUN_TRACE 628 printf("Run access operation.\n"); 629 #endif 630 run_expr(run, access->arg, &rarg); 631 if (rarg == NULL) { 632 printf("Error: Sub-expression has no value.\n"); 633 exit(1); 634 } 635 636 run_access_item(run, access, rarg, res); 637 } 638 639 /** Evaluate member acccess (with base already evaluated). */ 640 static void run_access_item(run_t *run, stree_access_t *access, 641 rdata_item_t *arg, rdata_item_t **res) 642 { 643 var_class_t vc; 644 645 #ifdef DEBUG_RUN_TRACE 646 printf("Run access operation on pre-evaluated base.\n"); 647 #endif 648 switch (arg->ic) { 649 case ic_value: 650 vc = arg->u.value->var->vc; 651 break; 652 case ic_address: 653 vc = arg->u.address->vref->vc; 654 break; 655 default: 656 /* Silence warning. */ 657 abort(); 658 } 659 660 switch (vc) { 661 case vc_ref: 662 run_access_ref(run, access, arg, res); 663 break; 664 case vc_deleg: 665 run_access_deleg(run, access, arg, res); 666 break; 667 case vc_object: 668 run_access_object(run, access, arg, res); 669 break; 670 default: 671 printf("Unimplemented: Using access operator ('.') " 672 "with unsupported data type (value/%d).\n", vc); 673 exit(1); 674 } 675 } 676 677 /** Evaluate reference acccess. */ 678 static void run_access_ref(run_t *run, stree_access_t *access, 679 rdata_item_t *arg, rdata_item_t **res) 680 { 681 rdata_item_t *darg; 682 683 /* Implicitly dereference. */ 684 rdata_dereference(arg, &darg); 685 686 /* Try again. */ 687 run_access_item(run, access, darg, res); 688 } 689 690 /** Evaluate delegate-member acccess. */ 691 static void run_access_deleg(run_t *run, stree_access_t *access, 692 rdata_item_t *arg, rdata_item_t **res) 693 { 694 rdata_item_t *arg_vi; 695 rdata_value_t *arg_val; 349 696 rdata_deleg_t *deleg_v; 350 697 stree_symbol_t *member; 351 698 352 699 #ifdef DEBUG_RUN_TRACE 353 printf("Run access operation.\n"); 354 #endif 355 run_expr(run, access->arg, &rarg); 356 357 if (rarg->ic == ic_value && rarg->u.value->var->vc == vc_deleg) { 358 #ifdef DEBUG_RUN_TRACE 359 printf("Accessing delegate.\n"); 360 #endif 361 deleg_v = rarg->u.value->var->u.deleg_v; 362 if (deleg_v->obj != NULL || deleg_v->sym->sc != sc_csi) { 363 printf("Error: Using '.' with symbol of wrong " 364 "type (%d).\n", deleg_v->sym->sc); 365 exit(1); 366 } 367 368 member = symbol_search_csi(run->program, deleg_v->sym->u.csi, 369 access->member_name); 370 371 if (member == NULL) { 372 printf("Error: No such member.\n"); 373 exit(1); 374 } 375 376 #ifdef DEBUG_RUN_TRACE 377 printf("Found member '%s'.\n", 700 printf("Run delegate access operation.\n"); 701 #endif 702 rdata_cvt_value_item(arg, &arg_vi); 703 arg_val = arg_vi->u.value; 704 assert(arg_val->var->vc == vc_deleg); 705 706 deleg_v = arg_val->var->u.deleg_v; 707 if (deleg_v->obj != NULL || deleg_v->sym->sc != sc_csi) { 708 printf("Error: Using '.' with delegate to different object " 709 "than a CSI (%d).\n", deleg_v->sym->sc); 710 exit(1); 711 } 712 713 member = symbol_search_csi(run->program, deleg_v->sym->u.csi, 714 access->member_name); 715 716 if (member == NULL) { 717 printf("Error: CSI '"); 718 symbol_print_fqn(run->program, deleg_v->sym); 719 printf("' has no member named '%s'.\n", 378 720 strtab_get_str(access->member_name->sid)); 379 #endif 380 381 /* Reuse existing item, value, var, deleg. */ 721 exit(1); 722 } 723 724 #ifdef DEBUG_RUN_TRACE 725 printf("Found member '%s'.\n", 726 strtab_get_str(access->member_name->sid)); 727 #endif 728 729 /* 730 * Reuse existing item, value, var, deleg. 731 * XXX This is maybe not a good idea because it complicates memory 732 * management as there is not a single owner 733 */ 734 deleg_v->sym = member; 735 *res = arg; 736 } 737 738 /** Evaluate object member acccess. */ 739 static void run_access_object(run_t *run, stree_access_t *access, 740 rdata_item_t *arg, rdata_item_t **res) 741 { 742 stree_symbol_t *member; 743 rdata_object_t *object; 744 rdata_item_t *ritem; 745 rdata_address_t *address; 746 747 rdata_value_t *value; 748 rdata_deleg_t *deleg_v; 749 rdata_var_t *var; 750 751 #ifdef DEBUG_RUN_TRACE 752 printf("Run object access operation.\n"); 753 #endif 754 assert(arg->ic == ic_address); 755 assert(arg->u.value->var->vc == vc_object); 756 757 object = arg->u.value->var->u.object_v; 758 759 member = symbol_search_csi(run->program, object->class_sym->u.csi, 760 access->member_name); 761 762 if (member == NULL) { 763 printf("Error: Object of class '"); 764 symbol_print_fqn(run->program, object->class_sym); 765 printf("' has no member named '%s'.\n", 766 strtab_get_str(access->member_name->sid)); 767 exit(1); 768 } 769 770 #ifdef DEBUG_RUN_TRACE 771 printf("Found member '%s'.\n", 772 strtab_get_str(access->member_name->sid)); 773 #endif 774 775 switch (member->sc) { 776 case sc_csi: 777 printf("Error: Accessing object member which is nested CSI.\n"); 778 exit(1); 779 case sc_fun: 780 /* Construct delegate. */ 781 ritem = rdata_item_new(ic_value); 782 value = rdata_value_new(); 783 ritem->u.value = value; 784 785 var = rdata_var_new(vc_deleg); 786 value->var = var; 787 deleg_v = rdata_deleg_new(); 788 var->u.deleg_v = deleg_v; 789 790 deleg_v->obj = arg->u.value->var; 382 791 deleg_v->sym = member; 383 384 *res = rarg; 385 return; 386 } 387 388 *res = NULL; 792 break; 793 case sc_var: 794 /* Construct variable address item. */ 795 ritem = rdata_item_new(ic_address); 796 address = rdata_address_new(); 797 ritem->u.address = address; 798 799 address->vref = intmap_get(&object->fields, 800 access->member_name->sid); 801 assert(address->vref != NULL); 802 break; 803 case sc_prop: 804 printf("Unimplemented: Accessing object property.\n"); 805 exit(1); 806 } 807 808 *res = ritem; 389 809 } 390 810 … … 399 819 rdata_item_t *rarg_i, *rarg_vi; 400 820 821 stree_fun_t *fun; 822 run_fun_ar_t *fun_ar; 823 401 824 #ifdef DEBUG_RUN_TRACE 402 825 printf("Run call operation.\n"); … … 422 845 printf("'\n"); 423 846 #endif 424 425 847 /* Evaluate function arguments. */ 426 848 list_init(&arg_vals); … … 430 852 arg = list_node_data(node, stree_expr_t *); 431 853 run_expr(run, arg, &rarg_i); 432 r un_cvt_value_item(run,rarg_i, &rarg_vi);854 rdata_cvt_value_item(rarg_i, &rarg_vi); 433 855 434 856 list_append(&arg_vals, rarg_vi); … … 436 858 } 437 859 438 run_fun(run, deleg_v->sym->u.fun, &arg_vals); 860 fun = symbol_to_fun(deleg_v->sym); 861 assert(fun != NULL); 862 863 /* Create function activation record. */ 864 run_fun_ar_create(run, deleg_v->obj, fun, &fun_ar); 865 866 /* Fill in argument values. */ 867 run_fun_ar_set_args(run, fun_ar, &arg_vals); 868 869 /* Run the function. */ 870 run_fun(run, fun_ar, res); 439 871 440 872 #ifdef DEBUG_RUN_TRACE 441 873 printf("Returned from function call.\n"); 442 874 #endif 443 *res = NULL;444 875 } 445 876 … … 457 888 run_expr(run, assign->src, &rsrc_i); 458 889 459 r un_cvt_value_item(run,rsrc_i, &rsrc_vi);890 rdata_cvt_value_item(rsrc_i, &rsrc_vi); 460 891 src_val = rsrc_vi->u.value; 461 892 … … 466 897 } 467 898 468 r un_address_write(run,rdest_i->u.address, rsrc_vi->u.value);899 rdata_address_write(rdest_i->u.address, rsrc_vi->u.value); 469 900 470 901 *res = NULL; … … 483 914 rdata_var_t *var; 484 915 485 run_cvt_value_item(run, item, &vitem); 916 (void) run; 917 rdata_cvt_value_item(item, &vitem); 486 918 487 919 assert(vitem->ic == ic_value); … … 495 927 return (var->u.int_v->value != 0); 496 928 } 497 498 /** Convert item to value item.499 *500 * If @a item is a value, we just return a copy. If @a item is an address,501 * we read from the address.502 */503 void run_cvt_value_item(run_t *run, rdata_item_t *item,504 rdata_item_t **ritem)505 {506 rdata_value_t *value;507 508 /* Address item. Perform read operation. */509 if (item->ic == ic_address) {510 run_address_read(run, item->u.address, ritem);511 return;512 }513 514 /* It already is a value, we can share the @c var. */515 value = rdata_value_new();516 value->var = item->u.value->var;517 *ritem = rdata_item_new(ic_value);518 (*ritem)->u.value = value;519 }520 521 /** Read data from an address.522 *523 * Return value stored in a variable at the specified address.524 */525 static void run_address_read(run_t *run, rdata_address_t *address,526 rdata_item_t **ritem)527 {528 rdata_value_t *value;529 rdata_var_t *rvar;530 (void) run;531 532 /* Perform a shallow copy of @c var. */533 rdata_var_copy(address->vref, &rvar);534 535 value = rdata_value_new();536 value->var = rvar;537 *ritem = rdata_item_new(ic_value);538 (*ritem)->u.value = value;539 }540 541 /** Write data to an address.542 *543 * Store @a value to the variable at @a address.544 */545 static void run_address_write(run_t *run, rdata_address_t *address,546 rdata_value_t *value)547 {548 rdata_var_t *nvar;549 rdata_var_t *orig_var;550 551 /* Perform a shallow copy of @c value->var. */552 rdata_var_copy(value->var, &nvar);553 orig_var = address->vref;554 555 /* XXX do this in a prettier way. */556 557 orig_var->vc = nvar->vc;558 switch (nvar->vc) {559 case vc_int: orig_var->u.int_v = nvar->u.int_v; break;560 case vc_ref: orig_var->u.ref_v = nvar->u.ref_v; break;561 case vc_deleg: orig_var->u.deleg_v = nvar->u.deleg_v; break;562 case vc_object: orig_var->u.object_v = nvar->u.object_v; break;563 default: assert(b_false);564 }565 566 /* XXX We should free some stuff around here. */567 }
Note:
See TracChangeset
for help on using the changeset viewer.