Changes in / [1614ce3:b64eac6] in mainline
- Files:
-
- 6 added
- 3 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r1614ce3 rb64eac6 42 42 CONFIG_HEADER = config.h 43 43 44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check distfile dist44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check releasefile release 45 45 46 46 all: $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) … … 88 88 $(CONFIG) $< 89 89 90 # Distributionfiles90 # Release files 91 91 92 distfile: all93 $(MAKE) -C dist distfile92 releasefile: all 93 $(MAKE) -C release releasefile 94 94 95 dist:96 $(MAKE) -C dist dist95 release: 96 $(MAKE) -C release release 97 97 98 98 # Cleaning 99 99 100 100 distclean: clean 101 rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc dist/HelenOS-*101 rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc release/HelenOS-* 102 102 103 103 clean: -
uspace/app/sbi/Makefile
r1614ce3 rb64eac6 35 35 SOURCES = \ 36 36 src/builtin/bi_boxed.c \ 37 src/builtin/bi_error.c \ 37 38 src/builtin/bi_char.c \ 38 src/builtin/bi_error.c \ 39 src/builtin/bi_fun.c \ 39 src/builtin/bi_console.c \ 40 40 src/builtin/bi_int.c \ 41 src/builtin/bi_task.c \ 41 42 src/builtin/bi_textfile.c \ 42 43 src/builtin/bi_string.c \ -
uspace/app/sbi/src/builtin.c
r1614ce3 rb64eac6 43 43 #include "builtin/bi_error.h" 44 44 #include "builtin/bi_char.h" 45 #include "builtin/bi_ fun.h"45 #include "builtin/bi_console.h" 46 46 #include "builtin/bi_int.h" 47 #include "builtin/bi_task.h" 47 48 #include "builtin/bi_textfile.h" 48 49 #include "builtin/bi_string.h" … … 93 94 bi_error_declare(bi); 94 95 bi_char_declare(bi); 95 bi_ fun_declare(bi);96 bi_console_declare(bi); 96 97 bi_int_declare(bi); 98 bi_task_declare(bi); 97 99 bi_textfile_declare(bi); 98 100 bi_string_declare(bi); … … 111 113 bi_error_bind(bi); 112 114 bi_char_bind(bi); 113 bi_ fun_bind(bi);115 bi_console_bind(bi); 114 116 bi_int_bind(bi); 117 bi_task_bind(bi); 115 118 bi_textfile_bind(bi); 116 119 bi_string_bind(bi); -
uspace/app/sbi/src/imode.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 178 178 /* Convert expression result to value item. */ 179 179 run_cvt_value_item(&run, rexpr, &rexpr_vi); 180 rdata_item_destroy(rexpr); 181 182 /* Check for unhandled exceptions. */ 183 run_exc_check_unhandled(&run); 184 } else { 185 rexpr_vi = NULL; 186 } 187 188 /* 189 * rexpr_vi can be NULL if either repxr was null or 190 * if the conversion to value item raised an exception. 191 */ 192 if (rexpr_vi != NULL) { 180 193 assert(rexpr_vi->ic == ic_value); 181 194 … … 184 197 rdata_value_print(rexpr_vi->u.value); 185 198 printf("\n"); 199 200 rdata_item_destroy(rexpr_vi); 186 201 } 187 202 } 203 204 run_proc_ar_destroy(&run, proc_ar); 188 205 189 206 /* Remove block visit record from the stack, */ -
uspace/app/sbi/src/intmap.c
r1614ce3 rb64eac6 50 50 } 51 51 52 /** Deinitialize map. 53 * 54 * The map must be already empty. 55 * 56 * @param intmap Map to initialize. 57 */ 58 void intmap_fini(intmap_t *intmap) 59 { 60 list_fini(&intmap->elem); 61 } 62 52 63 /** Set value corresponding to a key. 53 64 * … … 56 67 * is removed from the map. 57 68 * 58 * @param intmap Map .59 * @param key Key (integer) .60 * @param value Value (must be a pointer) or @c NULL .69 * @param intmap Map 70 * @param key Key (integer) 71 * @param value Value (must be a pointer) or @c NULL 61 72 */ 62 73 void intmap_set(intmap_t *intmap, int key, void *value) … … 75 86 /* Remove map element. */ 76 87 list_remove(&intmap->elem, node); 77 node->data = NULL; 78 free(node); 88 free(elem); 79 89 } 80 90 return; … … 98 108 /** Get value corresponding to a key. 99 109 * 100 * @param intmap Map .101 * @param key Key for which to retrieve mapping .110 * @param intmap Map 111 * @param key Key for which to retrieve mapping 102 112 * 103 113 * @return Value correspoding to @a key or @c NULL if no mapping … … 121 131 return NULL; 122 132 } 133 134 /** Get first element in the map. 135 * 136 * For iterating over the map, this returns the first element (in no 137 * particular order). 138 * 139 * @param intmap Map 140 * @return Map element or NULL if the map is empty 141 */ 142 map_elem_t *intmap_first(intmap_t *intmap) 143 { 144 list_node_t *node; 145 146 node = list_first(&intmap->elem); 147 if (node == NULL) 148 return NULL; 149 150 return list_node_data(node, map_elem_t *); 151 } 152 153 /** Get element key. 154 * 155 * Giver a map element, return the key. 156 * 157 * @param elem Map element 158 * @return Key 159 */ 160 int intmap_elem_get_key(map_elem_t *elem) 161 { 162 return elem->key; 163 } 164 165 /** Get element value. 166 * 167 * Giver a map element, return the value. 168 * 169 * @param elem Map element 170 * @return Value 171 */ 172 void *intmap_elem_get_value(map_elem_t *elem) 173 { 174 return elem->value; 175 } -
uspace/app/sbi/src/intmap.h
r1614ce3 rb64eac6 33 33 34 34 void intmap_init(intmap_t *intmap); 35 void intmap_fini(intmap_t *intmap); 35 36 void intmap_set(intmap_t *intmap, int key, void *data); 36 37 void *intmap_get(intmap_t *intmap, int key); 38 map_elem_t *intmap_first(intmap_t *intmap); 39 int intmap_elem_get_key(map_elem_t *elem); 40 void *intmap_elem_get_value(map_elem_t *elem); 37 41 38 42 #endif -
uspace/app/sbi/src/lex.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 #define TAB_WIDTH 8 46 46 47 typedef enum { 48 cs_chr, 49 cs_str 50 } chr_str_t; 51 47 52 static void lex_touch(lex_t *lex); 48 53 static bool_t lex_read_try(lex_t *lex); … … 57 62 static void lex_number(lex_t *lex); 58 63 static void lex_string(lex_t *lex); 64 static void lex_char_string_core(lex_t *lex, chr_str_t cs); 59 65 static int digit_value(char c); 60 66 … … 117 123 { lc_string, "string" }, 118 124 { lc_struct, "struct" }, 125 { lc_switch, "switch" }, 119 126 { lc_then, "then" }, 120 127 { lc_this, "this" }, … … 122 129 { lc_var, "var" }, 123 130 { lc_with, "with" }, 131 { lc_when, "when" }, 124 132 { lc_while, "while" }, 125 133 { lc_yield, "yield" }, … … 535 543 static void lex_char(lex_t *lex) 536 544 { 537 char *bp;538 int idx;539 545 size_t len; 540 546 int char_val; 541 547 542 bp = lex->ibp + 1; 543 idx = 0; 544 545 while (bp[idx] != '\'') { 546 if (idx >= SLBUF_SIZE) { 547 printf("Error: Character literal too long.\n"); 548 exit(1); 549 } 550 551 if (bp[idx] == '\0') { 552 printf("Error: Unterminated character literal.\n"); 553 exit(1); 554 } 555 556 strlit_buf[idx] = bp[idx]; 557 ++idx; 558 } 559 560 lex->ibp = bp + idx + 1; 561 562 strlit_buf[idx] = '\0'; 548 lex_char_string_core(lex, cs_chr); 549 563 550 len = os_str_length(strlit_buf); 564 551 if (len != 1) { … … 620 607 static void lex_string(lex_t *lex) 621 608 { 622 char *bp; 623 int idx; 624 625 bp = lex->ibp + 1; 626 idx = 0; 627 628 while (bp[idx] != '"') { 629 if (idx >= SLBUF_SIZE) { 630 printf("Error: String literal too long.\n"); 631 exit(1); 632 } 633 634 if (bp[idx] == '\0') { 635 printf("Error: Unterminated string literal.\n"); 636 exit(1); 637 } 638 639 strlit_buf[idx] = bp[idx]; 640 ++idx; 641 } 642 643 lex->ibp = bp + idx + 1; 644 645 strlit_buf[idx] = '\0'; 609 lex_char_string_core(lex, cs_str); 646 610 647 611 lex->current.lclass = lc_lit_string; 648 612 lex->current.u.lit_string.value = os_str_dup(strlit_buf); 613 } 614 615 static void lex_char_string_core(lex_t *lex, chr_str_t cs) 616 { 617 char *bp; 618 int sidx, didx; 619 char term; 620 const char *descr, *cap_descr; 621 char spchar; 622 623 /* Make compiler happy */ 624 term = '\0'; 625 descr = NULL; 626 cap_descr = NULL; 627 628 switch (cs) { 629 case cs_chr: 630 term = '\''; 631 descr = "character"; 632 cap_descr = "Character"; 633 break; 634 case cs_str: 635 term = '"'; 636 descr = "string"; 637 cap_descr = "String"; 638 break; 639 } 640 641 bp = lex->ibp + 1; 642 sidx = didx = 0; 643 644 while (bp[sidx] != term) { 645 if (didx >= SLBUF_SIZE) { 646 printf("Error: %s literal too long.\n", cap_descr); 647 exit(1); 648 } 649 650 if (bp[sidx] == '\0') { 651 printf("Error: Unterminated %s literal.\n", descr); 652 exit(1); 653 } 654 655 if (bp[sidx] == '\\') { 656 switch (bp[sidx + 1]) { 657 case '\\': 658 spchar = '\\'; 659 break; 660 case '\'': 661 spchar = '\''; 662 break; 663 case '"': 664 spchar = '"'; 665 break; 666 case 'n': 667 spchar = '\n'; 668 break; 669 case 't': 670 spchar = '\t'; 671 break; 672 default: 673 printf("Error: Unknown character escape sequence.\n"); 674 exit(1); 675 } 676 677 strlit_buf[didx] = spchar; 678 ++didx; 679 sidx += 2; 680 } else { 681 strlit_buf[didx] = bp[sidx]; 682 ++sidx; ++didx; 683 } 684 } 685 686 lex->ibp = bp + sidx + 1; 687 688 strlit_buf[didx] = '\0'; 649 689 } 650 690 -
uspace/app/sbi/src/lex_t.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 85 85 lc_string, 86 86 lc_struct, 87 lc_switch, 87 88 lc_then, 88 89 lc_this, … … 90 91 lc_var, 91 92 lc_with, 93 lc_when, 92 94 lc_while, 93 95 lc_yield, -
uspace/app/sbi/src/list.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 57 57 } 58 58 59 /** Deinitialize list. 60 * 61 * @param list List to deinitialize. 62 */ 63 void list_fini(list_t *list) 64 { 65 assert(list_is_empty(list)); 66 67 list->head.prev = NULL; 68 list->head.next = NULL; 69 } 70 59 71 /** Append data to list. 60 72 * -
uspace/app/sbi/src/list.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 35 35 void list_init(list_t *list); 36 void list_fini(list_t *list); 36 37 void list_append(list_t *list, void *data); 37 38 void list_prepend(list_t *list, void *data); -
uspace/app/sbi/src/parse.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 82 82 static stree_vdecl_t *parse_vdecl(parse_t *parse); 83 83 static stree_if_t *parse_if(parse_t *parse); 84 static stree_switch_t *parse_switch(parse_t *parse); 84 85 static stree_while_t *parse_while(parse_t *parse); 85 86 static stree_for_t *parse_for(parse_t *parse); … … 667 668 stree_prop_t *prop; 668 669 stree_symbol_t *symbol; 669 bool_t body_expected;670 670 671 671 stree_ident_t *ident; … … 720 720 /* Parse attributes. */ 721 721 parse_symbol_attrs(parse, symbol); 722 723 body_expected = (outer_csi->cc != csi_interface);724 722 725 723 lmatch(parse, lc_is); … … 1070 1068 stree_vdecl_t *vdecl_s; 1071 1069 stree_if_t *if_s; 1070 stree_switch_t *switch_s; 1072 1071 stree_while_t *while_s; 1073 1072 stree_for_t *for_s; … … 1092 1091 stat->u.if_s = if_s; 1093 1092 break; 1093 case lc_switch: 1094 switch_s = parse_switch(parse); 1095 stat = stree_stat_new(st_switch); 1096 stat->u.switch_s = switch_s; 1097 break; 1094 1098 case lc_while: 1095 1099 while_s = parse_while(parse); … … 1214 1218 lmatch(parse, lc_end); 1215 1219 return if_s; 1220 } 1221 1222 /** Parse @c switch statement. 1223 * 1224 * @param parse Parser object. 1225 * @return New syntax tree node. 1226 */ 1227 static stree_switch_t *parse_switch(parse_t *parse) 1228 { 1229 stree_switch_t *switch_s; 1230 stree_when_t *when_c; 1231 stree_expr_t *expr; 1232 1233 #ifdef DEBUG_PARSE_TRACE 1234 printf("Parse 'switch' statement.\n"); 1235 #endif 1236 lmatch(parse, lc_switch); 1237 1238 switch_s = stree_switch_new(); 1239 list_init(&switch_s->when_clauses); 1240 1241 switch_s->expr = parse_expr(parse); 1242 lmatch(parse, lc_is); 1243 1244 /* Parse @c when clauses. */ 1245 while (lcur_lc(parse) == lc_when) { 1246 lskip(parse); 1247 when_c = stree_when_new(); 1248 list_init(&when_c->exprs); 1249 while (b_true) { 1250 expr = parse_expr(parse); 1251 list_append(&when_c->exprs, expr); 1252 if (lcur_lc(parse) != lc_comma) 1253 break; 1254 lskip(parse); 1255 } 1256 1257 lmatch(parse, lc_do); 1258 when_c->block = parse_block(parse); 1259 1260 list_append(&switch_s->when_clauses, when_c); 1261 } 1262 1263 /* Parse @c else clause. */ 1264 if (lcur_lc(parse) == lc_else) { 1265 lskip(parse); 1266 lmatch(parse, lc_do); 1267 switch_s->else_block = parse_block(parse); 1268 } else { 1269 switch_s->else_block = NULL; 1270 } 1271 1272 lmatch(parse, lc_end); 1273 return switch_s; 1216 1274 } 1217 1275 … … 1654 1712 case lc_except: 1655 1713 case lc_finally: 1714 case lc_when: 1656 1715 return b_true; 1657 1716 default: -
uspace/app/sbi/src/rdata.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 49 49 #include <assert.h> 50 50 #include "bigint.h" 51 #include "list.h" 51 52 #include "mytypes.h" 52 53 #include "stree.h" … … 69 70 static void rdata_symbol_copy(rdata_symbol_t *src, rdata_symbol_t **dest); 70 71 72 static void rdata_var_destroy_inner(rdata_var_t *var); 73 74 static void rdata_bool_destroy(rdata_bool_t *bool_v); 75 static void rdata_char_destroy(rdata_char_t *char_v); 76 static void rdata_int_destroy(rdata_int_t *int_v); 77 static void rdata_string_destroy(rdata_string_t *string_v); 78 static void rdata_ref_destroy(rdata_ref_t *ref_v); 79 static void rdata_deleg_destroy(rdata_deleg_t *deleg_v); 80 static void rdata_enum_destroy(rdata_enum_t *enum_v); 81 static void rdata_array_destroy(rdata_array_t *array_v); 82 static void rdata_object_destroy(rdata_object_t *object_v); 83 static void rdata_resource_destroy(rdata_resource_t *resource_v); 84 static void rdata_symbol_destroy(rdata_symbol_t *symbol_v); 85 71 86 static int rdata_array_get_dim(rdata_array_t *array); 87 static void rdata_var_copy_to(rdata_var_t *src, rdata_var_t *dest); 72 88 73 89 static void rdata_address_print(rdata_address_t *address); … … 414 430 /** Allocate array elements. 415 431 * 416 * Allocates var nodes for elementsof @a array.432 * Allocates element array of @a array. 417 433 * 418 434 * @param array Array. … … 420 436 void rdata_array_alloc_element(rdata_array_t *array) 421 437 { 422 int dim , idx;438 int dim; 423 439 424 440 dim = rdata_array_get_dim(array); … … 428 444 printf("Memory allocation failed.\n"); 429 445 exit(1); 430 }431 432 for (idx = 0; idx < dim; ++idx) {433 array->element[idx] = calloc(1, sizeof(rdata_var_t));434 if (array->element[idx] == NULL) {435 printf("Memory allocation failed.\n");436 exit(1);437 }438 446 } 439 447 } … … 457 465 } 458 466 467 /** Deallocate item. 468 * 469 * @param item Item node 470 */ 471 void rdata_item_delete(rdata_item_t *item) 472 { 473 assert(item != NULL); 474 free(item); 475 } 476 477 /** Deallocate variable address. 478 * 479 * @param addr_var Variable address node 480 */ 481 void rdata_addr_var_delete(rdata_addr_var_t *addr_var) 482 { 483 assert(addr_var != NULL); 484 free(addr_var); 485 } 486 487 /** Deallocate property address. 488 * 489 * @param addr_prop Variable address node 490 */ 491 void rdata_addr_prop_delete(rdata_addr_prop_t *addr_prop) 492 { 493 assert(addr_prop != NULL); 494 free(addr_prop); 495 } 496 497 /** Deallocate named property address. 498 * 499 * @param aprop_named Variable address node 500 */ 501 void rdata_aprop_named_delete(rdata_aprop_named_t *aprop_named) 502 { 503 assert(aprop_named != NULL); 504 free(aprop_named); 505 } 506 507 /** Deallocate indexed property address. 508 * 509 * @param aprop_indexed Variable address node 510 */ 511 void rdata_aprop_indexed_delete(rdata_aprop_indexed_t *aprop_indexed) 512 { 513 assert(aprop_indexed != NULL); 514 free(aprop_indexed); 515 } 516 517 /** Deallocate address. 518 * 519 * @param address Address node 520 */ 521 void rdata_address_delete(rdata_address_t *address) 522 { 523 assert(address != NULL); 524 free(address); 525 } 526 527 /** Deallocate value. 528 * 529 * @param value Value node 530 */ 531 void rdata_value_delete(rdata_value_t *value) 532 { 533 assert(value != NULL); 534 free(value); 535 } 536 537 /** Deallocate var node. 538 * 539 * @param var Var node 540 */ 541 void rdata_var_delete(rdata_var_t *var) 542 { 543 assert(var != NULL); 544 free(var); 545 } 546 547 /** Deallocate boolean. 548 * 549 * @param bool_v Boolean 550 */ 551 void rdata_bool_delete(rdata_bool_t *bool_v) 552 { 553 assert(bool_v != NULL); 554 free(bool_v); 555 } 556 557 /** Deallocate character. 558 * 559 * @param char_v Character 560 */ 561 void rdata_char_delete(rdata_char_t *char_v) 562 { 563 assert(char_v != NULL); 564 free(char_v); 565 } 566 567 /** Deallocate integer. 568 * 569 * @param int_v Integer 570 */ 571 void rdata_int_delete(rdata_int_t *int_v) 572 { 573 assert(int_v != NULL); 574 free(int_v); 575 } 576 577 /** Deallocate string. 578 * 579 * @param string_v String 580 */ 581 void rdata_string_delete(rdata_string_t *string_v) 582 { 583 assert(string_v != NULL); 584 free(string_v); 585 } 586 587 /** Deallocate reference. 588 * 589 * @param ref_v Reference 590 */ 591 void rdata_ref_delete(rdata_ref_t *ref_v) 592 { 593 assert(ref_v != NULL); 594 free(ref_v); 595 } 596 597 /** Deallocate delegate. 598 * 599 * @param deleg_v Reference 600 */ 601 void rdata_deleg_delete(rdata_deleg_t *deleg_v) 602 { 603 assert(deleg_v != NULL); 604 free(deleg_v); 605 } 606 607 /** Deallocate enum. 608 * 609 * @param enum_v Reference 610 */ 611 void rdata_enum_delete(rdata_enum_t *enum_v) 612 { 613 assert(enum_v != NULL); 614 free(enum_v); 615 } 616 617 /** Deallocate array. 618 * 619 * @param array_v Array 620 */ 621 void rdata_array_delete(rdata_array_t *array_v) 622 { 623 assert(array_v != NULL); 624 free(array_v); 625 } 626 627 /** Deallocate object. 628 * 629 * @param object_v Object 630 */ 631 void rdata_object_delete(rdata_object_t *object_v) 632 { 633 assert(object_v != NULL); 634 free(object_v); 635 } 636 637 /** Deallocate resource. 638 * 639 * @param resource_v Resource 640 */ 641 void rdata_resource_delete(rdata_resource_t *resource_v) 642 { 643 assert(resource_v != NULL); 644 free(resource_v); 645 } 646 647 /** Deallocate symbol. 648 * 649 * @param symbol_v Symbol 650 */ 651 void rdata_symbol_delete(rdata_symbol_t *symbol_v) 652 { 653 assert(symbol_v != NULL); 654 free(symbol_v); 655 } 656 657 /** Copy value. 658 * 659 * @param src Input value 660 * @param dest Place to store pointer to new value 661 */ 662 void rdata_value_copy(rdata_value_t *src, rdata_value_t **dest) 663 { 664 assert(src != NULL); 665 666 *dest = rdata_value_new(); 667 rdata_var_copy(src->var, &(*dest)->var); 668 } 669 459 670 /** Make copy of a variable. 460 671 * … … 470 681 471 682 nvar = rdata_var_new(src->vc); 683 rdata_var_copy_to(src, nvar); 684 685 *dest = nvar; 686 } 687 688 /** Copy variable content to another variable. 689 * 690 * Writes an exact copy of an existing var node to another var node. 691 * The varclass of @a src and @a dest must match. The content of 692 * @a dest.u must be invalid. 693 * 694 * @param src Source var node. 695 * @param dest Destination var node. 696 */ 697 static void rdata_var_copy_to(rdata_var_t *src, rdata_var_t *dest) 698 { 699 dest->vc = src->vc; 472 700 473 701 switch (src->vc) { 474 702 case vc_bool: 475 rdata_bool_copy(src->u.bool_v, & nvar->u.bool_v);703 rdata_bool_copy(src->u.bool_v, &dest->u.bool_v); 476 704 break; 477 705 case vc_char: 478 rdata_char_copy(src->u.char_v, & nvar->u.char_v);706 rdata_char_copy(src->u.char_v, &dest->u.char_v); 479 707 break; 480 708 case vc_int: 481 rdata_int_copy(src->u.int_v, & nvar->u.int_v);709 rdata_int_copy(src->u.int_v, &dest->u.int_v); 482 710 break; 483 711 case vc_string: 484 rdata_string_copy(src->u.string_v, & nvar->u.string_v);712 rdata_string_copy(src->u.string_v, &dest->u.string_v); 485 713 break; 486 714 case vc_ref: 487 rdata_ref_copy(src->u.ref_v, & nvar->u.ref_v);715 rdata_ref_copy(src->u.ref_v, &dest->u.ref_v); 488 716 break; 489 717 case vc_deleg: 490 rdata_deleg_copy(src->u.deleg_v, & nvar->u.deleg_v);718 rdata_deleg_copy(src->u.deleg_v, &dest->u.deleg_v); 491 719 break; 492 720 case vc_enum: 493 rdata_enum_copy(src->u.enum_v, & nvar->u.enum_v);721 rdata_enum_copy(src->u.enum_v, &dest->u.enum_v); 494 722 break; 495 723 case vc_array: 496 rdata_array_copy(src->u.array_v, & nvar->u.array_v);724 rdata_array_copy(src->u.array_v, &dest->u.array_v); 497 725 break; 498 726 case vc_object: 499 rdata_object_copy(src->u.object_v, & nvar->u.object_v);727 rdata_object_copy(src->u.object_v, &dest->u.object_v); 500 728 break; 501 729 case vc_resource: 502 rdata_resource_copy(src->u.resource_v, & nvar->u.resource_v);730 rdata_resource_copy(src->u.resource_v, &dest->u.resource_v); 503 731 break; 504 732 case vc_symbol: 505 rdata_symbol_copy(src->u.symbol_v, &nvar->u.symbol_v); 506 break; 507 } 508 509 *dest = nvar; 510 } 733 rdata_symbol_copy(src->u.symbol_v, &dest->u.symbol_v); 734 break; 735 } 736 } 737 511 738 512 739 /** Copy boolean. 513 740 * 514 * @param src Source boolean .515 * @param dest Place to store pointer to new boolean .741 * @param src Source boolean 742 * @param dest Place to store pointer to new boolean 516 743 */ 517 744 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest) … … 523 750 /** Copy character. 524 751 * 525 * @param src Source character .526 * @param dest Place to store pointer to new character .752 * @param src Source character 753 * @param dest Place to store pointer to new character 527 754 */ 528 755 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest) … … 534 761 /** Copy integer. 535 762 * 536 * @param src Source integer .537 * @param dest Place to store pointer to new integer .763 * @param src Source integer 764 * @param dest Place to store pointer to new integer 538 765 */ 539 766 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest) … … 632 859 *dest = rdata_symbol_new(); 633 860 (*dest)->sym = src->sym; 861 } 862 863 /** Destroy var node. 864 * 865 * @param var Var node 866 */ 867 void rdata_var_destroy(rdata_var_t *var) 868 { 869 /* First destroy class-specific part */ 870 rdata_var_destroy_inner(var); 871 872 /* Deallocate var node */ 873 rdata_var_delete(var); 874 } 875 876 /** Destroy inside of var node. 877 * 878 * Destroy content of var node, but do not deallocate the var node 879 * itself. 880 * 881 * @param var Var node 882 */ 883 static void rdata_var_destroy_inner(rdata_var_t *var) 884 { 885 /* First destroy class-specific part */ 886 887 switch (var->vc) { 888 case vc_bool: 889 rdata_bool_destroy(var->u.bool_v); 890 break; 891 case vc_char: 892 rdata_char_destroy(var->u.char_v); 893 break; 894 case vc_int: 895 rdata_int_destroy(var->u.int_v); 896 break; 897 case vc_string: 898 rdata_string_destroy(var->u.string_v); 899 break; 900 case vc_ref: 901 rdata_ref_destroy(var->u.ref_v); 902 break; 903 case vc_deleg: 904 rdata_deleg_destroy(var->u.deleg_v); 905 break; 906 case vc_enum: 907 rdata_enum_destroy(var->u.enum_v); 908 break; 909 case vc_array: 910 rdata_array_destroy(var->u.array_v); 911 break; 912 case vc_object: 913 rdata_object_destroy(var->u.object_v); 914 break; 915 case vc_resource: 916 rdata_resource_destroy(var->u.resource_v); 917 break; 918 case vc_symbol: 919 rdata_symbol_destroy(var->u.symbol_v); 920 break; 921 } 922 } 923 924 /** Destroy item. 925 * 926 * Destroy an item including the value or address within. 927 * 928 * @param item Item 929 */ 930 void rdata_item_destroy(rdata_item_t *item) 931 { 932 /* First destroy class-specific part */ 933 934 switch (item->ic) { 935 case ic_address: 936 rdata_address_destroy(item->u.address); 937 break; 938 case ic_value: 939 rdata_value_destroy(item->u.value); 940 break; 941 } 942 943 /* Deallocate item node */ 944 rdata_item_delete(item); 945 } 946 947 /** Destroy address. 948 * 949 * Destroy an address node. 950 * 951 * @param address Address 952 */ 953 void rdata_address_destroy(rdata_address_t *address) 954 { 955 switch (address->ac) { 956 case ac_var: 957 rdata_addr_var_destroy(address->u.var_a); 958 break; 959 case ac_prop: 960 rdata_addr_prop_destroy(address->u.prop_a); 961 break; 962 } 963 964 /* Deallocate address node */ 965 rdata_address_delete(address); 966 } 967 968 /** Destroy variable address. 969 * 970 * Destroy a variable address node. 971 * 972 * @param addr_var Variable address 973 */ 974 void rdata_addr_var_destroy(rdata_addr_var_t *addr_var) 975 { 976 addr_var->vref = NULL; 977 978 /* Deallocate variable address node */ 979 rdata_addr_var_delete(addr_var); 980 } 981 982 /** Destroy property address. 983 * 984 * Destroy a property address node. 985 * 986 * @param addr_prop Property address 987 */ 988 void rdata_addr_prop_destroy(rdata_addr_prop_t *addr_prop) 989 { 990 switch (addr_prop->apc) { 991 case apc_named: 992 rdata_aprop_named_destroy(addr_prop->u.named); 993 break; 994 case apc_indexed: 995 rdata_aprop_indexed_destroy(addr_prop->u.indexed); 996 break; 997 } 998 999 if (addr_prop->tvalue != NULL) { 1000 rdata_value_destroy(addr_prop->tvalue); 1001 addr_prop->tvalue = NULL; 1002 } 1003 1004 addr_prop->tpos = NULL; 1005 1006 /* Deallocate property address node */ 1007 rdata_addr_prop_delete(addr_prop); 1008 } 1009 1010 /** Destroy named property address. 1011 * 1012 * Destroy a named property address node. 1013 * 1014 * @param aprop_named Named property address 1015 */ 1016 void rdata_aprop_named_destroy(rdata_aprop_named_t *aprop_named) 1017 { 1018 rdata_deleg_destroy(aprop_named->prop_d); 1019 1020 /* Deallocate named property address node */ 1021 rdata_aprop_named_delete(aprop_named); 1022 } 1023 1024 /** Destroy indexed property address. 1025 * 1026 * Destroy a indexed property address node. 1027 * 1028 * @param aprop_indexed Indexed property address 1029 */ 1030 void rdata_aprop_indexed_destroy(rdata_aprop_indexed_t *aprop_indexed) 1031 { 1032 list_node_t *arg_node; 1033 rdata_item_t *arg_i; 1034 1035 /* Destroy the object delegate. */ 1036 rdata_deleg_destroy(aprop_indexed->object_d); 1037 1038 /* 1039 * Walk through all argument items (indices) and destroy them, 1040 * removing them from the list as well. 1041 */ 1042 while (!list_is_empty(&aprop_indexed->args)) { 1043 arg_node = list_first(&aprop_indexed->args); 1044 arg_i = list_node_data(arg_node, rdata_item_t *); 1045 1046 rdata_item_destroy(arg_i); 1047 list_remove(&aprop_indexed->args, arg_node); 1048 } 1049 1050 /* Destroy the now empty list */ 1051 list_fini(&aprop_indexed->args); 1052 1053 /* Deallocate indexed property address node */ 1054 rdata_aprop_indexed_delete(aprop_indexed); 1055 } 1056 1057 /** Destroy value. 1058 * 1059 * Destroy a value node. 1060 * 1061 * @param value Value 1062 */ 1063 void rdata_value_destroy(rdata_value_t *value) 1064 { 1065 /* Assumption: Var nodes in values are not shared. */ 1066 rdata_var_destroy(value->var); 1067 1068 /* Deallocate value node */ 1069 rdata_value_delete(value); 1070 } 1071 1072 /** Destroy boolean. 1073 * 1074 * @param bool_v Boolean 1075 */ 1076 static void rdata_bool_destroy(rdata_bool_t *bool_v) 1077 { 1078 rdata_bool_delete(bool_v); 1079 } 1080 1081 /** Destroy character. 1082 * 1083 * @param char_v Character 1084 */ 1085 static void rdata_char_destroy(rdata_char_t *char_v) 1086 { 1087 bigint_destroy(&char_v->value); 1088 rdata_char_delete(char_v); 1089 } 1090 1091 /** Destroy integer. 1092 * 1093 * @param int_v Integer 1094 */ 1095 static void rdata_int_destroy(rdata_int_t *int_v) 1096 { 1097 bigint_destroy(&int_v->value); 1098 rdata_int_delete(int_v); 1099 } 1100 1101 /** Destroy string. 1102 * 1103 * @param string_v String 1104 */ 1105 static void rdata_string_destroy(rdata_string_t *string_v) 1106 { 1107 /* 1108 * String values are shared so we cannot free them. Just deallocate 1109 * the node. 1110 */ 1111 rdata_string_delete(string_v); 1112 } 1113 1114 /** Destroy reference. 1115 * 1116 * @param ref_v Reference 1117 */ 1118 static void rdata_ref_destroy(rdata_ref_t *ref_v) 1119 { 1120 ref_v->vref = NULL; 1121 rdata_ref_delete(ref_v); 1122 } 1123 1124 /** Destroy delegate. 1125 * 1126 * @param deleg_v Reference 1127 */ 1128 static void rdata_deleg_destroy(rdata_deleg_t *deleg_v) 1129 { 1130 deleg_v->obj = NULL; 1131 deleg_v->sym = NULL; 1132 rdata_deleg_delete(deleg_v); 1133 } 1134 1135 /** Destroy enum. 1136 * 1137 * @param enum_v Reference 1138 */ 1139 static void rdata_enum_destroy(rdata_enum_t *enum_v) 1140 { 1141 enum_v->value = NULL; 1142 rdata_enum_delete(enum_v); 1143 } 1144 1145 /** Destroy array. 1146 * 1147 * @param array_v Array 1148 */ 1149 static void rdata_array_destroy(rdata_array_t *array_v) 1150 { 1151 int d; 1152 size_t n_elems, p; 1153 1154 /* 1155 * Compute total number of elements in array. 1156 * At the same time zero out the extent array. 1157 */ 1158 n_elems = 1; 1159 for (d = 0; d < array_v->rank; d++) { 1160 n_elems = n_elems * array_v->extent[d]; 1161 array_v->extent[d] = 0; 1162 } 1163 1164 /* Destroy all elements and zero out the array */ 1165 for (p = 0; p < n_elems; p++) { 1166 rdata_var_delete(array_v->element[p]); 1167 array_v->element[p] = NULL; 1168 } 1169 1170 /* Free the arrays */ 1171 free(array_v->element); 1172 free(array_v->extent); 1173 1174 array_v->rank = 0; 1175 1176 /* Deallocate the node */ 1177 rdata_array_delete(array_v); 1178 } 1179 1180 /** Destroy object. 1181 * 1182 * @param object_v Object 1183 */ 1184 static void rdata_object_destroy(rdata_object_t *object_v) 1185 { 1186 /* XXX TODO */ 1187 rdata_object_delete(object_v); 1188 } 1189 1190 /** Destroy resource. 1191 * 1192 * @param resource_v Resource 1193 */ 1194 static void rdata_resource_destroy(rdata_resource_t *resource_v) 1195 { 1196 /* 1197 * XXX Presumably this should be handled by the appropriate 1198 * built-in module, so, some call-back function would be required. 1199 */ 1200 resource_v->data = NULL; 1201 rdata_resource_delete(resource_v); 1202 } 1203 1204 /** Destroy symbol. 1205 * 1206 * @param symbol_v Symbol 1207 */ 1208 static void rdata_symbol_destroy(rdata_symbol_t *symbol_v) 1209 { 1210 symbol_v->sym = NULL; 1211 rdata_symbol_delete(symbol_v); 634 1212 } 635 1213 … … 671 1249 void rdata_var_write(rdata_var_t *var, rdata_value_t *value) 672 1250 { 673 rdata_var_t *nvar; 1251 /* Free old content of var->u */ 1252 rdata_var_destroy_inner(var); 674 1253 675 1254 /* Perform a shallow copy of @c value->var. */ 676 rdata_var_copy(value->var, &nvar); 677 678 /* XXX do this in a prettier way. */ 679 680 var->vc = nvar->vc; 681 switch (nvar->vc) { 682 case vc_bool: var->u.bool_v = nvar->u.bool_v; break; 683 case vc_char: var->u.char_v = nvar->u.char_v; break; 684 case vc_int: var->u.int_v = nvar->u.int_v; break; 685 case vc_string: var->u.string_v = nvar->u.string_v; break; 686 case vc_ref: var->u.ref_v = nvar->u.ref_v; break; 687 case vc_deleg: var->u.deleg_v = nvar->u.deleg_v; break; 688 case vc_enum: var->u.enum_v = nvar->u.enum_v; break; 689 case vc_array: var->u.array_v = nvar->u.array_v; break; 690 case vc_object: var->u.object_v = nvar->u.object_v; break; 691 case vc_resource: var->u.resource_v = nvar->u.resource_v; break; 692 case vc_symbol: var->u.symbol_v = nvar->u.symbol_v; break; 693 } 694 695 /* XXX We should free some stuff around here. */ 1255 rdata_var_copy_to(value->var, var); 696 1256 } 697 1257 -
uspace/app/sbi/src/rdata.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 42 42 rdata_var_t *rdata_var_new(var_class_t vc); 43 void rdata_var_delete(rdata_var_t *var); 43 44 rdata_ref_t *rdata_ref_new(void); 44 45 rdata_deleg_t *rdata_deleg_new(void); … … 53 54 rdata_symbol_t *rdata_symbol_new(void); 54 55 56 void rdata_address_delete(rdata_address_t *address); 57 void rdata_value_delete(rdata_value_t *value); 58 void rdata_var_delete(rdata_var_t *var); 59 void rdata_item_delete(rdata_item_t *item); 60 void rdata_addr_var_delete(rdata_addr_var_t *addr_var); 61 void rdata_addr_prop_delete(rdata_addr_prop_t *addr_prop); 62 void rdata_aprop_named_delete(rdata_aprop_named_t *aprop_named); 63 void rdata_aprop_indexed_delete(rdata_aprop_indexed_t *aprop_indexed); 64 65 void rdata_bool_delete(rdata_bool_t *bool_v); 66 void rdata_char_delete(rdata_char_t *char_v); 67 void rdata_int_delete(rdata_int_t *int_v); 68 void rdata_string_delete(rdata_string_t *string_v); 69 void rdata_ref_delete(rdata_ref_t *ref_v); 70 void rdata_deleg_delete(rdata_deleg_t *deleg_v); 71 void rdata_enum_delete(rdata_enum_t *enum_v); 72 void rdata_array_delete(rdata_array_t *array_v); 73 void rdata_object_delete(rdata_object_t *object_v); 74 void rdata_resource_delete(rdata_resource_t *resource_v); 75 void rdata_symbol_delete(rdata_symbol_t *symbol_v); 76 55 77 void rdata_array_alloc_element(rdata_array_t *array); 78 void rdata_value_copy(rdata_value_t *val, rdata_value_t **rval); 56 79 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest); 80 81 void rdata_address_destroy(rdata_address_t *address); 82 void rdata_addr_var_destroy(rdata_addr_var_t *addr_var); 83 void rdata_addr_prop_destroy(rdata_addr_prop_t *addr_prop); 84 void rdata_aprop_named_destroy(rdata_aprop_named_t *aprop_named); 85 void rdata_aprop_indexed_destroy(rdata_aprop_indexed_t *aprop_indexed); 86 void rdata_value_destroy(rdata_value_t *value); 87 void rdata_var_destroy(rdata_var_t *var); 88 void rdata_item_destroy(rdata_item_t *item); 57 89 58 90 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem); -
uspace/app/sbi/src/rdata_t.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 272 272 typedef struct rdata_value { 273 273 /** 274 * Read-only Variable holding a copy of the data. The same @c var 275 * can be shared between different instances of @c rdata_value_t. 274 * Read-only Variable holding a copy of the data. Currently we don't 275 * allow sharing the same @c var node between different value nodes 276 * so that when destroying the value we can destroy the var. 277 * 278 * We could share this, but would need to reference-count it. 276 279 */ 277 280 rdata_var_t *var; -
uspace/app/sbi/src/run.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 53 53 static void run_vdecl(run_t *run, stree_vdecl_t *vdecl); 54 54 static void run_if(run_t *run, stree_if_t *if_s); 55 static void run_switch(run_t *run, stree_switch_t *switch_s); 55 56 static void run_while(run_t *run, stree_while_t *while_s); 56 57 static void run_raise(run_t *run, stree_raise_t *raise_s); … … 142 143 run_proc_ar_set_args(run, proc_ar, &main_args); 143 144 run_proc(run, proc_ar, &res); 145 run_proc_ar_destroy(run, proc_ar); 144 146 145 147 run_exc_check_unhandled(run); … … 272 274 assert(list_node_data(node, run_block_ar_t *) == block_ar); 273 275 list_remove(&proc_ar->block_ar, node); 276 277 /* Deallocate block activation record. */ 278 run_block_ar_destroy(run, block_ar); 274 279 } 275 280 … … 303 308 run_if(run, stat->u.if_s); 304 309 break; 310 case st_switch: 311 run_switch(run, stat->u.switch_s); 312 break; 305 313 case st_while: 306 314 run_while(run, stat->u.while_s); … … 342 350 run_expr(run, exps->expr, &rexpr); 343 351 352 /* 353 * If the expression has a value, the caller should have asked for it. 354 */ 355 assert(res != NULL || rexpr == NULL); 356 344 357 if (res != NULL) 345 358 *res = rexpr; … … 355 368 run_block_ar_t *block_ar; 356 369 rdata_var_t *var, *old_var; 357 tdata_item_t *var_ti;358 370 359 371 #ifdef DEBUG_RUN_TRACE 360 372 printf("Executing variable declaration statement.\n"); 361 373 #endif 362 /* Compute variable type. XXX Memoize. */363 run_texpr(run->program, run_get_current_csi(run), vdecl->type,364 &var_ti);365 366 374 /* Create variable and initialize with default value. */ 367 run_var_new(run, v ar_ti, &var);375 run_var_new(run, vdecl->titem, &var); 368 376 369 377 block_ar = run_get_current_block_ar(run); … … 393 401 list_node_t *ifc_node; 394 402 stree_if_clause_t *ifc; 395 bool_t clause_fired;403 bool_t rcond_b, clause_fired; 396 404 397 405 #ifdef DEBUG_RUN_TRACE … … 411 419 return; 412 420 413 if (run_item_boolean_value(run, rcond) == b_true) { 421 rcond_b = run_item_boolean_value(run, rcond); 422 rdata_item_destroy(rcond); 423 424 if (rcond_b == b_true) { 414 425 #ifdef DEBUG_RUN_TRACE 415 426 printf("Taking non-default path.\n"); … … 436 447 } 437 448 449 /** Run @c switch statement. 450 * 451 * @param run Runner object 452 * @param switch_s Switch statement to run 453 */ 454 static void run_switch(run_t *run, stree_switch_t *switch_s) 455 { 456 rdata_item_t *rsexpr, *rsexpr_vi; 457 rdata_item_t *rwexpr, *rwexpr_vi; 458 list_node_t *whenc_node; 459 stree_when_t *whenc; 460 list_node_t *expr_node; 461 stree_expr_t *expr; 462 bool_t clause_fired; 463 bool_t equal; 464 465 #ifdef DEBUG_RUN_TRACE 466 printf("Executing switch statement.\n"); 467 #endif 468 rsexpr_vi = NULL; 469 470 /* Evaluate switch expression */ 471 run_expr(run, switch_s->expr, &rsexpr); 472 if (run_is_bo(run)) 473 goto cleanup; 474 475 /* Convert to value item */ 476 run_cvt_value_item(run, rsexpr, &rsexpr_vi); 477 rdata_item_destroy(rsexpr); 478 if (run_is_bo(run)) 479 goto cleanup; 480 481 clause_fired = b_false; 482 whenc_node = list_first(&switch_s->when_clauses); 483 484 /* Walk through all when clauses and see if they fire. */ 485 486 while (whenc_node != NULL) { 487 /* Get when clause */ 488 whenc = list_node_data(whenc_node, stree_when_t *); 489 490 expr_node = list_first(&whenc->exprs); 491 492 /* Walk through all expressions in the when clause */ 493 while (expr_node != NULL) { 494 /* Get expression */ 495 expr = list_node_data(expr_node, stree_expr_t *); 496 497 /* Evaluate expression */ 498 run_expr(run, expr, &rwexpr); 499 if (run_is_bo(run)) 500 goto cleanup; 501 502 /* Convert to value item */ 503 run_cvt_value_item(run, rwexpr, &rwexpr_vi); 504 rdata_item_destroy(rwexpr); 505 if (run_is_bo(run)) { 506 rdata_item_destroy(rwexpr_vi); 507 goto cleanup; 508 } 509 510 /* Check if values are equal ('==') */ 511 run_equal(run, rsexpr_vi->u.value, 512 rwexpr_vi->u.value, &equal); 513 rdata_item_destroy(rwexpr_vi); 514 if (run_is_bo(run)) 515 goto cleanup; 516 517 if (equal) { 518 #ifdef DEBUG_RUN_TRACE 519 printf("Taking non-default path.\n"); 520 #endif 521 run_block(run, whenc->block); 522 clause_fired = b_true; 523 break; 524 } 525 526 expr_node = list_next(&whenc->exprs, expr_node); 527 } 528 529 if (clause_fired) 530 break; 531 532 whenc_node = list_next(&switch_s->when_clauses, whenc_node); 533 } 534 535 /* If no when clause fired, invoke the else clause. */ 536 if (clause_fired == b_false && switch_s->else_block != NULL) { 537 #ifdef DEBUG_RUN_TRACE 538 printf("Taking default path.\n"); 539 #endif 540 run_block(run, switch_s->else_block); 541 } 542 cleanup: 543 if (rsexpr_vi != NULL) 544 rdata_item_destroy(rsexpr_vi); 545 546 #ifdef DEBUG_RUN_TRACE 547 printf("Switch statement terminated.\n"); 548 #endif 549 } 550 438 551 /** Run @c while statement. 439 552 * … … 453 566 454 567 while (run_item_boolean_value(run, rcond) == b_true) { 568 rdata_item_destroy(rcond); 455 569 run_block(run, while_s->body); 456 570 run_expr(run, while_s->cond, &rcond); … … 459 573 } 460 574 575 if (rcond != NULL) 576 rdata_item_destroy(rcond); 577 461 578 if (run->thread_ar->bo_mode == bm_stat) { 462 579 /* Bailout due to break statement */ … … 487 604 488 605 run_cvt_value_item(run, rexpr, &rexpr_vi); 606 rdata_item_destroy(rexpr); 607 if (run_is_bo(run)) 608 return; 489 609 490 610 /* Store expression cspan in thread AR. */ … … 492 612 493 613 /* Store expression result in thread AR. */ 614 /* XXX rexpr_vi is leaked here, we only return ->u.value */ 494 615 run->thread_ar->exc_payload = rexpr_vi->u.value; 495 616 … … 541 662 542 663 run_cvt_value_item(run, rexpr, &rexpr_vi); 664 rdata_item_destroy(rexpr); 665 if (run_is_bo(run)) 666 return; 543 667 544 668 /* Store expression result in procedure AR. */ … … 632 756 { 633 757 stree_csi_t *exc_csi; 634 tdata_item_t *etype;635 758 636 759 /* Get CSI of active exception. */ 637 760 exc_csi = run_exc_payload_get_csi(run); 638 761 639 /* Evaluate type expression in except clause. */640 run_texpr(run->program, run_get_current_csi(run), except_c->etype,641 &etype);642 643 762 /* Determine if active exc. is derived from type in exc. clause. */ 644 763 /* XXX This is wrong, it does not work with generics. */ 645 return tdata_is_csi_derived_from_ti(exc_csi, e type);764 return tdata_is_csi_derived_from_ti(exc_csi, except_c->titem); 646 765 } 647 766 … … 1009 1128 (void) run; 1010 1129 1011 /* Create functionactivation record. */1130 /* Create procedure activation record. */ 1012 1131 proc_ar = run_proc_ar_new(); 1013 1132 proc_ar->obj = obj; … … 1024 1143 *rproc_ar = proc_ar; 1025 1144 } 1145 1146 /** Destroy a procedure AR. 1147 * 1148 * @param run Runner object 1149 * @param proc_ar Pointer to procedure activation record 1150 */ 1151 void run_proc_ar_destroy(run_t *run, run_proc_ar_t *proc_ar) 1152 { 1153 list_node_t *ar_node; 1154 run_block_ar_t *block_ar; 1155 1156 (void) run; 1157 1158 /* Destroy special block activation record. */ 1159 ar_node = list_first(&proc_ar->block_ar); 1160 block_ar = list_node_data(ar_node, run_block_ar_t *); 1161 list_remove(&proc_ar->block_ar, ar_node); 1162 run_block_ar_destroy(run, block_ar); 1163 1164 /* Destroy procedure activation record. */ 1165 proc_ar->obj = NULL; 1166 proc_ar->proc = NULL; 1167 list_fini(&proc_ar->block_ar); 1168 proc_ar->retval = NULL; 1169 run_proc_ar_delete(proc_ar); 1170 } 1171 1026 1172 1027 1173 /** Fill arguments in a procedure AR. … … 1055 1201 rdata_ref_t *ref; 1056 1202 rdata_array_t *array; 1203 rdata_var_t *elem_var; 1057 1204 int n_vargs, idx; 1058 1205 … … 1147 1294 assert(rarg->ic == ic_value); 1148 1295 1149 rdata_var_write(array->element[idx], rarg->u.value); 1296 run_value_item_to_var(rarg, &elem_var); 1297 array->element[idx] = elem_var; 1150 1298 1151 1299 rarg_n = list_next(arg_vals, rarg_n); … … 1241 1389 } 1242 1390 1391 /** Destroy a block AR. 1392 * 1393 * @param run Runner object 1394 * @param proc_ar Pointer to block activation record 1395 */ 1396 void run_block_ar_destroy(run_t *run, run_block_ar_t *block_ar) 1397 { 1398 map_elem_t *elem; 1399 rdata_var_t *var; 1400 int key; 1401 1402 (void) run; 1403 1404 elem = intmap_first(&block_ar->vars); 1405 while (elem != NULL) { 1406 /* Destroy the variable */ 1407 var = intmap_elem_get_value(elem); 1408 rdata_var_destroy(var); 1409 1410 /* Remove the map element */ 1411 key = intmap_elem_get_key(elem); 1412 intmap_set(&block_ar->vars, key, NULL); 1413 1414 elem = intmap_first(&block_ar->vars); 1415 } 1416 1417 intmap_fini(&block_ar->vars); 1418 run_block_ar_delete(block_ar); 1419 } 1420 1243 1421 /** Convert item to value item. 1244 1422 * … … 1269 1447 } 1270 1448 1271 /* It already is a value, we can share the @c var. */1449 /* Make a copy of the var node within. */ 1272 1450 value = rdata_value_new(); 1273 value->var = item->u.value->var;1451 rdata_var_copy(item->u.value->var, &value->var); 1274 1452 *ritem = rdata_item_new(ic_value); 1275 1453 (*ritem)->u.value = value; … … 1358 1536 { 1359 1537 (void) run; 1538 assert(ritem != NULL); 1360 1539 1361 1540 switch (address->ac) { … … 1368 1547 } 1369 1548 1370 assert( (*ritem)->ic == ic_value);1549 assert(*ritem == NULL || (*ritem)->ic == ic_value); 1371 1550 } 1372 1551 … … 1457 1636 run_proc(run, proc_ar, ritem); 1458 1637 1638 /* Destroy procedure activation record. */ 1639 run_proc_ar_destroy(run, proc_ar); 1640 1459 1641 #ifdef DEBUG_RUN_TRACE 1460 1642 printf("Getter returns "); … … 1529 1711 /* Setter should not return a value. */ 1530 1712 assert(ritem == NULL); 1713 1714 /* Destroy procedure activation record. */ 1715 run_proc_ar_destroy(run, proc_ar); 1531 1716 1532 1717 #ifdef DEBUG_RUN_TRACE … … 1590 1775 #endif 1591 1776 run_cvt_value_item(run, ref, &ref_val); 1777 if (run_is_bo(run)) { 1778 *ritem = run_recovery_item(run); 1779 return; 1780 } 1781 1592 1782 assert(ref_val->u.value->var->vc == vc_ref); 1593 1783 … … 1598 1788 address->u.var_a = addr_var; 1599 1789 addr_var->vref = ref_val->u.value->var->u.ref_v->vref; 1790 1791 rdata_item_destroy(ref_val); 1600 1792 1601 1793 if (addr_var->vref == NULL) { … … 1840 2032 } 1841 2033 1842 /** Construct a new procedure activation record. 1843 * 1844 * @param run Runner object 2034 /** Allocate a new procedure activation record. 2035 * 1845 2036 * @return New procedure AR. 1846 2037 */ … … 1858 2049 } 1859 2050 1860 /** Construct a new block activation record. 2051 /** Deallocate a procedure activation record. 2052 * 2053 * @return New procedure AR. 2054 */ 2055 void run_proc_ar_delete(run_proc_ar_t *proc_ar) 2056 { 2057 assert(proc_ar != NULL); 2058 free(proc_ar); 2059 } 2060 2061 /** Allocate a new block activation record. 1861 2062 * 1862 2063 * @param run Runner object … … 1875 2076 return block_ar; 1876 2077 } 2078 2079 /** Deallocate a new block activation record. 2080 * 2081 * @param run Runner object 2082 * @return New block AR. 2083 */ 2084 void run_block_ar_delete(run_block_ar_t *block_ar) 2085 { 2086 assert(block_ar != NULL); 2087 free(block_ar); 2088 } -
uspace/app/sbi/src/run.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 61 61 void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc, 62 62 run_proc_ar_t **rproc_ar); 63 void run_proc_ar_destroy(run_t *run, run_proc_ar_t *proc_ar); 63 64 64 65 var_class_t run_item_get_vc(run_t *run, rdata_item_t *item); … … 79 80 run_thread_ar_t *run_thread_ar_new(void); 80 81 run_proc_ar_t *run_proc_ar_new(void); 82 void run_proc_ar_delete(run_proc_ar_t *proc_ar); 81 83 run_block_ar_t *run_block_ar_new(void); 84 void run_block_ar_delete(run_block_ar_t *block_ar); 85 void run_proc_ar_delete(run_proc_ar_t *proc_ar); 86 void run_block_ar_destroy(run_t *run, run_block_ar_t *block_ar); 87 82 88 83 89 #endif -
uspace/app/sbi/src/run_expr.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 113 113 static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res); 114 114 static void run_call_args(run_t *run, list_t *args, list_t *arg_vals); 115 static void run_destroy_arg_vals(list_t *arg_vals); 115 116 116 117 static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res); … … 200 201 rdata_address_t *address; 201 202 rdata_addr_var_t *addr_var; 203 rdata_addr_prop_t *addr_prop; 204 rdata_aprop_named_t *aprop_named; 205 rdata_deleg_t *deleg_p; 202 206 rdata_value_t *value; 203 207 rdata_var_t *var; … … 334 338 break; 335 339 case sc_var: 336 #ifdef DEBUG_RUN_TRACE 337 printf("Referencing member variable.\n"); 338 #endif 339 /* There should be no global variables. */ 340 case sc_prop: 341 #ifdef DEBUG_RUN_TRACE 342 if (sym->sc == sc_var) 343 printf("Referencing member variable.\n"); 344 else 345 printf("Referencing unqualified property.\n"); 346 #endif 347 /* There should be no global variables or properties. */ 340 348 assert(csi != NULL); 341 349 342 350 if (symbol_search_csi(run->program, csi, nameref->name) 343 351 == NULL && !stree_symbol_is_static(sym)) { 344 /* Variableis not in the current object. */352 /* Symbol is not in the current object. */ 345 353 printf("Error: Cannot access non-static member " 346 354 "variable '"); … … 352 360 } 353 361 362 /* 363 * Determine object in which the symbol resides 364 */ 354 365 if (stree_symbol_is_static(sym)) { 355 366 /* 367 * Class object 356 368 * XXX This is too slow! 357 369 * … … 365 377 aobj = sobj->u.object_v; 366 378 } else { 367 aobj = obj; 379 /* 380 * Instance object. Currently we don't support 381 * true inner classes, thus we know the symbol is 382 * in the active object (there is no dynamic parent). 383 */ 384 sobj = proc_ar->obj; 385 aobj = sobj->u.object_v;; 368 386 } 369 387 370 /* Find member variable in object. */ 371 member_var = intmap_get(&aobj->fields, nameref->name->sid); 372 assert(member_var != NULL); 373 374 /* Return address of the variable. */ 375 item = rdata_item_new(ic_address); 376 address = rdata_address_new(ac_var); 377 addr_var = rdata_addr_var_new(); 378 379 item->u.address = address; 380 address->u.var_a = addr_var; 381 addr_var->vref = member_var; 382 383 *res = item; 384 break; 385 case sc_prop: 386 /* XXX TODO */ 387 printf("Unimplemented: Property name reference.\n"); 388 abort(); 388 if (sym->sc == sc_var) { 389 /* Find member variable in object. */ 390 member_var = intmap_get(&aobj->fields, 391 nameref->name->sid); 392 assert(member_var != NULL); 393 394 /* Return address of the variable. */ 395 item = rdata_item_new(ic_address); 396 address = rdata_address_new(ac_var); 397 addr_var = rdata_addr_var_new(); 398 399 item->u.address = address; 400 address->u.var_a = addr_var; 401 addr_var->vref = member_var; 402 403 *res = item; 404 } else { 405 /* Construct named property address. */ 406 item = rdata_item_new(ic_address); 407 address = rdata_address_new(ac_prop); 408 addr_prop = rdata_addr_prop_new(apc_named); 409 aprop_named = rdata_aprop_named_new(); 410 item->u.address = address; 411 address->u.prop_a = addr_prop; 412 addr_prop->u.named = aprop_named; 413 414 deleg_p = rdata_deleg_new(); 415 deleg_p->obj = sobj; 416 deleg_p->sym = sym; 417 addr_prop->u.named->prop_d = deleg_p; 418 419 *res = item; 420 } 389 421 break; 390 422 } … … 611 643 rdata_value_t *v1, *v2; 612 644 645 rarg1_i = NULL; 646 rarg2_i = NULL; 647 rarg1_vi = NULL; 648 rarg2_vi = NULL; 649 613 650 #ifdef DEBUG_RUN_TRACE 614 651 printf("Run binary operation.\n"); … … 616 653 run_expr(run, binop->arg1, &rarg1_i); 617 654 if (run_is_bo(run)) { 618 *res = NULL; 619 return; 655 *res = run_recovery_item(run); 656 goto cleanup; 657 } 658 659 #ifdef DEBUG_RUN_TRACE 660 printf("Check binop argument result.\n"); 661 #endif 662 run_cvt_value_item(run, rarg1_i, &rarg1_vi); 663 if (run_is_bo(run)) { 664 *res = run_recovery_item(run); 665 goto cleanup; 620 666 } 621 667 622 668 run_expr(run, binop->arg2, &rarg2_i); 623 669 if (run_is_bo(run)) { 624 *res = NULL; 625 return; 626 } 627 628 #ifdef DEBUG_RUN_TRACE 629 printf("Check binop argument results.\n"); 630 #endif 631 632 run_cvt_value_item(run, rarg1_i, &rarg1_vi); 670 *res = run_recovery_item(run); 671 goto cleanup; 672 } 673 674 #ifdef DEBUG_RUN_TRACE 675 printf("Check binop argument result.\n"); 676 #endif 633 677 run_cvt_value_item(run, rarg2_i, &rarg2_vi); 678 if (run_is_bo(run)) { 679 *res = run_recovery_item(run); 680 goto cleanup; 681 } 634 682 635 683 v1 = rarg1_vi->u.value; … … 668 716 assert(b_false); 669 717 } 718 719 cleanup: 720 if (rarg1_i != NULL) 721 rdata_item_destroy(rarg1_i); 722 if (rarg2_i != NULL) 723 rdata_item_destroy(rarg2_i); 724 if (rarg1_vi != NULL) 725 rdata_item_destroy(rarg1_vi); 726 if (rarg2_vi != NULL) 727 rdata_item_destroy(rarg2_vi); 670 728 } 671 729 … … 1054 1112 rdata_bool_t *bool_v; 1055 1113 1056 rdata_var_t *ref1, *ref2;1114 stree_embr_t *e1, *e2; 1057 1115 1058 1116 (void) run; … … 1067 1125 var->u.bool_v = bool_v; 1068 1126 1069 ref1 = v1->var->u.ref_v->vref;1070 ref2 = v2->var->u.ref_v->vref;1127 e1 = v1->var->u.enum_v->value; 1128 e2 = v2->var->u.enum_v->value; 1071 1129 1072 1130 switch (binop->bc) { 1073 1131 case bo_equal: 1074 bool_v->value = ( ref1 == ref2);1132 bool_v->value = (e1 == e2); 1075 1133 break; 1076 1134 case bo_notequal: 1077 bool_v->value = ( ref1 != ref2);1135 bool_v->value = (e1 != e2); 1078 1136 break; 1079 1137 default: … … 1100 1158 printf("Run unary operation.\n"); 1101 1159 #endif 1160 rarg_i = NULL; 1161 rarg_vi = NULL; 1162 1102 1163 run_expr(run, unop->arg, &rarg_i); 1103 1164 if (run_is_bo(run)) { 1104 *res = NULL;1105 return;1165 *res = run_recovery_item(run); 1166 goto cleanup; 1106 1167 } 1107 1168 … … 1110 1171 #endif 1111 1172 run_cvt_value_item(run, rarg_i, &rarg_vi); 1173 if (run_is_bo(run)) { 1174 *res = run_recovery_item(run); 1175 goto cleanup; 1176 } 1112 1177 1113 1178 val = rarg_vi->u.value; … … 1124 1189 "type %d.\n", val->var->vc); 1125 1190 run_raise_error(run); 1126 *res = NULL; 1127 break; 1128 } 1191 *res = run_recovery_item(run); 1192 break; 1193 } 1194 cleanup: 1195 if (rarg_i != NULL) 1196 rdata_item_destroy(rarg_i); 1197 if (rarg_vi != NULL) 1198 rdata_item_destroy(rarg_vi); 1129 1199 } 1130 1200 … … 1208 1278 *res = item; 1209 1279 } 1280 1281 /** Run equality comparison of two values 1282 * 1283 * This should be equivalent to equality ('==') binary operation. 1284 * XXX Duplicating code of run_binop_xxx(). 1285 * 1286 * @param run Runner object 1287 * @param v1 Value of first argument 1288 * @param v2 Value of second argument 1289 * @param res Place to store result (plain boolean value) 1290 */ 1291 void run_equal(run_t *run, rdata_value_t *v1, rdata_value_t *v2, bool_t *res) 1292 { 1293 bool_t b1, b2; 1294 bigint_t *c1, *c2; 1295 bigint_t *i1, *i2; 1296 bigint_t diff; 1297 const char *s1, *s2; 1298 rdata_var_t *ref1, *ref2; 1299 stree_embr_t *e1, *e2; 1300 1301 (void) run; 1302 assert(v1->var->vc == v2->var->vc); 1303 1304 switch (v1->var->vc) { 1305 case vc_bool: 1306 b1 = v1->var->u.bool_v->value; 1307 b2 = v2->var->u.bool_v->value; 1308 1309 *res = (b1 == b2); 1310 break; 1311 case vc_char: 1312 c1 = &v1->var->u.char_v->value; 1313 c2 = &v2->var->u.char_v->value; 1314 1315 bigint_sub(c1, c2, &diff); 1316 *res = bigint_is_zero(&diff); 1317 break; 1318 case vc_int: 1319 i1 = &v1->var->u.int_v->value; 1320 i2 = &v2->var->u.int_v->value; 1321 1322 bigint_sub(i1, i2, &diff); 1323 *res = bigint_is_zero(&diff); 1324 break; 1325 case vc_string: 1326 s1 = v1->var->u.string_v->value; 1327 s2 = v2->var->u.string_v->value; 1328 1329 *res = os_str_cmp(s1, s2) == 0; 1330 break; 1331 case vc_ref: 1332 ref1 = v1->var->u.ref_v->vref; 1333 ref2 = v2->var->u.ref_v->vref; 1334 1335 *res = (ref1 == ref2); 1336 break; 1337 case vc_enum: 1338 e1 = v1->var->u.enum_v->value; 1339 e2 = v2->var->u.enum_v->value; 1340 1341 *res = (e1 == e2); 1342 break; 1343 1344 case vc_deleg: 1345 case vc_array: 1346 case vc_object: 1347 case vc_resource: 1348 case vc_symbol: 1349 assert(b_false); 1350 } 1351 } 1352 1210 1353 1211 1354 /** Evaluate @c new operation. … … 1297 1440 run_expr(run, expr, &rexpr); 1298 1441 if (run_is_bo(run)) { 1299 *res = NULL;1442 *res = run_recovery_item(run); 1300 1443 return; 1301 1444 } 1302 1445 1303 1446 run_cvt_value_item(run, rexpr, &rexpr_vi); 1447 if (run_is_bo(run)) { 1448 *res = run_recovery_item(run); 1449 return; 1450 } 1451 1304 1452 assert(rexpr_vi->ic == ic_value); 1305 1453 rexpr_var = rexpr_vi->u.value->var; … … 1375 1523 run_call_args(run, &new_op->ctor_args, &arg_vals); 1376 1524 if (run_is_bo(run)) { 1377 *res = NULL;1525 *res = run_recovery_item(run); 1378 1526 return; 1379 1527 } … … 1387 1535 assert(obj_i->u.address->ac == ac_var); 1388 1536 run_object_ctor(run, obj_i->u.address->u.var_a->vref, &arg_vals); 1537 rdata_item_destroy(obj_i); 1538 1539 /* Destroy argument values */ 1540 run_destroy_arg_vals(&arg_vals); 1389 1541 } 1390 1542 … … 1404 1556 printf("Run access operation.\n"); 1405 1557 #endif 1558 rarg = NULL; 1559 1406 1560 run_expr(run, access->arg, &rarg); 1407 1561 if (run_is_bo(run)) { 1408 *res = NULL;1409 return;1562 *res = run_recovery_item(run); 1563 goto cleanup; 1410 1564 } 1411 1565 … … 1416 1570 1417 1571 run_access_item(run, access, rarg, res); 1572 cleanup: 1573 if (rarg != NULL) 1574 rdata_item_destroy(rarg); 1418 1575 } 1419 1576 … … 1484 1641 /* Try again. */ 1485 1642 run_access_item(run, access, darg, res); 1643 1644 /* Destroy temporary */ 1645 rdata_item_destroy(darg); 1486 1646 } 1487 1647 … … 1790 1950 #endif 1791 1951 run_cvt_value_item(run, arg, &arg_vi); 1952 if (run_is_bo(run)) { 1953 *res = run_recovery_item(run); 1954 return; 1955 } 1956 1792 1957 arg_val = arg_vi->u.value; 1793 1958 assert(arg_val->var->vc == vc_symbol); … … 1800 1965 embr = stree_enum_find_mbr(symbol_v->sym->u.enum_d, 1801 1966 access->member_name); 1967 1968 rdata_item_destroy(arg_vi); 1802 1969 1803 1970 /* Member existence should be ensured by static type checking. */ … … 1841 2008 printf("Run call operation.\n"); 1842 2009 #endif 2010 rdeleg = NULL; 2011 rdeleg_vi = NULL; 2012 1843 2013 run_expr(run, call->fun, &rdeleg); 1844 2014 if (run_is_bo(run)) { 1845 *res = NULL;1846 return;1847 }1848 1849 if (run->thread_ar->bo_mode != bm_none) {1850 2015 *res = run_recovery_item(run); 1851 return;2016 goto cleanup; 1852 2017 } 1853 2018 1854 2019 run_cvt_value_item(run, rdeleg, &rdeleg_vi); 2020 if (run_is_bo(run)) { 2021 *res = run_recovery_item(run); 2022 goto cleanup; 2023 } 2024 1855 2025 assert(rdeleg_vi->ic == ic_value); 1856 2026 … … 1877 2047 run_call_args(run, &call->args, &arg_vals); 1878 2048 if (run_is_bo(run)) { 1879 *res = NULL;1880 return;2049 *res = run_recovery_item(run); 2050 goto cleanup; 1881 2051 } 1882 2052 … … 1889 2059 /* Fill in argument values. */ 1890 2060 run_proc_ar_set_args(run, proc_ar, &arg_vals); 2061 2062 /* Destroy arg_vals, they are no longer needed. */ 2063 run_destroy_arg_vals(&arg_vals); 1891 2064 1892 2065 /* Run the function. */ … … 1900 2073 } 1901 2074 2075 /* Destroy procedure activation record. */ 2076 run_proc_ar_destroy(run, proc_ar); 2077 2078 cleanup: 2079 if (rdeleg != NULL) 2080 rdata_item_destroy(rdeleg); 2081 if (rdeleg_vi != NULL) 2082 rdata_item_destroy(rdeleg_vi); 2083 1902 2084 #ifdef DEBUG_RUN_TRACE 1903 2085 printf("Returned from function call.\n"); … … 1928 2110 run_expr(run, arg, &rarg_i); 1929 2111 if (run_is_bo(run)) 1930 return;2112 goto error; 1931 2113 1932 2114 run_cvt_value_item(run, rarg_i, &rarg_vi); 2115 rdata_item_destroy(rarg_i); 2116 if (run_is_bo(run)) 2117 goto error; 1933 2118 1934 2119 list_append(arg_vals, rarg_vi); 1935 2120 arg_n = list_next(args, arg_n); 1936 2121 } 2122 return; 2123 2124 error: 2125 /* 2126 * An exception or error occured while evaluating one of the 2127 * arguments. Destroy already obtained argument values and 2128 * dismantle the list. 2129 */ 2130 run_destroy_arg_vals(arg_vals); 2131 } 2132 2133 /** Destroy list of evaluated arguments. 2134 * 2135 * Provided a list of evaluated arguments, destroy them, removing them 2136 * from the list and fini the list itself. 2137 * 2138 * @param arg_vals List of evaluated arguments (value items, 2139 * rdata_item_t). 2140 */ 2141 static void run_destroy_arg_vals(list_t *arg_vals) 2142 { 2143 list_node_t *val_n; 2144 rdata_item_t *val_i; 2145 2146 /* 2147 * An exception or error occured while evaluating one of the 2148 * arguments. Destroy already obtained argument values and 2149 * dismantle the list. 2150 */ 2151 while (!list_is_empty(arg_vals)) { 2152 val_n = list_first(arg_vals); 2153 val_i = list_node_data(val_n, rdata_item_t *); 2154 2155 rdata_item_destroy(val_i); 2156 list_remove(arg_vals, val_n); 2157 } 2158 list_fini(arg_vals); 1937 2159 } 1938 2160 … … 1954 2176 var_class_t vc; 1955 2177 list_t arg_vals; 2178 list_node_t *val_n; 2179 rdata_item_t *val_i; 1956 2180 1957 2181 #ifdef DEBUG_RUN_TRACE … … 1960 2184 run_expr(run, index->base, &rbase); 1961 2185 if (run_is_bo(run)) { 1962 *res = NULL;2186 *res = run_recovery_item(run); 1963 2187 return; 1964 2188 } … … 1969 2193 if (vc == vc_ref) { 1970 2194 run_dereference(run, rbase, index->base->cspan, &base_i); 2195 rdata_item_destroy(rbase); 1971 2196 if (run_is_bo(run)) { 1972 *res = NULL;2197 *res = run_recovery_item(run); 1973 2198 return; 1974 2199 } … … 1987 2212 run_expr(run, arg, &rarg_i); 1988 2213 if (run_is_bo(run)) { 1989 *res = NULL;1990 return;2214 *res = run_recovery_item(run); 2215 goto cleanup; 1991 2216 } 1992 2217 1993 2218 run_cvt_value_item(run, rarg_i, &rarg_vi); 2219 rdata_item_destroy(rarg_i); 2220 if (run_is_bo(run)) { 2221 *res = run_recovery_item(run); 2222 goto cleanup; 2223 } 1994 2224 1995 2225 list_append(&arg_vals, rarg_vi); … … 2012 2242 exit(1); 2013 2243 } 2244 2245 /* Destroy the indexing base temporary */ 2246 rdata_item_destroy(base_i); 2247 cleanup: 2248 /* 2249 * An exception or error occured while evaluating one of the 2250 * arguments. Destroy already obtained argument values and 2251 * dismantle the list. 2252 */ 2253 while (!list_is_empty(&arg_vals)) { 2254 val_n = list_first(&arg_vals); 2255 val_i = list_node_data(val_n, rdata_item_t *); 2256 2257 rdata_item_destroy(val_i); 2258 list_remove(&arg_vals, val_n); 2259 } 2260 2261 list_fini(&arg_vals); 2014 2262 } 2015 2263 … … 2136 2384 2137 2385 list_node_t *node; 2138 rdata_item_t *arg ;2386 rdata_item_t *arg, *arg_copy; 2139 2387 2140 2388 #ifdef DEBUG_RUN_TRACE … … 2186 2434 while (node != NULL) { 2187 2435 arg = list_node_data(node, rdata_item_t *); 2188 list_append(&aprop_indexed->args, arg); 2436 2437 /* 2438 * Clone argument so that original can 2439 * be freed. 2440 */ 2441 assert(arg->ic == ic_value); 2442 arg_copy = rdata_item_new(ic_value); 2443 rdata_value_copy(arg->u.value, &arg_copy->u.value); 2444 2445 list_append(&aprop_indexed->args, arg_copy); 2189 2446 node = list_next(args, node); 2190 2447 } … … 2225 2482 2226 2483 run_cvt_value_item(run, base, &base_vi); 2484 if (run_is_bo(run)) { 2485 *res = run_recovery_item(run); 2486 return; 2487 } 2488 2227 2489 assert(base_vi->u.value->var->vc == vc_string); 2228 2490 string = base_vi->u.value->var->u.string_v; … … 2277 2539 index->expr->cspan); 2278 2540 *res = run_recovery_item(run); 2279 return;2541 goto cleanup; 2280 2542 } 2281 2543 … … 2291 2553 2292 2554 *res = ritem; 2555 cleanup: 2556 rdata_item_destroy(base_vi); 2293 2557 } 2294 2558 … … 2310 2574 printf("Run assign operation.\n"); 2311 2575 #endif 2576 rdest_i = NULL; 2577 rsrc_i = NULL; 2578 rsrc_vi = NULL; 2579 2312 2580 run_expr(run, assign->dest, &rdest_i); 2313 2581 if (run_is_bo(run)) { 2314 *res = NULL;2315 return;2582 *res = run_recovery_item(run); 2583 goto cleanup; 2316 2584 } 2317 2585 2318 2586 run_expr(run, assign->src, &rsrc_i); 2319 2587 if (run_is_bo(run)) { 2320 *res = NULL;2321 return;2588 *res = run_recovery_item(run); 2589 goto cleanup; 2322 2590 } 2323 2591 2324 2592 run_cvt_value_item(run, rsrc_i, &rsrc_vi); 2593 if (run_is_bo(run)) { 2594 *res = run_recovery_item(run); 2595 goto cleanup; 2596 } 2597 2325 2598 assert(rsrc_vi->ic == ic_value); 2326 2599 … … 2334 2607 2335 2608 *res = NULL; 2609 cleanup: 2610 if (rdest_i != NULL) 2611 rdata_item_destroy(rdest_i); 2612 if (rsrc_i != NULL) 2613 rdata_item_destroy(rsrc_i); 2614 if (rsrc_vi != NULL) 2615 rdata_item_destroy(rsrc_vi); 2336 2616 } 2337 2617 … … 2359 2639 run_expr(run, as_op->arg, &rarg_i); 2360 2640 if (run_is_bo(run)) { 2361 *res = NULL;2641 *res = run_recovery_item(run); 2362 2642 return; 2363 2643 } … … 2369 2649 assert(run_item_get_vc(run, rarg_i) == vc_ref); 2370 2650 run_cvt_value_item(run, rarg_i, &rarg_vi); 2651 rdata_item_destroy(rarg_i); 2652 2653 if (run_is_bo(run)) { 2654 *res = run_recovery_item(run); 2655 return; 2656 } 2657 2371 2658 assert(rarg_vi->ic == ic_value); 2372 2659 … … 2405 2692 } 2406 2693 2694 /* The dereferenced item is not used anymore. */ 2695 rdata_item_destroy(rarg_di); 2696 2407 2697 *res = rarg_vi; 2408 2698 } … … 2435 2725 run_expr(run, box->arg, &rarg_i); 2436 2726 if (run_is_bo(run)) { 2437 *res = NULL;2727 *res = run_recovery_item(run); 2438 2728 return; 2439 2729 } 2440 2730 2441 2731 run_cvt_value_item(run, rarg_i, &rarg_vi); 2732 rdata_item_destroy(rarg_i); 2733 if (run_is_bo(run)) { 2734 *res = run_recovery_item(run); 2735 return; 2736 } 2737 2442 2738 assert(rarg_vi->ic == ic_value); 2443 2739 … … 2482 2778 2483 2779 rdata_var_write(mbr_var, rarg_vi->u.value); 2780 rdata_item_destroy(rarg_vi); 2484 2781 } 2485 2782 … … 2657 2954 assert(res == NULL); 2658 2955 2956 /* Destroy procedure activation record. */ 2957 run_proc_ar_destroy(run, proc_ar); 2958 2659 2959 #ifdef DEBUG_RUN_TRACE 2660 2960 printf("Returned from constructor..\n"); … … 2675 2975 rdata_item_t *vitem; 2676 2976 rdata_var_t *var; 2977 bool_t res; 2677 2978 2678 2979 (void) run; 2679 2980 run_cvt_value_item(run, item, &vitem); 2981 if (run_is_bo(run)) 2982 return b_true; 2680 2983 2681 2984 assert(vitem->ic == ic_value); … … 2683 2986 2684 2987 assert(var->vc == vc_bool); 2685 return var->u.bool_v->value; 2686 } 2988 res = var->u.bool_v->value; 2989 2990 /* Free value item */ 2991 rdata_item_destroy(vitem); 2992 return res; 2993 } -
uspace/app/sbi/src/run_expr.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 rdata_var_t **res); 40 40 41 void run_equal(run_t *run, rdata_value_t *v1, rdata_value_t *v2, bool_t *res); 41 42 bool_t run_item_boolean_value(run_t *run, rdata_item_t *item); 42 43 -
uspace/app/sbi/src/stree.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 397 397 } 398 398 399 /** Allocate new @c switch statement. 400 * 401 * @return New @c if statement 402 */ 403 stree_switch_t *stree_switch_new(void) 404 { 405 stree_switch_t *switch_s; 406 407 switch_s = calloc(1, sizeof(stree_switch_t)); 408 if (switch_s == NULL) { 409 printf("Memory allocation failed.\n"); 410 exit(1); 411 } 412 413 return switch_s; 414 } 415 399 416 /** Allocate new @c while statement. 400 417 * … … 548 565 549 566 return if_clause; 567 } 568 569 /** Allocate new @c when clause. 570 * 571 * @return New @c when clause 572 */ 573 stree_when_t *stree_when_new(void) 574 { 575 stree_when_t *when_c; 576 577 when_c = calloc(1, sizeof(stree_when_t)); 578 if (when_c == NULL) { 579 printf("Memory allocation failed.\n"); 580 exit(1); 581 } 582 583 return when_c; 550 584 } 551 585 -
uspace/app/sbi/src/stree.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 55 55 stree_vdecl_t *stree_vdecl_new(void); 56 56 stree_if_t *stree_if_new(void); 57 stree_switch_t *stree_switch_new(void); 57 58 stree_while_t *stree_while_new(void); 58 59 stree_for_t *stree_for_new(void); … … 65 66 stree_except_t *stree_except_new(void); 66 67 stree_if_clause_t *stree_if_clause_new(void); 68 stree_when_t *stree_when_new(void); 67 69 stree_block_t *stree_block_new(void); 68 70 -
uspace/app/sbi/src/stree_t.h
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 364 364 } texpr_class_t; 365 365 366 /** Arithmeticexpression */366 /** Type expression */ 367 367 typedef struct stree_texpr { 368 368 texpr_class_t tc; … … 394 394 stree_ident_t *name; 395 395 stree_texpr_t *type; 396 397 /** Type of this variable or @c NULL if not typed yet */ 398 struct tdata_item *titem; 396 399 } stree_vdecl_t; 397 400 … … 401 404 stree_texpr_t *etype; 402 405 stree_block_t *block; 406 407 /** Evaluated etype or @c NULL if not typed yet */ 408 struct tdata_item *titem; 403 409 } stree_except_t; 404 410 … … 418 424 } stree_if_t; 419 425 426 /** @c when clause */ 427 typedef struct { 428 /** List of expressions -- cases -- for this clause */ 429 list_t exprs; /* of stree_expr_t */ 430 stree_block_t *block; 431 } stree_when_t; 432 433 /** Switch statement */ 434 typedef struct { 435 /** Switch expression */ 436 stree_expr_t *expr; 437 438 /** When clauses */ 439 list_t when_clauses; /* of stree_when_t */ 440 441 /** Else block */ 442 stree_block_t *else_block; 443 } stree_switch_t; 444 420 445 /** While statement */ 421 446 typedef struct { … … 448 473 } stree_exps_t; 449 474 450 /** With-try-except-finally statement (WEF)*/475 /** With-try-except-finally (WEF) statement */ 451 476 typedef struct { 452 477 stree_block_t *with_block; … … 459 484 st_vdecl, 460 485 st_if, 486 st_switch, 461 487 st_while, 462 488 st_for, … … 475 501 stree_vdecl_t *vdecl_s; 476 502 stree_if_t *if_s; 503 stree_switch_t *switch_s; 477 504 stree_while_t *while_s; 478 505 stree_for_t *for_s; … … 510 537 /** Function signature. 511 538 * 512 * Fo ormal parameters and return type. This is common to function and delegate539 * Formal parameters and return type. This is common to function and delegate 513 540 * delcarations. 514 541 */ … … 788 815 } u; 789 816 790 /** Containing CSI (for all symbols)*/817 /** Containing CSI */ 791 818 stree_csi_t *outer_csi; 792 819 793 /** Containing block (for block-level symbols) */ 794 stree_block_t *outer_block; 795 796 /** Symbol attributes. */ 820 /** Symbol attributes */ 797 821 list_t attr; /* of stree_symbol_attr_t */ 798 822 } stree_symbol_t; -
uspace/app/sbi/src/stype.c
r1614ce3 rb64eac6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 76 76 static void stype_vdecl(stype_t *stype, stree_vdecl_t *vdecl_s); 77 77 static void stype_if(stype_t *stype, stree_if_t *if_s); 78 static void stype_switch(stype_t *stype, stree_switch_t *switch_s); 78 79 static void stype_while(stype_t *stype, stree_while_t *while_s); 79 80 static void stype_for(stype_t *stype, stree_for_t *for_s); … … 889 890 case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break; 890 891 case st_if: stype_if(stype, stat->u.if_s); break; 892 case st_switch: stype_switch(stype, stat->u.switch_s); break; 891 893 case st_while: stype_while(stype, stat->u.while_s); break; 892 894 case st_for: stype_for(stype, stat->u.for_s); break; … … 931 933 } 932 934 935 /* Annotate with variable type */ 936 vdecl_s->titem = titem; 937 933 938 intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s); 934 939 } … … 973 978 if (if_s->else_block != NULL) 974 979 stype_block(stype, if_s->else_block); 980 } 981 982 /** Type @c switch statement. 983 * 984 * @param stype Static typing object 985 * @param switch_s @c switch statement 986 */ 987 static void stype_switch(stype_t *stype, stree_switch_t *switch_s) 988 { 989 stree_expr_t *expr, *cexpr; 990 list_node_t *whenc_node; 991 stree_when_t *whenc; 992 list_node_t *expr_node; 993 tdata_item_t *titem1, *titem2; 994 995 #ifdef DEBUG_TYPE_TRACE 996 printf("Type 'switch' statement.\n"); 997 #endif 998 stype_expr(stype, switch_s->expr); 999 1000 titem1 = switch_s->expr->titem; 1001 if (titem1 == NULL) { 1002 cspan_print(switch_s->expr->cspan); 1003 printf(" Error: Switch expression has no value.\n"); 1004 stype_note_error(stype); 1005 return; 1006 } 1007 1008 /* Walk through all when clauses. */ 1009 whenc_node = list_first(&switch_s->when_clauses); 1010 1011 while (whenc_node != NULL) { 1012 /* Get when clause */ 1013 whenc = list_node_data(whenc_node, stree_when_t *); 1014 1015 /* Walk through all expressions of the when clause */ 1016 expr_node = list_first(&whenc->exprs); 1017 while (expr_node != NULL) { 1018 expr = list_node_data(expr_node, stree_expr_t *); 1019 1020 stype_expr(stype, expr); 1021 titem2 = expr->titem; 1022 if (titem2 == NULL) { 1023 cspan_print(expr->cspan); 1024 printf(" Error: When expression has no value.\n"); 1025 stype_note_error(stype); 1026 return; 1027 } 1028 1029 /* Convert expression to same type as switch expr. */ 1030 cexpr = stype_convert(stype, expr, titem1); 1031 1032 /* Patch code with augmented expression. */ 1033 list_node_setdata(expr_node, cexpr); 1034 1035 expr_node = list_next(&whenc->exprs, expr_node); 1036 } 1037 1038 /* Type the @c when block */ 1039 stype_block(stype, whenc->block); 1040 1041 whenc_node = list_next(&switch_s->when_clauses, whenc_node); 1042 } 1043 1044 /* Type the @c else block */ 1045 if (switch_s->else_block != NULL) 1046 stype_block(stype, switch_s->else_block); 975 1047 } 976 1048 … … 1168 1240 while (ec_n != NULL) { 1169 1241 ec = list_node_data(ec_n, stree_except_t *); 1242 run_texpr(stype->program, stype->current_csi, ec->etype, 1243 &ec->titem); 1170 1244 stype_block(stype, ec->block); 1171 1245 -
uspace/app/sbi/src/stype_expr.c
r1614ce3 rb64eac6 894 894 895 895 titem = unop->arg->titem; 896 if (titem == NULL) { 897 cspan_print(unop->arg->cspan); 898 printf(" Error: Argument of unary operation has no value.\n"); 899 stype_note_error(stype); 900 *rtitem = stype_recovery_titem(stype); 901 return; 902 } 896 903 897 904 if (titem->tic == tic_ignore) { -
uspace/dist/src/sysel/demos/arith.sy
r1614ce3 rb64eac6 30 30 fun Main(), static is 31 31 -- Test addition, multiplication and precedence. 32 Builtin.Write("2*2 + 2*2 = ");33 Builtin.Write(2*2 + 2*2);34 Builtin.WriteLine(" (expected: 8)");32 Console.Write("2*2 + 2*2 = "); 33 Console.Write(2*2 + 2*2); 34 Console.WriteLine(" (expected: 8)"); 35 35 36 36 -- Test subtraction, multiplication and precedence. 37 Builtin.Write("1111 - 1 - 10 - 10*10 - 10*10*10 = ");38 Builtin.Write(1111 - 1 - 10 - 10*10 - 10*10*10);39 Builtin.WriteLine(" (expected: 0)");37 Console.Write("1111 - 1 - 10 - 10*10 - 10*10*10 = "); 38 Console.Write(1111 - 1 - 10 - 10*10 - 10*10*10); 39 Console.WriteLine(" (expected: 0)"); 40 40 41 41 -- Test parenthesized sub-expressions. 42 Builtin.Write("10 * (1 - 1) = ");43 Builtin.Write(10 * (1 - 1));44 Builtin.WriteLine(" (expected: 0)");42 Console.Write("10 * (1 - 1) = "); 43 Console.Write(10 * (1 - 1)); 44 Console.WriteLine(" (expected: 0)"); 45 45 46 46 -- Test unary plus and minus. 47 Builtin.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = ");48 Builtin.Write((+1) - (-1) - (+(+1)) + (+(-1)));49 Builtin.WriteLine(" (expected: 0)");47 Console.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = "); 48 Console.Write((+1) - (-1) - (+(+1)) + (+(-1))); 49 Console.WriteLine(" (expected: 0)"); 50 50 51 51 -- Test signed multiplication. 52 Builtin.Write("+1 * +1 = ");53 Builtin.Write(+1 * +1);54 Builtin.WriteLine(" (expected: 1)");52 Console.Write("+1 * +1 = "); 53 Console.Write(+1 * +1); 54 Console.WriteLine(" (expected: 1)"); 55 55 56 Builtin.Write("-1 * -1 = ");57 Builtin.Write(-1 * -1);58 Builtin.WriteLine(" (expected: 1)");56 Console.Write("-1 * -1 = "); 57 Console.Write(-1 * -1); 58 Console.WriteLine(" (expected: 1)"); 59 59 60 Builtin.Write("+1 * -1 = ");61 Builtin.Write(+1 * -1);62 Builtin.WriteLine(" (expected: -1)");60 Console.Write("+1 * -1 = "); 61 Console.Write(+1 * -1); 62 Console.WriteLine(" (expected: -1)"); 63 63 64 Builtin.Write("-1 * +1 = ");65 Builtin.Write(-1 * +1);66 Builtin.WriteLine(" (expected: -1)");64 Console.Write("-1 * +1 = "); 65 Console.Write(-1 * +1); 66 Console.WriteLine(" (expected: -1)"); 67 67 68 68 -- Test multiplication with large result. 69 Builtin.Write("1000000 * 1000000 * 1000000 * 1000000 = ");70 Builtin.Write(1000000 * 1000000 * 1000000 * 1000000);71 Builtin.WriteLine(" (expected: 1000000000000000000000000)");69 Console.Write("1000000 * 1000000 * 1000000 * 1000000 = "); 70 Console.Write(1000000 * 1000000 * 1000000 * 1000000); 71 Console.WriteLine(" (expected: 1000000000000000000000000)"); 72 72 73 73 -- Test large literals. 74 Builtin.Write("1000000000000000000000000 = ");75 Builtin.Write(1000000000000000000000000);76 Builtin.WriteLine(" (expected: 1000000000000000000000000)");74 Console.Write("1000000000000000000000000 = "); 75 Console.Write(1000000000000000000000000); 76 Console.WriteLine(" (expected: 1000000000000000000000000)"); 77 77 78 78 -- Test large factorials. 79 79 var n : int; 80 80 81 Builtin.WriteLine("Factorials:");81 Console.WriteLine("Factorials:"); 82 82 n = 1; 83 83 while n <= 40 do 84 Builtin.WriteLine(Factorial(n));84 Console.WriteLine(Factorial(n)); 85 85 n = n + 1; 86 86 end -
uspace/dist/src/sysel/demos/array.sy
r1614ce3 rb64eac6 40 40 i = 0; 41 41 while i < 3 do 42 Builtin.WriteLine(a[i, 0]);42 Console.WriteLine(a[i, 0]); 43 43 i = i + 1; 44 44 end -
uspace/dist/src/sysel/demos/autobox.sy
r1614ce3 rb64eac6 39 39 -- 40 40 b = true; 41 Builtin.WriteLine(b.Value);41 Console.WriteLine(b.Value); 42 42 c = 'a'; 43 Builtin.WriteLine(c.Value);43 Console.WriteLine(c.Value); 44 44 i = 1; 45 Builtin.WriteLine(i.Value);45 Console.WriteLine(i.Value); 46 46 s = "Hello"; 47 Builtin.WriteLine(s.Value);47 Console.WriteLine(s.Value); 48 48 49 49 -- Anything can be converted to Object. -
uspace/dist/src/sysel/demos/count.sy
r1614ce3 rb64eac6 33 33 i = a; 34 34 while i < b do 35 Builtin.WriteLine(i);35 Console.WriteLine(i); 36 36 i = i + 1; 37 37 end -
uspace/dist/src/sysel/demos/ctor.sy
r1614ce3 rb64eac6 32 32 33 33 a = new A(1); 34 Builtin.Write("a.v = ");35 Builtin.WriteLine(a.v);34 Console.Write("a.v = "); 35 Console.WriteLine(a.v); 36 36 end 37 37 end … … 41 41 42 42 new(i : int) is 43 Builtin.WriteLine("A.new()");43 Console.WriteLine("A.new()"); 44 44 v = i; 45 45 end -
uspace/dist/src/sysel/demos/deleg.sy
r1614ce3 rb64eac6 55 55 -- Function having delegate as the first parameger 56 56 fun Operate(op : BinaryOp; opName : string) is 57 Builtin.Write(opName + "(1, 2): ");58 Builtin.WriteLine(op(1, 2));57 Console.Write(opName + "(1, 2): "); 58 Console.WriteLine(op(1, 2)); 59 59 end 60 60 -
uspace/dist/src/sysel/demos/enum.sy
r1614ce3 rb64eac6 31 31 var color : ChessColor; 32 32 33 Builtin.WriteLine("Set color to ChessColor.Black.");33 Console.WriteLine("Set color to ChessColor.Black."); 34 34 color = ChessColor.Black; 35 35 36 Builtin.Write("Test color == ChessColor.Black.. ");36 Console.Write("Test color == ChessColor.Black.. "); 37 37 if color == ChessColor.Black then 38 Builtin.WriteLine("True - OK");38 Console.WriteLine("True - OK"); 39 39 else 40 Builtin.WriteLine("False - Fail!");40 Console.WriteLine("False - Fail!"); 41 41 raise new Error.Base(); 42 42 end 43 43 44 Builtin.Write("Test color != ChessColor.Black.. ");44 Console.Write("Test color != ChessColor.Black.. "); 45 45 if color != ChessColor.Black then 46 Builtin.WriteLine("True - Fail!");46 Console.WriteLine("True - Fail!"); 47 47 raise new Error.Base(); 48 48 else 49 Builtin.WriteLine("False - OK");49 Console.WriteLine("False - OK"); 50 50 end 51 51 52 Builtin.Write("Test color == ChessColor.White.. ");52 Console.Write("Test color == ChessColor.White.. "); 53 53 if color == ChessColor.White then 54 Builtin.WriteLine("True - Fail!");54 Console.WriteLine("True - Fail!"); 55 55 raise new Error.Base(); 56 56 else 57 Builtin.WriteLine("False - OK");57 Console.WriteLine("False - OK"); 58 58 end 59 59 60 Builtin.Write("Test color != ChessColor.White.. ");60 Console.Write("Test color != ChessColor.White.. "); 61 61 if color != ChessColor.White then 62 Builtin.WriteLine("True - OK");62 Console.WriteLine("True - OK"); 63 63 else 64 Builtin.WriteLine("False - Fail!");64 Console.WriteLine("False - Fail!"); 65 65 raise new Error.Base(); 66 66 end 67 67 68 Builtin.WriteLine("Success");68 Console.WriteLine("Success"); 69 69 70 70 -- Test enum declared in non-CSI scope -
uspace/dist/src/sysel/demos/except.sy
r1614ce3 rb64eac6 29 29 class ExceptionDemo is 30 30 fun foo(), static is 31 Builtin.WriteLine("Entered foo().");31 Console.WriteLine("Entered foo()."); 32 32 raise new BaseException(); 33 33 end … … 38 38 foo(); 39 39 except e : DerivedException do 40 Builtin.WriteLine("Caught derived exception.");40 Console.WriteLine("Caught derived exception."); 41 41 except e : BaseException do 42 Builtin.WriteLine("Caught base exception.");42 Console.WriteLine("Caught base exception."); 43 43 finally do 44 Builtin.WriteLine("Finally.");44 Console.WriteLine("Finally."); 45 45 end 46 46 end -
uspace/dist/src/sysel/demos/gen.sy
r1614ce3 rb64eac6 31 31 class GenericsDemo is 32 32 fun Main(), static is 33 Builtin.WriteLine("Let's try some generics.");33 Console.WriteLine("Let's try some generics."); 34 34 35 35 var f : B/int/string; -
uspace/dist/src/sysel/demos/hello.sy
r1614ce3 rb64eac6 29 29 class HelloWorld is 30 30 fun Main(), static is 31 Builtin.WriteLine("Hello world!");31 Console.WriteLine("Hello world!"); 32 32 end 33 33 end -
uspace/dist/src/sysel/demos/htxtfile.sy
r1614ce3 rb64eac6 45 45 while not in_file.EOF do 46 46 line = in_file.ReadLine(); 47 Builtin.WriteLine(name + ": " + line);47 Console.WriteLine(name + ": " + line); 48 48 out_file.WriteLine(name + ": " + line); 49 49 end -
uspace/dist/src/sysel/demos/iface.sy
r1614ce3 rb64eac6 43 43 f = g as Foo; 44 44 45 Builtin.WriteLine(g.a());45 Console.WriteLine(g.a()); 46 46 end 47 47 end -
uspace/dist/src/sysel/demos/inherit.sy
r1614ce3 rb64eac6 29 29 class A is 30 30 fun Foo() is 31 Builtin.WriteLine("A.Foo()");31 Console.WriteLine("A.Foo()"); 32 32 end 33 33 end … … 35 35 class B : A is 36 36 fun Foo() is 37 Builtin.WriteLine("B.Foo()");37 Console.WriteLine("B.Foo()"); 38 38 end 39 39 end -
uspace/dist/src/sysel/demos/list.sy
r1614ce3 rb64eac6 43 43 e = list.GetEnumerator(); 44 44 while e.MoveNext() do 45 Builtin.WriteLine(e.Data);45 Console.WriteLine(e.Data); 46 46 end 47 47 end -
uspace/dist/src/sysel/demos/map.sy
r1614ce3 rb64eac6 43 43 e = map.GetEnumerator(); 44 44 while e.MoveNext() do 45 Builtin.Write(e.Data);46 Builtin.Write(" -> ");47 Builtin.WriteLine(map[e.Data]);45 Console.Write(e.Data); 46 Console.Write(" -> "); 47 Console.WriteLine(map[e.Data]); 48 48 end 49 49 end -
uspace/dist/src/sysel/demos/property.sy
r1614ce3 rb64eac6 33 33 prop X : int is 34 34 get is 35 Builtin.Write("Getting value of X which is ");36 Builtin.WriteLine(x);35 Console.Write("Getting value of X which is "); 36 Console.WriteLine(x); 37 37 return x; 38 38 end 39 39 40 40 set value is 41 Builtin.Write("Setting value of X to ");42 Builtin.WriteLine(value);41 Console.Write("Setting value of X to "); 42 Console.WriteLine(value); 43 43 x = value; 44 44 end 45 end 46 47 -- Test accessing property via an unqualified name 48 fun TestUnqualPropAcc() is 49 var i : int; 50 51 X = 1; 52 i = X; 53 54 Console.Write("TestUnqualPropAcc(): Got "); 55 Console.WriteLine(i); 45 56 end 46 57 … … 51 62 prop self[index : int] : int is 52 63 get is 53 Builtin.Write("Getting property with index ");54 Builtin.Write(index);55 Builtin.Write(" which is ");56 Builtin.WriteLine(iprops[index]);64 Console.Write("Getting property with index "); 65 Console.Write(index); 66 Console.Write(" which is "); 67 Console.WriteLine(iprops[index]); 57 68 58 69 return iprops[index]; … … 60 71 61 72 set value is 62 Builtin.Write("Setting property with index ");63 Builtin.Write(index);64 Builtin.Write(" to ");65 Builtin.WriteLine(value);73 Console.Write("Setting property with index "); 74 Console.Write(index); 75 Console.Write(" to "); 76 Console.WriteLine(value); 66 77 67 78 iprops[index] = value; … … 82 93 prop B : Bar is 83 94 get is 84 Builtin.WriteLine("Getting B");95 Console.WriteLine("Getting B"); 85 96 return bprop; 86 97 end 87 98 set value is 88 Builtin.WriteLine("Setting B");99 Console.WriteLine("Setting B"); 89 100 bprop = value; 90 101 end … … 110 121 i = a.X; 111 122 112 Builtin.Write("Main(): Got "); 113 Builtin.WriteLine(i); 123 Console.Write("Main(): Got "); 124 Console.WriteLine(i); 125 126 a.TestUnqualPropAcc(); 114 127 115 128 a.iprops = new int[5]; … … 121 134 i = a[1]; 122 135 123 Builtin.Write("Main(): Got ");124 Builtin.WriteLine(i);136 Console.Write("Main(): Got "); 137 Console.WriteLine(i); 125 138 126 139 -- Property field access … … 132 145 a.bprop = b; 133 146 134 Builtin.WriteLine(a.bprop.i);147 Console.WriteLine(a.bprop.i); 135 148 a.bprop.i = 2; 136 Builtin.WriteLine(a.bprop.i);149 Console.WriteLine(a.bprop.i); 137 150 end 138 151 end -
uspace/dist/src/sysel/demos/string.sy
r1614ce3 rb64eac6 30 30 fun Main(), static is 31 31 -- Concatenate some strings. 32 Builtin.WriteLine("One-" + "two-" + "three!");32 Console.WriteLine("One-" + "two-" + "three!"); 33 33 34 34 -- Extract characters from a string. … … 36 36 i = 0; 37 37 while i < 5 do 38 Builtin.WriteLine("ABCDE"[i]);38 Console.WriteLine("ABCDE"[i]); 39 39 i = i + 1; 40 40 end 41 41 42 Builtin.WriteLine("Abracadabra".Slice(2, 4));42 Console.WriteLine("Abracadabra".Slice(2, 4)); 43 43 end 44 44 end -
uspace/dist/src/sysel/demos/svar.sy
r1614ce3 rb64eac6 31 31 -- Test static member variable 32 32 A.B.a = 1; 33 Builtin.WriteLine(A.B.a);33 Console.WriteLine(A.B.a); 34 34 A.B.a = 2; 35 Builtin.WriteLine(A.B.a);35 Console.WriteLine(A.B.a); 36 36 37 37 -- Test static property 38 38 A.B.P = 1; 39 Builtin.WriteLine(A.B.P);39 Console.WriteLine(A.B.P); 40 40 A.B.P = 2; 41 Builtin.WriteLine(A.B.P);41 Console.WriteLine(A.B.P); 42 42 end 43 43 end -
uspace/dist/src/sysel/demos/varargs.sy
r1614ce3 rb64eac6 44 44 -- implemented... 45 45 do 46 Builtin.WriteLine(args[i]);46 Console.WriteLine(args[i]); 47 47 except e : Error.OutOfBounds do 48 48 error = true; -
uspace/srv/hid/console/gcons.c
r1614ce3 rb64eac6 285 285 ssize_t nx = (ssize_t) mouse_x + dx; 286 286 ssize_t ny = (ssize_t) mouse_y + dy; 287 288 if (!use_gcons) 287 288 /* Until gcons is initalized we don't have the screen resolution */ 289 if (xres == 0 || yres == 0) 289 290 return; 290 291
Note:
See TracChangeset
for help on using the changeset viewer.