Changes in / [1ef0fc3:2721a75] in mainline
- Location:
- uspace
- Files:
-
- 6 deleted
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/Makefile
r1ef0fc3 r2721a75 50 50 src/p_type.c \ 51 51 src/parse.c \ 52 src/program.c \53 52 src/rdata.c \ 54 53 src/run.c \ -
uspace/app/sbi/src/builtin/bi_fun.c
r1ef0fc3 r2721a75 99 99 { 100 100 rdata_var_t *var; 101 int char_val;102 int rc;103 101 104 102 #ifdef DEBUG_RUN_TRACE … … 109 107 110 108 switch (var->vc) { 111 case vc_char:112 rc = bigint_get_value_int(&var->u.char_v->value, &char_val);113 if (rc == EOK)114 printf("%lc\n", char_val);115 else116 printf("???\n");117 break;118 109 case vc_int: 119 110 bigint_print(&var->u.int_v->value); -
uspace/app/sbi/src/imode.c
r1ef0fc3 r2721a75 47 47 #include "list.h" 48 48 #include "mytypes.h" 49 #include "program.h"50 49 #include "rdata.h" 51 50 #include "stree.h" … … 91 90 builtin_declare(program); 92 91 93 /* Process the library. */94 if (program_lib_process(program) != EOK)95 exit(1);96 97 92 /* Resolve ancestry. */ 98 93 ancr_module_process(program, program->module); … … 135 130 parse.error = b_false; 136 131 stype.error = b_false; 137 run.thread_ar->exc_payload = NULL;138 run.thread_ar->bo_mode = bm_none;139 132 140 133 input_new_interactive(&input); -
uspace/app/sbi/src/input.c
r1ef0fc3 r2721a75 45 45 #define INPUT_BUFFER_SIZE 256 46 46 47 static int input_init_file(input_t *input, c onst char *fname);47 static int input_init_file(input_t *input, char *fname); 48 48 static void input_init_interactive(input_t *input); 49 49 static void input_init_string(input_t *input, const char *str); … … 57 57 * ENOENT when opening file fails. 58 58 */ 59 int input_new_file(input_t **input, c onst char *fname)59 int input_new_file(input_t **input, char *fname) 60 60 { 61 61 *input = malloc(sizeof(input_t)); … … 104 104 * @return EOK on success, ENOENT when opening file fails. 105 105 */ 106 static int input_init_file(input_t *input, c onst char *fname)106 static int input_init_file(input_t *input, char *fname) 107 107 { 108 108 FILE *f; -
uspace/app/sbi/src/input.h
r1ef0fc3 r2721a75 32 32 #include "mytypes.h" 33 33 34 int input_new_file(input_t **input, c onst char *fname);34 int input_new_file(input_t **input, char *fname); 35 35 int input_new_interactive(input_t **input); 36 36 int input_new_string(input_t **input, const char *str); -
uspace/app/sbi/src/lex.c
r1ef0fc3 r2721a75 53 53 static bool_t is_digit(char c); 54 54 static void lex_word(lex_t *lex); 55 static void lex_char(lex_t *lex);56 55 static void lex_number(lex_t *lex); 57 56 static void lex_string(lex_t *lex); … … 75 74 static struct lc_name keywords[] = { 76 75 { lc_as, "as" }, 77 { lc_bool, "bool" },78 { lc_char, "char" },79 76 { lc_builtin, "builtin" }, 80 77 { lc_class, "class" }, … … 84 81 { lc_end, "end" }, 85 82 { lc_except, "except" }, 86 { lc_false, "false" },87 83 { lc_finally, "finally" }, 88 84 { lc_for, "for" }, … … 112 108 { lc_then, "then" }, 113 109 { lc_this, "this" }, 114 { lc_true, "true" },115 110 { lc_var, "var" }, 116 111 { lc_with, "with" }, … … 343 338 } 344 339 345 if (bp[0] == '\'') {346 lex_char(lex);347 return b_true;348 }349 350 340 if (is_digit(bp[0])) { 351 341 lex_number(lex); … … 470 460 lex->current.lclass = lc_ident; 471 461 lex->current.u.ident.sid = strtab_get_sid(ident_buf); 472 }473 474 /** Lex a character literal.475 *476 * Reads in a character literal and stores it in the current lem in @a lex.477 *478 * @param lex Lexer object.479 */480 static void lex_char(lex_t *lex)481 {482 char *bp;483 int idx;484 size_t len;485 int char_val;486 487 bp = lex->ibp + 1;488 idx = 0;489 490 while (bp[idx] != '\'') {491 if (idx >= SLBUF_SIZE) {492 printf("Error: Character literal too long.\n");493 exit(1);494 }495 496 if (bp[idx] == '\0') {497 printf("Error: Unterminated character literal.\n");498 exit(1);499 }500 501 strlit_buf[idx] = bp[idx];502 ++idx;503 }504 505 lex->ibp = bp + idx + 1;506 507 strlit_buf[idx] = '\0';508 len = os_str_length(strlit_buf);509 if (len != 1) {510 printf("Character literal should contain one character, "511 "but contains %u characters instead.\n", (unsigned) len);512 exit(1);513 }514 515 os_str_get_char(strlit_buf, 0, &char_val);516 lex->current.lclass = lc_lit_char;517 bigint_init(&lex->current.u.lit_char.value, char_val);518 462 } 519 463 -
uspace/app/sbi/src/lex_t.h
r1ef0fc3 r2721a75 38 38 39 39 lc_ident, 40 lc_lit_char,41 40 lc_lit_int, 42 41 lc_lit_string, … … 44 43 /* Keywords */ 45 44 lc_as, 46 lc_bool,47 45 lc_builtin, 48 lc_char,49 46 lc_class, 50 47 lc_constructor, … … 53 50 lc_end, 54 51 lc_except, 55 lc_false,56 52 lc_finally, 57 53 lc_for, … … 81 77 lc_then, 82 78 lc_this, 83 lc_true,84 79 lc_var, 85 80 lc_with, … … 120 115 121 116 typedef struct { 122 /* Character value */123 bigint_t value;124 } lem_lit_char_t;125 126 typedef struct {127 117 /* Integer value */ 128 118 bigint_t value; … … 141 131 union { 142 132 lem_ident_t ident; 143 lem_lit_char_t lit_char;144 133 lem_lit_int_t lit_int; 145 134 lem_lit_string_t lit_string; -
uspace/app/sbi/src/main.c
r1ef0fc3 r2721a75 37 37 #include <stdlib.h> 38 38 #include "ancr.h" 39 #include "os/os.h"40 39 #include "builtin.h" 41 40 #include "imode.h" 42 41 #include "mytypes.h" 43 #include "program.h"44 42 #include "strtab.h" 45 43 #include "stree.h" … … 50 48 #include "run.h" 51 49 52 staticvoid syntax_print(void);50 void syntax_print(void); 53 51 54 52 /** Main entry point. … … 58 56 int main(int argc, char *argv[]) 59 57 { 58 input_t *input; 59 lex_t lex; 60 parse_t parse; 60 61 stree_program_t *program; 61 62 stype_t stype; … … 63 64 int rc; 64 65 65 /* Store executable file path under which we have been invoked. */ 66 os_store_ef_path(*argv); 67 68 argv += 1; 69 argc -= 1; 70 71 if (argc == 0) { 66 if (argc == 1) { 72 67 /* Enter interactive mode */ 73 68 strtab_init(); … … 76 71 } 77 72 78 if ( os_str_cmp(*argv, "-h") == 0) {73 if (argc != 2) { 79 74 syntax_print(); 80 return 0; 75 exit(1); 76 } 77 78 rc = input_new_file(&input, argv[1]); 79 if (rc != EOK) { 80 printf("Failed opening source file '%s'.\n", argv[1]); 81 exit(1); 81 82 } 82 83 … … 88 89 builtin_declare(program); 89 90 90 /* Process source files in the library. */ 91 if (program_lib_process(program) != EOK) 91 /* Parse input file. */ 92 lex_init(&lex, input); 93 parse_init(&parse, program, &lex); 94 parse_module(&parse); 95 96 /* Check for parse errors. */ 97 if (parse.error) 92 98 return 1; 93 99 94 /* Process all source files specified in command-line arguments. */95 while (argc > 0) {96 rc = program_file_process(program, *argv);97 if (rc != EOK)98 return 1;99 100 argv += 1;101 argc -= 1;102 }103 104 100 /* Resolve ancestry. */ 105 ancr_module_process(program, p rogram->module);101 ancr_module_process(program, parse.cur_mod); 106 102 107 103 /* Type program. */ … … 126 122 127 123 /** Print command-line syntax help. */ 128 staticvoid syntax_print(void)124 void syntax_print(void) 129 125 { 126 printf("Missing or invalid arguments.\n"); 130 127 printf("Syntax: sbi <source_file.sy>\n"); 131 128 } -
uspace/app/sbi/src/os/helenos.c
r1ef0fc3 r2721a75 38 38 #include "os.h" 39 39 40 /** Path to executable file via which we have been invoked. */41 static char *ef_path;42 43 40 /* 44 41 * Using HelenOS-specific string API. … … 73 70 { 74 71 return str_cmp(a, b); 75 }76 77 /** Return number of characters in string. */78 size_t os_str_length(const char *str)79 {80 return str_length(str);81 72 } 82 73 … … 165 156 return EOK; 166 157 } 167 168 /** Store the executable file path via which we were executed. */169 void os_store_ef_path(char *path)170 {171 ef_path = path;172 }173 174 /** Return path to the Sysel library175 *176 * @return New string. Caller should deallocate it using @c free().177 */178 char *os_get_lib_path(void)179 {180 return os_str_dup("/src/sysel/lib");181 } -
uspace/app/sbi/src/os/os.h
r1ef0fc3 r2721a75 33 33 int os_str_cmp(const char *a, const char *b); 34 34 char *os_str_dup(const char *str); 35 size_t os_str_length(const char *str);36 35 int os_str_get_char(const char *str, int index, int *out_char); 37 36 void os_input_disp_help(void); … … 39 38 int os_exec(char *const cmd[]); 40 39 41 void os_store_ef_path(char *path);42 char *os_get_lib_path(void);43 40 44 41 #endif -
uspace/app/sbi/src/os/posix.c
r1ef0fc3 r2721a75 29 29 /** @file POSIX-specific code. */ 30 30 31 #include <libgen.h>32 31 #include <stdio.h> 33 32 #include <stdlib.h> … … 40 39 41 40 #include "os.h" 42 43 /** Path to executable file via which we have been invoked. */44 static char *ef_path;45 41 46 42 /* … … 75 71 { 76 72 return strcmp(a, b); 77 }78 79 /** Return number of characters in string. */80 size_t os_str_length(const char *str)81 {82 return strlen(str);83 73 } 84 74 … … 156 146 return EOK; 157 147 } 158 159 /** Store the executable file path via which we were executed. */160 void os_store_ef_path(char *path)161 {162 ef_path = path;163 }164 165 /** Return path to the Sysel library166 *167 * @return New string. Caller should deallocate it using @c free().168 */169 char *os_get_lib_path(void)170 {171 return os_str_acat(dirname(ef_path), "/lib");172 } -
uspace/app/sbi/src/p_expr.c
r1ef0fc3 r2721a75 56 56 static stree_expr_t *parse_primitive(parse_t *parse); 57 57 static stree_expr_t *parse_nameref(parse_t *parse); 58 static stree_expr_t *parse_lit_bool(parse_t *parse);59 static stree_expr_t *parse_lit_char(parse_t *parse);60 58 static stree_expr_t *parse_lit_int(parse_t *parse); 61 59 static stree_expr_t *parse_lit_ref(parse_t *parse); … … 496 494 expr = parse_nameref(parse); 497 495 break; 498 case lc_false:499 case lc_true:500 expr = parse_lit_bool(parse);501 break;502 case lc_lit_char:503 expr = parse_lit_char(parse);504 break;505 496 case lc_lit_int: 506 497 expr = parse_lit_int(parse); … … 540 531 } 541 532 542 /** Parse boolean literal.543 *544 * @param parse Parser object.545 */546 static stree_expr_t *parse_lit_bool(parse_t *parse)547 {548 stree_literal_t *literal;549 stree_expr_t *expr;550 bool_t value;551 552 switch (lcur_lc(parse)) {553 case lc_false: value = b_false; break;554 case lc_true: value = b_true; break;555 default: assert(b_false);556 }557 558 lskip(parse);559 560 literal = stree_literal_new(ltc_bool);561 literal->u.lit_bool.value = value;562 563 expr = stree_expr_new(ec_literal);564 expr->u.literal = literal;565 566 return expr;567 }568 569 /** Parse character literal.570 *571 * @param parse Parser object.572 */573 static stree_expr_t *parse_lit_char(parse_t *parse)574 {575 stree_literal_t *literal;576 stree_expr_t *expr;577 578 lcheck(parse, lc_lit_char);579 580 literal = stree_literal_new(ltc_char);581 bigint_clone(&lcur(parse)->u.lit_char.value,582 &literal->u.lit_char.value);583 584 lskip(parse);585 586 expr = stree_expr_new(ec_literal);587 expr->u.literal = literal;588 589 return expr;590 }591 592 533 /** Parse integer literal. 593 534 * -
uspace/app/sbi/src/p_type.c
r1ef0fc3 r2721a75 78 78 static stree_texpr_t *parse_tapply(parse_t *parse) 79 79 { 80 stree_texpr_t *gtype; 81 stree_texpr_t *aexpr; 82 stree_texpr_t *targ; 80 stree_texpr_t *a, *b, *tmp; 83 81 stree_tapply_t *tapply; 84 82 85 gtype = parse_tpostfix(parse); 86 if (lcur_lc(parse) != lc_slash) 87 return gtype; 88 89 tapply = stree_tapply_new(); 90 tapply->gtype = gtype; 91 list_init(&tapply->targs); 92 83 a = parse_tpostfix(parse); 93 84 while (lcur_lc(parse) == lc_slash) { 94 85 … … 97 88 98 89 lskip(parse); 99 targ = parse_tpostfix(parse); 100 101 list_append(&tapply->targs, targ); 102 } 103 104 aexpr = stree_texpr_new(tc_tapply); 105 aexpr->u.tapply = tapply; 106 return aexpr; 90 b = parse_tpostfix(parse); 91 92 tapply = stree_tapply_new(); 93 tapply->gtype = a; 94 tapply->targ = b; 95 96 tmp = stree_texpr_new(tc_tapply); 97 tmp->u.tapply = tapply; 98 a = tmp; 99 } 100 101 return a; 107 102 } 108 103 … … 229 224 texpr->u.tnameref = parse_tnameref(parse); 230 225 break; 231 case lc_bool:232 case lc_char:233 226 case lc_int: 234 227 case lc_string: … … 256 249 257 250 switch (lcur_lc(parse)) { 258 case lc_bool:259 tlc = tlc_bool;260 break;261 case lc_char:262 tlc = tlc_char;263 break;264 251 case lc_int: 265 252 tlc = tlc_int; -
uspace/app/sbi/src/parse.c
r1ef0fc3 r2721a75 156 156 stree_csimbr_t *csimbr; 157 157 stree_symbol_t *symbol; 158 stree_ident_t *targ_name;159 158 160 159 switch (dclass) { … … 169 168 csi = stree_csi_new(cc); 170 169 csi->name = parse_ident(parse); 171 172 list_init(&csi->targ_names);173 174 while (lcur_lc(parse) == lc_slash) {175 lskip(parse);176 targ_name = parse_ident(parse);177 list_append(&csi->targ_names, targ_name);178 }179 170 180 171 symbol = stree_symbol_new(sc_csi); -
uspace/app/sbi/src/rdata.c
r1ef0fc3 r2721a75 51 51 #include "mytypes.h" 52 52 #include "stree.h" 53 #include "symbol.h"54 53 55 54 #include "rdata.h" 56 55 57 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest);58 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest);59 56 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest); 60 57 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest); … … 290 287 } 291 288 292 /** Allocate new boolean.293 *294 * @return New boolean.295 */296 rdata_bool_t *rdata_bool_new(void)297 {298 rdata_bool_t *bool_v;299 300 bool_v = calloc(1, sizeof(rdata_bool_t));301 if (bool_v == NULL) {302 printf("Memory allocation failed.\n");303 exit(1);304 }305 306 return bool_v;307 }308 309 /** Allocate new character.310 *311 * @return New character.312 */313 rdata_char_t *rdata_char_new(void)314 {315 rdata_char_t *char_v;316 317 char_v = calloc(1, sizeof(rdata_char_t));318 if (char_v == NULL) {319 printf("Memory allocation failed.\n");320 exit(1);321 }322 323 return char_v;324 }325 326 289 /** Allocate new integer. 327 290 * … … 435 398 436 399 switch (src->vc) { 437 case vc_bool:438 rdata_bool_copy(src->u.bool_v, &nvar->u.bool_v);439 break;440 case vc_char:441 rdata_char_copy(src->u.char_v, &nvar->u.char_v);442 break;443 400 case vc_int: 444 401 rdata_int_copy(src->u.int_v, &nvar->u.int_v); … … 465 422 466 423 *dest = nvar; 467 }468 469 /** Copy boolean.470 *471 * @param src Source boolean.472 * @param dest Place to store pointer to new boolean.473 */474 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest)475 {476 *dest = rdata_bool_new();477 (*dest)->value = src->value;478 }479 480 /** Copy character.481 *482 * @param src Source character.483 * @param dest Place to store pointer to new character.484 */485 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest)486 {487 *dest = rdata_char_new();488 bigint_clone(&src->value, &(*dest)->value);489 424 } 490 425 … … 615 550 var->vc = nvar->vc; 616 551 switch (nvar->vc) { 617 case vc_bool: var->u.bool_v = nvar->u.bool_v; break;618 case vc_char: var->u.char_v = nvar->u.char_v; break;619 552 case vc_int: var->u.int_v = nvar->u.int_v; break; 620 553 case vc_string: var->u.string_v = nvar->u.string_v; break; … … 688 621 static void rdata_var_print(rdata_var_t *var) 689 622 { 690 int val;691 692 623 switch (var->vc) { 693 case vc_bool:694 printf("bool(%s)", var->u.bool_v->value ? "true" : "false");695 break;696 case vc_char:697 printf("char(");698 if (bigint_get_value_int(&var->u.char_v->value, &val) == EOK)699 printf("'%c'", val);700 else701 printf("???:x%x\n", (unsigned) val);702 printf(")");703 break;704 624 case vc_int: 705 625 printf("int("); … … 711 631 break; 712 632 case vc_ref: 713 printf("ref("); 714 rdata_var_print(var->u.ref_v->vref); 715 printf(")"); 633 printf("ref"); 716 634 break; 717 635 case vc_deleg: 718 printf("deleg("); 719 if (var->u.deleg_v->obj != NULL) { 720 rdata_var_print(var->u.deleg_v->obj); 721 printf(","); 722 } 723 symbol_print_fqn(var->u.deleg_v->sym); 724 printf(")"); 725 break; 726 case vc_array: 727 printf("array"); 636 printf("deleg"); 728 637 break; 729 638 case vc_object: 730 639 printf("object"); 731 640 break; 732 case vc_resource:733 printf(" resource(%p)", var->u.resource_v->data);734 break;735 } 736 } 641 default: 642 printf("print(%d)\n", var->vc); 643 assert(b_false); 644 } 645 } -
uspace/app/sbi/src/rdata.h
r1ef0fc3 r2721a75 45 45 rdata_array_t *rdata_array_new(int rank); 46 46 rdata_object_t *rdata_object_new(void); 47 rdata_bool_t *rdata_bool_new(void);48 rdata_char_t *rdata_char_new(void);49 47 rdata_int_t *rdata_int_new(void); 50 48 rdata_string_t *rdata_string_new(void); -
uspace/app/sbi/src/rdata_t.h
r1ef0fc3 r2721a75 35 35 #include "intmap_t.h" 36 36 37 /** Boolean variable. */38 typedef struct {39 bool_t value;40 } rdata_bool_t;41 42 /** Character variable.43 *44 * Sysel character type should be able to store arbitrarily (or at least45 * very) large character sets.46 */47 typedef struct {48 bigint_t value;49 } rdata_char_t;50 51 37 /** Integer variable. 52 38 * … … 57 43 bigint_t value; 58 44 } rdata_int_t; 45 59 46 60 47 /** String variable */ … … 117 104 118 105 typedef enum var_class { 119 /** Boolean */120 vc_bool,121 122 /** Character **/123 vc_char,124 125 106 /** Integer */ 126 107 vc_int, … … 155 136 156 137 union { 157 rdata_bool_t *bool_v;158 rdata_char_t *char_v;159 138 rdata_int_t *int_v; 160 139 rdata_string_t *string_v; -
uspace/app/sbi/src/run.c
r1ef0fc3 r2721a75 657 657 void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var) 658 658 { 659 rdata_char_t *char_v;660 659 rdata_int_t *int_v; 661 660 rdata_string_t *string_v; … … 667 666 668 667 switch (in_var->vc) { 669 case vc_char:670 *var = rdata_var_new(vc_char);671 char_v = rdata_char_new();672 673 (*var)->u.char_v = char_v;674 bigint_clone(&item->u.value->var->u.char_v->value,675 &char_v->value);676 break;677 668 case vc_int: 678 669 *var = rdata_var_new(vc_int); -
uspace/app/sbi/src/run_expr.c
r1ef0fc3 r2721a75 53 53 static void run_literal(run_t *run, stree_literal_t *literal, 54 54 rdata_item_t **res); 55 static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool,56 rdata_item_t **res);57 static void run_lit_char(run_t *run, stree_lit_char_t *lit_char,58 rdata_item_t **res);59 55 static void run_lit_int(run_t *run, stree_lit_int_t *lit_int, 60 56 rdata_item_t **res); … … 68 64 69 65 static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res); 70 static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1,71 rdata_value_t *v2, rdata_item_t **res);72 static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1,73 rdata_value_t *v2, rdata_item_t **res);74 66 static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1, 75 67 rdata_value_t *v2, rdata_item_t **res); … … 323 315 printf("Run literal.\n"); 324 316 #endif 317 325 318 switch (literal->ltc) { 326 case ltc_bool:327 run_lit_bool(run, &literal->u.lit_bool, res);328 break;329 case ltc_char:330 run_lit_char(run, &literal->u.lit_char, res);331 break;332 319 case ltc_int: 333 320 run_lit_int(run, &literal->u.lit_int, res); … … 339 326 run_lit_string(run, &literal->u.lit_string, res); 340 327 break; 341 } 342 } 343 344 /** Evaluate Boolean literal. */ 345 static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool, 346 rdata_item_t **res) 347 { 348 rdata_item_t *item; 349 rdata_value_t *value; 350 rdata_var_t *var; 351 rdata_bool_t *bool_v; 352 353 #ifdef DEBUG_RUN_TRACE 354 printf("Run Boolean literal.\n"); 355 #endif 356 (void) run; 357 358 item = rdata_item_new(ic_value); 359 value = rdata_value_new(); 360 var = rdata_var_new(vc_bool); 361 bool_v = rdata_bool_new(); 362 363 item->u.value = value; 364 value->var = var; 365 var->u.bool_v = bool_v; 366 bool_v->value = lit_bool->value; 367 368 *res = item; 369 } 370 371 /** Evaluate character literal. */ 372 static void run_lit_char(run_t *run, stree_lit_char_t *lit_char, 373 rdata_item_t **res) 374 { 375 rdata_item_t *item; 376 rdata_value_t *value; 377 rdata_var_t *var; 378 rdata_char_t *char_v; 379 380 #ifdef DEBUG_RUN_TRACE 381 printf("Run character literal.\n"); 382 #endif 383 (void) run; 384 385 item = rdata_item_new(ic_value); 386 value = rdata_value_new(); 387 var = rdata_var_new(vc_char); 388 char_v = rdata_char_new(); 389 390 item->u.value = value; 391 value->var = var; 392 var->u.char_v = char_v; 393 bigint_clone(&lit_char->value, &char_v->value); 394 395 *res = item; 328 default: 329 assert(b_false); 330 } 396 331 } 397 332 … … 551 486 552 487 switch (v1->var->vc) { 553 case vc_bool:554 run_binop_bool(run, binop, v1, v2, res);555 break;556 case vc_char:557 run_binop_char(run, binop, v1, v2, res);558 break;559 488 case vc_int: 560 489 run_binop_int(run, binop, v1, v2, res); … … 566 495 run_binop_ref(run, binop, v1, v2, res); 567 496 break; 568 case vc_deleg:569 case vc_array:570 case vc_object:571 case vc_resource:572 assert(b_false);573 }574 }575 576 /** Evaluate binary operation on bool arguments. */577 static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1,578 rdata_value_t *v2, rdata_item_t **res)579 {580 rdata_item_t *item;581 rdata_value_t *value;582 rdata_var_t *var;583 rdata_bool_t *bool_v;584 585 bool_t b1, b2;586 587 (void) run;588 589 item = rdata_item_new(ic_value);590 value = rdata_value_new();591 var = rdata_var_new(vc_bool);592 bool_v = rdata_bool_new();593 594 item->u.value = value;595 value->var = var;596 var->u.bool_v = bool_v;597 598 b1 = v1->var->u.bool_v->value;599 b2 = v2->var->u.bool_v->value;600 601 switch (binop->bc) {602 case bo_plus:603 case bo_minus:604 case bo_mult:605 assert(b_false);606 607 case bo_equal:608 bool_v->value = (b1 == b2);609 break;610 case bo_notequal:611 bool_v->value = (b1 != b2);612 break;613 case bo_lt:614 bool_v->value = (b1 == b_false) && (b2 == b_true);615 break;616 case bo_gt:617 bool_v->value = (b1 == b_true) && (b2 == b_false);618 break;619 case bo_lt_equal:620 bool_v->value = (b1 == b_false) || (b2 == b_true);621 break;622 case bo_gt_equal:623 bool_v->value = (b1 == b_true) || (b2 == b_false);624 break;625 }626 627 *res = item;628 }629 630 /** Evaluate binary operation on char arguments. */631 static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1,632 rdata_value_t *v2, rdata_item_t **res)633 {634 rdata_item_t *item;635 rdata_value_t *value;636 rdata_var_t *var;637 rdata_bool_t *bool_v;638 639 bigint_t *c1, *c2;640 bigint_t diff;641 bool_t zf, nf;642 643 (void) run;644 645 item = rdata_item_new(ic_value);646 value = rdata_value_new();647 648 item->u.value = value;649 650 c1 = &v1->var->u.char_v->value;651 c2 = &v2->var->u.char_v->value;652 653 var = rdata_var_new(vc_bool);654 bool_v = rdata_bool_new();655 var->u.bool_v = bool_v;656 value->var = var;657 658 bigint_sub(c1, c2, &diff);659 zf = bigint_is_zero(&diff);660 nf = bigint_is_negative(&diff);661 662 switch (binop->bc) {663 case bo_plus:664 case bo_minus:665 case bo_mult:666 assert(b_false);667 668 case bo_equal:669 bool_v->value = zf;670 break;671 case bo_notequal:672 bool_v->value = !zf;673 break;674 case bo_lt:675 bool_v->value = (!zf && nf);676 break;677 case bo_gt:678 bool_v->value = (!zf && !nf);679 break;680 case bo_lt_equal:681 bool_v->value = (zf || nf);682 break;683 case bo_gt_equal:684 bool_v->value = !nf;685 break;686 497 default: 687 assert(b_false);688 }689 690 *res = item;498 printf("Unimplemented: Binary operation arguments of " 499 "type %d.\n", v1->var->vc); 500 exit(1); 501 } 691 502 } 692 503 … … 699 510 rdata_var_t *var; 700 511 rdata_int_t *int_v; 701 rdata_bool_t *bool_v;702 512 703 513 bigint_t *i1, *i2; … … 710 520 item = rdata_item_new(ic_value); 711 521 value = rdata_value_new(); 522 var = rdata_var_new(vc_int); 523 int_v = rdata_int_new(); 712 524 713 525 item->u.value = value; 526 value->var = var; 527 var->u.int_v = int_v; 714 528 715 529 i1 = &v1->var->u.int_v->value; … … 720 534 switch (binop->bc) { 721 535 case bo_plus: 722 int_v = rdata_int_new();723 536 bigint_add(i1, i2, &int_v->value); 724 537 break; 725 538 case bo_minus: 726 int_v = rdata_int_new();727 539 bigint_sub(i1, i2, &int_v->value); 728 540 break; 729 541 case bo_mult: 730 int_v = rdata_int_new();731 542 bigint_mul(i1, i2, &int_v->value); 732 543 break; … … 737 548 738 549 if (done) { 739 var = rdata_var_new(vc_int);740 var->u.int_v = int_v;741 value->var = var;742 550 *res = item; 743 551 return; 744 552 } 745 746 var = rdata_var_new(vc_bool);747 bool_v = rdata_bool_new();748 var->u.bool_v = bool_v;749 value->var = var;750 553 751 554 /* Relational operation. */ … … 755 558 nf = bigint_is_negative(&diff); 756 559 560 /* XXX We should have a real boolean type. */ 757 561 switch (binop->bc) { 758 562 case bo_equal: 759 b ool_v->value = zf;563 bigint_init(&int_v->value, zf ? 1 : 0); 760 564 break; 761 565 case bo_notequal: 762 b ool_v->value = !zf;566 bigint_init(&int_v->value, !zf ? 1 : 0); 763 567 break; 764 568 case bo_lt: 765 b ool_v->value = (!zf && nf);569 bigint_init(&int_v->value, (!zf && nf) ? 1 : 0); 766 570 break; 767 571 case bo_gt: 768 b ool_v->value = (!zf && !nf);572 bigint_init(&int_v->value, (!zf && !nf) ? 1 : 0); 769 573 break; 770 574 case bo_lt_equal: 771 b ool_v->value = (zf || nf);575 bigint_init(&int_v->value, (zf || nf) ? 1 : 0); 772 576 break; 773 577 case bo_gt_equal: 774 b ool_v->value = !nf;578 bigint_init(&int_v->value, !nf ? 1 : 0); 775 579 break; 776 580 default: … … 827 631 rdata_value_t *value; 828 632 rdata_var_t *var; 829 rdata_ bool_t *bool_v;633 rdata_int_t *int_v; 830 634 831 635 rdata_var_t *ref1, *ref2; … … 835 639 item = rdata_item_new(ic_value); 836 640 value = rdata_value_new(); 837 var = rdata_var_new(vc_ bool);838 bool_v = rdata_bool_new();641 var = rdata_var_new(vc_int); 642 int_v = rdata_int_new(); 839 643 840 644 item->u.value = value; 841 645 value->var = var; 842 var->u. bool_v = bool_v;646 var->u.int_v = int_v; 843 647 844 648 ref1 = v1->var->u.ref_v->vref; … … 846 650 847 651 switch (binop->bc) { 652 /* XXX We should have a real boolean type. */ 848 653 case bo_equal: 849 b ool_v->value = (ref1 == ref2);654 bigint_init(&int_v->value, (ref1 == ref2) ? 1 : 0); 850 655 break; 851 656 case bo_notequal: 852 b ool_v->value = (ref1 != ref2);657 bigint_init(&int_v->value, (ref1 != ref2) ? 1 : 0); 853 658 break; 854 659 default: … … 1175 980 access->member_name); 1176 981 1177 /* Member existence should be ensured by static type checking. */ 1178 assert(member != NULL); 982 if (member == NULL) { 983 printf("Error: CSI '"); 984 symbol_print_fqn(deleg_v->sym); 985 printf("' has no member named '%s'.\n", 986 strtab_get_str(access->member_name->sid)); 987 exit(1); 988 } 1179 989 1180 990 #ifdef DEBUG_RUN_TRACE … … 1665 1475 1666 1476 if (rc1 != EOK || rc2 != EOK) { 1667 #ifdef DEBUG_RUN_TRACE1668 1477 printf("Error: String index (value: %d) is out of range.\n", 1669 1478 arg_val); 1670 #endif 1671 /* Raise Error.OutOfBounds */ 1672 run_raise_exc(run, run->program->builtin->error_outofbounds); 1673 *res = run_recovery_item(run); 1674 return; 1479 exit(1); 1675 1480 } 1676 1481 … … 1680 1485 ritem->u.value = value; 1681 1486 1682 cvar = rdata_var_new(vc_ char);1683 cvar->u. char_v = rdata_char_new();1684 bigint_init(&cvar->u. char_v->value, cval);1487 cvar = rdata_var_new(vc_int); 1488 cvar->u.int_v = rdata_int_new(); 1489 bigint_init(&cvar->u.int_v->value, cval); 1685 1490 value->var = cvar; 1686 1491 … … 1846 1651 * Tries to interpret @a item as a boolean value. If it is not a boolean 1847 1652 * value, this generates an error. 1653 * 1654 * XXX Currently int supplants the role of a true boolean type. 1848 1655 */ 1849 1656 bool_t run_item_boolean_value(run_t *run, rdata_item_t *item) … … 1858 1665 var = vitem->u.value->var; 1859 1666 1860 assert(var->vc == vc_bool); 1861 return var->u.bool_v->value; 1862 } 1667 if (var->vc != vc_int) { 1668 printf("Error: Boolean (int) expression expected.\n"); 1669 exit(1); 1670 } 1671 1672 return !bigint_is_zero(&var->u.int_v->value); 1673 } -
uspace/app/sbi/src/run_texpr.c
r1ef0fc3 r2721a75 33 33 #include "list.h" 34 34 #include "mytypes.h" 35 #include "strtab.h"36 35 #include "symbol.h" 37 36 #include "tdata.h" … … 47 46 static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx, 48 47 stree_tnameref_t *tnameref, tdata_item_t **res); 49 static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,50 stree_tapply_t *tapply, tdata_item_t **res);51 48 52 49 void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr, … … 67 64 break; 68 65 case tc_tapply: 69 run_tapply(prog, ctx, texpr->u.tapply, res); 70 break; 66 printf("Unimplemented: Evaluate type expression type %d.\n", 67 texpr->tc); 68 exit(1); 71 69 } 72 70 } … … 87 85 run_texpr(prog, ctx, taccess->arg, &targ_i); 88 86 89 if (targ_i->tic == tic_ignore) {90 *res = tdata_item_new(tic_ignore);91 return;92 }93 94 87 if (targ_i->tic != tic_tobject) { 95 88 printf("Error: Using '.' with type which is not an object.\n"); 96 *res = tdata_item_new(tic_ignore); 97 return; 89 exit(1); 98 90 } 99 91 … … 102 94 103 95 sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name); 104 if (sym == NULL) { 105 printf("Error: CSI '"); 106 symbol_print_fqn(csi_to_symbol(base_csi)); 107 printf("' has no member named '%s'.\n", 108 strtab_get_str(taccess->member_name->sid)); 109 *res = tdata_item_new(tic_ignore); 110 return; 111 } 96 97 /* Existence should have been verified in type checking phase. */ 98 assert(sym != NULL); 112 99 113 100 if (sym->sc != sc_csi) { … … 115 102 symbol_print_fqn(sym); 116 103 printf("' is not a CSI.\n"); 117 *res = tdata_item_new(tic_ignore); 118 return; 104 exit(1); 119 105 } 120 106 … … 144 130 /* Evaluate base type. */ 145 131 run_texpr(prog, ctx, tindex->base_type, &base_ti); 146 147 if (base_ti->tic == tic_ignore) {148 *res = tdata_item_new(tic_ignore);149 return;150 }151 132 152 133 /* Construct type item. */ … … 186 167 187 168 switch (tliteral->tlc) { 188 case tlc_bool: tpc = tpc_bool; break;189 case tlc_char: tpc = tpc_char; break;190 169 case tlc_int: tpc = tpc_int; break; 191 170 case tlc_string: tpc = tpc_string; break; … … 212 191 #endif 213 192 sym = symbol_lookup_in_csi(prog, ctx, tnameref->name); 214 if (sym == NULL) { 215 printf("Error: Symbol '%s' not found.\n", 216 strtab_get_str(tnameref->name->sid)); 217 *res = tdata_item_new(tic_ignore); 218 return; 219 } 193 194 /* Existence should have been verified in type-checking phase. */ 195 assert(sym); 220 196 221 197 if (sym->sc != sc_csi) { … … 223 199 symbol_print_fqn(sym); 224 200 printf("' is not a CSI.\n"); 225 *res = tdata_item_new(tic_ignore); 226 return; 201 exit(1); 227 202 } 228 203 … … 237 212 *res = titem; 238 213 } 239 240 static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,241 stree_tapply_t *tapply, tdata_item_t **res)242 {243 tdata_item_t *base_ti;244 tdata_item_t *arg_ti;245 tdata_item_t *titem;246 tdata_object_t *tobject;247 248 list_node_t *arg_n;249 stree_texpr_t *arg;250 251 #ifdef DEBUG_RUN_TRACE252 printf("Evaluating type apply operation.\n");253 #endif254 /* Construct type item. */255 titem = tdata_item_new(tic_tobject);256 tobject = tdata_object_new();257 titem->u.tobject = tobject;258 259 /* Evaluate base (generic) type. */260 run_texpr(prog, ctx, tapply->gtype, &base_ti);261 262 if (base_ti->tic != tic_tobject) {263 printf("Error: Base type of generic application is not "264 "a CSI.\n");265 *res = tdata_item_new(tic_ignore);266 return;267 }268 269 tobject->static_ref = b_false;270 tobject->csi = base_ti->u.tobject->csi;271 list_init(&tobject->targs);272 273 /* Evaluate type arguments. */274 arg_n = list_first(&tapply->targs);275 while (arg_n != NULL) {276 arg = list_node_data(arg_n, stree_texpr_t *);277 run_texpr(prog, ctx, arg, &arg_ti);278 279 if (arg_ti->tic == tic_ignore) {280 *res = tdata_item_new(tic_ignore);281 return;282 }283 284 list_append(&tobject->targs, arg_ti);285 286 arg_n = list_next(&tapply->targs, arg_n);287 }288 289 *res = titem;290 } -
uspace/app/sbi/src/stree_t.h
r1ef0fc3 r2721a75 54 54 } stree_self_ref_t; 55 55 56 /** Boolean literal */57 typedef struct {58 bool_t value;59 } stree_lit_bool_t;60 61 /** Character literal */62 typedef struct {63 bigint_t value;64 } stree_lit_char_t;65 66 /** Integer literal */67 56 typedef struct { 68 57 bigint_t value; … … 73 62 } stree_lit_ref_t; 74 63 75 /** String literal */76 64 typedef struct { 77 65 char *value; … … 79 67 80 68 typedef enum { 81 ltc_bool,82 ltc_char,83 69 ltc_int, 84 70 ltc_ref, … … 90 76 literal_class_t ltc; 91 77 union { 92 stree_lit_bool_t lit_bool;93 stree_lit_char_t lit_char;94 78 stree_lit_int_t lit_int; 95 79 stree_lit_ref_t lit_ref; … … 230 214 /** Type literal class */ 231 215 typedef enum { 232 tlc_bool,233 tlc_char,234 216 tlc_int, 235 217 tlc_resource, … … 257 239 /** Type application operation */ 258 240 typedef struct { 259 /* Base type */ 260 struct stree_texpr *gtype; 261 262 /** (Formal) type arguments */ 263 list_t targs; /* of stree_texpr_t */ 241 /** Arguments */ 242 struct stree_texpr *gtype, *targ; 264 243 } stree_tapply_t; 265 244 … … 517 496 stree_ident_t *name; 518 497 519 /** List of type argument names */520 list_t targ_names; /* of stree_ident_t */521 522 498 /** Symbol for this CSI */ 523 499 struct stree_symbol *symbol; -
uspace/app/sbi/src/stype.c
r1ef0fc3 r2721a75 64 64 static void stype_wef(stype_t *stype, stree_wef_t *wef_s); 65 65 66 static tdata_item_t *stype_boolean_titem(stype_t *stype); 67 66 68 /** Type module */ 67 69 void stype_module(stype_t *stype, stree_module_t *module) … … 187 189 static void stype_var(stype_t *stype, stree_var_t *var) 188 190 { 189 tdata_item_t *titem;190 191 191 (void) stype; 192 192 (void) var; 193 194 run_texpr(stype->program, stype->current_csi, var->type,195 &titem);196 if (titem->tic == tic_ignore) {197 /* An error occured. */198 stype_note_error(stype);199 return;200 }201 193 } 202 194 … … 291 283 stype_block_vr_t *block_vr; 292 284 stree_vdecl_t *old_vdecl; 293 tdata_item_t *titem;294 285 295 286 #ifdef DEBUG_TYPE_TRACE … … 306 297 } 307 298 308 run_texpr(stype->program, stype->current_csi, vdecl_s->type,309 &titem);310 if (titem->tic == tic_ignore) {311 /* An error occured. */312 stype_note_error(stype);313 return;314 }315 316 299 intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s); 300 317 301 } 318 302 … … 540 524 goto failure; 541 525 break; 542 case tic_tfun:526 default: 543 527 printf("Error: Unimplemented: Converting '"); 544 528 tdata_item_print(src); … … 547 531 printf("'.\n"); 548 532 stype_note_error(stype); 549 break;550 case tic_ignore:551 assert(b_false);552 533 } 553 534 … … 566 547 567 548 /** Return a boolean type item */ 568 tdata_item_t *stype_boolean_titem(stype_t *stype)549 static tdata_item_t *stype_boolean_titem(stype_t *stype) 569 550 { 570 551 tdata_item_t *titem; … … 573 554 (void) stype; 574 555 556 /* XXX Use a true boolean type */ 575 557 titem = tdata_item_new(tic_tprimitive); 576 tprimitive = tdata_primitive_new(tpc_ bool);558 tprimitive = tdata_primitive_new(tpc_int); 577 559 titem->u.tprimitive = tprimitive; 578 560 -
uspace/app/sbi/src/stype.h
r1ef0fc3 r2721a75 41 41 tdata_item_t *dest); 42 42 43 tdata_item_t *stype_boolean_titem(stype_t *stype);44 45 43 stree_vdecl_t *stype_local_vars_lookup(stype_t *stype, sid_t name); 46 44 stree_proc_arg_t *stype_proc_args_lookup(stype_t *stype, sid_t name); -
uspace/app/sbi/src/stype_expr.c
r1ef0fc3 r2721a75 53 53 static void stype_binop(stype_t *stype, stree_binop_t *binop, 54 54 tdata_item_t **rtitem); 55 56 55 static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop, 57 56 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem); 58 static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,59 tdata_item_t **rtitem);60 static void stype_binop_char(stype_t *stype, stree_binop_t *binop,61 tdata_item_t **rtitem);62 static void stype_binop_int(stype_t *stype, stree_binop_t *binop,63 tdata_item_t **rtitem);64 static void stype_binop_nil(stype_t *stype, stree_binop_t *binop,65 tdata_item_t **rtitem);66 static void stype_binop_string(stype_t *stype, stree_binop_t *binop,67 tdata_item_t **rtitem);68 static void stype_binop_resource(stype_t *stype, stree_binop_t *binop,69 tdata_item_t **rtitem);70 71 57 static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop, 72 58 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem); … … 87 73 static void stype_access_tarray(stype_t *stype, stree_access_t *access, 88 74 tdata_item_t *arg_ti, tdata_item_t **rtitem); 75 static void stype_access_tgeneric(stype_t *stype, stree_access_t *access, 76 tdata_item_t *arg_ti, tdata_item_t **rtitem); 89 77 90 78 static void stype_call(stype_t *stype, stree_call_t *call, … … 98 86 tdata_item_t *base_ti, tdata_item_t **rtitem); 99 87 static void stype_index_tarray(stype_t *stype, stree_index_t *index, 88 tdata_item_t *base_ti, tdata_item_t **rtitem); 89 static void stype_index_tgeneric(stype_t *stype, stree_index_t *index, 100 90 tdata_item_t *base_ti, tdata_item_t **rtitem); 101 91 … … 258 248 259 249 switch (literal->ltc) { 260 case ltc_bool: tpc = tpc_bool; break;261 case ltc_char: tpc = tpc_char; break;262 250 case ltc_int: tpc = tpc_int; break; 263 251 case ltc_ref: tpc = tpc_nil; break; … … 345 333 } 346 334 347 /** Type a binary operation witharguments of primitive type. */335 /** Type a binary operation arguments of primitive type. */ 348 336 static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop, 349 337 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem) 350 338 { 339 tprimitive_class_t rtpc; 340 tdata_item_t *res_ti; 341 342 (void) stype; 343 351 344 assert(ta->tic == tic_tprimitive); 352 345 assert(tb->tic == tic_tprimitive); 353 346 354 347 switch (ta->u.tprimitive->tpc) { 355 case tpc_bool:356 stype_binop_bool(stype, binop, rtitem);357 break;358 case tpc_char:359 stype_binop_char(stype, binop, rtitem);360 break;361 348 case tpc_int: 362 stype_binop_int(stype, binop, rtitem);349 rtpc = tpc_int; 363 350 break; 364 351 case tpc_nil: 365 stype_binop_nil(stype, binop, rtitem); 352 printf("Unimplemented; Binary operation on nil.\n"); 353 stype_note_error(stype); 354 rtpc = tpc_nil; 366 355 break; 367 356 case tpc_string: 368 stype_binop_string(stype, binop, rtitem); 357 if (binop->bc != bo_plus) { 358 printf("Unimplemented: Binary operation(%d) " 359 "on strings.\n", binop->bc); 360 stype_note_error(stype); 361 } 362 rtpc = tpc_string; 369 363 break; 370 364 case tpc_resource: 371 stype_binop_resource(stype, binop, rtitem); 372 break; 373 } 374 } 375 376 /** Type a binary operation with bool arguments. */ 377 static void stype_binop_bool(stype_t *stype, stree_binop_t *binop, 378 tdata_item_t **rtitem) 379 { 380 tprimitive_class_t rtpc; 381 tdata_item_t *res_ti; 382 383 switch (binop->bc) { 384 case bo_equal: 385 case bo_notequal: 386 case bo_lt: 387 case bo_gt: 388 case bo_lt_equal: 389 case bo_gt_equal: 390 /* Comparison -> boolean type */ 391 rtpc = tpc_bool; 392 break; 393 case bo_plus: 394 case bo_minus: 395 case bo_mult: 396 /* Arithmetic -> error */ 397 printf("Error: Binary operation (%d) on booleans.\n", 398 binop->bc); 399 stype_note_error(stype); 400 *rtitem = stype_recovery_titem(stype); 401 return; 365 printf("Error: Cannot apply operator to resource type.\n"); 366 stype_note_error(stype); 367 rtpc = tpc_resource; 402 368 } 403 369 … … 408 374 } 409 375 410 /** Type a binary operation with char arguments. */ 411 static void stype_binop_char(stype_t *stype, stree_binop_t *binop, 412 tdata_item_t **rtitem) 413 { 414 tprimitive_class_t rtpc; 415 tdata_item_t *res_ti; 416 417 (void) stype; 418 419 switch (binop->bc) { 420 case bo_equal: 421 case bo_notequal: 422 case bo_lt: 423 case bo_gt: 424 case bo_lt_equal: 425 case bo_gt_equal: 426 /* Comparison -> boolean type */ 427 rtpc = tpc_bool; 428 break; 429 case bo_plus: 430 case bo_minus: 431 case bo_mult: 432 /* Arithmetic -> error */ 433 printf("Error: Binary operation (%d) on characters.\n", 434 binop->bc); 435 stype_note_error(stype); 436 rtpc = tpc_char; 437 break; 438 } 439 440 res_ti = tdata_item_new(tic_tprimitive); 441 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 442 443 *rtitem = res_ti; 444 } 445 446 /** Type a binary operation with int arguments. */ 447 static void stype_binop_int(stype_t *stype, stree_binop_t *binop, 448 tdata_item_t **rtitem) 449 { 450 tprimitive_class_t rtpc; 451 tdata_item_t *res_ti; 452 453 (void) stype; 454 455 switch (binop->bc) { 456 case bo_equal: 457 case bo_notequal: 458 case bo_lt: 459 case bo_gt: 460 case bo_lt_equal: 461 case bo_gt_equal: 462 /* Comparison -> boolean type */ 463 rtpc = tpc_bool; 464 break; 465 case bo_plus: 466 case bo_minus: 467 case bo_mult: 468 /* Arithmetic -> int type */ 469 rtpc = tpc_int; 470 break; 471 } 472 473 res_ti = tdata_item_new(tic_tprimitive); 474 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 475 476 *rtitem = res_ti; 477 } 478 479 /** Type a binary operation with nil arguments. */ 480 static void stype_binop_nil(stype_t *stype, stree_binop_t *binop, 481 tdata_item_t **rtitem) 482 { 483 (void) binop; 484 485 printf("Unimplemented; Binary operation on nil.\n"); 486 stype_note_error(stype); 487 *rtitem = stype_recovery_titem(stype); 488 } 489 490 /** Type a binary operation with string arguments. */ 491 static void stype_binop_string(stype_t *stype, stree_binop_t *binop, 492 tdata_item_t **rtitem) 493 { 494 tprimitive_class_t rtpc; 495 tdata_item_t *res_ti; 496 497 if (binop->bc != bo_plus) { 498 printf("Unimplemented: Binary operation(%d) " 499 "on strings.\n", binop->bc); 500 stype_note_error(stype); 501 *rtitem = stype_recovery_titem(stype); 502 return; 503 } 504 505 rtpc = tpc_string; 506 507 res_ti = tdata_item_new(tic_tprimitive); 508 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 509 510 *rtitem = res_ti; 511 } 512 513 /** Type a binary operation with resource arguments. */ 514 static void stype_binop_resource(stype_t *stype, stree_binop_t *binop, 515 tdata_item_t **rtitem) 516 { 517 tprimitive_class_t rtpc; 518 tdata_item_t *res_ti; 519 520 (void) binop; 521 522 printf("Error: Cannot apply operator to resource type.\n"); 523 stype_note_error(stype); 524 rtpc = tpc_resource; 525 526 res_ti = tdata_item_new(tic_tprimitive); 527 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 528 529 *rtitem = res_ti; 530 } 531 532 /** Type a binary operation with arguments of an object type. */ 376 /** Type a binary operation arguments of an object type. */ 533 377 static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop, 534 378 tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem) … … 546 390 case bo_equal: 547 391 case bo_notequal: 548 /* Comparing objects -> boolean type */ 549 res_ti = stype_boolean_titem(stype); 392 /* Comparing objects -> boolean (XXX int for now) type */ 393 res_ti = tdata_item_new(tic_tprimitive); 394 res_ti->u.tprimitive = tdata_primitive_new(tpc_int); 550 395 break; 551 396 default: 552 397 printf("Error: Binary operation (%d) on objects.\n", 553 398 binop->bc); 554 stype_note_error(stype); 555 *rtitem = stype_recovery_titem(stype); 399 res_ti = NULL; 556 400 return; 557 401 } … … 607 451 608 452 switch (ta->u.tprimitive->tpc) { 609 case tpc_bool:610 rtpc = tpc_bool;611 break;612 453 case tpc_int: 613 454 rtpc = tpc_int; … … 639 480 */ 640 481 run_texpr(stype->program, stype->current_csi, new_op->texpr, rtitem); 641 642 if ((*rtitem)->tic == tic_ignore) {643 /* An error occured when evaluating the type expression. */644 stype_note_error(stype);645 }646 482 } 647 483 … … 674 510 case tic_tarray: 675 511 stype_access_tarray(stype, access, arg_ti, rtitem); 512 break; 513 case tic_tgeneric: 514 stype_access_tgeneric(stype, access, arg_ti, rtitem); 676 515 break; 677 516 case tic_tfun: … … 727 566 printf("' has no member named '%s'.\n", 728 567 strtab_get_str(access->member_name->sid)); 729 stype_note_error(stype);730 568 *rtitem = stype_recovery_titem(stype); 731 569 return; … … 777 615 778 616 printf("Error: Unimplemented: Accessing array type '"); 617 tdata_item_print(arg_ti); 618 printf("'.\n"); 619 stype_note_error(stype); 620 *rtitem = stype_recovery_titem(stype); 621 } 622 623 /** Type a generic access operation. */ 624 static void stype_access_tgeneric(stype_t *stype, stree_access_t *access, 625 tdata_item_t *arg_ti, tdata_item_t **rtitem) 626 { 627 (void) stype; 628 (void) access; 629 (void) rtitem; 630 631 printf("Error: Unimplemented: Accessing generic type '"); 779 632 tdata_item_print(arg_ti); 780 633 printf("'.\n"); … … 939 792 stype_index_tarray(stype, index, base_ti, rtitem); 940 793 break; 794 case tic_tgeneric: 795 stype_index_tgeneric(stype, index, base_ti, rtitem); 796 break; 941 797 case tic_tfun: 942 798 printf("Error: Indexing a function.\n"); … … 965 821 if (tprimitive->tpc == tpc_string) { 966 822 titem = tdata_item_new(tic_tprimitive); 967 titem->u.tprimitive = tdata_primitive_new(tpc_ char);823 titem->u.tprimitive = tdata_primitive_new(tpc_int); 968 824 *rtitem = titem; 969 825 return; … … 1058 914 } 1059 915 916 /** Type a generic indexing operation. */ 917 static void stype_index_tgeneric(stype_t *stype, stree_index_t *index, 918 tdata_item_t *base_ti, tdata_item_t **rtitem) 919 { 920 (void) stype; 921 (void) index; 922 (void) rtitem; 923 924 printf("Error: Unimplemented: Indexing generic type '"); 925 tdata_item_print(base_ti); 926 printf("'.\n"); 927 stype_note_error(stype); 928 *rtitem = stype_recovery_titem(stype); 929 } 930 1060 931 /** Type an assignment. */ 1061 932 static void stype_assign(stype_t *stype, stree_assign_t *assign, -
uspace/app/sbi/src/symbol.c
r1ef0fc3 r2721a75 68 68 return b; 69 69 case tc_tapply: 70 return symbol_xlookup_in_csi(prog, scope,71 texpr->u.tapply->gtype);70 printf("Internal error: Generic types not implemented.\n"); 71 exit(1); 72 72 default: 73 73 assert(b_false); -
uspace/app/sbi/src/tdata.c
r1ef0fc3 r2721a75 31 31 #include <stdlib.h> 32 32 #include <assert.h> 33 #include "list.h"34 33 #include "mytypes.h" 35 34 #include "stree.h" … … 41 40 static void tdata_tobject_print(tdata_object_t *tobject); 42 41 static void tdata_tarray_print(tdata_array_t *tarray); 42 static void tdata_tgeneric_print(tdata_generic_t *tgeneric); 43 43 static void tdata_tfun_print(tdata_fun_t *tfun); 44 44 … … 142 142 tdata_tarray_print(titem->u.tarray); 143 143 break; 144 case tic_tgeneric: 145 tdata_tgeneric_print(titem->u.tgeneric); 146 break; 144 147 case tic_tfun: 145 148 tdata_tfun_print(titem->u.tfun); … … 154 157 { 155 158 switch (tprimitive->tpc) { 156 case tpc_bool: printf("bool"); break;157 case tpc_char: printf("char"); break;158 159 case tpc_int: printf("int"); break; 159 160 case tpc_nil: printf("nil"); break; … … 166 167 { 167 168 stree_symbol_t *csi_sym; 168 list_node_t *arg_n;169 tdata_item_t *arg;170 169 171 170 csi_sym = csi_to_symbol(tobject->csi); 172 171 assert(csi_sym != NULL); 173 172 symbol_print_fqn(csi_sym); 174 175 arg_n = list_first(&tobject->targs);176 while (arg_n != NULL) {177 arg = list_node_data(arg_n, tdata_item_t *);178 putchar('/');179 tdata_item_print(arg);180 arg_n = list_next(&tobject->targs, arg_n);181 }182 173 } 183 174 … … 194 185 } 195 186 187 static void tdata_tgeneric_print(tdata_generic_t *tgeneric) 188 { 189 (void) tgeneric; 190 printf("unimplemented(generic)"); 191 } 192 196 193 static void tdata_tfun_print(tdata_fun_t *tfun) 197 194 { -
uspace/app/sbi/src/tdata_t.h
r1ef0fc3 r2721a75 34 34 /** Class of primitive type. */ 35 35 typedef enum { 36 /** Boolean type */37 tpc_bool,38 /** Character type */39 tpc_char,40 36 /** Integer type */ 41 37 tpc_int, … … 61 57 /** CSI definition */ 62 58 struct stree_csi *csi; 63 64 /** (Real) type arguments */65 list_t targs; /* of tdata_item_t */66 59 } tdata_object_t; 67 60 … … 77 70 list_t extents; /* of stree_expr_t */ 78 71 } tdata_array_t; 72 73 /** Generic type. */ 74 typedef struct { 75 } tdata_generic_t; 79 76 80 77 /** Functional type. */ … … 93 90 /** Array type item */ 94 91 tic_tarray, 92 /** Generic type item */ 93 tic_tgeneric, 95 94 /** Function type item */ 96 95 tic_tfun, … … 107 106 tdata_object_t *tobject; 108 107 tdata_array_t *tarray; 108 tdata_generic_t *tgeneric; 109 109 tdata_fun_t *tfun; 110 110 } u; -
uspace/dist/src/sysel/demos/list.sy
r1ef0fc3 r2721a75 27 27 -- 28 28 29 -- Using the List class from the library. 29 -- Doubly-linked list implementation. 30 class List is 31 var head : ListNode; 32 33 -- Initialize list. 34 fun Init() is 35 head = new ListNode(); 36 head.prev = head; 37 head.next = head; 38 end 39 40 -- Append new entry at the end of the list. 41 fun Append(data : int) is 42 var n : ListNode; 43 var ntl : ListNode; 44 45 ntl = head.prev; 46 47 n = new ListNode(); 48 n.value = data; 49 50 n.prev = ntl; 51 n.next = head; 52 n.head = head; 53 54 ntl.next = n; 55 head.prev = n; 56 end 57 58 -- Return first node in the list or @c nil if there is none. 59 prop First : ListNode is 60 get is 61 return get_first(); 62 end 63 end 64 65 -- Return first node in the list or @c nil if there is none. 66 fun get_first() : ListNode is 67 if head.next == head then 68 return nil; 69 else 70 return head.next; 71 end 72 end 73 end 74 75 class ListNode is 76 var value : int; 77 78 var prev : ListNode; 79 var next : ListNode; 80 var head : ListNode; 81 82 -- Value stored in this node. 83 prop Value : int is 84 get is 85 return value; 86 end 87 end 88 89 -- Previous node in list. 90 prop Prev : ListNode is 91 get is 92 return get_prev(); 93 end 94 end 95 96 -- Next node in list. 97 prop Next : ListNode is 98 get is 99 return get_next(); 100 end 101 end 102 103 -- Get next node. 104 fun get_next() : ListNode is 105 if next != head then 106 return next; 107 else 108 return nil; 109 end 110 end 111 112 -- Get previous node. 113 fun get_prev() : ListNode is 114 if prev != head then 115 return next; 116 else 117 return nil; 118 end 119 end 120 121 end 122 30 123 class ListDemo is 31 124 fun Main() is 32 125 var list : List; 33 var i : Int;34 126 35 127 list = new List(); 36 128 list.Init(); 37 129 38 -- We need autoboxing or generics to get rid of this mess. 39 i = new Int(); i.Value = 5; list.Append(i); 40 i = new Int(); i.Value = 6; list.Append(i); 41 i = new Int(); i.Value = 7; list.Append(i); 42 i = new Int(); i.Value = 8; list.Append(i); 130 list.Append(5); 131 list.Append(6); 132 list.Append(7); 133 list.Append(8); 43 134 44 135 var n : ListNode; … … 46 137 n = list.First; 47 138 while n != nil do 48 Builtin.WriteLine( (n.value as Int).Value);139 Builtin.WriteLine(n.value); 49 140 n = n.Next; 50 141 end
Note:
See TracChangeset
for help on using the changeset viewer.