Changeset 39e8406 in mainline
- 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
- Location:
- uspace/app/sbi
- Files:
-
- 8 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/Makefile
r6ba20a6b r39e8406 51 51 src/stree.c \ 52 52 src/strtab.c \ 53 src/symbol.c 53 src/stype.c \ 54 src/stype_expr.c \ 55 src/symbol.c \ 56 src/tdata.c 54 57 55 58 include ../Makefile.common -
uspace/app/sbi/src/ancr.c
r6ba20a6b r39e8406 174 174 do { 175 175 node_sym = csi_to_symbol(node); 176 symbol_print_fqn( prog,node_sym);176 symbol_print_fqn(node_sym); 177 177 printf(", "); 178 178 … … 196 196 197 197 node_sym = csi_to_symbol(node); 198 symbol_print_fqn( prog,node_sym);198 symbol_print_fqn(node_sym); 199 199 } -
uspace/app/sbi/src/builtin.c
r6ba20a6b r39e8406 44 44 static stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name); 45 45 static void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name); 46 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name); 46 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name, 47 stree_texpr_t *type); 48 49 static stree_texpr_t *builtin_mktype_string_array(void); 47 50 48 51 static void builtin_write_line(run_t *run); … … 86 89 87 90 bi_exec = builtin_declare_fun(csi, "Exec"); 88 builtin_fun_add_vararg(bi_exec, "args"); 89 } 90 91 void builtin_run_proc(run_t *run, stree_symbol_t *proc_sym) 92 { 91 builtin_fun_add_vararg(bi_exec, "args", 92 builtin_mktype_string_array()); 93 } 94 95 void builtin_run_proc(run_t *run, stree_proc_t *proc) 96 { 97 stree_symbol_t *fun_sym; 98 93 99 #ifdef DEBUG_RUN_TRACE 94 100 printf("Run builtin procedure.\n"); 95 101 #endif 96 if (proc_sym == bi_write_line) { 102 fun_sym = proc->outer_symbol; 103 104 if (fun_sym == bi_write_line) { 97 105 builtin_write_line(run); 98 } else if ( proc_sym == bi_exec) {106 } else if (fun_sym == bi_exec) { 99 107 builtin_exec(run); 100 108 } else { … … 109 117 stree_fun_t *fun; 110 118 stree_csimbr_t *csimbr; 111 stree_symbol_t * symbol;119 stree_symbol_t *fun_sym; 112 120 113 121 ident = stree_ident_new(); … … 116 124 fun = stree_fun_new(); 117 125 fun->name = ident; 118 fun->body = NULL; 126 fun->proc = stree_proc_new(); 127 fun->proc->body = NULL; 119 128 list_init(&fun->args); 120 129 … … 122 131 csimbr->u.fun = fun; 123 132 124 symbol = stree_symbol_new(sc_fun); 125 symbol->u.fun = fun; 126 symbol->outer_csi = csi; 127 fun->symbol = symbol; 133 fun_sym = stree_symbol_new(sc_fun); 134 fun_sym->u.fun = fun; 135 fun_sym->outer_csi = csi; 136 fun->symbol = fun_sym; 137 fun->proc->outer_symbol = fun_sym; 128 138 129 139 list_append(&csi->members, csimbr); 130 140 131 return symbol;141 return fun_sym; 132 142 } 133 143 … … 150 160 151 161 /** Add variadic formal parameter to function. */ 152 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name) 162 static void builtin_fun_add_vararg(stree_symbol_t *fun_sym, const char *name, 163 stree_texpr_t *type) 153 164 { 154 165 stree_proc_arg_t *proc_arg; … … 161 172 proc_arg->name = stree_ident_new(); 162 173 proc_arg->name->sid = strtab_get_sid(name); 163 proc_arg->type = NULL; /* XXX */174 proc_arg->type = type; 164 175 165 176 fun->varg = proc_arg; 177 } 178 179 /** Construct a @c string[] type expression. */ 180 static stree_texpr_t *builtin_mktype_string_array(void) 181 { 182 stree_texpr_t *tstring; 183 stree_texpr_t *tsarray; 184 stree_tliteral_t *tliteral; 185 stree_tindex_t *tindex; 186 187 /* Construct @c string */ 188 tstring = stree_texpr_new(tc_tliteral); 189 tliteral = stree_tliteral_new(tlc_string); 190 tstring->u.tliteral = tliteral; 191 192 /* Construct the indexing node */ 193 tsarray = stree_texpr_new(tc_tindex); 194 tindex = stree_tindex_new(); 195 tsarray->u.tindex = tindex; 196 197 tindex->base_type = tstring; 198 tindex->n_args = 1; 199 list_init(&tindex->args); 200 201 return tsarray; 166 202 } 167 203 -
uspace/app/sbi/src/builtin.h
r6ba20a6b r39e8406 33 33 34 34 void builtin_declare(stree_program_t *program); 35 void builtin_run_proc(run_t *run, stree_ symbol_t *proc_sym);35 void builtin_run_proc(run_t *run, stree_proc_t *proc); 36 36 37 37 #endif -
uspace/app/sbi/src/debug.h
r6ba20a6b r39e8406 33 33 //#define DEBUG_PARSE_TRACE 34 34 35 /** Uncomment this to get verbose debugging messagges during typing. */ 36 //#define DEBUG_TYPE_TRACE 37 35 38 /** Uncomment this to get verbose debugging messages during execution. */ 36 39 //#define DEBUG_RUN_TRACE -
uspace/app/sbi/src/list.c
r6ba20a6b r39e8406 130 130 } 131 131 132 /** Change node data. */ 133 void list_node_setdata(list_node_t *node, void *data) 134 { 135 node->data = data; 136 } 137 132 138 /** Create new node. */ 133 139 static list_node_t *list_node_new(void *data) -
uspace/app/sbi/src/list.h
r6ba20a6b r39e8406 44 44 bool_t list_is_empty(list_t *list); 45 45 46 void list_node_setdata(list_node_t *node, void *data); 47 46 48 #define list_node_data(node, dtype) ((dtype)(node->data)) 47 49 -
uspace/app/sbi/src/main.c
r6ba20a6b r39e8406 36 36 #include "strtab.h" 37 37 #include "stree.h" 38 #include "stype.h" 38 39 #include "input.h" 39 40 #include "lex.h" … … 49 50 parse_t parse; 50 51 stree_program_t *program; 52 stype_t stype; 51 53 run_t run; 52 54 int rc; … … 78 80 ancr_module_process(program, parse.cur_mod); 79 81 82 /* Type program. */ 83 stype.program = program; 84 stype_module(&stype, program->module); 85 80 86 /* Run program. */ 81 87 run_init(&run); -
uspace/app/sbi/src/mytypes.h
r6ba20a6b r39e8406 56 56 #include "stree_t.h" 57 57 #include "strtab_t.h" 58 #include "stype_t.h" 59 #include "tdata_t.h" 58 60 59 61 #endif -
uspace/app/sbi/src/p_type.c
r6ba20a6b r39e8406 194 194 { 195 195 stree_tliteral_t *tliteral; 196 197 tliteral = stree_tliteral_new(); 196 tliteral_class_t tlc; 198 197 199 198 switch (lcur_lc(parse)) { 200 199 case lc_int: 201 tl iteral->tlc = tlc_int;200 tlc = tlc_int; 202 201 break; 203 202 case lc_string: 204 tl iteral->tlc = tlc_string;203 tlc = tlc_string; 205 204 break; 206 205 default: … … 210 209 lskip(parse); 211 210 211 tliteral = stree_tliteral_new(tlc); 212 212 return tliteral; 213 213 } -
uspace/app/sbi/src/parse.c
r6ba20a6b r39e8406 35 35 #include <assert.h> 36 36 #include <stdlib.h> 37 #include "debug.h" 37 38 #include "lex.h" 38 39 #include "list.h" … … 133 134 csi = stree_csi_new(cc); 134 135 csi->name = parse_ident(parse); 135 /* 136 137 #ifdef DEBUG_PARSE_TRACE 136 138 printf("parse_csi: csi=%p, csi->name = %p (%s)\n", csi, csi->name, 137 139 strtab_get_str(csi->name->sid)); 138 */ 140 #endif 139 141 if (lcur_lc(parse) == lc_colon) { 140 142 /* Inheritance list */ … … 193 195 symbol->outer_csi = outer_csi; 194 196 fun->symbol = symbol; 197 fun->proc->outer_symbol = symbol; 195 198 break; 196 199 case lc_var: … … 213 216 symbol->outer_csi = outer_csi; 214 217 prop->symbol = symbol; 218 if (prop->getter) 219 prop->getter->outer_symbol = symbol; 220 if (prop->setter) 221 prop->setter->outer_symbol = symbol; 215 222 break; 216 223 default: … … 235 242 lmatch(parse, lc_lparen); 236 243 244 #ifdef DEBUG_PARSE_TRACE 245 printf("Parsing function '%s'.\n", strtab_get_str(fun->name->sid)); 246 #endif 247 237 248 list_init(&fun->args); 238 249 … … 242 253 while (b_true) { 243 254 arg = parse_proc_arg(parse); 255 244 256 if (stree_arg_has_attr(arg, aac_packed)) { 245 257 fun->varg = arg; … … 266 278 267 279 lmatch(parse, lc_is); 268 fun->body = parse_block(parse); 280 fun->proc = stree_proc_new(); 281 fun->proc->body = parse_block(parse); 269 282 lmatch(parse, lc_end); 270 283 … … 342 355 lskip(parse); 343 356 lmatch(parse, lc_is); 344 if (prop->getter _body!= NULL) {357 if (prop->getter != NULL) { 345 358 printf("Error: Duplicate getter.\n"); 346 359 exit(1); 347 360 } 348 prop->getter_body = parse_block(parse); 361 362 /* Create setter procedure */ 363 prop->getter = stree_proc_new(); 364 prop->getter->body = parse_block(parse); 365 349 366 lmatch(parse, lc_end); 350 367 break; 351 368 case lc_set: 352 369 lskip(parse); 353 prop->setter_arg_name = parse_ident(parse); 370 prop->setter_arg = stree_proc_arg_new(); 371 prop->setter_arg->name = parse_ident(parse); 372 prop->setter_arg->type = prop->type; 354 373 lmatch(parse, lc_is); 355 if (prop->setter _body!= NULL) {374 if (prop->setter != NULL) { 356 375 printf("Error: Duplicate setter.\n"); 357 376 exit(1); 358 377 } 359 prop->setter_body = parse_block(parse); 378 379 /* Create setter procedure */ 380 prop->setter = stree_proc_new(); 381 prop->setter->body = parse_block(parse); 382 360 383 lmatch(parse, lc_end); 361 384 break; … … 390 413 } 391 414 415 #ifdef DEBUG_PARSE_TRACE 416 printf("Parsed arg attr, type=%p.\n", arg->type); 417 #endif 392 418 return arg; 393 419 } -
uspace/app/sbi/src/rdata.c
r6ba20a6b r39e8406 243 243 } 244 244 245 rdata_titem_t *rdata_titem_new(titem_class_t tic)246 {247 rdata_titem_t *titem;248 249 titem = calloc(1, sizeof(rdata_titem_t));250 if (titem == NULL) {251 printf("Memory allocation failed.\n");252 exit(1);253 }254 255 titem->tic = tic;256 return titem;257 }258 259 rdata_tarray_t *rdata_tarray_new(void)260 {261 rdata_tarray_t *tarray;262 263 tarray = calloc(1, sizeof(rdata_tarray_t));264 if (tarray == NULL) {265 printf("Memory allocation failed.\n");266 exit(1);267 }268 269 return tarray;270 }271 272 rdata_tcsi_t *rdata_tcsi_new(void)273 {274 rdata_tcsi_t *tcsi;275 276 tcsi = calloc(1, sizeof(rdata_tcsi_t));277 if (tcsi == NULL) {278 printf("Memory allocation failed.\n");279 exit(1);280 }281 282 return tcsi;283 }284 285 rdata_tprimitive_t *rdata_tprimitive_new(void)286 {287 rdata_tprimitive_t *tprimitive;288 289 tprimitive = calloc(1, sizeof(rdata_tprimitive_t));290 if (tprimitive == NULL) {291 printf("Memory allocation failed.\n");292 exit(1);293 }294 295 return tprimitive;296 }297 298 245 void rdata_array_alloc_element(rdata_array_t *array) 299 246 { … … 447 394 } 448 395 449 /** Get item var-class.450 *451 * Get var-class of @a item, regardless whether it is a value or address.452 * (I.e. the var class of the value or variable at the given address).453 */454 var_class_t rdata_item_get_vc(rdata_item_t *item)455 {456 var_class_t vc;457 458 switch (item->ic) {459 case ic_value:460 vc = item->u.value->var->vc;461 break;462 case ic_address:463 switch (item->u.address->ac) {464 case ac_var:465 vc = item->u.address->u.var_a->vref->vc;466 break;467 case ac_prop:468 printf("Unimplemented: Get property address "469 "varclass.\n");470 exit(1);471 default:472 assert(b_false);473 }474 break;475 default:476 assert(b_false);477 }478 479 return vc;480 }481 482 /** Determine if CSI @a a is derived from CSI described by type item @a tb. */483 bool_t rdata_is_csi_derived_from_ti(stree_csi_t *a, rdata_titem_t *tb)484 {485 bool_t res;486 487 switch (tb->tic) {488 case tic_tcsi:489 res = stree_is_csi_derived_from_csi(a, tb->u.tcsi->csi);490 break;491 default:492 printf("Error: Base type is not a CSI.\n");493 exit(1);494 }495 496 return res;497 }498 499 396 void rdata_item_print(rdata_item_t *item) 500 397 { -
uspace/app/sbi/src/rdata.h
r6ba20a6b r39e8406 48 48 rdata_string_t *rdata_string_new(void); 49 49 50 rdata_titem_t *rdata_titem_new(titem_class_t tic);51 rdata_tarray_t *rdata_tarray_new(void);52 rdata_tcsi_t *rdata_tcsi_new(void);53 rdata_tprimitive_t *rdata_tprimitive_new(void);54 55 50 void rdata_array_alloc_element(rdata_array_t *array); 56 51 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest); … … 59 54 void rdata_var_write(rdata_var_t *var, rdata_value_t *value); 60 55 61 var_class_t rdata_item_get_vc(rdata_item_t *item);62 bool_t rdata_is_csi_derived_from_ti(stree_csi_t *a, rdata_titem_t *tb);63 64 56 void rdata_item_print(rdata_item_t *item); 65 57 -
uspace/app/sbi/src/rdata_t.h
r6ba20a6b r39e8406 171 171 /** Property address. 172 172 * 173 * When accessing part of a property that is non-scalar and mutable, 174 * a read-modify-write (or get-modify-set) operation is necessary. 175 * To accomodate this, the address item must hold a temporary copy of the 176 * property value. 173 * When an access or index operation is performed on a property, the getter 174 * is run and the prefetched value is stored in @c tvalue. If the property 175 * is a non-scalar value type (a struct), then we might want to point to 176 * the proper @c var node inside it. @c tpos is used for this purpose. 177 * 178 * The assignment operator will modify @c tvalue and at the end the setter 179 * is called to store @c tvalue back into the property. 177 180 */ 178 181 typedef struct { … … 236 239 } rdata_item_t; 237 240 238 /** Primitive type. */239 typedef struct {240 } rdata_tprimitive_t;241 242 /** Class, struct or interface type. */243 typedef struct {244 struct stree_csi *csi;245 } rdata_tcsi_t;246 247 /** Array type. */248 typedef struct {249 /** Base type item */250 struct rdata_titem *base_ti;251 252 /** Rank */253 int rank;254 255 /** Extents */256 list_t extents; /* of stree_expr_t */257 } rdata_tarray_t;258 259 /** Generic type. */260 typedef struct {261 } rdata_tgeneric_t;262 263 typedef enum {264 tic_tprimitive,265 tic_tcsi,266 tic_tarray,267 tic_tgeneric268 } titem_class_t;269 270 /** Type item, the result of evaluating a type expression. */271 typedef struct rdata_titem {272 titem_class_t tic;273 274 union {275 rdata_tprimitive_t *tprimitive;276 rdata_tcsi_t *tcsi;277 rdata_tarray_t *tarray;278 rdata_tgeneric_t *tgeneric;279 } u;280 } rdata_titem_t;281 282 241 #endif -
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). */ -
uspace/app/sbi/src/run.h
r6ba20a6b r39e8406 48 48 void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar, 49 49 rdata_item_t *arg_val); 50 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_ symbol_t *proc_sym,51 stree_block_t *proc_block,run_proc_ar_t **rproc_ar);50 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc, 51 run_proc_ar_t **rproc_ar); 52 52 53 var_class_t run_item_get_vc(run_t *run, rdata_item_t *item); 53 54 void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem); 54 55 void run_address_read(run_t *run, rdata_address_t *address, -
uspace/app/sbi/src/run_expr.c
r6ba20a6b r39e8406 43 43 #include "stree.h" 44 44 #include "strtab.h" 45 #include "tdata.h" 45 46 46 47 #include "run_expr.h" … … 72 73 static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res); 73 74 static void run_new_array(run_t *run, stree_new_t *new_op, 74 rdata_titem_t *titem, rdata_item_t **res);75 tdata_item_t *titem, rdata_item_t **res); 75 76 static void run_new_object(run_t *run, stree_new_t *new_op, 76 rdata_titem_t *titem, rdata_item_t **res);77 tdata_item_t *titem, rdata_item_t **res); 77 78 78 79 static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res); … … 199 200 assert(csi != NULL); 200 201 } else { 201 csi = proc_ar->proc _sym->outer_csi;202 csi = proc_ar->proc->outer_symbol->outer_csi; 202 203 obj = NULL; 203 204 } … … 231 232 printf("Error: Cannot access non-static member " 232 233 "function '"); 233 symbol_print_fqn( run->program,sym);234 symbol_print_fqn(sym); 234 235 printf("' from nested CSI '"); 235 symbol_print_fqn( run->program,csi_sym);236 symbol_print_fqn(csi_sym); 236 237 printf("'.\n"); 237 238 exit(1); … … 267 268 printf("Error: Cannot access non-static member " 268 269 "variable '"); 269 symbol_print_fqn( run->program,sym);270 symbol_print_fqn(sym); 270 271 printf("' from nested CSI '"); 271 symbol_print_fqn( run->program,csi_sym);272 symbol_print_fqn(csi_sym); 272 273 printf("'.\n"); 273 274 exit(1); … … 632 633 static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res) 633 634 { 634 rdata_titem_t *titem;635 tdata_item_t *titem; 635 636 636 637 #ifdef DEBUG_RUN_TRACE … … 638 639 #endif 639 640 /* Evaluate type expression */ 640 run_texpr(run, new_op->texpr, &titem); 641 run_texpr(run->program, run_get_current_csi(run), new_op->texpr, 642 &titem); 641 643 642 644 switch (titem->tic) { … … 644 646 run_new_array(run, new_op, titem, res); 645 647 break; 646 case tic_t csi:648 case tic_tobject: 647 649 run_new_object(run, new_op, titem, res); 648 650 break; … … 656 658 /** Create new array. */ 657 659 static void run_new_array(run_t *run, stree_new_t *new_op, 658 rdata_titem_t *titem, rdata_item_t **res)659 { 660 rdata_tarray_t *tarray;660 tdata_item_t *titem, rdata_item_t **res) 661 { 662 tdata_array_t *tarray; 661 663 rdata_array_t *array; 662 664 rdata_var_t *array_var; … … 744 746 /** Create new object. */ 745 747 static void run_new_object(run_t *run, stree_new_t *new_op, 746 rdata_titem_t *titem, rdata_item_t **res)748 tdata_item_t *titem, rdata_item_t **res) 747 749 { 748 750 rdata_object_t *obj; … … 764 766 765 767 /* Lookup object CSI. */ 766 assert(titem->tic == tic_t csi);767 csi = titem->u.t csi->csi;768 assert(titem->tic == tic_tobject); 769 csi = titem->u.tobject->csi; 768 770 csi_sym = csi_to_symbol(csi); 769 771 … … 823 825 printf("Run access operation on pre-evaluated base.\n"); 824 826 #endif 825 vc = r data_item_get_vc(arg);827 vc = run_item_get_vc(run, arg); 826 828 827 829 switch (vc) { … … 883 885 if (member == NULL) { 884 886 printf("Error: CSI '"); 885 symbol_print_fqn( run->program,deleg_v->sym);887 symbol_print_fqn(deleg_v->sym); 886 888 printf("' has no member named '%s'.\n", 887 889 strtab_get_str(access->member_name->sid)); … … 936 938 if (member == NULL) { 937 939 printf("Error: Object of class '"); 938 symbol_print_fqn( run->program,object->class_sym);940 symbol_print_fqn(object->class_sym); 939 941 printf("' has no member named '%s'.\n", 940 942 strtab_get_str(access->member_name->sid)); … … 1030 1032 #ifdef DEBUG_RUN_TRACE 1031 1033 printf("Call function '"); 1032 symbol_print_fqn( run->program,deleg_v->sym);1034 symbol_print_fqn(deleg_v->sym); 1033 1035 printf("'\n"); 1034 1036 #endif … … 1050 1052 1051 1053 /* Create procedure activation record. */ 1052 run_proc_ar_create(run, deleg_v->obj, deleg_v->sym, fun->body, 1053 &proc_ar); 1054 run_proc_ar_create(run, deleg_v->obj, fun->proc, &proc_ar); 1054 1055 1055 1056 /* Fill in argument values. */ … … 1080 1081 run_expr(run, index->base, &rbase); 1081 1082 1082 vc = r data_item_get_vc(rbase);1083 vc = run_item_get_vc(run, rbase); 1083 1084 1084 1085 /* Implicitly dereference. */ … … 1089 1090 } 1090 1091 1091 vc = r data_item_get_vc(base_i);1092 vc = run_item_get_vc(run, base_i); 1092 1093 1093 1094 /* Evaluate arguments (indices). */ … … 1224 1225 printf("Run object index operation.\n"); 1225 1226 #endif 1226 (void) run;1227 1227 (void) index; 1228 1228 … … 1252 1252 indexer_sym = symbol_search_csi(run->program, obj_csi, indexer_ident); 1253 1253 1254 if (indexer_sym == NULL) { 1255 printf("Error: Accessing object which does not have an " 1256 "indexer.\n"); 1257 exit(1); 1258 } 1259 1254 1260 /* Construct delegate. */ 1255 1261 object_d = rdata_deleg_new(); -
uspace/app/sbi/src/run_t.h
r6ba20a6b r39e8406 54 54 struct rdata_var *obj; 55 55 56 /** Definition of function or property being invoked */ 57 struct stree_symbol *proc_sym; 58 59 /** Main block of procedure being invoked */ 60 struct stree_block *proc_block; 56 /** Procedure being invoked */ 57 struct stree_proc *proc; 61 58 62 59 /** Block activation records */ -
uspace/app/sbi/src/run_texpr.c
r6ba20a6b r39e8406 29 29 /** @file Evaluates type expressions. */ 30 30 31 #include <assert.h> 31 32 #include <stdlib.h> 32 33 #include "list.h" 33 34 #include "mytypes.h" 34 #include "rdata.h"35 #include "run.h"36 35 #include "symbol.h" 36 #include "tdata.h" 37 37 38 38 #include "run_texpr.h" 39 39 40 static void run_taccess(run_t *run, stree_taccess_t *taccess, 41 rdata_titem_t **res); 42 static void run_tindex(run_t *run, stree_tindex_t *tindex, 43 rdata_titem_t **res); 44 static void run_tliteral(run_t *run, stree_tliteral_t *tliteral, 45 rdata_titem_t **res); 46 static void run_tnameref(run_t *run, stree_tnameref_t *tnameref, 47 rdata_titem_t **res); 48 49 void run_texpr(run_t *run, stree_texpr_t *texpr, rdata_titem_t **res) 40 static void run_taccess(stree_program_t *prog, stree_csi_t *ctx, 41 stree_taccess_t *taccess, tdata_item_t **res); 42 static void run_tindex(stree_program_t *prog, stree_csi_t *ctx, 43 stree_tindex_t *tindex, tdata_item_t **res); 44 static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx, 45 stree_tliteral_t *tliteral, tdata_item_t **res); 46 static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx, 47 stree_tnameref_t *tnameref, tdata_item_t **res); 48 49 void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr, 50 tdata_item_t **res) 50 51 { 51 52 switch (texpr->tc) { 52 53 case tc_taccess: 53 run_taccess( run, texpr->u.taccess, res);54 run_taccess(prog, ctx, texpr->u.taccess, res); 54 55 break; 55 56 case tc_tindex: 56 run_tindex( run, texpr->u.tindex, res);57 run_tindex(prog, ctx, texpr->u.tindex, res); 57 58 break; 58 59 case tc_tliteral: 59 run_tliteral( run, texpr->u.tliteral, res);60 run_tliteral(prog, ctx, texpr->u.tliteral, res); 60 61 break; 61 62 case tc_tnameref: 62 run_tnameref( run, texpr->u.tnameref, res);63 run_tnameref(prog, ctx, texpr->u.tnameref, res); 63 64 break; 64 65 case tc_tapply: … … 69 70 } 70 71 71 static void run_taccess( run_t *run, stree_taccess_t *taccess,72 rdata_titem_t **res)72 static void run_taccess(stree_program_t *prog, stree_csi_t *ctx, 73 stree_taccess_t *taccess, tdata_item_t **res) 73 74 { 74 75 stree_symbol_t *sym; 75 rdata_titem_t *targ_i;76 rdata_titem_t *titem;77 rdata_tcsi_t *tcsi;76 tdata_item_t *targ_i; 77 tdata_item_t *titem; 78 tdata_object_t *tobject; 78 79 stree_csi_t *base_csi; 79 80 … … 82 83 #endif 83 84 /* Evaluate base type. */ 84 run_texpr( run, taccess->arg, &targ_i);85 86 if (targ_i->tic != tic_t csi) {87 printf("Error: Using '.' with type which is not CSI.\n");85 run_texpr(prog, ctx, taccess->arg, &targ_i); 86 87 if (targ_i->tic != tic_tobject) { 88 printf("Error: Using '.' with type which is not an object.\n"); 88 89 exit(1); 89 90 } 90 91 91 92 /* Get base CSI. */ 92 base_csi = targ_i->u.tcsi->csi; 93 94 sym = symbol_lookup_in_csi(run->program, base_csi, 95 taccess->member_name); 93 base_csi = targ_i->u.tobject->csi; 94 95 sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name); 96 96 if (sym->sc != sc_csi) { 97 97 printf("Error: Symbol '"); 98 symbol_print_fqn( run->program,sym);98 symbol_print_fqn(sym); 99 99 printf("' is not a CSI.\n"); 100 100 exit(1); … … 102 102 103 103 /* Construct type item. */ 104 titem = rdata_titem_new(tic_tcsi); 105 tcsi = rdata_tcsi_new(); 106 titem->u.tcsi = tcsi; 107 108 tcsi->csi = sym->u.csi; 109 110 *res = titem; 111 } 112 113 static void run_tindex(run_t *run, stree_tindex_t *tindex, rdata_titem_t **res) 114 { 115 rdata_titem_t *base_ti; 116 rdata_titem_t *titem; 117 rdata_tarray_t *tarray; 104 titem = tdata_item_new(tic_tobject); 105 tobject = tdata_object_new(); 106 titem->u.tobject = tobject; 107 108 tobject->static_ref = b_false; 109 tobject->csi = sym->u.csi; 110 111 *res = titem; 112 } 113 114 static void run_tindex(stree_program_t *prog, stree_csi_t *ctx, 115 stree_tindex_t *tindex, tdata_item_t **res) 116 { 117 tdata_item_t *base_ti; 118 tdata_item_t *titem; 119 tdata_array_t *tarray; 118 120 stree_expr_t *arg_expr; 119 121 list_node_t *arg_node; … … 123 125 #endif 124 126 /* Evaluate base type. */ 125 run_texpr( run, tindex->base_type, &base_ti);126 127 /* Construct type item. */ 128 titem = rdata_titem_new(tic_tarray);129 tarray = rdata_tarray_new();127 run_texpr(prog, ctx, tindex->base_type, &base_ti); 128 129 /* Construct type item. */ 130 titem = tdata_item_new(tic_tarray); 131 tarray = tdata_array_new(); 130 132 titem->u.tarray = tarray; 131 133 … … 146 148 } 147 149 148 static void run_tliteral(run_t *run, stree_tliteral_t *tliteral, 149 rdata_titem_t **res) 150 { 151 rdata_titem_t *titem; 152 rdata_tprimitive_t *tprimitive; 150 static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx, 151 stree_tliteral_t *tliteral, tdata_item_t **res) 152 { 153 tdata_item_t *titem; 154 tdata_primitive_t *tprimitive; 155 tprimitive_class_t tpc; 153 156 154 157 #ifdef DEBUG_RUN_TRACE 155 158 printf("Evaluating type literal.\n"); 156 159 #endif 157 158 (void) run;160 (void) prog; 161 (void) ctx; 159 162 (void) tliteral; 160 163 161 /* Construct type item. */ 162 titem = rdata_titem_new(tic_tprimitive); 163 tprimitive = rdata_tprimitive_new(); 164 switch (tliteral->tlc) { 165 case tlc_int: tpc = tpc_int; break; 166 case tlc_string: tpc = tpc_string; break; 167 } 168 169 /* Construct type item. */ 170 titem = tdata_item_new(tic_tprimitive); 171 tprimitive = tdata_primitive_new(tpc); 164 172 titem->u.tprimitive = tprimitive; 165 173 … … 167 175 } 168 176 169 static void run_tnameref(run_t *run, stree_tnameref_t *tnameref, 170 rdata_titem_t **res) 171 { 172 stree_csi_t *current_csi; 177 static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx, 178 stree_tnameref_t *tnameref, tdata_item_t **res) 179 { 173 180 stree_symbol_t *sym; 174 rdata_titem_t *titem;175 rdata_tcsi_t *tcsi;181 tdata_item_t *titem; 182 tdata_object_t *tobject; 176 183 177 184 #ifdef DEBUG_RUN_TRACE 178 185 printf("Evaluating type name reference.\n"); 179 186 #endif 180 current_csi = run_get_current_csi(run); 181 sym = symbol_lookup_in_csi(run->program, current_csi, tnameref->name); 187 sym = symbol_lookup_in_csi(prog, ctx, tnameref->name); 182 188 183 189 if (sym->sc != sc_csi) { 184 190 printf("Error: Symbol '"); 185 symbol_print_fqn( run->program,sym);191 symbol_print_fqn(sym); 186 192 printf("' is not a CSI.\n"); 187 193 exit(1); … … 189 195 190 196 /* Construct type item. */ 191 titem = rdata_titem_new(tic_tcsi); 192 tcsi = rdata_tcsi_new(); 193 titem->u.tcsi = tcsi; 194 195 tcsi->csi = sym->u.csi; 196 197 *res = titem; 198 } 197 titem = tdata_item_new(tic_tobject); 198 tobject = tdata_object_new(); 199 titem->u.tobject = tobject; 200 201 tobject->static_ref = b_false; 202 tobject->csi = sym->u.csi; 203 204 *res = titem; 205 } -
uspace/app/sbi/src/run_texpr.h
r6ba20a6b r39e8406 32 32 #include "mytypes.h" 33 33 34 void run_texpr(run_t *run, stree_texpr_t *texpr, rdata_titem_t **res); 34 void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr, 35 tdata_item_t **res); 35 36 36 37 #endif -
uspace/app/sbi/src/stree.c
r6ba20a6b r39e8406 136 136 } 137 137 138 stree_proc_t *stree_proc_new(void) 139 { 140 stree_proc_t *proc; 141 142 proc = calloc(1, sizeof(stree_proc_t)); 143 if (proc == NULL) { 144 printf("Memory allocation failed.\n"); 145 exit(1); 146 } 147 148 return proc; 149 } 150 138 151 stree_proc_arg_t *stree_proc_arg_new(void) 139 152 { … … 507 520 } 508 521 509 stree_tliteral_t *stree_tliteral_new( void)522 stree_tliteral_t *stree_tliteral_new(tliteral_class_t tlc) 510 523 { 511 524 stree_tliteral_t *tliteral; … … 517 530 } 518 531 532 tliteral->tlc = tlc; 519 533 return tliteral; 520 534 } -
uspace/app/sbi/src/stree.h
r6ba20a6b r39e8406 40 40 stree_prop_t *stree_prop_new(void); 41 41 42 stree_proc_t *stree_proc_new(void); 42 43 stree_proc_arg_t *stree_proc_arg_new(void); 43 44 stree_arg_attr_t *stree_arg_attr_new(arg_attr_class_t aac); … … 73 74 stree_tapply_t *stree_tapply_new(void); 74 75 stree_tindex_t *stree_tindex_new(void); 75 stree_tliteral_t *stree_tliteral_new( void);76 stree_tliteral_t *stree_tliteral_new(tliteral_class_t tlc); 76 77 stree_tnameref_t *stree_tnameref_new(void); 77 78 -
uspace/app/sbi/src/stree_t.h
r6ba20a6b r39e8406 82 82 /** Binary operation class */ 83 83 typedef enum { 84 bo_period,85 bo_slash,86 bo_sbr,87 84 bo_equal, 88 85 bo_notequal, … … 178 175 expr_class_t ec; 179 176 177 struct tdata_item *titem; 178 180 179 union { 181 180 stree_nameref_t *nameref; … … 379 378 } stree_proc_arg_t; 380 379 380 /** Procedure 381 * 382 * Procedure is the common term for a getter, setter or function body. 383 * A procedure can be invoked. However, the arguments are specified by 384 * the containing symbol. 385 */ 386 typedef struct stree_proc { 387 /** Symbol (function or property) containing the procedure */ 388 struct stree_symbol *outer_symbol; 389 390 /** Main block */ 391 stree_block_t *body; 392 } stree_proc_t; 393 381 394 /** Member function declaration */ 382 typedef struct {395 typedef struct stree_fun { 383 396 /** Function name */ 384 397 stree_ident_t *name; … … 396 409 stree_texpr_t *rtype; 397 410 398 /** Function body*/399 stree_ block_t *body;411 /** Function implementation */ 412 stree_proc_t *proc; 400 413 } stree_fun_t; 401 414 402 415 /** Member variable declaration */ 403 typedef struct {416 typedef struct stree_var { 404 417 stree_ident_t *name; 405 418 struct stree_symbol *symbol; … … 408 421 409 422 /** Member property declaration */ 410 typedef struct {423 typedef struct stree_prop { 411 424 stree_ident_t *name; 412 425 struct stree_symbol *symbol; 413 426 stree_texpr_t *type; 414 427 415 stree_block_t *getter_body; 416 stree_ident_t *setter_arg_name; 417 stree_block_t *setter_body; 428 stree_proc_t *getter; 429 430 stree_proc_t *setter; 431 stree_proc_arg_t *setter_arg; 418 432 419 433 /** Formal parameters (for indexed properties) */ … … 425 439 426 440 /** 427 * Fake identifier used with indexed properties. (Mostly for error messages.) 441 * Fake identifiers used with symbols that do not really have one. 442 * (Mostly for error messages.) 428 443 */ 429 444 #define INDEXER_IDENT "$indexer" … … 504 519 } symbol_class_t; 505 520 506 /** Symbol */ 521 /** Symbol 522 * 523 * A symbol is a common superclass of different program elements that 524 * allow us to refer to them, print their fully qualified names, etc. 525 */ 507 526 typedef struct stree_symbol { 508 527 symbol_class_t sc; -
uspace/app/sbi/src/symbol.c
r6ba20a6b r39e8406 322 322 323 323 /** Print fully qualified name of symbol. */ 324 void symbol_print_fqn(stree_ program_t *prog, stree_symbol_t *symbol)324 void symbol_print_fqn(stree_symbol_t *symbol) 325 325 { 326 326 stree_ident_t *name; … … 329 329 if (symbol->outer_csi != NULL) { 330 330 outer_sym = csi_to_symbol(symbol->outer_csi); 331 symbol_print_fqn( prog,outer_sym);331 symbol_print_fqn( outer_sym); 332 332 printf("."); 333 333 } -
uspace/app/sbi/src/symbol.h
r6ba20a6b r39e8406 49 49 stree_symbol_t *prop_to_symbol(stree_prop_t *prop); 50 50 51 void symbol_print_fqn(stree_ program_t *prog, stree_symbol_t *symbol);51 void symbol_print_fqn(stree_symbol_t *symbol); 52 52 53 53 #endif
Note:
See TracChangeset
for help on using the changeset viewer.