Changeset 39e8406 in mainline for uspace/app/sbi/src/run.c
- Timestamp:
- 2010-03-20T21:57:13Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b535aeb
- Parents:
- 6ba20a6b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/run.c
r6ba20a6b r39e8406 43 43 #include "strtab.h" 44 44 #include "symbol.h" 45 #include "tdata.h" 45 46 46 47 #include "run.h" … … 57 58 58 59 static bool_t run_exc_match(run_t *run, stree_except_t *except_c); 60 static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *aprop); 59 61 60 62 static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop, … … 102 104 103 105 #ifdef DEBUG_RUN_TRACE 104 printf("Found function '"); symbol_print_fqn( prog,main_fun_sym);106 printf("Found function '"); symbol_print_fqn(main_fun_sym); 105 107 printf("'.\n"); 106 108 #endif … … 108 110 /* Run function @c main. */ 109 111 list_init(&main_args); 110 run_proc_ar_create(run, NULL, main_fun _sym, main_fun->body, &proc_ar);112 run_proc_ar_create(run, NULL, main_fun->proc, &proc_ar); 111 113 run_proc_ar_set_args(run, proc_ar, &main_args); 112 114 run_proc(run, proc_ar, &res); … … 123 125 void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res) 124 126 { 125 stree_ symbol_t *proc_sym;127 stree_proc_t *proc; 126 128 list_node_t *node; 127 129 128 proc _sym = proc_ar->proc_sym;130 proc = proc_ar->proc; 129 131 130 132 #ifdef DEBUG_RUN_TRACE 131 133 printf("Start executing function '"); 132 symbol_print_fqn( run->program,proc_sym);134 symbol_print_fqn(proc_sym); 133 135 printf("'.\n"); 134 136 #endif … … 137 139 138 140 /* Run main procedure block. */ 139 if (proc _ar->proc_block!= NULL) {140 run_block(run, proc _ar->proc_block);141 if (proc->body != NULL) { 142 run_block(run, proc->body); 141 143 } else { 142 builtin_run_proc(run, proc _sym);144 builtin_run_proc(run, proc); 143 145 } 144 146 … … 157 159 #ifdef DEBUG_RUN_TRACE 158 160 printf("Done executing procedure '"); 159 symbol_print_fqn( run->program, proc_sym);161 symbol_print_fqn(proc); 160 162 printf("'.\n"); 161 163 … … 469 471 rdata_var_t *payload_v; 470 472 rdata_object_t *payload_o; 471 rdata_titem_t *etype;473 tdata_item_t *etype; 472 474 473 475 payload = run->thread_ar->exc_payload; … … 491 493 #ifdef DEBUG_RUN_TRACE 492 494 printf("Active exception: '"); 493 symbol_print_fqn( run->program,payload_o->class_sym);495 symbol_print_fqn(payload_o->class_sym); 494 496 printf("'.\n"); 495 497 #endif … … 498 500 499 501 /* Evaluate type expression in except clause. */ 500 run_texpr(run, except_c->etype, &etype); 501 502 return rdata_is_csi_derived_from_ti(payload_o->class_sym->u.csi, 502 run_texpr(run->program, run_get_current_csi(run), except_c->etype, 503 &etype); 504 505 return tdata_is_csi_derived_from_ti(payload_o->class_sym->u.csi, 503 506 etype); 504 507 } … … 556 559 557 560 proc_ar = run_get_current_proc_ar(run); 558 return proc_ar->proc _sym->outer_csi;561 return proc_ar->proc->outer_symbol->outer_csi; 559 562 } 560 563 … … 606 609 607 610 /** Construct a function AR. */ 608 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_ symbol_t *proc_sym,609 stree_block_t *proc_block,run_proc_ar_t **rproc_ar)611 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc, 612 run_proc_ar_t **rproc_ar) 610 613 { 611 614 run_proc_ar_t *proc_ar; … … 617 620 proc_ar = run_proc_ar_new(); 618 621 proc_ar->obj = obj; 619 proc_ar->proc_sym = proc_sym; 620 proc_ar->proc_block = proc_block; 622 proc_ar->proc = proc; 621 623 list_init(&proc_ar->block_ar); 622 624 … … 642 644 list_t *args; 643 645 stree_proc_arg_t *varg; 646 stree_symbol_t *outer_symbol; 644 647 645 648 run_block_ar_t *block_ar; … … 655 658 int n_vargs, idx; 656 659 660 (void) run; 661 657 662 /* AR should have been created with run_proc_ar_create(). */ 658 assert(proc_ar->proc_sym != NULL); 663 assert(proc_ar->proc != NULL); 664 outer_symbol = proc_ar->proc->outer_symbol; 659 665 660 666 /* 661 * The procedure being activated should be a member function or667 * The procedure being activated should belong to a member function or 662 668 * property getter/setter. 663 669 */ 664 switch ( proc_ar->proc_sym->sc) {670 switch (outer_symbol->sc) { 665 671 case sc_fun: 666 fun = symbol_to_fun( proc_ar->proc_sym);672 fun = symbol_to_fun(outer_symbol); 667 673 args = &fun->args; 668 674 varg = fun->varg; 669 675 break; 670 676 case sc_prop: 671 prop = symbol_to_prop( proc_ar->proc_sym);677 prop = symbol_to_prop(outer_symbol); 672 678 args = &prop->args; 673 679 varg = prop->varg; … … 688 694 while (parg_n != NULL) { 689 695 if (rarg_n == NULL) { 690 printf("Error: Too few arguments to function'");691 symbol_print_fqn( run->program, proc_ar->proc_sym);696 printf("Error: Too few arguments to '"); 697 symbol_print_fqn(outer_symbol); 692 698 printf("'.\n"); 693 699 exit(1); … … 752 758 /* Check for excess real parameters. */ 753 759 if (rarg_n != NULL) { 754 printf("Error: Too many arguments to function'");755 symbol_print_fqn( run->program, proc_ar->proc_sym);760 printf("Error: Too many arguments to '"); 761 symbol_print_fqn(outer_symbol); 756 762 printf("'.\n"); 757 763 exit(1); … … 775 781 776 782 /* AR should have been created with run_proc_ar_create(). */ 777 assert(proc_ar->proc _sym!= NULL);778 779 /* The procedure being activated should be a property setter. */780 prop = symbol_to_prop(proc_ar->proc _sym);783 assert(proc_ar->proc != NULL); 784 785 /* The procedure being activated should belong to a property setter. */ 786 prop = symbol_to_prop(proc_ar->proc->outer_symbol); 781 787 assert(prop != NULL); 788 assert(proc_ar->proc == prop->setter); 782 789 783 790 /* Fetch first block activation record. */ … … 792 799 793 800 /* Declare variable using name of formal argument. */ 794 intmap_set(&block_ar->vars, prop->setter_arg _name->sid, var);801 intmap_set(&block_ar->vars, prop->setter_arg->name->sid, var); 795 802 } 796 803 … … 806 813 printf(" * "); 807 814 proc_ar = list_node_data(node, run_proc_ar_t *); 808 symbol_print_fqn( run->program, proc_ar->proc_sym);815 symbol_print_fqn(proc_ar->proc->outer_symbol); 809 816 printf("\n"); 810 817 … … 844 851 } 845 852 853 /** Get item var-class. 854 * 855 * Get var-class of @a item, regardless whether it is a value or address. 856 * (I.e. the var class of the value or variable at the given address). 857 */ 858 var_class_t run_item_get_vc(run_t *run, rdata_item_t *item) 859 { 860 var_class_t vc; 861 rdata_var_t *tpos; 862 863 (void) run; 864 865 switch (item->ic) { 866 case ic_value: 867 vc = item->u.value->var->vc; 868 break; 869 case ic_address: 870 switch (item->u.address->ac) { 871 case ac_var: 872 vc = item->u.address->u.var_a->vref->vc; 873 break; 874 case ac_prop: 875 /* Prefetch the value of the property. */ 876 tpos = run_aprop_get_tpos(run, item->u.address); 877 vc = tpos->vc; 878 break; 879 default: 880 assert(b_false); 881 } 882 break; 883 default: 884 assert(b_false); 885 } 886 887 return vc; 888 } 889 890 /** Get pointer to current var node in temporary copy in property address. 891 * 892 * A property address refers to a specific @c var node in a property. 893 * This function will fetch a copy of the property value (by running 894 * its getter) if there is not a temporary copy in the address yet. 895 * It returns a pointer to the relevant @c var node in the temporary 896 * copy. 897 * 898 * @param run Runner object. 899 * @param addr Address of class @c ac_prop. 900 * @param Pointer to var node. 901 */ 902 static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *addr) 903 { 904 rdata_item_t *ritem; 905 906 assert(addr->ac == ac_prop); 907 908 if (addr->u.prop_a->tvalue == NULL) { 909 /* Fetch value of the property. */ 910 run_address_read(run, addr, &ritem); 911 assert(ritem->ic == ic_value); 912 addr->u.prop_a->tvalue = ritem->u.value; 913 addr->u.prop_a->tpos = addr->u.prop_a->tvalue->var; 914 } 915 916 return addr->u.prop_a->tpos; 917 } 846 918 847 919 /** Read data from an address. … … 894 966 895 967 run_proc_ar_t *proc_ar; 968 969 rdata_var_t *cvar; 896 970 897 971 #ifdef DEBUG_RUN_TRACE … … 903 977 */ 904 978 if (addr_prop->tvalue != NULL) { 905 printf("Unimplemented: Property field access.\n"); 906 exit(1); 979 /* Copy the value */ 980 rdata_var_copy(addr_prop->tpos, &cvar); 981 *ritem = rdata_item_new(ic_value); 982 (*ritem)->u.value = rdata_value_new(); 983 (*ritem)->u.value->var = cvar; 984 return; 907 985 } 908 986 … … 917 995 assert(prop != NULL); 918 996 919 if (prop->getter _body== NULL) {997 if (prop->getter == NULL) { 920 998 printf("Error: Property is not readable.\n"); 921 999 exit(1); … … 923 1001 924 1002 /* Create procedure activation record. */ 925 run_proc_ar_create(run, obj, prop _sym, prop->getter_body, &proc_ar);1003 run_proc_ar_create(run, obj, prop->getter, &proc_ar); 926 1004 927 1005 /* Fill in arguments (indices). */ … … 973 1051 assert(prop != NULL); 974 1052 975 if (prop->setter _body== NULL) {1053 if (prop->setter == NULL) { 976 1054 printf("Error: Property is not writable.\n"); 977 1055 exit(1); … … 982 1060 983 1061 /* Create procedure activation record. */ 984 run_proc_ar_create(run, obj, prop _sym, prop->setter_body, &proc_ar);1062 run_proc_ar_create(run, obj, prop->setter, &proc_ar); 985 1063 986 1064 /* Fill in arguments (indices). */
Note:
See TracChangeset
for help on using the changeset viewer.