Changes in / [b64eac6:1614ce3] in mainline
- Files:
-
- 3 added
- 6 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile
rb64eac6 r1614ce3 42 42 CONFIG_HEADER = config.h 43 43 44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check releasefile release44 .PHONY: all precheck cscope autotool config_auto config_default config distclean clean check distfile dist 45 45 46 46 all: $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) … … 88 88 $(CONFIG) $< 89 89 90 # Releasefiles90 # Distribution files 91 91 92 releasefile: all93 $(MAKE) -C release releasefile92 distfile: all 93 $(MAKE) -C dist distfile 94 94 95 release:96 $(MAKE) -C release release95 dist: 96 $(MAKE) -C dist dist 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 release/HelenOS-*101 rm -f $(CSCOPE).out $(COMMON_MAKEFILE) $(COMMON_HEADER) $(COMMON_HEADER_PREV) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) tools/*.pyc tools/checkers/*.pyc dist/HelenOS-* 102 102 103 103 clean: -
uspace/app/sbi/Makefile
rb64eac6 r1614ce3 35 35 SOURCES = \ 36 36 src/builtin/bi_boxed.c \ 37 src/builtin/bi_char.c \ 37 38 src/builtin/bi_error.c \ 38 src/builtin/bi_char.c \ 39 src/builtin/bi_console.c \ 39 src/builtin/bi_fun.c \ 40 40 src/builtin/bi_int.c \ 41 src/builtin/bi_task.c \42 41 src/builtin/bi_textfile.c \ 43 42 src/builtin/bi_string.c \ -
uspace/app/sbi/src/builtin.c
rb64eac6 r1614ce3 43 43 #include "builtin/bi_error.h" 44 44 #include "builtin/bi_char.h" 45 #include "builtin/bi_ console.h"45 #include "builtin/bi_fun.h" 46 46 #include "builtin/bi_int.h" 47 #include "builtin/bi_task.h"48 47 #include "builtin/bi_textfile.h" 49 48 #include "builtin/bi_string.h" … … 94 93 bi_error_declare(bi); 95 94 bi_char_declare(bi); 96 bi_ console_declare(bi);95 bi_fun_declare(bi); 97 96 bi_int_declare(bi); 98 bi_task_declare(bi);99 97 bi_textfile_declare(bi); 100 98 bi_string_declare(bi); … … 113 111 bi_error_bind(bi); 114 112 bi_char_bind(bi); 115 bi_ console_bind(bi);113 bi_fun_bind(bi); 116 114 bi_int_bind(bi); 117 bi_task_bind(bi);118 115 bi_textfile_bind(bi); 119 116 bi_string_bind(bi); -
uspace/app/sbi/src/imode.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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 or190 * if the conversion to value item raised an exception.191 */192 if (rexpr_vi != NULL) {193 180 assert(rexpr_vi->ic == ic_value); 194 181 … … 197 184 rdata_value_print(rexpr_vi->u.value); 198 185 printf("\n"); 199 200 rdata_item_destroy(rexpr_vi);201 186 } 202 187 } 203 204 run_proc_ar_destroy(&run, proc_ar);205 188 206 189 /* Remove block visit record from the stack, */ -
uspace/app/sbi/src/intmap.c
rb64eac6 r1614ce3 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 63 52 /** Set value corresponding to a key. 64 53 * … … 67 56 * is removed from the map. 68 57 * 69 * @param intmap Map 70 * @param key Key (integer) 71 * @param value Value (must be a pointer) or @c NULL 58 * @param intmap Map. 59 * @param key Key (integer). 60 * @param value Value (must be a pointer) or @c NULL. 72 61 */ 73 62 void intmap_set(intmap_t *intmap, int key, void *value) … … 86 75 /* Remove map element. */ 87 76 list_remove(&intmap->elem, node); 88 free(elem); 77 node->data = NULL; 78 free(node); 89 79 } 90 80 return; … … 108 98 /** Get value corresponding to a key. 109 99 * 110 * @param intmap Map 111 * @param key Key for which to retrieve mapping 100 * @param intmap Map. 101 * @param key Key for which to retrieve mapping. 112 102 * 113 103 * @return Value correspoding to @a key or @c NULL if no mapping … … 131 121 return NULL; 132 122 } 133 134 /** Get first element in the map.135 *136 * For iterating over the map, this returns the first element (in no137 * particular order).138 *139 * @param intmap Map140 * @return Map element or NULL if the map is empty141 */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 element158 * @return Key159 */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 element170 * @return Value171 */172 void *intmap_elem_get_value(map_elem_t *elem)173 {174 return elem->value;175 } -
uspace/app/sbi/src/intmap.h
rb64eac6 r1614ce3 33 33 34 34 void intmap_init(intmap_t *intmap); 35 void intmap_fini(intmap_t *intmap);36 35 void intmap_set(intmap_t *intmap, int key, void *data); 37 36 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);41 37 42 38 #endif -
uspace/app/sbi/src/lex.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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_str50 } chr_str_t;51 52 47 static void lex_touch(lex_t *lex); 53 48 static bool_t lex_read_try(lex_t *lex); … … 62 57 static void lex_number(lex_t *lex); 63 58 static void lex_string(lex_t *lex); 64 static void lex_char_string_core(lex_t *lex, chr_str_t cs);65 59 static int digit_value(char c); 66 60 … … 123 117 { lc_string, "string" }, 124 118 { lc_struct, "struct" }, 125 { lc_switch, "switch" },126 119 { lc_then, "then" }, 127 120 { lc_this, "this" }, … … 129 122 { lc_var, "var" }, 130 123 { lc_with, "with" }, 131 { lc_when, "when" },132 124 { lc_while, "while" }, 133 125 { lc_yield, "yield" }, … … 543 535 static void lex_char(lex_t *lex) 544 536 { 537 char *bp; 538 int idx; 545 539 size_t len; 546 540 int char_val; 547 541 548 lex_char_string_core(lex, cs_chr); 549 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'; 550 563 len = os_str_length(strlit_buf); 551 564 if (len != 1) { … … 607 620 static void lex_string(lex_t *lex) 608 621 { 609 lex_char_string_core(lex, cs_str); 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'; 610 646 611 647 lex->current.lclass = lc_lit_string; 612 648 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';689 649 } 690 650 -
uspace/app/sbi/src/lex_t.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 85 85 lc_string, 86 86 lc_struct, 87 lc_switch,88 87 lc_then, 89 88 lc_this, … … 91 90 lc_var, 92 91 lc_with, 93 lc_when,94 92 lc_while, 95 93 lc_yield, -
uspace/app/sbi/src/list.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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 71 59 /** Append data to list. 72 60 * -
uspace/app/sbi/src/list.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);37 36 void list_append(list_t *list, void *data); 38 37 void list_prepend(list_t *list, void *data); -
uspace/app/sbi/src/parse.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);85 84 static stree_while_t *parse_while(parse_t *parse); 86 85 static stree_for_t *parse_for(parse_t *parse); … … 668 667 stree_prop_t *prop; 669 668 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); 722 724 723 725 lmatch(parse, lc_is); … … 1068 1070 stree_vdecl_t *vdecl_s; 1069 1071 stree_if_t *if_s; 1070 stree_switch_t *switch_s;1071 1072 stree_while_t *while_s; 1072 1073 stree_for_t *for_s; … … 1091 1092 stat->u.if_s = if_s; 1092 1093 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;1098 1094 case lc_while: 1099 1095 while_s = parse_while(parse); … … 1218 1214 lmatch(parse, lc_end); 1219 1215 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_TRACE1234 printf("Parse 'switch' statement.\n");1235 #endif1236 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;1274 1216 } 1275 1217 … … 1712 1654 case lc_except: 1713 1655 case lc_finally: 1714 case lc_when:1715 1656 return b_true; 1716 1657 default: -
uspace/app/sbi/src/rdata.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 49 49 #include <assert.h> 50 50 #include "bigint.h" 51 #include "list.h"52 51 #include "mytypes.h" 53 52 #include "stree.h" … … 70 69 static void rdata_symbol_copy(rdata_symbol_t *src, rdata_symbol_t **dest); 71 70 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 86 71 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);88 72 89 73 static void rdata_address_print(rdata_address_t *address); … … 430 414 /** Allocate array elements. 431 415 * 432 * Allocates element arrayof @a array.416 * Allocates var nodes for elements of @a array. 433 417 * 434 418 * @param array Array. … … 436 420 void rdata_array_alloc_element(rdata_array_t *array) 437 421 { 438 int dim ;422 int dim, idx; 439 423 440 424 dim = rdata_array_get_dim(array); … … 444 428 printf("Memory allocation failed.\n"); 445 429 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 } 446 438 } 447 439 } … … 465 457 } 466 458 467 /** Deallocate item.468 *469 * @param item Item node470 */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 node480 */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 node490 */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 node500 */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 node510 */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 node520 */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 node530 */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 node540 */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 Boolean550 */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 Character560 */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 Integer570 */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 String580 */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 Reference590 */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 Reference600 */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 Reference610 */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 Array620 */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 Object630 */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 Resource640 */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 Symbol650 */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 value660 * @param dest Place to store pointer to new value661 */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 670 459 /** Make copy of a variable. 671 460 * … … 681 470 682 471 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 of692 * @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;700 472 701 473 switch (src->vc) { 702 474 case vc_bool: 703 rdata_bool_copy(src->u.bool_v, & dest->u.bool_v);475 rdata_bool_copy(src->u.bool_v, &nvar->u.bool_v); 704 476 break; 705 477 case vc_char: 706 rdata_char_copy(src->u.char_v, & dest->u.char_v);478 rdata_char_copy(src->u.char_v, &nvar->u.char_v); 707 479 break; 708 480 case vc_int: 709 rdata_int_copy(src->u.int_v, & dest->u.int_v);481 rdata_int_copy(src->u.int_v, &nvar->u.int_v); 710 482 break; 711 483 case vc_string: 712 rdata_string_copy(src->u.string_v, & dest->u.string_v);484 rdata_string_copy(src->u.string_v, &nvar->u.string_v); 713 485 break; 714 486 case vc_ref: 715 rdata_ref_copy(src->u.ref_v, & dest->u.ref_v);487 rdata_ref_copy(src->u.ref_v, &nvar->u.ref_v); 716 488 break; 717 489 case vc_deleg: 718 rdata_deleg_copy(src->u.deleg_v, & dest->u.deleg_v);490 rdata_deleg_copy(src->u.deleg_v, &nvar->u.deleg_v); 719 491 break; 720 492 case vc_enum: 721 rdata_enum_copy(src->u.enum_v, & dest->u.enum_v);493 rdata_enum_copy(src->u.enum_v, &nvar->u.enum_v); 722 494 break; 723 495 case vc_array: 724 rdata_array_copy(src->u.array_v, & dest->u.array_v);496 rdata_array_copy(src->u.array_v, &nvar->u.array_v); 725 497 break; 726 498 case vc_object: 727 rdata_object_copy(src->u.object_v, & dest->u.object_v);499 rdata_object_copy(src->u.object_v, &nvar->u.object_v); 728 500 break; 729 501 case vc_resource: 730 rdata_resource_copy(src->u.resource_v, & dest->u.resource_v);502 rdata_resource_copy(src->u.resource_v, &nvar->u.resource_v); 731 503 break; 732 504 case vc_symbol: 733 rdata_symbol_copy(src->u.symbol_v, &dest->u.symbol_v); 734 break; 735 } 736 } 737 505 rdata_symbol_copy(src->u.symbol_v, &nvar->u.symbol_v); 506 break; 507 } 508 509 *dest = nvar; 510 } 738 511 739 512 /** Copy boolean. 740 513 * 741 * @param src Source boolean 742 * @param dest Place to store pointer to new boolean 514 * @param src Source boolean. 515 * @param dest Place to store pointer to new boolean. 743 516 */ 744 517 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest) … … 750 523 /** Copy character. 751 524 * 752 * @param src Source character 753 * @param dest Place to store pointer to new character 525 * @param src Source character. 526 * @param dest Place to store pointer to new character. 754 527 */ 755 528 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest) … … 761 534 /** Copy integer. 762 535 * 763 * @param src Source integer 764 * @param dest Place to store pointer to new integer 536 * @param src Source integer. 537 * @param dest Place to store pointer to new integer. 765 538 */ 766 539 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest) … … 859 632 *dest = rdata_symbol_new(); 860 633 (*dest)->sym = src->sym; 861 }862 863 /** Destroy var node.864 *865 * @param var Var node866 */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 node879 * itself.880 *881 * @param var Var node882 */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 Item929 */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 Address952 */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 address973 */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 address987 */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 address1015 */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 address1029 */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 Value1062 */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 Boolean1075 */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 Character1084 */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 Integer1094 */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 String1104 */1105 static void rdata_string_destroy(rdata_string_t *string_v)1106 {1107 /*1108 * String values are shared so we cannot free them. Just deallocate1109 * the node.1110 */1111 rdata_string_delete(string_v);1112 }1113 1114 /** Destroy reference.1115 *1116 * @param ref_v Reference1117 */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 Reference1127 */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 Reference1138 */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 Array1148 */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 Object1183 */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 Resource1193 */1194 static void rdata_resource_destroy(rdata_resource_t *resource_v)1195 {1196 /*1197 * XXX Presumably this should be handled by the appropriate1198 * 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 Symbol1207 */1208 static void rdata_symbol_destroy(rdata_symbol_t *symbol_v)1209 {1210 symbol_v->sym = NULL;1211 rdata_symbol_delete(symbol_v);1212 634 } 1213 635 … … 1249 671 void rdata_var_write(rdata_var_t *var, rdata_value_t *value) 1250 672 { 1251 /* Free old content of var->u */ 1252 rdata_var_destroy_inner(var); 673 rdata_var_t *nvar; 1253 674 1254 675 /* Perform a shallow copy of @c value->var. */ 1255 rdata_var_copy_to(value->var, 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. */ 1256 696 } 1257 697 -
uspace/app/sbi/src/rdata.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);44 43 rdata_ref_t *rdata_ref_new(void); 45 44 rdata_deleg_t *rdata_deleg_new(void); … … 54 53 rdata_symbol_t *rdata_symbol_new(void); 55 54 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 77 55 void rdata_array_alloc_element(rdata_array_t *array); 78 void rdata_value_copy(rdata_value_t *val, rdata_value_t **rval);79 56 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);89 57 90 58 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem); -
uspace/app/sbi/src/rdata_t.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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. 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. 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. 279 276 */ 280 277 rdata_var_t *var; -
uspace/app/sbi/src/run.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);56 55 static void run_while(run_t *run, stree_while_t *while_s); 57 56 static void run_raise(run_t *run, stree_raise_t *raise_s); … … 143 142 run_proc_ar_set_args(run, proc_ar, &main_args); 144 143 run_proc(run, proc_ar, &res); 145 run_proc_ar_destroy(run, proc_ar);146 144 147 145 run_exc_check_unhandled(run); … … 274 272 assert(list_node_data(node, run_block_ar_t *) == block_ar); 275 273 list_remove(&proc_ar->block_ar, node); 276 277 /* Deallocate block activation record. */278 run_block_ar_destroy(run, block_ar);279 274 } 280 275 … … 308 303 run_if(run, stat->u.if_s); 309 304 break; 310 case st_switch:311 run_switch(run, stat->u.switch_s);312 break;313 305 case st_while: 314 306 run_while(run, stat->u.while_s); … … 350 342 run_expr(run, exps->expr, &rexpr); 351 343 352 /*353 * If the expression has a value, the caller should have asked for it.354 */355 assert(res != NULL || rexpr == NULL);356 357 344 if (res != NULL) 358 345 *res = rexpr; … … 368 355 run_block_ar_t *block_ar; 369 356 rdata_var_t *var, *old_var; 357 tdata_item_t *var_ti; 370 358 371 359 #ifdef DEBUG_RUN_TRACE 372 360 printf("Executing variable declaration statement.\n"); 373 361 #endif 362 /* Compute variable type. XXX Memoize. */ 363 run_texpr(run->program, run_get_current_csi(run), vdecl->type, 364 &var_ti); 365 374 366 /* Create variable and initialize with default value. */ 375 run_var_new(run, v decl->titem, &var);367 run_var_new(run, var_ti, &var); 376 368 377 369 block_ar = run_get_current_block_ar(run); … … 401 393 list_node_t *ifc_node; 402 394 stree_if_clause_t *ifc; 403 bool_t rcond_b,clause_fired;395 bool_t clause_fired; 404 396 405 397 #ifdef DEBUG_RUN_TRACE … … 419 411 return; 420 412 421 rcond_b = run_item_boolean_value(run, rcond); 422 rdata_item_destroy(rcond); 423 424 if (rcond_b == b_true) { 413 if (run_item_boolean_value(run, rcond) == b_true) { 425 414 #ifdef DEBUG_RUN_TRACE 426 415 printf("Taking non-default path.\n"); … … 447 436 } 448 437 449 /** Run @c switch statement.450 *451 * @param run Runner object452 * @param switch_s Switch statement to run453 */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_TRACE466 printf("Executing switch statement.\n");467 #endif468 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_TRACE519 printf("Taking non-default path.\n");520 #endif521 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_TRACE538 printf("Taking default path.\n");539 #endif540 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_TRACE547 printf("Switch statement terminated.\n");548 #endif549 }550 551 438 /** Run @c while statement. 552 439 * … … 566 453 567 454 while (run_item_boolean_value(run, rcond) == b_true) { 568 rdata_item_destroy(rcond);569 455 run_block(run, while_s->body); 570 456 run_expr(run, while_s->cond, &rcond); … … 573 459 } 574 460 575 if (rcond != NULL)576 rdata_item_destroy(rcond);577 578 461 if (run->thread_ar->bo_mode == bm_stat) { 579 462 /* Bailout due to break statement */ … … 604 487 605 488 run_cvt_value_item(run, rexpr, &rexpr_vi); 606 rdata_item_destroy(rexpr);607 if (run_is_bo(run))608 return;609 489 610 490 /* Store expression cspan in thread AR. */ … … 612 492 613 493 /* Store expression result in thread AR. */ 614 /* XXX rexpr_vi is leaked here, we only return ->u.value */615 494 run->thread_ar->exc_payload = rexpr_vi->u.value; 616 495 … … 662 541 663 542 run_cvt_value_item(run, rexpr, &rexpr_vi); 664 rdata_item_destroy(rexpr);665 if (run_is_bo(run))666 return;667 543 668 544 /* Store expression result in procedure AR. */ … … 756 632 { 757 633 stree_csi_t *exc_csi; 634 tdata_item_t *etype; 758 635 759 636 /* Get CSI of active exception. */ 760 637 exc_csi = run_exc_payload_get_csi(run); 761 638 639 /* Evaluate type expression in except clause. */ 640 run_texpr(run->program, run_get_current_csi(run), except_c->etype, 641 &etype); 642 762 643 /* Determine if active exc. is derived from type in exc. clause. */ 763 644 /* XXX This is wrong, it does not work with generics. */ 764 return tdata_is_csi_derived_from_ti(exc_csi, e xcept_c->titem);645 return tdata_is_csi_derived_from_ti(exc_csi, etype); 765 646 } 766 647 … … 1128 1009 (void) run; 1129 1010 1130 /* Create procedureactivation record. */1011 /* Create function activation record. */ 1131 1012 proc_ar = run_proc_ar_new(); 1132 1013 proc_ar->obj = obj; … … 1143 1024 *rproc_ar = proc_ar; 1144 1025 } 1145 1146 /** Destroy a procedure AR.1147 *1148 * @param run Runner object1149 * @param proc_ar Pointer to procedure activation record1150 */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 1172 1026 1173 1027 /** Fill arguments in a procedure AR. … … 1201 1055 rdata_ref_t *ref; 1202 1056 rdata_array_t *array; 1203 rdata_var_t *elem_var;1204 1057 int n_vargs, idx; 1205 1058 … … 1294 1147 assert(rarg->ic == ic_value); 1295 1148 1296 run_value_item_to_var(rarg, &elem_var); 1297 array->element[idx] = elem_var; 1149 rdata_var_write(array->element[idx], rarg->u.value); 1298 1150 1299 1151 rarg_n = list_next(arg_vals, rarg_n); … … 1389 1241 } 1390 1242 1391 /** Destroy a block AR.1392 *1393 * @param run Runner object1394 * @param proc_ar Pointer to block activation record1395 */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 1421 1243 /** Convert item to value item. 1422 1244 * … … 1447 1269 } 1448 1270 1449 /* Make a copy of the var node within. */1271 /* It already is a value, we can share the @c var. */ 1450 1272 value = rdata_value_new(); 1451 rdata_var_copy(item->u.value->var, &value->var);1273 value->var = item->u.value->var; 1452 1274 *ritem = rdata_item_new(ic_value); 1453 1275 (*ritem)->u.value = value; … … 1536 1358 { 1537 1359 (void) run; 1538 assert(ritem != NULL);1539 1360 1540 1361 switch (address->ac) { … … 1547 1368 } 1548 1369 1549 assert( *ritem == NULL ||(*ritem)->ic == ic_value);1370 assert((*ritem)->ic == ic_value); 1550 1371 } 1551 1372 … … 1636 1457 run_proc(run, proc_ar, ritem); 1637 1458 1638 /* Destroy procedure activation record. */1639 run_proc_ar_destroy(run, proc_ar);1640 1641 1459 #ifdef DEBUG_RUN_TRACE 1642 1460 printf("Getter returns "); … … 1711 1529 /* Setter should not return a value. */ 1712 1530 assert(ritem == NULL); 1713 1714 /* Destroy procedure activation record. */1715 run_proc_ar_destroy(run, proc_ar);1716 1531 1717 1532 #ifdef DEBUG_RUN_TRACE … … 1775 1590 #endif 1776 1591 run_cvt_value_item(run, ref, &ref_val); 1777 if (run_is_bo(run)) {1778 *ritem = run_recovery_item(run);1779 return;1780 }1781 1782 1592 assert(ref_val->u.value->var->vc == vc_ref); 1783 1593 … … 1788 1598 address->u.var_a = addr_var; 1789 1599 addr_var->vref = ref_val->u.value->var->u.ref_v->vref; 1790 1791 rdata_item_destroy(ref_val);1792 1600 1793 1601 if (addr_var->vref == NULL) { … … 2032 1840 } 2033 1841 2034 /** Allocate a new procedure activation record. 2035 * 1842 /** Construct a new procedure activation record. 1843 * 1844 * @param run Runner object 2036 1845 * @return New procedure AR. 2037 1846 */ … … 2049 1858 } 2050 1859 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. 1860 /** Construct a new block activation record. 2062 1861 * 2063 1862 * @param run Runner object … … 2076 1875 return block_ar; 2077 1876 } 2078 2079 /** Deallocate a new block activation record.2080 *2081 * @param run Runner object2082 * @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
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);64 63 65 64 var_class_t run_item_get_vc(run_t *run, rdata_item_t *item); … … 80 79 run_thread_ar_t *run_thread_ar_new(void); 81 80 run_proc_ar_t *run_proc_ar_new(void); 82 void run_proc_ar_delete(run_proc_ar_t *proc_ar);83 81 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 88 82 89 83 #endif -
uspace/app/sbi/src/run_expr.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);116 115 117 116 static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res); … … 201 200 rdata_address_t *address; 202 201 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;206 202 rdata_value_t *value; 207 203 rdata_var_t *var; … … 338 334 break; 339 335 case sc_var: 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. */ 336 #ifdef DEBUG_RUN_TRACE 337 printf("Referencing member variable.\n"); 338 #endif 339 /* There should be no global variables. */ 348 340 assert(csi != NULL); 349 341 350 342 if (symbol_search_csi(run->program, csi, nameref->name) 351 343 == NULL && !stree_symbol_is_static(sym)) { 352 /* Symbolis not in the current object. */344 /* Variable is not in the current object. */ 353 345 printf("Error: Cannot access non-static member " 354 346 "variable '"); … … 360 352 } 361 353 362 /*363 * Determine object in which the symbol resides364 */365 354 if (stree_symbol_is_static(sym)) { 366 355 /* 367 * Class object368 356 * XXX This is too slow! 369 357 * … … 377 365 aobj = sobj->u.object_v; 378 366 } else { 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;; 367 aobj = obj; 386 368 } 387 369 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 } 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(); 421 389 break; 422 390 } … … 643 611 rdata_value_t *v1, *v2; 644 612 645 rarg1_i = NULL;646 rarg2_i = NULL;647 rarg1_vi = NULL;648 rarg2_vi = NULL;649 650 613 #ifdef DEBUG_RUN_TRACE 651 614 printf("Run binary operation.\n"); … … 653 616 run_expr(run, binop->arg1, &rarg1_i); 654 617 if (run_is_bo(run)) { 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; 618 *res = NULL; 619 return; 666 620 } 667 621 668 622 run_expr(run, binop->arg2, &rarg2_i); 669 623 if (run_is_bo(run)) { 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 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); 677 633 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 }682 634 683 635 v1 = rarg1_vi->u.value; … … 716 668 assert(b_false); 717 669 } 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);728 670 } 729 671 … … 1112 1054 rdata_bool_t *bool_v; 1113 1055 1114 stree_embr_t *e1, *e2;1056 rdata_var_t *ref1, *ref2; 1115 1057 1116 1058 (void) run; … … 1125 1067 var->u.bool_v = bool_v; 1126 1068 1127 e1 = v1->var->u.enum_v->value;1128 e2 = v2->var->u.enum_v->value;1069 ref1 = v1->var->u.ref_v->vref; 1070 ref2 = v2->var->u.ref_v->vref; 1129 1071 1130 1072 switch (binop->bc) { 1131 1073 case bo_equal: 1132 bool_v->value = ( e1 == e2);1074 bool_v->value = (ref1 == ref2); 1133 1075 break; 1134 1076 case bo_notequal: 1135 bool_v->value = ( e1 != e2);1077 bool_v->value = (ref1 != ref2); 1136 1078 break; 1137 1079 default: … … 1158 1100 printf("Run unary operation.\n"); 1159 1101 #endif 1160 rarg_i = NULL;1161 rarg_vi = NULL;1162 1163 1102 run_expr(run, unop->arg, &rarg_i); 1164 1103 if (run_is_bo(run)) { 1165 *res = run_recovery_item(run);1166 goto cleanup;1104 *res = NULL; 1105 return; 1167 1106 } 1168 1107 … … 1171 1110 #endif 1172 1111 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 }1177 1112 1178 1113 val = rarg_vi->u.value; … … 1189 1124 "type %d.\n", val->var->vc); 1190 1125 run_raise_error(run); 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); 1126 *res = NULL; 1127 break; 1128 } 1199 1129 } 1200 1130 … … 1278 1208 *res = item; 1279 1209 } 1280 1281 /** Run equality comparison of two values1282 *1283 * This should be equivalent to equality ('==') binary operation.1284 * XXX Duplicating code of run_binop_xxx().1285 *1286 * @param run Runner object1287 * @param v1 Value of first argument1288 * @param v2 Value of second argument1289 * @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 1353 1210 1354 1211 /** Evaluate @c new operation. … … 1440 1297 run_expr(run, expr, &rexpr); 1441 1298 if (run_is_bo(run)) { 1442 *res = run_recovery_item(run);1299 *res = NULL; 1443 1300 return; 1444 1301 } 1445 1302 1446 1303 run_cvt_value_item(run, rexpr, &rexpr_vi); 1447 if (run_is_bo(run)) {1448 *res = run_recovery_item(run);1449 return;1450 }1451 1452 1304 assert(rexpr_vi->ic == ic_value); 1453 1305 rexpr_var = rexpr_vi->u.value->var; … … 1523 1375 run_call_args(run, &new_op->ctor_args, &arg_vals); 1524 1376 if (run_is_bo(run)) { 1525 *res = run_recovery_item(run);1377 *res = NULL; 1526 1378 return; 1527 1379 } … … 1535 1387 assert(obj_i->u.address->ac == ac_var); 1536 1388 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);1541 1389 } 1542 1390 … … 1556 1404 printf("Run access operation.\n"); 1557 1405 #endif 1558 rarg = NULL;1559 1560 1406 run_expr(run, access->arg, &rarg); 1561 1407 if (run_is_bo(run)) { 1562 *res = run_recovery_item(run);1563 goto cleanup;1408 *res = NULL; 1409 return; 1564 1410 } 1565 1411 … … 1570 1416 1571 1417 run_access_item(run, access, rarg, res); 1572 cleanup:1573 if (rarg != NULL)1574 rdata_item_destroy(rarg);1575 1418 } 1576 1419 … … 1641 1484 /* Try again. */ 1642 1485 run_access_item(run, access, darg, res); 1643 1644 /* Destroy temporary */1645 rdata_item_destroy(darg);1646 1486 } 1647 1487 … … 1950 1790 #endif 1951 1791 run_cvt_value_item(run, arg, &arg_vi); 1952 if (run_is_bo(run)) {1953 *res = run_recovery_item(run);1954 return;1955 }1956 1957 1792 arg_val = arg_vi->u.value; 1958 1793 assert(arg_val->var->vc == vc_symbol); … … 1965 1800 embr = stree_enum_find_mbr(symbol_v->sym->u.enum_d, 1966 1801 access->member_name); 1967 1968 rdata_item_destroy(arg_vi);1969 1802 1970 1803 /* Member existence should be ensured by static type checking. */ … … 2008 1841 printf("Run call operation.\n"); 2009 1842 #endif 2010 rdeleg = NULL;2011 rdeleg_vi = NULL;2012 2013 1843 run_expr(run, call->fun, &rdeleg); 2014 1844 if (run_is_bo(run)) { 1845 *res = NULL; 1846 return; 1847 } 1848 1849 if (run->thread_ar->bo_mode != bm_none) { 2015 1850 *res = run_recovery_item(run); 2016 goto cleanup;1851 return; 2017 1852 } 2018 1853 2019 1854 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 2025 1855 assert(rdeleg_vi->ic == ic_value); 2026 1856 … … 2047 1877 run_call_args(run, &call->args, &arg_vals); 2048 1878 if (run_is_bo(run)) { 2049 *res = run_recovery_item(run);2050 goto cleanup;1879 *res = NULL; 1880 return; 2051 1881 } 2052 1882 … … 2059 1889 /* Fill in argument values. */ 2060 1890 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);2064 1891 2065 1892 /* Run the function. */ … … 2073 1900 } 2074 1901 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 2084 1902 #ifdef DEBUG_RUN_TRACE 2085 1903 printf("Returned from function call.\n"); … … 2110 1928 run_expr(run, arg, &rarg_i); 2111 1929 if (run_is_bo(run)) 2112 goto error;1930 return; 2113 1931 2114 1932 run_cvt_value_item(run, rarg_i, &rarg_vi); 2115 rdata_item_destroy(rarg_i);2116 if (run_is_bo(run))2117 goto error;2118 1933 2119 1934 list_append(arg_vals, rarg_vi); 2120 1935 arg_n = list_next(args, arg_n); 2121 1936 } 2122 return;2123 2124 error:2125 /*2126 * An exception or error occured while evaluating one of the2127 * arguments. Destroy already obtained argument values and2128 * 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 them2136 * 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 the2148 * arguments. Destroy already obtained argument values and2149 * 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);2159 1937 } 2160 1938 … … 2176 1954 var_class_t vc; 2177 1955 list_t arg_vals; 2178 list_node_t *val_n;2179 rdata_item_t *val_i;2180 1956 2181 1957 #ifdef DEBUG_RUN_TRACE … … 2184 1960 run_expr(run, index->base, &rbase); 2185 1961 if (run_is_bo(run)) { 2186 *res = run_recovery_item(run);1962 *res = NULL; 2187 1963 return; 2188 1964 } … … 2193 1969 if (vc == vc_ref) { 2194 1970 run_dereference(run, rbase, index->base->cspan, &base_i); 2195 rdata_item_destroy(rbase);2196 1971 if (run_is_bo(run)) { 2197 *res = run_recovery_item(run);1972 *res = NULL; 2198 1973 return; 2199 1974 } … … 2212 1987 run_expr(run, arg, &rarg_i); 2213 1988 if (run_is_bo(run)) { 2214 *res = run_recovery_item(run);2215 goto cleanup;1989 *res = NULL; 1990 return; 2216 1991 } 2217 1992 2218 1993 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 }2224 1994 2225 1995 list_append(&arg_vals, rarg_vi); … … 2242 2012 exit(1); 2243 2013 } 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 the2250 * arguments. Destroy already obtained argument values and2251 * 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);2262 2014 } 2263 2015 … … 2384 2136 2385 2137 list_node_t *node; 2386 rdata_item_t *arg , *arg_copy;2138 rdata_item_t *arg; 2387 2139 2388 2140 #ifdef DEBUG_RUN_TRACE … … 2434 2186 while (node != NULL) { 2435 2187 arg = list_node_data(node, rdata_item_t *); 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); 2188 list_append(&aprop_indexed->args, arg); 2446 2189 node = list_next(args, node); 2447 2190 } … … 2482 2225 2483 2226 run_cvt_value_item(run, base, &base_vi); 2484 if (run_is_bo(run)) {2485 *res = run_recovery_item(run);2486 return;2487 }2488 2489 2227 assert(base_vi->u.value->var->vc == vc_string); 2490 2228 string = base_vi->u.value->var->u.string_v; … … 2539 2277 index->expr->cspan); 2540 2278 *res = run_recovery_item(run); 2541 goto cleanup;2279 return; 2542 2280 } 2543 2281 … … 2553 2291 2554 2292 *res = ritem; 2555 cleanup:2556 rdata_item_destroy(base_vi);2557 2293 } 2558 2294 … … 2574 2310 printf("Run assign operation.\n"); 2575 2311 #endif 2576 rdest_i = NULL;2577 rsrc_i = NULL;2578 rsrc_vi = NULL;2579 2580 2312 run_expr(run, assign->dest, &rdest_i); 2581 2313 if (run_is_bo(run)) { 2582 *res = run_recovery_item(run);2583 goto cleanup;2314 *res = NULL; 2315 return; 2584 2316 } 2585 2317 2586 2318 run_expr(run, assign->src, &rsrc_i); 2587 2319 if (run_is_bo(run)) { 2588 *res = run_recovery_item(run);2589 goto cleanup;2320 *res = NULL; 2321 return; 2590 2322 } 2591 2323 2592 2324 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 2598 2325 assert(rsrc_vi->ic == ic_value); 2599 2326 … … 2607 2334 2608 2335 *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);2616 2336 } 2617 2337 … … 2639 2359 run_expr(run, as_op->arg, &rarg_i); 2640 2360 if (run_is_bo(run)) { 2641 *res = run_recovery_item(run);2361 *res = NULL; 2642 2362 return; 2643 2363 } … … 2649 2369 assert(run_item_get_vc(run, rarg_i) == vc_ref); 2650 2370 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 2658 2371 assert(rarg_vi->ic == ic_value); 2659 2372 … … 2692 2405 } 2693 2406 2694 /* The dereferenced item is not used anymore. */2695 rdata_item_destroy(rarg_di);2696 2697 2407 *res = rarg_vi; 2698 2408 } … … 2725 2435 run_expr(run, box->arg, &rarg_i); 2726 2436 if (run_is_bo(run)) { 2727 *res = run_recovery_item(run);2437 *res = NULL; 2728 2438 return; 2729 2439 } 2730 2440 2731 2441 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 2738 2442 assert(rarg_vi->ic == ic_value); 2739 2443 … … 2778 2482 2779 2483 rdata_var_write(mbr_var, rarg_vi->u.value); 2780 rdata_item_destroy(rarg_vi);2781 2484 } 2782 2485 … … 2954 2657 assert(res == NULL); 2955 2658 2956 /* Destroy procedure activation record. */2957 run_proc_ar_destroy(run, proc_ar);2958 2959 2659 #ifdef DEBUG_RUN_TRACE 2960 2660 printf("Returned from constructor..\n"); … … 2975 2675 rdata_item_t *vitem; 2976 2676 rdata_var_t *var; 2977 bool_t res;2978 2677 2979 2678 (void) run; 2980 2679 run_cvt_value_item(run, item, &vitem); 2981 if (run_is_bo(run))2982 return b_true;2983 2680 2984 2681 assert(vitem->ic == ic_value); … … 2986 2683 2987 2684 assert(var->vc == vc_bool); 2988 res = var->u.bool_v->value; 2989 2990 /* Free value item */ 2991 rdata_item_destroy(vitem); 2992 return res; 2993 } 2685 return var->u.bool_v->value; 2686 } -
uspace/app/sbi/src/run_expr.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);42 41 bool_t run_item_boolean_value(run_t *run, rdata_item_t *item); 43 42 -
uspace/app/sbi/src/stree.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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 statement402 */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 416 399 /** Allocate new @c while statement. 417 400 * … … 565 548 566 549 return if_clause; 567 }568 569 /** Allocate new @c when clause.570 *571 * @return New @c when clause572 */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;584 550 } 585 551 -
uspace/app/sbi/src/stree.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);58 57 stree_while_t *stree_while_new(void); 59 58 stree_for_t *stree_for_new(void); … … 66 65 stree_except_t *stree_except_new(void); 67 66 stree_if_clause_t *stree_if_clause_new(void); 68 stree_when_t *stree_when_new(void);69 67 stree_block_t *stree_block_new(void); 70 68 -
uspace/app/sbi/src/stree_t.h
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 364 364 } texpr_class_t; 365 365 366 /** Typeexpression */366 /** Arithmetic 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;399 396 } stree_vdecl_t; 400 397 … … 404 401 stree_texpr_t *etype; 405 402 stree_block_t *block; 406 407 /** Evaluated etype or @c NULL if not typed yet */408 struct tdata_item *titem;409 403 } stree_except_t; 410 404 … … 424 418 } stree_if_t; 425 419 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 445 420 /** While statement */ 446 421 typedef struct { … … 473 448 } stree_exps_t; 474 449 475 /** With-try-except-finally (WEF) statement*/450 /** With-try-except-finally statement (WEF) */ 476 451 typedef struct { 477 452 stree_block_t *with_block; … … 484 459 st_vdecl, 485 460 st_if, 486 st_switch,487 461 st_while, 488 462 st_for, … … 501 475 stree_vdecl_t *vdecl_s; 502 476 stree_if_t *if_s; 503 stree_switch_t *switch_s;504 477 stree_while_t *while_s; 505 478 stree_for_t *for_s; … … 537 510 /** Function signature. 538 511 * 539 * Fo rmal parameters and return type. This is common to function and delegate512 * Foormal parameters and return type. This is common to function and delegate 540 513 * delcarations. 541 514 */ … … 815 788 } u; 816 789 817 /** Containing CSI */790 /** Containing CSI (for all symbols) */ 818 791 stree_csi_t *outer_csi; 819 792 820 /** Symbol attributes */ 793 /** Containing block (for block-level symbols) */ 794 stree_block_t *outer_block; 795 796 /** Symbol attributes. */ 821 797 list_t attr; /* of stree_symbol_attr_t */ 822 798 } stree_symbol_t; -
uspace/app/sbi/src/stype.c
rb64eac6 r1614ce3 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 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);79 78 static void stype_while(stype_t *stype, stree_while_t *while_s); 80 79 static void stype_for(stype_t *stype, stree_for_t *for_s); … … 890 889 case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break; 891 890 case st_if: stype_if(stype, stat->u.if_s); break; 892 case st_switch: stype_switch(stype, stat->u.switch_s); break;893 891 case st_while: stype_while(stype, stat->u.while_s); break; 894 892 case st_for: stype_for(stype, stat->u.for_s); break; … … 933 931 } 934 932 935 /* Annotate with variable type */936 vdecl_s->titem = titem;937 938 933 intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s); 939 934 } … … 978 973 if (if_s->else_block != NULL) 979 974 stype_block(stype, if_s->else_block); 980 }981 982 /** Type @c switch statement.983 *984 * @param stype Static typing object985 * @param switch_s @c switch statement986 */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_TRACE996 printf("Type 'switch' statement.\n");997 #endif998 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);1047 975 } 1048 976 … … 1240 1168 while (ec_n != NULL) { 1241 1169 ec = list_node_data(ec_n, stree_except_t *); 1242 run_texpr(stype->program, stype->current_csi, ec->etype,1243 &ec->titem);1244 1170 stype_block(stype, ec->block); 1245 1171 -
uspace/app/sbi/src/stype_expr.c
rb64eac6 r1614ce3 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 }903 896 904 897 if (titem->tic == tic_ignore) { -
uspace/dist/src/sysel/demos/arith.sy
rb64eac6 r1614ce3 30 30 fun Main(), static is 31 31 -- Test addition, multiplication and precedence. 32 Console.Write("2*2 + 2*2 = ");33 Console.Write(2*2 + 2*2);34 Console.WriteLine(" (expected: 8)");32 Builtin.Write("2*2 + 2*2 = "); 33 Builtin.Write(2*2 + 2*2); 34 Builtin.WriteLine(" (expected: 8)"); 35 35 36 36 -- Test subtraction, multiplication and precedence. 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)");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)"); 40 40 41 41 -- Test parenthesized sub-expressions. 42 Console.Write("10 * (1 - 1) = ");43 Console.Write(10 * (1 - 1));44 Console.WriteLine(" (expected: 0)");42 Builtin.Write("10 * (1 - 1) = "); 43 Builtin.Write(10 * (1 - 1)); 44 Builtin.WriteLine(" (expected: 0)"); 45 45 46 46 -- Test unary plus and minus. 47 Console.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = ");48 Console.Write((+1) - (-1) - (+(+1)) + (+(-1)));49 Console.WriteLine(" (expected: 0)");47 Builtin.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = "); 48 Builtin.Write((+1) - (-1) - (+(+1)) + (+(-1))); 49 Builtin.WriteLine(" (expected: 0)"); 50 50 51 51 -- Test signed multiplication. 52 Console.Write("+1 * +1 = ");53 Console.Write(+1 * +1);54 Console.WriteLine(" (expected: 1)");52 Builtin.Write("+1 * +1 = "); 53 Builtin.Write(+1 * +1); 54 Builtin.WriteLine(" (expected: 1)"); 55 55 56 Console.Write("-1 * -1 = ");57 Console.Write(-1 * -1);58 Console.WriteLine(" (expected: 1)");56 Builtin.Write("-1 * -1 = "); 57 Builtin.Write(-1 * -1); 58 Builtin.WriteLine(" (expected: 1)"); 59 59 60 Console.Write("+1 * -1 = ");61 Console.Write(+1 * -1);62 Console.WriteLine(" (expected: -1)");60 Builtin.Write("+1 * -1 = "); 61 Builtin.Write(+1 * -1); 62 Builtin.WriteLine(" (expected: -1)"); 63 63 64 Console.Write("-1 * +1 = ");65 Console.Write(-1 * +1);66 Console.WriteLine(" (expected: -1)");64 Builtin.Write("-1 * +1 = "); 65 Builtin.Write(-1 * +1); 66 Builtin.WriteLine(" (expected: -1)"); 67 67 68 68 -- Test multiplication with large result. 69 Console.Write("1000000 * 1000000 * 1000000 * 1000000 = ");70 Console.Write(1000000 * 1000000 * 1000000 * 1000000);71 Console.WriteLine(" (expected: 1000000000000000000000000)");69 Builtin.Write("1000000 * 1000000 * 1000000 * 1000000 = "); 70 Builtin.Write(1000000 * 1000000 * 1000000 * 1000000); 71 Builtin.WriteLine(" (expected: 1000000000000000000000000)"); 72 72 73 73 -- Test large literals. 74 Console.Write("1000000000000000000000000 = ");75 Console.Write(1000000000000000000000000);76 Console.WriteLine(" (expected: 1000000000000000000000000)");74 Builtin.Write("1000000000000000000000000 = "); 75 Builtin.Write(1000000000000000000000000); 76 Builtin.WriteLine(" (expected: 1000000000000000000000000)"); 77 77 78 78 -- Test large factorials. 79 79 var n : int; 80 80 81 Console.WriteLine("Factorials:");81 Builtin.WriteLine("Factorials:"); 82 82 n = 1; 83 83 while n <= 40 do 84 Console.WriteLine(Factorial(n));84 Builtin.WriteLine(Factorial(n)); 85 85 n = n + 1; 86 86 end -
uspace/dist/src/sysel/demos/array.sy
rb64eac6 r1614ce3 40 40 i = 0; 41 41 while i < 3 do 42 Console.WriteLine(a[i, 0]);42 Builtin.WriteLine(a[i, 0]); 43 43 i = i + 1; 44 44 end -
uspace/dist/src/sysel/demos/autobox.sy
rb64eac6 r1614ce3 39 39 -- 40 40 b = true; 41 Console.WriteLine(b.Value);41 Builtin.WriteLine(b.Value); 42 42 c = 'a'; 43 Console.WriteLine(c.Value);43 Builtin.WriteLine(c.Value); 44 44 i = 1; 45 Console.WriteLine(i.Value);45 Builtin.WriteLine(i.Value); 46 46 s = "Hello"; 47 Console.WriteLine(s.Value);47 Builtin.WriteLine(s.Value); 48 48 49 49 -- Anything can be converted to Object. -
uspace/dist/src/sysel/demos/count.sy
rb64eac6 r1614ce3 33 33 i = a; 34 34 while i < b do 35 Console.WriteLine(i);35 Builtin.WriteLine(i); 36 36 i = i + 1; 37 37 end -
uspace/dist/src/sysel/demos/ctor.sy
rb64eac6 r1614ce3 32 32 33 33 a = new A(1); 34 Console.Write("a.v = ");35 Console.WriteLine(a.v);34 Builtin.Write("a.v = "); 35 Builtin.WriteLine(a.v); 36 36 end 37 37 end … … 41 41 42 42 new(i : int) is 43 Console.WriteLine("A.new()");43 Builtin.WriteLine("A.new()"); 44 44 v = i; 45 45 end -
uspace/dist/src/sysel/demos/deleg.sy
rb64eac6 r1614ce3 55 55 -- Function having delegate as the first parameger 56 56 fun Operate(op : BinaryOp; opName : string) is 57 Console.Write(opName + "(1, 2): ");58 Console.WriteLine(op(1, 2));57 Builtin.Write(opName + "(1, 2): "); 58 Builtin.WriteLine(op(1, 2)); 59 59 end 60 60 -
uspace/dist/src/sysel/demos/enum.sy
rb64eac6 r1614ce3 31 31 var color : ChessColor; 32 32 33 Console.WriteLine("Set color to ChessColor.Black.");33 Builtin.WriteLine("Set color to ChessColor.Black."); 34 34 color = ChessColor.Black; 35 35 36 Console.Write("Test color == ChessColor.Black.. ");36 Builtin.Write("Test color == ChessColor.Black.. "); 37 37 if color == ChessColor.Black then 38 Console.WriteLine("True - OK");38 Builtin.WriteLine("True - OK"); 39 39 else 40 Console.WriteLine("False - Fail!");40 Builtin.WriteLine("False - Fail!"); 41 41 raise new Error.Base(); 42 42 end 43 43 44 Console.Write("Test color != ChessColor.Black.. ");44 Builtin.Write("Test color != ChessColor.Black.. "); 45 45 if color != ChessColor.Black then 46 Console.WriteLine("True - Fail!");46 Builtin.WriteLine("True - Fail!"); 47 47 raise new Error.Base(); 48 48 else 49 Console.WriteLine("False - OK");49 Builtin.WriteLine("False - OK"); 50 50 end 51 51 52 Console.Write("Test color == ChessColor.White.. ");52 Builtin.Write("Test color == ChessColor.White.. "); 53 53 if color == ChessColor.White then 54 Console.WriteLine("True - Fail!");54 Builtin.WriteLine("True - Fail!"); 55 55 raise new Error.Base(); 56 56 else 57 Console.WriteLine("False - OK");57 Builtin.WriteLine("False - OK"); 58 58 end 59 59 60 Console.Write("Test color != ChessColor.White.. ");60 Builtin.Write("Test color != ChessColor.White.. "); 61 61 if color != ChessColor.White then 62 Console.WriteLine("True - OK");62 Builtin.WriteLine("True - OK"); 63 63 else 64 Console.WriteLine("False - Fail!");64 Builtin.WriteLine("False - Fail!"); 65 65 raise new Error.Base(); 66 66 end 67 67 68 Console.WriteLine("Success");68 Builtin.WriteLine("Success"); 69 69 70 70 -- Test enum declared in non-CSI scope -
uspace/dist/src/sysel/demos/except.sy
rb64eac6 r1614ce3 29 29 class ExceptionDemo is 30 30 fun foo(), static is 31 Console.WriteLine("Entered foo().");31 Builtin.WriteLine("Entered foo()."); 32 32 raise new BaseException(); 33 33 end … … 38 38 foo(); 39 39 except e : DerivedException do 40 Console.WriteLine("Caught derived exception.");40 Builtin.WriteLine("Caught derived exception."); 41 41 except e : BaseException do 42 Console.WriteLine("Caught base exception.");42 Builtin.WriteLine("Caught base exception."); 43 43 finally do 44 Console.WriteLine("Finally.");44 Builtin.WriteLine("Finally."); 45 45 end 46 46 end -
uspace/dist/src/sysel/demos/gen.sy
rb64eac6 r1614ce3 31 31 class GenericsDemo is 32 32 fun Main(), static is 33 Console.WriteLine("Let's try some generics.");33 Builtin.WriteLine("Let's try some generics."); 34 34 35 35 var f : B/int/string; -
uspace/dist/src/sysel/demos/hello.sy
rb64eac6 r1614ce3 29 29 class HelloWorld is 30 30 fun Main(), static is 31 Console.WriteLine("Hello world!");31 Builtin.WriteLine("Hello world!"); 32 32 end 33 33 end -
uspace/dist/src/sysel/demos/htxtfile.sy
rb64eac6 r1614ce3 45 45 while not in_file.EOF do 46 46 line = in_file.ReadLine(); 47 Console.WriteLine(name + ": " + line);47 Builtin.WriteLine(name + ": " + line); 48 48 out_file.WriteLine(name + ": " + line); 49 49 end -
uspace/dist/src/sysel/demos/iface.sy
rb64eac6 r1614ce3 43 43 f = g as Foo; 44 44 45 Console.WriteLine(g.a());45 Builtin.WriteLine(g.a()); 46 46 end 47 47 end -
uspace/dist/src/sysel/demos/inherit.sy
rb64eac6 r1614ce3 29 29 class A is 30 30 fun Foo() is 31 Console.WriteLine("A.Foo()");31 Builtin.WriteLine("A.Foo()"); 32 32 end 33 33 end … … 35 35 class B : A is 36 36 fun Foo() is 37 Console.WriteLine("B.Foo()");37 Builtin.WriteLine("B.Foo()"); 38 38 end 39 39 end -
uspace/dist/src/sysel/demos/list.sy
rb64eac6 r1614ce3 43 43 e = list.GetEnumerator(); 44 44 while e.MoveNext() do 45 Console.WriteLine(e.Data);45 Builtin.WriteLine(e.Data); 46 46 end 47 47 end -
uspace/dist/src/sysel/demos/map.sy
rb64eac6 r1614ce3 43 43 e = map.GetEnumerator(); 44 44 while e.MoveNext() do 45 Console.Write(e.Data);46 Console.Write(" -> ");47 Console.WriteLine(map[e.Data]);45 Builtin.Write(e.Data); 46 Builtin.Write(" -> "); 47 Builtin.WriteLine(map[e.Data]); 48 48 end 49 49 end -
uspace/dist/src/sysel/demos/property.sy
rb64eac6 r1614ce3 33 33 prop X : int is 34 34 get is 35 Console.Write("Getting value of X which is ");36 Console.WriteLine(x);35 Builtin.Write("Getting value of X which is "); 36 Builtin.WriteLine(x); 37 37 return x; 38 38 end 39 39 40 40 set value is 41 Console.Write("Setting value of X to ");42 Console.WriteLine(value);41 Builtin.Write("Setting value of X to "); 42 Builtin.WriteLine(value); 43 43 x = value; 44 44 end 45 end46 47 -- Test accessing property via an unqualified name48 fun TestUnqualPropAcc() is49 var i : int;50 51 X = 1;52 i = X;53 54 Console.Write("TestUnqualPropAcc(): Got ");55 Console.WriteLine(i);56 45 end 57 46 … … 62 51 prop self[index : int] : int is 63 52 get is 64 Console.Write("Getting property with index ");65 Console.Write(index);66 Console.Write(" which is ");67 Console.WriteLine(iprops[index]);53 Builtin.Write("Getting property with index "); 54 Builtin.Write(index); 55 Builtin.Write(" which is "); 56 Builtin.WriteLine(iprops[index]); 68 57 69 58 return iprops[index]; … … 71 60 72 61 set value is 73 Console.Write("Setting property with index ");74 Console.Write(index);75 Console.Write(" to ");76 Console.WriteLine(value);62 Builtin.Write("Setting property with index "); 63 Builtin.Write(index); 64 Builtin.Write(" to "); 65 Builtin.WriteLine(value); 77 66 78 67 iprops[index] = value; … … 93 82 prop B : Bar is 94 83 get is 95 Console.WriteLine("Getting B");84 Builtin.WriteLine("Getting B"); 96 85 return bprop; 97 86 end 98 87 set value is 99 Console.WriteLine("Setting B");88 Builtin.WriteLine("Setting B"); 100 89 bprop = value; 101 90 end … … 121 110 i = a.X; 122 111 123 Console.Write("Main(): Got "); 124 Console.WriteLine(i); 125 126 a.TestUnqualPropAcc(); 112 Builtin.Write("Main(): Got "); 113 Builtin.WriteLine(i); 127 114 128 115 a.iprops = new int[5]; … … 134 121 i = a[1]; 135 122 136 Console.Write("Main(): Got ");137 Console.WriteLine(i);123 Builtin.Write("Main(): Got "); 124 Builtin.WriteLine(i); 138 125 139 126 -- Property field access … … 145 132 a.bprop = b; 146 133 147 Console.WriteLine(a.bprop.i);134 Builtin.WriteLine(a.bprop.i); 148 135 a.bprop.i = 2; 149 Console.WriteLine(a.bprop.i);136 Builtin.WriteLine(a.bprop.i); 150 137 end 151 138 end -
uspace/dist/src/sysel/demos/string.sy
rb64eac6 r1614ce3 30 30 fun Main(), static is 31 31 -- Concatenate some strings. 32 Console.WriteLine("One-" + "two-" + "three!");32 Builtin.WriteLine("One-" + "two-" + "three!"); 33 33 34 34 -- Extract characters from a string. … … 36 36 i = 0; 37 37 while i < 5 do 38 Console.WriteLine("ABCDE"[i]);38 Builtin.WriteLine("ABCDE"[i]); 39 39 i = i + 1; 40 40 end 41 41 42 Console.WriteLine("Abracadabra".Slice(2, 4));42 Builtin.WriteLine("Abracadabra".Slice(2, 4)); 43 43 end 44 44 end -
uspace/dist/src/sysel/demos/svar.sy
rb64eac6 r1614ce3 31 31 -- Test static member variable 32 32 A.B.a = 1; 33 Console.WriteLine(A.B.a);33 Builtin.WriteLine(A.B.a); 34 34 A.B.a = 2; 35 Console.WriteLine(A.B.a);35 Builtin.WriteLine(A.B.a); 36 36 37 37 -- Test static property 38 38 A.B.P = 1; 39 Console.WriteLine(A.B.P);39 Builtin.WriteLine(A.B.P); 40 40 A.B.P = 2; 41 Console.WriteLine(A.B.P);41 Builtin.WriteLine(A.B.P); 42 42 end 43 43 end -
uspace/dist/src/sysel/demos/varargs.sy
rb64eac6 r1614ce3 44 44 -- implemented... 45 45 do 46 Console.WriteLine(args[i]);46 Builtin.WriteLine(args[i]); 47 47 except e : Error.OutOfBounds do 48 48 error = true; -
uspace/srv/hid/console/gcons.c
rb64eac6 r1614ce3 285 285 ssize_t nx = (ssize_t) mouse_x + dx; 286 286 ssize_t ny = (ssize_t) mouse_y + dy; 287 288 /* Until gcons is initalized we don't have the screen resolution */ 289 if (xres == 0 || yres == 0) 287 288 if (!use_gcons) 290 289 return; 291 290
Note:
See TracChangeset
for help on using the changeset viewer.