Changes in / [ecb6ac32:73060801] in mainline
- Location:
- uspace
- Files:
-
- 6 deleted
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/Makefile
recb6ac32 r73060801 34 34 35 35 SOURCES = \ 36 src/builtin/bi_error.c \37 36 src/builtin/bi_fun.c \ 38 37 src/builtin/bi_textfile.c \ 39 38 src/os/helenos.c \ 40 39 src/ancr.c \ 41 src/bigint.c \42 40 src/builtin.c \ 43 41 src/imode.c \ -
uspace/app/sbi/src/builtin.c
recb6ac32 r73060801 41 41 #include <assert.h> 42 42 #include "ancr.h" 43 #include "builtin/bi_error.h"44 43 #include "builtin/bi_fun.h" 45 44 #include "builtin/bi_textfile.h" … … 87 86 */ 88 87 89 bi_error_declare(bi);90 88 bi_fun_declare(bi); 91 89 bi_textfile_declare(bi); … … 94 92 ancr_module_process(program, program->module); 95 93 96 bi_error_bind(bi);97 94 bi_fun_bind(bi); 98 95 bi_textfile_bind(bi); -
uspace/app/sbi/src/builtin/bi_fun.c
recb6ac32 r73060801 32 32 #include <stdlib.h> 33 33 #include <assert.h> 34 #include "../bigint.h"35 34 #include "../builtin.h" 36 35 #include "../list.h" … … 108 107 switch (var->vc) { 109 108 case vc_int: 110 bigint_print(&var->u.int_v->value); 111 putchar('\n'); 109 printf("%d\n", var->u.int_v->value); 112 110 break; 113 111 case vc_string: -
uspace/app/sbi/src/builtin/bi_textfile.c
recb6ac32 r73060801 32 32 #include <stdlib.h> 33 33 #include <assert.h> 34 #include "../bigint.h"35 34 #include "../builtin.h" 36 35 #include "../debug.h" … … 345 344 /* Construct return value. */ 346 345 eof_int = rdata_int_new(); 347 bigint_init(&eof_int->value, eof_flag);346 eof_int->value = eof_flag; 348 347 349 348 eof_var = rdata_var_new(vc_int); -
uspace/app/sbi/src/builtin_t.h
recb6ac32 r73060801 42 42 /** Grandfather object */ 43 43 struct stree_symbol *gf_class; 44 45 /** Error class for nil reference access. */46 struct stree_csi *error_nilreference;47 48 /** Error class for out-of-bounds array access. */49 struct stree_csi *error_outofbounds;50 44 } builtin_t; 51 45 -
uspace/app/sbi/src/debug.h
recb6ac32 r73060801 45 45 //#define DEBUG_RUN_TRACE 46 46 47 /** Uncomment this to get verbose debugging messages for bigint computation. */48 //#define DEBUG_BIGINT_TRACE49 50 47 #endif -
uspace/app/sbi/src/imode.c
recb6ac32 r73060801 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include "os/os.h"43 42 #include "ancr.h" 44 43 #include "assert.h" … … 123 122 list_append(&run.thread_ar->proc_ar, proc_ar); 124 123 125 printf("SBI interactive mode. ");126 os_input_disp_help();127 128 124 quit_im = b_false; 129 125 while (quit_im != b_true) { … … 156 152 run_stat(&run, stat, &rexpr); 157 153 158 /* Check for unhandled exceptions. */159 run_exc_check_unhandled(&run);160 161 154 if (rexpr != NULL) { 162 155 /* Convert expression result to value item. */ -
uspace/app/sbi/src/lex.c
recb6ac32 r73060801 34 34 #include <stdio.h> 35 35 #include <stdlib.h> 36 #include "bigint.h"37 36 #include "mytypes.h" 38 37 #include "input.h" … … 136 135 { lc_assign, "=" }, 137 136 { lc_plus, "+" }, 138 { lc_minus, "-" },139 { lc_mult, "*" },140 137 { lc_increase, "+=" }, 141 138 … … 208 205 break; 209 206 case lc_lit_int: 210 printf("("); 211 bigint_print(&lem->u.lit_int.value); 212 printf(")"); 207 printf("(%d)", lem->u.lit_int.value); 213 208 break; 214 209 case lc_lit_string: … … 272 267 * 273 268 * @param lex Lexer object. 274 * @return Pointer to current lem. Owned by @a lex and only valid275 * until next call to lex_next().276 269 */ 277 270 lem_t *lex_get_current(lex_t *lex) … … 383 376 lex->current.lclass = lc_plus; ++bp; break; 384 377 385 case '-':386 lex->current.lclass = lc_minus; ++bp; break;387 388 case '*':389 lex->current.lclass = lc_mult; ++bp; break;390 391 378 case '<': 392 379 if (bp[1] == '=') { … … 471 458 { 472 459 char *bp; 473 bigint_t value; 474 bigint_t dgval; 475 bigint_t base; 476 bigint_t tprod; 460 int value; 477 461 478 462 bp = lex->ibp; 479 480 bigint_init(&value, 0); 481 bigint_init(&base, 10); 463 value = 0; 482 464 483 465 while (is_digit(*bp)) { 484 bigint_mul(&value, &base, &tprod); 485 bigint_init(&dgval, digit_value(*bp)); 486 487 bigint_destroy(&value); 488 bigint_add(&tprod, &dgval, &value); 489 bigint_destroy(&tprod); 490 bigint_destroy(&dgval); 491 466 value = value * 10 + digit_value(*bp); 492 467 ++bp; 493 468 } 494 469 495 bigint_destroy(&base);496 497 470 lex->ibp = bp; 498 471 499 472 lex->current.lclass = lc_lit_int; 500 bigint_shallow_copy(&value, &lex->current.u.lit_int.value);473 lex->current.u.lit_int.value = value; 501 474 } 502 475 -
uspace/app/sbi/src/lex_t.h
recb6ac32 r73060801 29 29 #ifndef LEX_T_H_ 30 30 #define LEX_T_H_ 31 32 #include "bigint_t.h"33 31 34 32 /** Lexical element class */ … … 97 95 lc_assign, 98 96 lc_plus, 99 lc_minus,100 lc_mult,101 97 lc_increase, 102 98 … … 116 112 typedef struct { 117 113 /* Integer value */ 118 bigint_t value;114 int value; 119 115 } lem_lit_int_t; 120 116 -
uspace/app/sbi/src/main.c
recb6ac32 r73060801 94 94 parse_module(&parse); 95 95 96 /* Check for parse errors. */97 96 if (parse.error) 98 97 return 1; … … 106 105 stype_module(&stype, program->module); 107 106 108 /* Check for typing errors. */109 107 if (stype.error) 110 108 return 1; … … 113 111 run_init(&run); 114 112 run_program(&run, program); 115 116 /* Check for run-time errors. */117 if (run.thread_ar->error)118 return 1;119 113 120 114 return 0; -
uspace/app/sbi/src/mytypes.h
recb6ac32 r73060801 47 47 #define EOK 0 48 48 49 #include "bigint_t.h"50 49 #include "builtin_t.h" 51 50 #include "input_t.h" -
uspace/app/sbi/src/os/helenos.c
recb6ac32 r73060801 101 101 } 102 102 103 /** Display survival help message. */104 void os_input_disp_help(void)105 {106 printf("Press Ctrl-Q to quit.\n");107 }108 109 103 /** Read one line of input from the user. */ 110 104 int os_input_line(char **ptr) -
uspace/app/sbi/src/os/os.h
recb6ac32 r73060801 34 34 char *os_str_dup(const char *str); 35 35 int os_str_get_char(const char *str, int index, int *out_char); 36 void os_input_disp_help(void);37 36 int os_input_line(char **ptr); 38 37 int os_exec(char *const cmd[]); -
uspace/app/sbi/src/os/posix.c
recb6ac32 r73060801 95 95 static char os_input_buffer[OS_INPUT_BUFFER_SIZE]; 96 96 97 /** Display survival help message. */98 void os_input_disp_help(void)99 {100 printf("Send ^C (SIGINT) to quit.\n");101 }102 103 97 /** Read one line of input from the user. */ 104 98 int os_input_line(char **ptr) -
uspace/app/sbi/src/p_expr.c
recb6ac32 r73060801 31 31 #include <assert.h> 32 32 #include <stdlib.h> 33 #include "bigint.h"34 33 #include "debug.h" 35 34 #include "lex.h" … … 45 44 static stree_expr_t *parse_comparative(parse_t *parse); 46 45 static stree_expr_t *parse_additive(parse_t *parse); 47 static stree_expr_t *parse_multip(parse_t *parse);48 46 static stree_expr_t *parse_prefix(parse_t *parse); 49 47 static stree_expr_t *parse_prefix_new(parse_t *parse); … … 53 51 static stree_expr_t *parse_pf_index(parse_t *parse, stree_expr_t *a); 54 52 static stree_expr_t *parse_pf_as(parse_t *parse, stree_expr_t *a); 55 static stree_expr_t *parse_paren(parse_t *parse);56 53 static stree_expr_t *parse_primitive(parse_t *parse); 57 54 static stree_expr_t *parse_nameref(parse_t *parse); … … 169 166 stree_expr_t *a, *b, *tmp; 170 167 stree_binop_t *binop; 171 binop_class_t bc; 172 173 a = parse_multip(parse); 174 while (lcur_lc(parse) == lc_plus || lcur_lc(parse) == lc_minus) { 168 169 a = parse_prefix(parse); 170 while (lcur_lc(parse) == lc_plus) { 175 171 if (parse_is_error(parse)) 176 172 break; 177 173 178 switch (lcur_lc(parse)) {179 case lc_plus: bc = bo_plus; break;180 case lc_minus: bc = bo_minus; break;181 default: assert(b_false);182 }183 184 174 lskip(parse); 185 b = parse_ multip(parse);186 187 binop = stree_binop_new(b c);175 b = parse_prefix(parse); 176 177 binop = stree_binop_new(bo_plus); 188 178 binop->arg1 = a; 189 179 binop->arg2 = b; … … 197 187 } 198 188 199 /** Parse multiplicative expression.200 *201 * @param parse Parser object.202 */203 static stree_expr_t *parse_multip(parse_t *parse)204 {205 stree_expr_t *a, *b, *tmp;206 stree_binop_t *binop;207 binop_class_t bc;208 209 a = parse_prefix(parse);210 while (lcur_lc(parse) == lc_mult) {211 if (parse_is_error(parse))212 break;213 214 switch (lcur_lc(parse)) {215 case lc_mult: bc = bo_mult; break;216 default: assert(b_false);217 }218 219 lskip(parse);220 b = parse_prefix(parse);221 222 binop = stree_binop_new(bc);223 binop->arg1 = a;224 binop->arg2 = b;225 226 tmp = stree_expr_new(ec_binop);227 tmp->u.binop = binop;228 a = tmp;229 }230 231 return a;232 }233 234 189 /** Parse prefix expression. 235 190 * … … 239 194 { 240 195 stree_expr_t *a; 241 stree_expr_t *tmp;242 stree_unop_t *unop;243 unop_class_t uc;244 196 245 197 switch (lcur_lc(parse)) { 246 198 case lc_plus: 247 case lc_minus: 248 if (parse_is_error(parse)) 249 return parse_recovery_expr(parse); 250 251 switch (lcur_lc(parse)) { 252 case lc_plus: uc = uo_plus; break; 253 case lc_minus: uc = uo_minus; break; 254 default: assert(b_false); 255 } 256 257 lskip(parse); 258 a = parse_postfix(parse); 259 260 unop = stree_unop_new(uc); 261 unop->arg = a; 262 263 tmp = stree_expr_new(ec_unop); 264 tmp->u.unop = unop; 265 a = tmp; 199 printf("Unimplemented: Unary plus.\n"); 200 a = parse_recovery_expr(parse); 201 parse_note_error(parse); 266 202 break; 267 203 case lc_new: … … 312 248 stree_expr_t *tmp; 313 249 314 a = parse_p aren(parse);250 a = parse_primitive(parse); 315 251 316 252 while (lcur_lc(parse) == lc_period || lcur_lc(parse) == lc_lparen || … … 462 398 } 463 399 464 /** Parse possibly partenthesized expression.465 *466 * @param parse Parser object.467 */468 static stree_expr_t *parse_paren(parse_t *parse)469 {470 stree_expr_t *expr;471 472 if (lcur_lc(parse) == lc_lparen) {473 lskip(parse);474 expr = parse_expr(parse);475 lmatch(parse, lc_rparen);476 } else {477 expr = parse_primitive(parse);478 }479 480 return expr;481 }482 483 484 400 /** Parse primitive expression. 485 401 * … … 543 459 544 460 literal = stree_literal_new(ltc_int); 545 bigint_clone(&lcur(parse)->u.lit_int.value, 546 &literal->u.lit_int.value); 461 literal->u.lit_int.value = lcur(parse)->u.lit_int.value; 547 462 548 463 lskip(parse); -
uspace/app/sbi/src/parse.c
recb6ac32 r73060801 79 79 static stree_except_t *parse_except(parse_t *parse); 80 80 81 /** Initialize parser object.82 *83 * Set up parser @a parse to use lexer @a lex for input and to store84 * output (i.e. new declarations) to program @a prog. @a prog is not85 * necessarily empty, the declarations being parsed are simply added86 * to it.87 *88 * @param parse Parser object.89 * @param prog Destination program stree.90 * @param lex Input lexer.91 */92 81 void parse_init(parse_t *parse, stree_program_t *prog, struct lex *lex) 93 82 { … … 102 91 } 103 92 104 /** Parse module. 105 * 106 * Parse a program module. 107 * 108 * The input is read using the lexer associated with @a parse. The resulting 109 * declarations are added to existing declarations in the program associated 110 * with @a parse. 111 * 112 * If any parse error occurs, parse->error will @c b_true when this function 113 * returns. parse->error_bailout will be @c b_true if the error has not 114 * been recovered yet. Similar holds for other parsing functions in this 115 * module. 116 * 117 * @param parse Parser object. 118 */ 93 /** Parse module. */ 119 94 void parse_module(parse_t *parse) 120 95 { … … 142 117 } 143 118 144 /** Parse class, struct or interface declaration. 145 * 146 * @param parse Parser object. 147 * @param dclass What to parse: @c lc_class, @c lc_struct or @c lc_csi. 148 * @param outer_csi CSI containing this declaration or @c NULL if global. 149 * @return New syntax tree node. 150 */ 119 /** Parse class, struct or interface declaration. */ 151 120 static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass, 152 121 stree_csi_t *outer_csi) … … 200 169 } 201 170 202 /** Parse class, struct or interface member. 203 * 204 * @param parse Parser object. 205 * @param outer_csi CSI containing this declaration or @c NULL if global. 206 * @return New syntax tree node. 207 */ 171 /** Parse class, struct or interface member. */ 208 172 static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi) 209 173 { … … 247 211 248 212 249 /** Parse member function. 250 * 251 * @param parse Parser object. 252 * @param outer_csi CSI containing this declaration or @c NULL if global. 253 * @return New syntax tree node. 254 */ 213 /** Parse member function. */ 255 214 static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi) 256 215 { … … 338 297 } 339 298 340 /** Parse member variable. 341 * 342 * @param parse Parser object. 343 * @param outer_csi CSI containing this declaration or @c NULL if global. 344 * @return New syntax tree node. 345 */ 299 /** Parse member variable. */ 346 300 static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi) 347 301 { … … 364 318 } 365 319 366 /** Parse member property. 367 * 368 * @param parse Parser object. 369 * @param outer_csi CSI containing this declaration or @c NULL if global. 370 * @return New syntax tree node. 371 */ 320 /** Parse member property. */ 372 321 static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi) 373 322 { … … 475 424 } 476 425 477 /** Parse symbol attribute. 478 * 479 * @param parse Parser object. 480 * @param outer_csi CSI containing this declaration or @c NULL if global. 481 * @return New syntax tree node. 482 */ 426 /** Parse symbol attribute. */ 483 427 static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse) 484 428 { … … 498 442 } 499 443 500 /** Parse formal function argument. 501 * 502 * @param parse Parser object. 503 * @return New syntax tree node. 504 */ 444 /** Parse formal function argument. */ 505 445 static stree_proc_arg_t *parse_proc_arg(parse_t *parse) 506 446 { … … 528 468 } 529 469 530 /** Parse argument attribute. 531 * 532 * @param parse Parser object. 533 * @return New syntax tree node. 534 */ 470 /** Parse argument attribute. */ 535 471 static stree_arg_attr_t *parse_arg_attr(parse_t *parse) 536 472 { … … 550 486 } 551 487 552 /** Parse statement block. 553 * 554 * @param parse Parser object. 555 * @return New syntax tree node. 556 */ 488 /** Parse statement block. */ 557 489 static stree_block_t *parse_block(parse_t *parse) 558 490 { … … 577 509 } 578 510 579 /** Parse statement. 580 * 581 * @param parse Parser object. 582 * @return New syntax tree node. 583 */ 511 /** Parse statement. */ 584 512 stree_stat_t *parse_stat(parse_t *parse) 585 513 { … … 648 576 } 649 577 650 /** Parse variable declaration statement. 651 * 652 * @param parse Parser object. 653 * @return New syntax tree node. 654 */ 578 /** Parse variable declaration statement. */ 655 579 static stree_vdecl_t *parse_vdecl(parse_t *parse) 656 580 { … … 679 603 } 680 604 681 /** Parse @c if statement. 682 * 683 * @param parse Parser object. 684 * @return New syntax tree node. 685 */ 605 /** Parse @c if statement, */ 686 606 static stree_if_t *parse_if(parse_t *parse) 687 607 { … … 709 629 } 710 630 711 /** Parse @c while statement. 712 * 713 * @param parse Parser object. 714 */ 631 /** Parse @c while statement. */ 715 632 static stree_while_t *parse_while(parse_t *parse) 716 633 { … … 731 648 } 732 649 733 /** Parse @c for statement. 734 * 735 * @param parse Parser object. 736 * @return New syntax tree node. 737 */ 650 /** Parse @c for statement. */ 738 651 static stree_for_t *parse_for(parse_t *parse) 739 652 { … … 758 671 } 759 672 760 /** Parse @c raise statement. 761 * 762 * @param parse Parser object. 763 */ 673 /** Parse @c raise statement. */ 764 674 static stree_raise_t *parse_raise(parse_t *parse) 765 675 { … … 777 687 } 778 688 779 /** Parse @c return statement. 780 * 781 * @param parse Parser object. 782 * @return New syntax tree node. 783 */ 689 /** Parse @c return statement. */ 784 690 static stree_return_t *parse_return(parse_t *parse) 785 691 { … … 798 704 } 799 705 800 /* Parse @c with-except-finally statement. 801 * 802 * @param parse Parser object. 803 * @return New syntax tree node. 804 */ 706 /* Parse @c with-except-finally statement. */ 805 707 static stree_wef_t *parse_wef(parse_t *parse) 806 708 { … … 844 746 } 845 747 846 /* Parse expression statement. 847 * 848 * @param parse Parser object. 849 * @return New syntax tree node. 850 */ 748 /* Parse expression statement. */ 851 749 static stree_exps_t *parse_exps(parse_t *parse) 852 750 { … … 866 764 } 867 765 868 /* Parse @c except clause. 869 * 870 * @param parse Parser object. 871 * @return New syntax tree node. 872 */ 766 /* Parse @c except clause. */ 873 767 static stree_except_t *parse_except(parse_t *parse) 874 768 { … … 891 785 } 892 786 893 /** Parse identifier. 894 * 895 * @param parse Parser object. 896 * @return New syntax tree node. 897 */ 787 /** Parse identifier. */ 898 788 stree_ident_t *parse_ident(parse_t *parse) 899 789 { … … 911 801 } 912 802 913 /** Signal a parse error, start bailing out from parser. 914 * 915 * @param parse Parser object. 916 */ 803 /** Signal a parse error, start bailing out from parser. */ 917 804 void parse_raise_error(parse_t *parse) 918 805 { … … 921 808 } 922 809 923 /** Note a parse error that has been immediately recovered. 924 * 925 * @param parse Parser object. 926 */ 810 /** Note a parse error that has been immediately recovered. */ 927 811 void parse_note_error(parse_t *parse) 928 812 { … … 930 814 } 931 815 932 /** Check if we are currently bailing out of parser due to a parse error. 933 * 934 * @param parse Parser object. 935 */ 816 /** Check if we are currently bailing out of parser due to a parse error. */ 936 817 bool_t parse_is_error(parse_t *parse) 937 818 { … … 942 823 * 943 824 * Still remember that there was an error, but stop bailing out. 944 *945 * @param parse Parser object.946 825 */ 947 826 void parse_recover_error(parse_t *parse) … … 953 832 } 954 833 955 /** Return current lem. 956 * 957 * @param parse Parser object. 958 * @return Pointer to current lem. Only valid until the lexing 959 * position is advanced. 960 */ 834 /** Return current lem. */ 961 835 lem_t *lcur(parse_t *parse) 962 836 { … … 967 841 } 968 842 969 /** Return current lem lclass. 970 * 971 * @param parse Parser object. 972 * @return Lclass of the current lem. 973 */ 843 /** Retturn current lem lclass. */ 974 844 lclass_t lcur_lc(parse_t *parse) 975 845 { … … 991 861 } 992 862 993 /** Skip to next lem. 994 * 995 * @param parse Parser object. 996 */ 863 /** Skip to next lem. */ 997 864 void lskip(parse_t *parse) 998 865 { … … 1003 870 } 1004 871 1005 /** Verify that lclass of current lem is @a lc. 1006 * 1007 * If a lem of different lclass is found, a parse error is raised and 1008 * a message is printed. 1009 * 1010 * @param parse Parser object. 1011 * @param lc Expected lclass. 1012 */ 872 /** Verify that lclass of current lem is @a lc. */ 1013 873 void lcheck(parse_t *parse, lclass_t lc) 1014 874 { … … 1027 887 } 1028 888 1029 /** Verify that lclass of current lem is @a lc and go to next lem. 1030 * 1031 * If a lem of different lclass is found, a parse error is raised and 1032 * a message is printed. 1033 * 1034 * @param parse Parser object. 1035 * @param lc Expected lclass. 1036 */ 889 /** Verify that lclass of current lem is @a lc and go to next lem. */ 1037 890 void lmatch(parse_t *parse, lclass_t lc) 1038 891 { … … 1057 910 } 1058 911 1059 /** Raise and display generic parsing error. 1060 * 1061 * @param parse Parser object. 1062 */ 912 /** Display generic parsing error. */ 1063 913 void lunexpected_error(parse_t *parse) 1064 914 { … … 1070 920 } 1071 921 1072 /** Determine whether @a lclass is in follow(block). 1073 * 1074 * Tests whether @a lclass belongs to the follow(block) set, i.e. if it is 1075 * lclass of a lem that can follow a block in the program. 1076 * 1077 * @param lclass Lclass. 1078 */ 922 /** Basically tells us whether @a lclass is in next(block). */ 1079 923 bool_t terminates_block(lclass_t lclass) 1080 924 { -
uspace/app/sbi/src/rdata.c
recb6ac32 r73060801 27 27 */ 28 28 29 /** @file Run-time data representation. 30 * 31 * At run time SBI represents all data as a graph of interconnected @c var 32 * nodes (variable nodes). Any piece of memory addressable by the program 33 * (i.e. all variables) are stored in var nodes. However, var nodes are also 34 * used internally to implement value items. (I.e. values in value items 35 * have exactly the same structure as program variables). 36 * 37 * Unlike byte- or word-oriented memory on a real machine, var nodes provide 38 * structured and typed storage. (This typing is dynamic, however and has 39 * nothing to do with the static type system). 40 * 41 * There are several types of var nodes, one for each primitive type, 42 * reference, delegate, array, and object. A reference var node contains 43 * a pointer to another var node. Delegate var node points to some stree 44 * declaration. Array and object var nodes refer to a collection of child 45 * nodes (fields, elements). 46 */ 29 /** @file Run-time data representation. */ 47 30 48 31 #include <stdlib.h> 49 32 #include <assert.h> 50 #include "bigint.h"51 33 #include "mytypes.h" 52 34 #include "stree.h" … … 68 50 static void rdata_var_print(rdata_var_t *var); 69 51 70 /** Allocate new data item. 71 * 72 * @param ic Item class. 73 * @return New item. 74 */ 52 75 53 rdata_item_t *rdata_item_new(item_class_t ic) 76 54 { … … 87 65 } 88 66 89 /** Allocate new address.90 *91 * @return New address.92 */93 67 rdata_addr_var_t *rdata_addr_var_new(void) 94 68 { … … 104 78 } 105 79 106 /** Allocate new named property address.107 *108 * @return New named property address.109 */110 80 rdata_aprop_named_t *rdata_aprop_named_new(void) 111 81 { … … 121 91 } 122 92 123 /** Allocate new indexed property address.124 *125 * @return New indexed property address.126 */127 93 rdata_aprop_indexed_t *rdata_aprop_indexed_new(void) 128 94 { … … 138 104 } 139 105 140 /** Allocate new property address.141 *142 * @param apc Property address class.143 * @return New property address.144 */145 106 rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc) 146 107 { … … 157 118 } 158 119 159 /** Allocate new address.160 *161 * @param ac Address class.162 * @return New address.163 */164 120 rdata_address_t *rdata_address_new(address_class_t ac) 165 121 { … … 176 132 } 177 133 178 /** Allocate new value.179 *180 * @return New value.181 */182 134 rdata_value_t *rdata_value_new(void) 183 135 { … … 193 145 } 194 146 195 /** Allocate new var node.196 *197 * @param vc Var node class (varclass).198 * @return New var node.199 */200 147 rdata_var_t *rdata_var_new(var_class_t vc) 201 148 { … … 212 159 } 213 160 214 /** Allocate new reference.215 *216 * @return New reference.217 */218 161 rdata_ref_t *rdata_ref_new(void) 219 162 { … … 229 172 } 230 173 231 /** Allocate new delegate.232 *233 * @return New delegate.234 */235 174 rdata_deleg_t *rdata_deleg_new(void) 236 175 { … … 246 185 } 247 186 248 /** Allocate new array.249 *250 * @return New array.251 */252 187 rdata_array_t *rdata_array_new(int rank) 253 188 { … … 270 205 } 271 206 272 /** Allocate new object.273 *274 * @return New object.275 */276 207 rdata_object_t *rdata_object_new(void) 277 208 { … … 287 218 } 288 219 289 /** Allocate new integer.290 *291 * @return New integer.292 */293 220 rdata_int_t *rdata_int_new(void) 294 221 { … … 304 231 } 305 232 306 /** Allocate new string.307 *308 * @return New string.309 */310 233 rdata_string_t *rdata_string_new(void) 311 234 { … … 321 244 } 322 245 323 /** Allocate new resource.324 *325 * @return New resource.326 */327 246 rdata_resource_t *rdata_resource_new(void) 328 247 { … … 338 257 } 339 258 340 /** Allocate array elements.341 *342 * Allocates var nodes for elements of @a array.343 *344 * @param array Array.345 */346 259 void rdata_array_alloc_element(rdata_array_t *array) 347 260 { … … 369 282 * Dimension is the total number of elements in an array, in other words, 370 283 * the product of all extents. 371 *372 * @param array Array.373 284 */ 374 285 static int rdata_array_get_dim(rdata_array_t *array) … … 383 294 } 384 295 385 /** Make copy of a variable. 386 * 387 * Creates a new var node that is an exact copy of an existing var node. 388 * This can be thought of as a shallow copy. 389 * 390 * @param src Source var node. 391 * @param dest Place to store pointer to new var node. 392 */ 296 /** Make copy of a variable. */ 393 297 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest) 394 298 { … … 424 328 } 425 329 426 /** Copy integer.427 *428 * @param src Source integer.429 * @param dest Place to store pointer to new integer.430 */431 330 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest) 432 331 { 433 332 *dest = rdata_int_new(); 434 bigint_clone(&src->value, &(*dest)->value); 435 } 436 437 /** Copy string. 438 * 439 * @param src Source string. 440 * @param dest Place to store pointer to new string. 441 */ 333 (*dest)->value = src->value; 334 } 335 442 336 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest) 443 337 { … … 446 340 } 447 341 448 /** Copy reference.449 *450 * @param src Source reference.451 * @param dest Place to store pointer to new reference.452 */453 342 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest) 454 343 { … … 457 346 } 458 347 459 /** Copy delegate.460 *461 * @param src Source delegate.462 * @param dest Place to store pointer to new delegate.463 */464 348 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest) 465 349 { … … 469 353 } 470 354 471 /** Copy array.472 *473 * @param src Source array.474 * @param dest Place to store pointer to new array.475 */476 355 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest) 477 356 { … … 481 360 } 482 361 483 /** Copy object.484 *485 * @param src Source object.486 * @param dest Place to store pointer to new object.487 */488 362 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest) 489 363 { … … 493 367 } 494 368 495 /** Copy resource.496 *497 * @param src Source resource.498 * @param dest Place to store pointer to new resource.499 */500 369 static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest) 501 370 { … … 506 375 /** Read data from a variable. 507 376 * 508 * This copies data from the variable to a value item. Ideally any read access 509 * to a program variable should go through this function. (Keep in mind 510 * that although values are composed of var nodes internally, but are not 511 * variables per se. Therefore this function is not used to read from values) 512 * 513 * @param var Variable to read from (var node where it is stored). 514 * @param ritem Place to store pointer to new value item read from 515 * the variable. 377 * Return value stored in variable @a var. 516 378 */ 517 379 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem) … … 531 393 /** Write data to a variable. 532 394 * 533 * This copies data to the variable from a value. Ideally any write access 534 * to a program variable should go through this function. (Keep in mind 535 * that even though values are composed of var nodes internally, but are not 536 * variables per se. Therefore this function is not used to write to values) 537 * 538 * @param var Variable to write to (var node where it is stored). 539 * @param value The value to write. 395 * Store @a value to variable @a var. 540 396 */ 541 397 void rdata_var_write(rdata_var_t *var, rdata_value_t *value) … … 562 418 } 563 419 564 /** Print data item in human-readable form.565 *566 * @param item Item to print.567 */568 420 void rdata_item_print(rdata_item_t *item) 569 421 { … … 585 437 } 586 438 587 /** Print address in human-readable form.588 *589 * Actually this displays contents of the var node that is being addressed.590 *591 * XXX Maybe we should really rather print the address and not the data592 * it is pointing to?593 *594 * @param item Address to print.595 */596 439 static void rdata_address_print(rdata_address_t *address) 597 440 { … … 606 449 } 607 450 608 /** Print value in human-readable form.609 *610 * @param value Value to print.611 */612 451 void rdata_value_print(rdata_value_t *value) 613 452 { … … 615 454 } 616 455 617 /** Print contents of var node in human-readable form.618 *619 * @param item Var node to print.620 */621 456 static void rdata_var_print(rdata_var_t *var) 622 457 { 623 458 switch (var->vc) { 624 459 case vc_int: 625 printf("int("); 626 bigint_print(&var->u.int_v->value); 627 printf(")"); 460 printf("int(%d)", var->u.int_v->value); 628 461 break; 629 462 case vc_string: -
uspace/app/sbi/src/rdata_t.h
recb6ac32 r73060801 35 35 #include "intmap_t.h" 36 36 37 /** Integer variable .38 * 39 * Sysel int type should be able to store arbitrarily (or at least 40 * very) large numbers. 41 */ 42 typedef struct { 43 bigint_t value;37 /** Integer variable */ 38 typedef struct { 39 /* 40 * Note: Sysel int type should be able to store arbitrarily large 41 * numbers. But for now we can live with limited width. 42 */ 43 int value; 44 44 } rdata_int_t; 45 45 -
uspace/app/sbi/src/run.c
recb6ac32 r73060801 32 32 #include <stdlib.h> 33 33 #include <assert.h> 34 #include "bigint.h"35 34 #include "builtin.h" 36 35 #include "debug.h" … … 58 57 59 58 static bool_t run_exc_match(run_t *run, stree_except_t *except_c); 60 static stree_csi_t *run_exc_payload_get_csi(run_t *run);61 62 59 static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *aprop); 63 60 … … 116 113 run_proc(run, proc_ar, &res); 117 114 118 run_exc_check_unhandled(run); 115 /* Check for unhandled exceptions. */ 116 if (run->thread_ar->bo_mode != bm_none) { 117 assert(run->thread_ar->bo_mode == bm_exc); 118 printf("Error: Unhandled exception.\n"); 119 exit(1); 120 } 119 121 } 120 122 … … 300 302 301 303 var->u.int_v = int_v; 302 bigint_init(&int_v->value, 0);304 int_v->value = 0; 303 305 304 306 block_ar = run_get_current_block_ar(run); … … 327 329 #endif 328 330 run_expr(run, if_s->cond, &rcond); 329 if (run_is_bo(run))330 return;331 331 332 332 if (run_item_boolean_value(run, rcond) == b_true) { … … 357 357 #endif 358 358 run_expr(run, while_s->cond, &rcond); 359 if (run_is_bo(run))360 return;361 359 362 360 while (run_item_boolean_value(run, rcond) == b_true) { 363 361 run_block(run, while_s->body); 364 362 run_expr(run, while_s->cond, &rcond); 365 if (run_is_bo(run))366 return;367 363 368 364 if (run->thread_ar->bo_mode != bm_none) … … 385 381 #endif 386 382 run_expr(run, raise_s->expr, &rexpr); 387 if (run_is_bo(run))388 return;389 390 383 run_cvt_value_item(run, rexpr, &rexpr_vi); 391 384 … … 408 401 #endif 409 402 run_expr(run, return_s->expr, &rexpr); 410 if (run_is_bo(run))411 return;412 413 403 run_cvt_value_item(run, rexpr, &rexpr_vi); 414 404 … … 487 477 * 488 478 * Checks if the currently active exception in the runner object @c run 489 * matches except clause @c except_c. 479 * matches except clause @c except_c. Generates an error if the exception 480 * payload has invalid type (i.e. not an object). 490 481 * 491 482 * @param run Runner object. … … 495 486 static bool_t run_exc_match(run_t *run, stree_except_t *except_c) 496 487 { 497 stree_csi_t *exc_csi; 488 rdata_value_t *payload; 489 rdata_var_t *payload_v; 490 rdata_object_t *payload_o; 498 491 tdata_item_t *etype; 499 492 500 /* Get CSI of active exception. */ 501 exc_csi = run_exc_payload_get_csi(run); 493 payload = run->thread_ar->exc_payload; 494 assert(payload != NULL); 495 496 if (payload->var->vc != vc_ref) { 497 printf("Error: Exception payload must be an object " 498 "(found type %d).\n", payload->var->vc); 499 exit(1); 500 } 501 502 payload_v = payload->var->u.ref_v->vref; 503 if (payload_v->vc != vc_object) { 504 printf("Error: Exception payload must be an object " 505 "(found type %d).\n", payload_v->vc); 506 exit(1); 507 } 508 509 payload_o = payload_v->u.object_v; 510 511 #ifdef DEBUG_RUN_TRACE 512 printf("Active exception: '"); 513 symbol_print_fqn(payload_o->class_sym); 514 printf("'.\n"); 515 #endif 516 assert(payload_o->class_sym != NULL); 517 assert(payload_o->class_sym->sc == sc_csi); 502 518 503 519 /* Evaluate type expression in except clause. */ … … 505 521 &etype); 506 522 507 /* Determine if active exc. is derived from type in exc. clause. */ 508 return tdata_is_csi_derived_from_ti(exc_csi, etype); 509 } 510 511 /** Return CSI of the active exception. 512 * 513 * @param run Runner object. 514 * @return CSI of the active exception. 515 */ 516 static stree_csi_t *run_exc_payload_get_csi(run_t *run) 517 { 518 rdata_value_t *payload; 519 rdata_var_t *payload_v; 520 rdata_object_t *payload_o; 521 522 payload = run->thread_ar->exc_payload; 523 assert(payload != NULL); 524 525 if (payload->var->vc != vc_ref) { 526 /* XXX Prevent this via static type checking. */ 527 printf("Error: Exception payload must be an object " 528 "(found type %d).\n", payload->var->vc); 529 exit(1); 530 } 531 532 payload_v = payload->var->u.ref_v->vref; 533 if (payload_v->vc != vc_object) { 534 /* XXX Prevent this via static type checking. */ 535 printf("Error: Exception payload must be an object " 536 "(found type %d).\n", payload_v->vc); 537 exit(1); 538 } 539 540 payload_o = payload_v->u.object_v; 541 542 #ifdef DEBUG_RUN_TRACE 543 printf("Active exception: '"); 544 symbol_print_fqn(payload_o->class_sym); 545 printf("'.\n"); 546 #endif 547 assert(payload_o->class_sym != NULL); 548 assert(payload_o->class_sym->sc == sc_csi); 549 550 return payload_o->class_sym->u.csi; 551 } 552 553 554 /** Check for unhandled exception. 555 * 556 * Checks whether there is an active exception. If so, it prints an 557 * error message and raises a run-time error. 558 * 559 * @param run Runner object. 560 */ 561 void run_exc_check_unhandled(run_t *run) 562 { 563 stree_csi_t *exc_csi; 564 565 if (run->thread_ar->bo_mode != bm_none) { 566 assert(run->thread_ar->bo_mode == bm_exc); 567 568 exc_csi = run_exc_payload_get_csi(run); 569 570 printf("Error: Unhandled exception '"); 571 symbol_print_fqn(csi_to_symbol(exc_csi)); 572 printf("'.\n"); 573 574 run_raise_error(run); 575 } 523 return tdata_is_csi_derived_from_ti(payload_o->class_sym->u.csi, 524 etype); 576 525 } 577 526 … … 671 620 672 621 (*var)->u.int_v = int_v; 673 bigint_clone(&item->u.value->var->u.int_v->value, 674 &int_v->value); 622 int_v->value = item->u.value->var->u.int_v->value; 675 623 break; 676 624 case vc_string: … … 1223 1171 1224 1172 if (addr_var->vref == NULL) { 1225 #ifdef DEBUG_RUN_TRACE1226 1173 printf("Error: Accessing null reference.\n"); 1227 #endif 1228 /* Raise Error.NilReference */ 1229 run_raise_exc(run, run->program->builtin->error_nilreference); 1174 run_raise_error(run); 1230 1175 *ritem = run_recovery_item(run); 1231 1176 return; … … 1236 1181 #endif 1237 1182 *ritem = item; 1238 }1239 1240 /** Raise an exception of the given class.1241 *1242 * Used when the interpreter generates an exception due to a run-time1243 * error (not for the @c raise statement).1244 *1245 * @param run Runner object.1246 * @param csi Exception class.1247 */1248 void run_raise_exc(run_t *run, stree_csi_t *csi)1249 {1250 rdata_item_t *exc_vi;1251 1252 /* Create exception object. */1253 run_new_csi_inst(run, csi, &exc_vi);1254 assert(exc_vi->ic == ic_value);1255 1256 /* Store exception object in thread AR. */1257 run->thread_ar->exc_payload = exc_vi->u.value;1258 1259 /* Start exception bailout. */1260 run->thread_ar->bo_mode = bm_exc;1261 }1262 1263 /** Determine if we are bailing out. */1264 bool_t run_is_bo(run_t *run)1265 {1266 return run->thread_ar->bo_mode != bm_none;1267 1183 } 1268 1184 -
uspace/app/sbi/src/run.h
recb6ac32 r73060801 39 39 void run_print_fun_bt(run_t *run); 40 40 41 void run_exc_check_unhandled(run_t *run);42 41 void run_raise_error(run_t *run); 43 42 rdata_item_t *run_recovery_item(run_t *run); … … 65 64 void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem); 66 65 67 void run_raise_exc(run_t *run, stree_csi_t *csi);68 bool_t run_is_bo(run_t *run);69 70 66 run_thread_ar_t *run_thread_ar_new(void); 71 67 run_proc_ar_t *run_proc_ar_new(void); -
uspace/app/sbi/src/run_expr.c
recb6ac32 r73060801 32 32 #include <stdlib.h> 33 33 #include <assert.h> 34 #include "bigint.h"35 34 #include "debug.h" 36 35 #include "intmap.h" … … 72 71 73 72 static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res); 74 static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val,75 rdata_item_t **res);76 77 73 static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res); 78 74 static void run_new_array(run_t *run, stree_new_t *new_op, … … 353 349 value->var = var; 354 350 var->u.int_v = int_v; 355 bigint_clone(&lit_int->value, &int_v->value);351 int_v->value = lit_int->value; 356 352 357 353 *res = item; … … 440 436 #endif 441 437 run_expr(run, binop->arg1, &rarg1_i); 442 if (run_is_bo(run)) {443 *res = NULL;444 return;445 }446 447 438 run_expr(run, binop->arg2, &rarg2_i); 448 if (run_is_bo(run)) {449 *res = NULL;450 return;451 }452 439 453 440 switch (binop->bc) { 454 441 case bo_plus: 455 case bo_minus:456 case bo_mult:457 442 case bo_equal: 458 443 case bo_notequal: … … 511 496 rdata_int_t *int_v; 512 497 513 bigint_t *i1, *i2; 514 bigint_t diff; 515 bool_t done; 516 bool_t zf, nf; 498 int i1, i2; 517 499 518 500 (void) run; … … 527 509 var->u.int_v = int_v; 528 510 529 i1 = &v1->var->u.int_v->value; 530 i2 = &v2->var->u.int_v->value; 531 532 done = b_true; 511 i1 = v1->var->u.int_v->value; 512 i2 = v2->var->u.int_v->value; 533 513 534 514 switch (binop->bc) { 535 515 case bo_plus: 536 bigint_add(i1, i2, &int_v->value); 537 break; 538 case bo_minus: 539 bigint_sub(i1, i2, &int_v->value); 540 break; 541 case bo_mult: 542 bigint_mul(i1, i2, &int_v->value); 543 break; 544 default: 545 done = b_false; 546 break; 547 } 548 549 if (done) { 550 *res = item; 551 return; 552 } 553 554 /* Relational operation. */ 555 556 bigint_sub(i1, i2, &diff); 557 zf = bigint_is_zero(&diff); 558 nf = bigint_is_negative(&diff); 516 int_v->value = i1 + i2; 517 break; 559 518 560 519 /* XXX We should have a real boolean type. */ 561 switch (binop->bc) {562 520 case bo_equal: 563 bigint_init(&int_v->value, zf ? 1 : 0);521 int_v->value = (i1 == i2) ? 1 : 0; 564 522 break; 565 523 case bo_notequal: 566 bigint_init(&int_v->value, !zf ? 1 : 0);524 int_v->value = (i1 != i2) ? 1 : 0; 567 525 break; 568 526 case bo_lt: 569 bigint_init(&int_v->value, (!zf && nf) ? 1 : 0);527 int_v->value = (i1 < i2) ? 1 : 0; 570 528 break; 571 529 case bo_gt: 572 bigint_init(&int_v->value, (!zf && !nf) ? 1 : 0);530 int_v->value = (i1 > i2) ? 1 : 0; 573 531 break; 574 532 case bo_lt_equal: 575 bigint_init(&int_v->value, (zf || nf) ? 1 : 0);533 int_v->value = (i1 <= i2) ? 1 : 0; 576 534 break; 577 535 case bo_gt_equal: 578 bigint_init(&int_v->value, !nf ? 1 : 0);536 int_v->value = (i1 >= i2) ? 1 : 0; 579 537 break; 580 538 default: … … 652 610 /* XXX We should have a real boolean type. */ 653 611 case bo_equal: 654 bigint_init(&int_v->value, (ref1 == ref2) ? 1 : 0);612 int_v->value = (ref1 == ref2) ? 1 : 0; 655 613 break; 656 614 case bo_notequal: 657 bigint_init(&int_v->value, (ref1 != ref2) ? 1 : 0);615 int_v->value = (ref1 != ref2) ? 1 : 0; 658 616 break; 659 617 default: … … 670 628 static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res) 671 629 { 672 rdata_item_t *rarg_i; 673 rdata_item_t *rarg_vi; 674 rdata_value_t *val; 630 rdata_item_t *rarg; 675 631 676 632 #ifdef DEBUG_RUN_TRACE 677 633 printf("Run unary operation.\n"); 678 634 #endif 679 run_expr(run, unop->arg, &rarg_i); 680 if (run_is_bo(run)) { 681 *res = NULL; 682 return; 683 } 684 685 #ifdef DEBUG_RUN_TRACE 686 printf("Check unop argument result.\n"); 687 #endif 688 run_cvt_value_item(run, rarg_i, &rarg_vi); 689 690 val = rarg_vi->u.value; 691 692 switch (val->var->vc) { 693 case vc_int: 694 run_unop_int(run, unop, val, res); 695 break; 696 default: 697 printf("Unimplemented: Unrary operation argument of " 698 "type %d.\n", val->var->vc); 699 run_raise_error(run); 700 *res = NULL; 701 break; 702 } 703 } 704 705 /** Evaluate unary operation on int argument. */ 706 static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val, 707 rdata_item_t **res) 708 { 709 rdata_item_t *item; 710 rdata_value_t *value; 711 rdata_var_t *var; 712 rdata_int_t *int_v; 713 714 (void) run; 715 716 item = rdata_item_new(ic_value); 717 value = rdata_value_new(); 718 var = rdata_var_new(vc_int); 719 int_v = rdata_int_new(); 720 721 item->u.value = value; 722 value->var = var; 723 var->u.int_v = int_v; 724 725 switch (unop->uc) { 726 case uo_plus: 727 bigint_clone(&val->var->u.int_v->value, &int_v->value); 728 break; 729 case uo_minus: 730 bigint_reverse_sign(&val->var->u.int_v->value, 731 &int_v->value); 732 break; 733 } 734 735 *res = item; 736 } 737 635 run_expr(run, unop->arg, &rarg); 636 *res = NULL; 637 } 738 638 739 639 /** Evaluate @c new operation. */ … … 780 680 int length; 781 681 int i; 782 int rc;783 int iextent;784 682 785 683 #ifdef DEBUG_RUN_TRACE … … 810 708 /* Evaluate extent argument. */ 811 709 run_expr(run, expr, &rexpr); 812 if (run_is_bo(run)) {813 *res = NULL;814 return;815 }816 817 710 run_cvt_value_item(run, rexpr, &rexpr_vi); 818 711 assert(rexpr_vi->ic == ic_value); … … 825 718 826 719 #ifdef DEBUG_RUN_TRACE 827 printf("Array extent: "); 828 bigint_print(&rexpr_var->u.int_v->value); 829 printf(".\n"); 830 #endif 831 rc = bigint_get_value_int(&rexpr_var->u.int_v->value, 832 &iextent); 833 if (rc != EOK) { 834 printf("Memory allocation failed (big int used).\n"); 835 exit(1); 836 } 837 838 array->extent[i] = iextent; 720 printf("Array extent: %d.\n", rexpr_var->u.int_v->value); 721 #endif 722 array->extent[i] = rexpr_var->u.int_v->value; 839 723 length = length * array->extent[i]; 840 724 … … 854 738 elem_var = rdata_var_new(vc_int); 855 739 elem_var->u.int_v = rdata_int_new(); 856 bigint_init(&elem_var->u.int_v->value, 0);740 elem_var->u.int_v->value = 0; 857 741 858 742 array->element[i] = elem_var; … … 871 755 tdata_item_t *titem, rdata_item_t **res) 872 756 { 757 rdata_object_t *obj; 758 rdata_var_t *obj_var; 759 760 stree_symbol_t *csi_sym; 873 761 stree_csi_t *csi; 762 stree_csimbr_t *csimbr; 763 764 rdata_var_t *mbr_var; 765 766 list_node_t *node; 874 767 875 768 #ifdef DEBUG_RUN_TRACE 876 769 printf("Create new object.\n"); 877 770 #endif 771 (void) run; 878 772 (void) new_op; 879 773 … … 881 775 assert(titem->tic == tic_tobject); 882 776 csi = titem->u.tobject->csi; 883 884 /* Create CSI instance. */ 885 run_new_csi_inst(run, csi, res); 777 csi_sym = csi_to_symbol(csi); 778 779 /* Create the object. */ 780 obj = rdata_object_new(); 781 obj->class_sym = csi_sym; 782 intmap_init(&obj->fields); 783 784 obj_var = rdata_var_new(vc_object); 785 obj_var->u.object_v = obj; 786 787 /* Create object fields. */ 788 node = list_first(&csi->members); 789 while (node != NULL) { 790 csimbr = list_node_data(node, stree_csimbr_t *); 791 if (csimbr->cc == csimbr_var) { 792 /* XXX Depends on member variable type. */ 793 mbr_var = rdata_var_new(vc_int); 794 mbr_var->u.int_v = rdata_int_new(); 795 mbr_var->u.int_v->value = 0; 796 797 intmap_set(&obj->fields, csimbr->u.var->name->sid, 798 mbr_var); 799 } 800 801 node = list_next(&csi->members, node); 802 } 803 804 /* Create reference to the new object. */ 805 run_reference(run, obj_var, res); 886 806 } 887 807 … … 895 815 #endif 896 816 run_expr(run, access->arg, &rarg); 897 if (run_is_bo(run)) {898 *res = NULL;899 return;900 }901 902 817 if (rarg == NULL) { 903 818 printf("Error: Sub-expression has no value.\n"); … … 1113 1028 #endif 1114 1029 run_expr(run, call->fun, &rfun); 1115 if (run_is_bo(run)) {1116 *res = NULL;1117 return;1118 }1119 1030 1120 1031 if (run->thread_ar->bo_mode != bm_none) { … … 1147 1058 arg = list_node_data(node, stree_expr_t *); 1148 1059 run_expr(run, arg, &rarg_i); 1149 if (run_is_bo(run)) {1150 *res = NULL;1151 return;1152 }1153 1154 1060 run_cvt_value_item(run, rarg_i, &rarg_vi); 1155 1061 … … 1190 1096 #endif 1191 1097 run_expr(run, index->base, &rbase); 1192 if (run_is_bo(run)) {1193 *res = NULL;1194 return;1195 }1196 1098 1197 1099 vc = run_item_get_vc(run, rbase); … … 1213 1115 arg = list_node_data(node, stree_expr_t *); 1214 1116 run_expr(run, arg, &rarg_i); 1215 if (run_is_bo(run)) {1216 *res = NULL;1217 return;1218 }1219 1220 1117 run_cvt_value_item(run, rarg_i, &rarg_vi); 1221 1118 … … 1252 1149 int elem_index; 1253 1150 int arg_val; 1254 int rc;1255 1151 1256 1152 rdata_item_t *ritem; … … 1293 1189 } 1294 1190 1295 rc = bigint_get_value_int( 1296 &arg->u.value->var->u.int_v->value, 1297 &arg_val); 1298 1299 if (rc != EOK || arg_val < 0 || arg_val >= array->extent[i]) { 1300 #ifdef DEBUG_RUN_TRACE 1191 arg_val = arg->u.value->var->u.int_v->value; 1192 1193 if (arg_val < 0 || arg_val >= array->extent[i]) { 1301 1194 printf("Error: Array index (value: %d) is out of range.\n", 1302 1195 arg_val); 1303 #endif 1304 /* Raise Error.OutOfBounds */ 1305 run_raise_exc(run, 1306 run->program->builtin->error_outofbounds); 1196 run_raise_error(run); 1307 1197 *res = run_recovery_item(run); 1308 1198 return; … … 1417 1307 int elem_index; 1418 1308 int arg_val; 1419 int rc 1, rc2;1309 int rc; 1420 1310 1421 1311 rdata_value_t *value; … … 1432 1322 run_cvt_value_item(run, base, &base_vi); 1433 1323 assert(base_vi->u.value->var->vc == vc_string); 1434 string = base _vi->u.value->var->u.string_v;1324 string = base->u.value->var->u.string_v; 1435 1325 1436 1326 /* … … 1456 1346 } 1457 1347 1458 rc1 = bigint_get_value_int( 1459 &arg->u.value->var->u.int_v->value, 1460 &arg_val); 1461 1348 arg_val = arg->u.value->var->u.int_v->value; 1462 1349 elem_index = arg_val; 1463 1350 … … 1471 1358 } 1472 1359 1473 if (rc1 == EOK) 1474 rc2 = os_str_get_char(string->value, elem_index, &cval); 1475 1476 if (rc1 != EOK || rc2 != EOK) { 1360 rc = os_str_get_char(string->value, elem_index, &cval); 1361 if (rc != EOK) { 1477 1362 printf("Error: String index (value: %d) is out of range.\n", 1478 1363 arg_val); … … 1487 1372 cvar = rdata_var_new(vc_int); 1488 1373 cvar->u.int_v = rdata_int_new(); 1489 bigint_init(&cvar->u.int_v->value, cval);1374 cvar->u.int_v->value = cval; 1490 1375 value->var = cvar; 1491 1376 … … 1504 1389 #endif 1505 1390 run_expr(run, assign->dest, &rdest_i); 1506 if (run_is_bo(run)) {1507 *res = NULL;1508 return;1509 }1510 1511 1391 run_expr(run, assign->src, &rsrc_i); 1512 if (run_is_bo(run)) {1513 *res = NULL;1514 return;1515 }1516 1392 1517 1393 run_cvt_value_item(run, rsrc_i, &rsrc_vi); … … 1547 1423 #endif 1548 1424 run_expr(run, as_op->arg, &rarg_i); 1549 if (run_is_bo(run)) {1550 *res = NULL;1551 return;1552 }1553 1425 1554 1426 /* … … 1595 1467 1596 1468 *res = rarg_vi; 1597 }1598 1599 /** Create new CSI instance. */1600 void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res)1601 {1602 rdata_object_t *obj;1603 rdata_var_t *obj_var;1604 1605 stree_symbol_t *csi_sym;1606 stree_csimbr_t *csimbr;1607 1608 rdata_var_t *mbr_var;1609 1610 list_node_t *node;1611 1612 csi_sym = csi_to_symbol(csi);1613 1614 #ifdef DEBUG_RUN_TRACE1615 printf("Create new instance of CSI '");1616 symbol_print_fqn(csi_sym);1617 printf("'.\n");1618 #endif1619 1620 /* Create the object. */1621 obj = rdata_object_new();1622 obj->class_sym = csi_sym;1623 intmap_init(&obj->fields);1624 1625 obj_var = rdata_var_new(vc_object);1626 obj_var->u.object_v = obj;1627 1628 /* Create object fields. */1629 node = list_first(&csi->members);1630 while (node != NULL) {1631 csimbr = list_node_data(node, stree_csimbr_t *);1632 if (csimbr->cc == csimbr_var) {1633 /* XXX Depends on member variable type. */1634 mbr_var = rdata_var_new(vc_int);1635 mbr_var->u.int_v = rdata_int_new();1636 bigint_init(&mbr_var->u.int_v->value, 0);1637 1638 intmap_set(&obj->fields, csimbr->u.var->name->sid,1639 mbr_var);1640 }1641 1642 node = list_next(&csi->members, node);1643 }1644 1645 /* Create reference to the new object. */1646 run_reference(run, obj_var, res);1647 1469 } 1648 1470 … … 1670 1492 } 1671 1493 1672 return !bigint_is_zero(&var->u.int_v->value);1673 } 1494 return (var->u.int_v->value != 0); 1495 } -
uspace/app/sbi/src/run_expr.h
recb6ac32 r73060801 34 34 void run_expr(run_t *run, stree_expr_t *expr, rdata_item_t **res); 35 35 36 void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res);37 36 bool_t run_item_boolean_value(run_t *run, rdata_item_t *item); 38 37 -
uspace/app/sbi/src/stree.c
recb6ac32 r73060801 376 376 } 377 377 378 stree_unop_t *stree_unop_new(unop_class_t uc)379 {380 stree_unop_t *unop;381 382 unop = calloc(1, sizeof(stree_unop_t));383 if (unop == NULL) {384 printf("Memory allocation failed.\n");385 exit(1);386 }387 388 unop->uc = uc;389 return unop;390 }391 392 378 stree_new_t *stree_new_new(void) 393 379 { -
uspace/app/sbi/src/stree.h
recb6ac32 r73060801 62 62 stree_assign_t *stree_assign_new(assign_class_t ac); 63 63 stree_binop_t *stree_binop_new(binop_class_t bc); 64 stree_unop_t *stree_unop_new(unop_class_t uc);65 64 stree_new_t *stree_new_new(void); 66 65 stree_access_t *stree_access_new(void); -
uspace/app/sbi/src/stree_t.h
recb6ac32 r73060801 30 30 #define STREE_T_H_ 31 31 32 #include "bigint_t.h"33 32 #include "list_t.h" 34 33 #include "builtin_t.h" … … 55 54 56 55 typedef struct { 57 bigint_t value;56 int value; 58 57 } stree_lit_int_t; 59 58 … … 90 89 bo_lt_equal, 91 90 bo_gt_equal, 92 bo_plus, 93 bo_minus, 94 bo_mult 91 bo_plus 95 92 } binop_class_t; 96 93 97 94 /** Unary operation class */ 98 95 typedef enum { 99 uo_plus, 100 uo_minus, 96 uo_plus 101 97 } unop_class_t; 102 98 … … 113 109 typedef struct { 114 110 /** Operation class */ 115 unop_class_t uc;111 unop_class_t oc; 116 112 117 113 /** Argument */ -
uspace/app/sbi/src/stype.c
recb6ac32 r73060801 162 162 &titem); 163 163 164 if (titem->tic != tic_tarray && titem->tic != tic_ignore) {164 if (titem->tic != tic_tarray) { 165 165 printf("Error: Packed argument is not an array.\n"); 166 166 stype_note_error(stype); … … 487 487 } 488 488 489 if (dest ->tic == tic_ignore || src->tic == tic_ignore)489 if (dest == NULL || src == NULL) 490 490 return expr; 491 491 … … 680 680 { 681 681 tdata_item_t *titem; 682 tdata_primitive_t *tprimitive; 682 683 683 684 (void) stype; 684 685 685 titem = tdata_item_new(tic_ignore); 686 titem = tdata_item_new(tic_tprimitive); 687 tprimitive = tdata_primitive_new(tpc_int); 688 689 titem->u.tprimitive = tprimitive; 690 686 691 return titem; 687 692 } -
uspace/app/sbi/src/stype_expr.c
recb6ac32 r73060801 60 60 static void stype_unop(stype_t *stype, stree_unop_t *unop, 61 61 tdata_item_t **rtitem); 62 static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop,63 tdata_item_t *ta, tdata_item_t **rtitem);64 62 static void stype_new(stype_t *stype, stree_new_t *new, 65 63 tdata_item_t **rtitem); … … 278 276 { 279 277 bool_t equal; 280 tdata_item_t *titem 1, *titem2;278 tdata_item_t *titem; 281 279 282 280 #ifdef DEBUG_TYPE_TRACE … … 286 284 stype_expr(stype, binop->arg2); 287 285 288 titem1 = binop->arg1->titem; 289 titem2 = binop->arg2->titem; 290 291 if (titem1 == NULL || titem2 == NULL) { 292 printf("Error: Binary operand has no value.\n"); 293 stype_note_error(stype); 294 *rtitem = stype_recovery_titem(stype); 295 return; 296 } 297 298 if (titem1->tic == tic_ignore || titem2->tic == tic_ignore) { 299 *rtitem = stype_recovery_titem(stype); 300 return; 301 } 302 303 equal = tdata_item_equal(titem1, titem2); 286 /* XXX This should be checked properly. */ 287 assert(binop->arg1->titem != NULL); 288 assert(binop->arg2->titem != NULL); 289 290 if (binop->arg1->titem == NULL) { 291 printf("Error First binary operand has no value.\n"); 292 stype_note_error(stype); 293 if (binop->arg2->titem != NULL) 294 *rtitem = binop->arg2->titem; 295 else 296 *rtitem = stype_recovery_titem(stype); 297 return; 298 } 299 300 if (binop->arg2->titem == NULL) { 301 printf("Error: Second binary operand has no value.\n"); 302 stype_note_error(stype); 303 *rtitem = binop->arg1->titem; 304 return; 305 } 306 307 equal = tdata_item_equal(binop->arg1->titem, binop->arg2->titem); 304 308 if (equal != b_true) { 305 309 printf("Error: Binary operation arguments " 306 310 "have different types ('"); 307 tdata_item_print( titem1);311 tdata_item_print(binop->arg1->titem); 308 312 printf("' and '"); 309 tdata_item_print( titem2);313 tdata_item_print(binop->arg2->titem); 310 314 printf("').\n"); 311 315 stype_note_error(stype); 312 *rtitem = stype_recovery_titem(stype); 313 return; 314 } 315 316 switch (titem1->tic) { 316 *rtitem = binop->arg1->titem; 317 return; 318 } 319 320 titem = binop->arg1->titem; 321 322 switch (titem->tic) { 317 323 case tic_tprimitive: 318 stype_binop_tprimitive(stype, binop, titem1, titem2, rtitem); 324 stype_binop_tprimitive(stype, binop, binop->arg1->titem, 325 binop->arg2->titem, rtitem); 319 326 break; 320 327 case tic_tobject: 321 stype_binop_tobject(stype, binop, titem1, titem2, rtitem); 328 stype_binop_tobject(stype, binop, binop->arg1->titem, 329 binop->arg2->titem, rtitem); 322 330 break; 323 331 default: 324 332 printf("Error: Binary operation on value which is not of a " 325 333 "supported type (found '"); 326 tdata_item_print(titem 1);334 tdata_item_print(titem); 327 335 printf("').\n"); 328 336 stype_note_error(stype); 329 *rtitem = stype_recovery_titem(stype);337 *rtitem = titem; 330 338 break; 331 339 } … … 409 417 tdata_item_t **rtitem) 410 418 { 411 tdata_item_t *titem;412 413 419 #ifdef DEBUG_TYPE_TRACE 414 420 printf("Evaluate type of unary operation.\n"); … … 416 422 stype_expr(stype, unop->arg); 417 423 418 titem = unop->arg->titem; 419 420 if (titem->tic == tic_ignore) { 421 *rtitem = stype_recovery_titem(stype); 422 return; 423 } 424 425 switch (titem->tic) { 426 case tic_tprimitive: 427 stype_unop_tprimitive(stype, unop, titem, rtitem); 428 break; 429 default: 430 printf("Error: Unary operation on value which is not of a " 431 "supported type (found '"); 432 tdata_item_print(titem); 433 printf("').\n"); 434 stype_note_error(stype); 435 *rtitem = stype_recovery_titem(stype); 436 break; 437 } 438 } 439 440 /** Type a binary operation arguments of primitive type. */ 441 static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop, 442 tdata_item_t *ta, tdata_item_t **rtitem) 443 { 444 tprimitive_class_t rtpc; 445 tdata_item_t *res_ti; 446 447 (void) stype; 448 (void) unop; 449 450 assert(ta->tic == tic_tprimitive); 451 452 switch (ta->u.tprimitive->tpc) { 453 case tpc_int: 454 rtpc = tpc_int; 455 break; 456 default: 457 printf("Error: Unary operator applied on unsupported " 458 "primitive type %d.\n", ta->u.tprimitive->tpc); 459 stype_note_error(stype); 460 *rtitem = stype_recovery_titem(stype); 461 return; 462 } 463 464 res_ti = tdata_item_new(tic_tprimitive); 465 res_ti->u.tprimitive = tdata_primitive_new(rtpc); 466 467 *rtitem = res_ti; 424 *rtitem = NULL; 468 425 } 469 426 … … 517 474 printf("Error: Using '.' operator on a function.\n"); 518 475 stype_note_error(stype); 519 *rtitem = stype_recovery_titem(stype);520 break;521 case tic_ignore:522 476 *rtitem = stype_recovery_titem(stype); 523 477 break; … … 659 613 stype_expr(stype, call->fun); 660 614 661 /* Check type item class */662 663 615 fun_ti = call->fun->titem; 664 switch (fun_ti->tic) { 665 case tic_tfun: 666 /* The expected case */ 667 break; 668 case tic_ignore: 669 *rtitem = stype_recovery_titem(stype); 670 return; 671 default: 672 printf("Error: Calling something which is not a function "); 673 printf("(found '"); 674 tdata_item_print(fun_ti); 675 printf("').\n"); 676 stype_note_error(stype); 677 *rtitem = stype_recovery_titem(stype); 678 return; 679 } 680 616 assert(fun_ti->tic == tic_tfun); 681 617 fun = fun_ti->u.tfun->fun; 682 618 fun_sym = fun_to_symbol(fun); … … 798 734 printf("Error: Indexing a function.\n"); 799 735 stype_note_error(stype); 800 *rtitem = stype_recovery_titem(stype);801 break;802 case tic_ignore:803 736 *rtitem = stype_recovery_titem(stype); 804 737 break; -
uspace/app/sbi/src/tdata.c
recb6ac32 r73060801 148 148 tdata_tfun_print(titem->u.tfun); 149 149 break; 150 case tic_ignore:151 printf("ignore");152 break;153 150 } 154 151 } -
uspace/app/sbi/src/tdata_t.h
recb6ac32 r73060801 84 84 85 85 typedef enum { 86 /** Primitive type item */87 86 tic_tprimitive, 88 /** Object type item */89 87 tic_tobject, 90 /** Array type item */91 88 tic_tarray, 92 /** Generic type item */93 89 tic_tgeneric, 94 /** Function type item */ 95 tic_tfun, 96 /** Special error-recovery type item */ 97 tic_ignore 90 tic_tfun 98 91 } titem_class_t; 99 92 -
uspace/dist/src/sysel/demos/varargs.sy
recb6ac32 r73060801 33 33 -- with the attribute 'packed'. 34 34 -- 35 fun Print(args : string[], packed) is 35 -- Note that we need to pass 'n' just because the array type 36 -- does not implement the Length property yet. 37 -- 38 fun Print(n : int; args : string[], packed) is 36 39 var i : int; 37 var error : int;38 40 39 error = 0;40 41 i = 0; 41 while error == 0 do 42 -- This is definitely the wrong way to determine 43 -- array bounds, but until a better one is 44 -- implemented... 45 do 46 Builtin.WriteLine(args[i]); 47 except e : Error.OutOfBounds do 48 error = 1; 49 end 50 42 while i < n do 43 Builtin.WriteLine(args[i]); 51 44 i = i + 1; 52 45 end … … 54 47 55 48 fun Main() is 56 Print( "One", "Two", "Three", "Four", "Five");49 Print(5, "One", "Two", "Three", "Four", "Five"); 57 50 end 58 51 end
Note:
See TracChangeset
for help on using the changeset viewer.