- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-compiler/core/parse.y
r331 r439 11 11 #endif 12 12 #define YYERROR_VERBOSE 1 13 /* 14 * Force yacc to use our memory management. This is a little evil because 15 * the macros assume that "parser_state *p" is in scope 16 */ 17 #define YYMALLOC(n) mrb_malloc(p->mrb, (n)) 18 #define YYFREE(o) mrb_free(p->mrb, (o)) 19 #define YYSTACK_USE_ALLOCA 0 13 #define YYSTACK_USE_ALLOCA 1 20 14 21 15 #include <ctype.h> … … 28 22 #include <mruby/error.h> 29 23 #include <mruby/throw.h> 24 #include <mruby/string.h> 30 25 #include "node.h" 31 26 … … 77 72 #define intn(x) ((int)(intptr_t)(x)) 78 73 74 #define NUM_SUFFIX_R (1<<0) 75 #define NUM_SUFFIX_I (1<<1) 76 79 77 static inline mrb_sym 80 78 intern_cstr_gen(parser_state *p, const char *s) … … 91 89 #define intern(s,len) intern_gen(p,(s),(len)) 92 90 93 static inline mrb_sym 94 intern_gen_c(parser_state *p, const char c) 95 { 96 return mrb_intern(p->mrb, &c, 1); 97 } 98 #define intern_c(c) intern_gen_c(p,(c)) 91 #define intern_lit(s) mrb_intern_lit(p->mrb, s) 99 92 100 93 static void … … 134 127 c->lineno = p->lineno; 135 128 c->filename_index = p->current_filename_index; 129 /* beginning of next partial file; need to point the previous file */ 130 if (p->lineno == 0 && p->current_filename_index > 0) { 131 c->filename_index-- ; 132 } 136 133 return c; 137 134 } … … 186 183 187 184 if (!a) return b; 185 if (!b) return a; 188 186 while (c->cdr) { 189 187 c = c->cdr; 190 188 } 191 if (b) { 192 c->cdr = b; 193 } 189 c->cdr = b; 194 190 return a; 195 191 } … … 216 212 #undef strdup 217 213 #define strdup(s) parser_strdup(p, s) 214 215 static void 216 dump_int(uint16_t i, char *s) 217 { 218 char *p = s; 219 char *t = s; 220 221 while (i > 0) { 222 *p++ = (i % 10)+'0'; 223 i /= 10; 224 } 225 if (p == s) *p++ = '0'; 226 *p = 0; 227 p--; /* point the last char */ 228 while (t < p) { 229 char c = *t; 230 *t++ = *p; 231 *p-- = c; 232 } 233 } 218 234 219 235 /* xxx ----------------------------- */ … … 280 296 } 281 297 298 static void 299 local_add_blk(parser_state *p, mrb_sym blk) 300 { 301 /* allocate register for block */ 302 local_add_f(p, blk ? blk : mrb_intern_lit(p->mrb, "&")); 303 } 304 305 static void 306 local_add_kw(parser_state *p, mrb_sym kwd) 307 { 308 /* allocate register for keywords hash */ 309 local_add_f(p, kwd ? kwd : mrb_intern_lit(p->mrb, "**")); 310 } 311 282 312 static node* 283 313 locals_node(parser_state *p) 284 314 { 285 315 return p->locals ? p->locals->car : NULL; 316 } 317 318 static void 319 nvars_nest(parser_state *p) 320 { 321 p->nvars = cons(nint(0), p->nvars); 322 } 323 324 static void 325 nvars_block(parser_state *p) 326 { 327 p->nvars = cons(nint(-2), p->nvars); 328 } 329 330 static void 331 nvars_unnest(parser_state *p) 332 { 333 p->nvars = p->nvars->cdr; 286 334 } 287 335 … … 569 617 } 570 618 619 /* (:kw_hash (k . v) (k . v)...) */ 620 static node* 621 new_kw_hash(parser_state *p, node *a) 622 { 623 return cons((node*)NODE_KW_HASH, a); 624 } 625 571 626 /* (:sym . a) */ 572 627 static node* … … 613 668 } 614 669 670 /* (:nvar . a) */ 671 static node* 672 new_nvar(parser_state *p, int num) 673 { 674 int nvars = intn(p->nvars->car); 675 676 p->nvars->car = nint(nvars > num ? nvars : num); 677 return cons((node*)NODE_NVAR, nint(num)); 678 } 679 615 680 /* (:const . a) */ 616 681 static node* … … 672 737 } 673 738 674 /* (m o r m2 b) */ 739 static void 740 local_add_margs(parser_state *p, node *n) 741 { 742 while (n) { 743 if (n->car->car == (node*)NODE_MASGN) { 744 node *t = n->car->cdr->cdr; 745 746 n->car->cdr->cdr = NULL; 747 while (t) { 748 local_add_f(p, sym(t->car)); 749 t = t->cdr; 750 } 751 local_add_margs(p, n->car->cdr->car->car); 752 local_add_margs(p, n->car->cdr->car->cdr->cdr->car); 753 } 754 n = n->cdr; 755 } 756 } 757 758 static void 759 local_add_lv(parser_state *p, node *lv) 760 { 761 while (lv) { 762 local_add_f(p, sym(lv->car)); 763 lv = lv->cdr; 764 } 765 } 766 767 /* (m o r m2 tail) */ 675 768 /* m: (a b c) */ 676 769 /* o: ((a . e1) (b . e2)) */ … … 679 772 /* b: a */ 680 773 static node* 681 new_args(parser_state *p, node *m, node *opt, mrb_sym rest, node *m2, mrb_sym blk)774 new_args(parser_state *p, node *m, node *opt, mrb_sym rest, node *m2, node *tail) 682 775 { 683 776 node *n; 684 777 685 n = cons(m2, nsym(blk)); 778 local_add_margs(p, m); 779 local_add_margs(p, m2); 780 n = cons(m2, tail); 686 781 n = cons(nsym(rest), n); 687 782 n = cons(opt, n); 783 while (opt) { 784 /* opt: (sym . (opt . lv)) -> (sym . opt) */ 785 local_add_lv(p, opt->car->cdr->cdr); 786 opt->car->cdr = opt->car->cdr->car; 787 opt = opt->cdr; 788 } 688 789 return cons(m, n); 689 790 } 690 791 792 /* (:args_tail keywords rest_keywords_sym block_sym) */ 793 static node* 794 new_args_tail(parser_state *p, node *kws, node *kwrest, mrb_sym blk) 795 { 796 node *k; 797 798 if (kws || kwrest) { 799 local_add_kw(p, (kwrest && kwrest->cdr)? sym(kwrest->cdr) : 0); 800 } 801 802 local_add_blk(p, blk); 803 804 /* allocate register for keywords arguments */ 805 /* order is for Proc#parameters */ 806 for (k = kws; k; k = k->cdr) { 807 if (!k->car->cdr->cdr->car) { /* allocate required keywords */ 808 local_add_f(p, sym(k->car->cdr->car)); 809 } 810 } 811 for (k = kws; k; k = k->cdr) { 812 if (k->car->cdr->cdr->car) { /* allocate keywords with default */ 813 local_add_lv(p, k->car->cdr->cdr->car->cdr); 814 k->car->cdr->cdr->car = k->car->cdr->cdr->car->car; 815 local_add_f(p, sym(k->car->cdr->car)); 816 } 817 } 818 819 return list4((node*)NODE_ARGS_TAIL, kws, kwrest, nsym(blk)); 820 } 821 822 /* (:kw_arg kw_sym def_arg) */ 823 static node* 824 new_kw_arg(parser_state *p, mrb_sym kw, node *def_arg) 825 { 826 mrb_assert(kw); 827 return list3((node*)NODE_KW_ARG, nsym(kw), def_arg); 828 } 829 691 830 /* (:block_arg . a) */ 692 831 static node* … … 696 835 } 697 836 837 static node* 838 setup_numparams(parser_state *p, node *a) 839 { 840 int nvars = intn(p->nvars->car); 841 if (nvars > 0) { 842 int i; 843 mrb_sym sym; 844 // m || opt || rest || tail 845 if (a && (a->car || (a->cdr && a->cdr->car) || (a->cdr->cdr && a->cdr->cdr->car) || (a->cdr->cdr->cdr->cdr && a->cdr->cdr->cdr->cdr->car))) { 846 yyerror(p, "ordinary parameter is defined"); 847 } 848 else if (p->locals) { 849 /* p->locals should not be NULL unless error happens before the point */ 850 node* args = 0; 851 for (i = nvars; i > 0; i--) { 852 char buf[3]; 853 854 buf[0] = '_'; 855 buf[1] = i+'0'; 856 buf[2] = '\0'; 857 sym = intern_cstr(buf); 858 args = cons(new_arg(p, sym), args); 859 p->locals->car = cons(nsym(sym), p->locals->car); 860 } 861 a = new_args(p, args, 0, 0, 0, 0); 862 } 863 } 864 return a; 865 } 866 698 867 /* (:block arg body) */ 699 868 static node* 700 869 new_block(parser_state *p, node *a, node *b) 701 870 { 871 a = setup_numparams(p, a); 702 872 return list4((node*)NODE_BLOCK, locals_node(p), a, b); 703 873 } … … 726 896 } 727 897 898 /* (:masgn mlhs mrhs) no check */ 899 static node* 900 new_masgn_param(parser_state *p, node *a, node *b) 901 { 902 return cons((node*)NODE_MASGN, cons(a, b)); 903 } 904 728 905 /* (:asgn lhs rhs) */ 729 906 static node* … … 734 911 } 735 912 913 static node* 914 new_imaginary(parser_state *p, node *imaginary) 915 { 916 return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Complex"), list1(list2(list3((node*)NODE_INT, (node*)strdup("0"), nint(10)), imaginary)), 1); 917 } 918 919 static node* 920 new_rational(parser_state *p, node *rational) 921 { 922 return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Rational"), list1(list1(rational)), 1); 923 } 924 736 925 /* (:int . i) */ 737 926 static node* 738 new_int(parser_state *p, const char *s, int base) 739 { 740 return list3((node*)NODE_INT, (node*)strdup(s), nint(base)); 741 } 742 927 new_int(parser_state *p, const char *s, int base, int suffix) 928 { 929 node* result = list3((node*)NODE_INT, (node*)strdup(s), nint(base)); 930 if (suffix & NUM_SUFFIX_R) { 931 result = new_rational(p, result); 932 } 933 if (suffix & NUM_SUFFIX_I) { 934 result = new_imaginary(p, result); 935 } 936 return result; 937 } 938 939 #ifndef MRB_WITHOUT_FLOAT 743 940 /* (:float . i) */ 744 941 static node* 745 new_float(parser_state *p, const char *s) 746 { 747 return cons((node*)NODE_FLOAT, (node*)strdup(s)); 748 } 942 new_float(parser_state *p, const char *s, int suffix) 943 { 944 node* result = cons((node*)NODE_FLOAT, (node*)strdup(s)); 945 if (suffix & NUM_SUFFIX_R) { 946 result = new_rational(p, result); 947 } 948 if (suffix & NUM_SUFFIX_I) { 949 result = new_imaginary(p, result); 950 } 951 return result; 952 } 953 #endif 749 954 750 955 /* (:str . (s . len)) */ 751 956 static node* 752 new_str(parser_state *p, const char *s, int len)957 new_str(parser_state *p, const char *s, size_t len) 753 958 { 754 959 return cons((node*)NODE_STR, cons((node*)strndup(s, len), nint(len))); … … 762 967 } 763 968 969 static int 970 string_node_p(node *n) 971 { 972 return (int)((enum node_type)(intptr_t)n->car == NODE_STR); 973 } 974 975 static node* 976 composite_string_node(parser_state *p, node *a, node *b) 977 { 978 size_t newlen = (size_t)a->cdr + (size_t)b->cdr; 979 char *str = (char*)mrb_pool_realloc(p->pool, a->car, (size_t)a->cdr + 1, newlen + 1); 980 memcpy(str + (size_t)a->cdr, b->car, (size_t)b->cdr); 981 str[newlen] = '\0'; 982 a->car = (node*)str; 983 a->cdr = (node*)newlen; 984 cons_free(b); 985 return a; 986 } 987 988 static node* 989 concat_string(parser_state *p, node *a, node *b) 990 { 991 if (string_node_p(a)) { 992 if (string_node_p(b)) { 993 /* a == NODE_STR && b == NODE_STR */ 994 composite_string_node(p, a->cdr, b->cdr); 995 cons_free(b); 996 return a; 997 } 998 else { 999 /* a == NODE_STR && b == NODE_DSTR */ 1000 1001 if (string_node_p(b->cdr->car)) { 1002 /* a == NODE_STR && b->[NODE_STR, ...] */ 1003 composite_string_node(p, a->cdr, b->cdr->car->cdr); 1004 cons_free(b->cdr->car); 1005 b->cdr->car = a; 1006 return b; 1007 } 1008 } 1009 } 1010 else { 1011 node *c; /* last node of a */ 1012 for (c = a; c->cdr != NULL; c = c->cdr) ; 1013 1014 if (string_node_p(b)) { 1015 /* a == NODE_DSTR && b == NODE_STR */ 1016 if (string_node_p(c->car)) { 1017 /* a->[..., NODE_STR] && b == NODE_STR */ 1018 composite_string_node(p, c->car->cdr, b->cdr); 1019 cons_free(b); 1020 return a; 1021 } 1022 1023 push(a, b); 1024 return a; 1025 } 1026 else { 1027 /* a == NODE_DSTR && b == NODE_DSTR */ 1028 if (string_node_p(c->car) && string_node_p(b->cdr->car)) { 1029 /* a->[..., NODE_STR] && b->[NODE_STR, ...] */ 1030 node *d = b->cdr; 1031 cons_free(b); 1032 composite_string_node(p, c->car->cdr, d->car->cdr); 1033 cons_free(d->car); 1034 c->cdr = d->cdr; 1035 cons_free(d); 1036 return a; 1037 } 1038 else { 1039 c->cdr = b->cdr; 1040 cons_free(b); 1041 return a; 1042 } 1043 } 1044 } 1045 1046 return new_dstr(p, list2(a, b)); 1047 } 1048 764 1049 /* (:str . (s . len)) */ 765 1050 static node* … … 780 1065 new_dsym(parser_state *p, node *a) 781 1066 { 782 return cons((node*)NODE_DSYM, new_dstr(p, a));1067 return cons((node*)NODE_DSYM, a); 783 1068 } 784 1069 … … 1024 1309 if (p->parsing_heredoc == NULL) { 1025 1310 p->lstate = EXPR_BEG; 1026 p->cmd_start = TRUE;1027 1311 end_strterm(p); 1028 1312 p->lex_strterm = p->lex_strterm_before_heredoc; 1029 1313 p->lex_strterm_before_heredoc = NULL; 1030 p->heredoc_end_now = TRUE;1031 1314 } 1032 1315 else { … … 1105 1388 keyword__ENCODING__ 1106 1389 1107 %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL 1390 %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL_TAG 1108 1391 %token <nd> tINTEGER tFLOAT tCHAR tXSTRING tREGEXP 1109 %token <nd> tSTRING tSTRING_PART tSTRING_MID tLABEL_END1392 %token <nd> tSTRING tSTRING_PART tSTRING_MID 1110 1393 %token <nd> tNTH_REF tBACK_REF 1111 1394 %token <num> tREGEXP_END 1112 1113 %type <nd> singleton string string_rep string_interp xstring regexp 1395 %token <num> tNUMPARAM 1396 1397 %type <nd> singleton string string_fragment string_rep string_interp xstring regexp 1114 1398 %type <nd> literal numeric cpath symbol 1115 1399 %type <nd> top_compstmt top_stmts top_stmt … … 1122 1406 %type <nd> command_asgn command_rhs mrhs superclass block_call block_command 1123 1407 %type <nd> f_block_optarg f_block_opt 1124 %type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs1408 %type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_margs 1125 1409 %type <nd> assoc_list assocs assoc undef_list backref for_var 1126 1410 %type <nd> block_param opt_block_param block_param_def f_opt … … 1132 1416 %type <nd> heredoc words symbols 1133 1417 %type <num> call_op call_op2 /* 0:'&.', 1:'.', 2:'::' */ 1418 1419 %type <nd> args_tail opt_args_tail f_kwarg f_kw f_kwrest 1420 %type <nd> f_block_kwarg f_block_kw block_args_tail opt_block_args_tail 1421 %type <id> f_label 1134 1422 1135 1423 %token tUPLUS /* unary+ */ … … 1158 1446 %token tLBRACE_ARG /* { */ 1159 1447 %token tSTAR /* * */ 1448 %token tDSTAR /* ** */ 1160 1449 %token tAMPER /* & */ 1161 1450 %token tLAMBDA /* -> */ … … 1179 1468 %right '=' tOP_ASGN 1180 1469 %left modifier_rescue 1181 %right '?' ':' 1470 %right '?' ':' tLABEL_TAG 1182 1471 %nonassoc tDOT2 tDOT3 1183 1472 %left tOROP … … 1237 1526 { 1238 1527 $<nd>$ = local_switch(p); 1528 nvars_block(p); 1239 1529 } 1240 1530 '{' top_compstmt '}' … … 1242 1532 yyerror(p, "BEGIN not supported"); 1243 1533 local_resume(p, $<nd>2); 1534 nvars_unnest(p); 1244 1535 $$ = 0; 1245 1536 } … … 1359 1650 $$ = new_op_asgn(p, $1, $2, $3); 1360 1651 } 1361 | primary_value '[' opt_call_args rbrackettOP_ASGN command_rhs1362 { 1363 $$ = new_op_asgn(p, new_call(p, $1, intern ("[]",2), $3, '.'), $5, $6);1652 | primary_value '[' opt_call_args ']' tOP_ASGN command_rhs 1653 { 1654 $$ = new_op_asgn(p, new_call(p, $1, intern_lit("[]"), $3, '.'), $5, $6); 1364 1655 } 1365 1656 | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs … … 1385 1676 $$ = new_begin(p, 0); 1386 1677 } 1387 1678 ; 1388 1679 1389 1680 command_rhs : command_call %prec tOP_ASGN … … 1439 1730 { 1440 1731 local_nest(p); 1732 nvars_nest(p); 1441 1733 } 1442 1734 opt_block_param … … 1446 1738 $$ = new_block(p, $3, $4); 1447 1739 local_unnest(p); 1740 nvars_unnest(p); 1448 1741 } 1449 1742 ; … … 1588 1881 assignable(p, $1); 1589 1882 } 1590 | primary_value '[' opt_call_args rbracket1591 { 1592 $$ = new_call(p, $1, intern ("[]",2), $3, '.');1883 | primary_value '[' opt_call_args ']' 1884 { 1885 $$ = new_call(p, $1, intern_lit("[]"), $3, '.'); 1593 1886 } 1594 1887 | primary_value call_op tIDENTIFIER … … 1627 1920 assignable(p, $1); 1628 1921 } 1629 | primary_value '[' opt_call_args rbracket1630 { 1631 $$ = new_call(p, $1, intern ("[]",2), $3, '.');1922 | primary_value '[' opt_call_args ']' 1923 { 1924 $$ = new_call(p, $1, intern_lit("[]"), $3, '.'); 1632 1925 } 1633 1926 | primary_value call_op tIDENTIFIER … … 1659 1952 backref_error(p, $1); 1660 1953 $$ = 0; 1954 } 1955 | tNUMPARAM 1956 { 1957 yyerror(p, "can't assign to numbered parameter"); 1661 1958 } 1662 1959 ; … … 1713 2010 ; 1714 2011 1715 op : '|' { $$ = intern_c('|'); } 1716 | '^' { $$ = intern_c('^'); } 1717 | '&' { $$ = intern_c('&'); } 1718 | tCMP { $$ = intern("<=>",3); } 1719 | tEQ { $$ = intern("==",2); } 1720 | tEQQ { $$ = intern("===",3); } 1721 | tMATCH { $$ = intern("=~",2); } 1722 | tNMATCH { $$ = intern("!~",2); } 1723 | '>' { $$ = intern_c('>'); } 1724 | tGEQ { $$ = intern(">=",2); } 1725 | '<' { $$ = intern_c('<'); } 1726 | tLEQ { $$ = intern("<=",2); } 1727 | tNEQ { $$ = intern("!=",2); } 1728 | tLSHFT { $$ = intern("<<",2); } 1729 | tRSHFT { $$ = intern(">>",2); } 1730 | '+' { $$ = intern_c('+'); } 1731 | '-' { $$ = intern_c('-'); } 1732 | '*' { $$ = intern_c('*'); } 1733 | tSTAR { $$ = intern_c('*'); } 1734 | '/' { $$ = intern_c('/'); } 1735 | '%' { $$ = intern_c('%'); } 1736 | tPOW { $$ = intern("**",2); } 1737 | '!' { $$ = intern_c('!'); } 1738 | '~' { $$ = intern_c('~'); } 1739 | tUPLUS { $$ = intern("+@",2); } 1740 | tUMINUS { $$ = intern("-@",2); } 1741 | tAREF { $$ = intern("[]",2); } 1742 | tASET { $$ = intern("[]=",3); } 1743 | '`' { $$ = intern_c('`'); } 2012 op : '|' { $$ = intern_lit("|"); } 2013 | '^' { $$ = intern_lit("^"); } 2014 | '&' { $$ = intern_lit("&"); } 2015 | tCMP { $$ = intern_lit("<=>"); } 2016 | tEQ { $$ = intern_lit("=="); } 2017 | tEQQ { $$ = intern_lit("==="); } 2018 | tMATCH { $$ = intern_lit("=~"); } 2019 | tNMATCH { $$ = intern_lit("!~"); } 2020 | '>' { $$ = intern_lit(">"); } 2021 | tGEQ { $$ = intern_lit(">="); } 2022 | '<' { $$ = intern_lit("<"); } 2023 | tLEQ { $$ = intern_lit("<="); } 2024 | tNEQ { $$ = intern_lit("!="); } 2025 | tLSHFT { $$ = intern_lit("<<"); } 2026 | tRSHFT { $$ = intern_lit(">>"); } 2027 | '+' { $$ = intern_lit("+"); } 2028 | '-' { $$ = intern_lit("-"); } 2029 | '*' { $$ = intern_lit("*"); } 2030 | tSTAR { $$ = intern_lit("*"); } 2031 | '/' { $$ = intern_lit("/"); } 2032 | '%' { $$ = intern_lit("%"); } 2033 | tPOW { $$ = intern_lit("**"); } 2034 | tDSTAR { $$ = intern_lit("**"); } 2035 | '!' { $$ = intern_lit("!"); } 2036 | '~' { $$ = intern_lit("~"); } 2037 | tUPLUS { $$ = intern_lit("+@"); } 2038 | tUMINUS { $$ = intern_lit("-@"); } 2039 | tAREF { $$ = intern_lit("[]"); } 2040 | tASET { $$ = intern_lit("[]="); } 2041 | '`' { $$ = intern_lit("`"); } 1744 2042 ; 1745 2043 … … 1766 2064 $$ = new_op_asgn(p, $1, $2, $3); 1767 2065 } 1768 | primary_value '[' opt_call_args rbrackettOP_ASGN arg_rhs1769 { 1770 $$ = new_op_asgn(p, new_call(p, $1, intern ("[]",2), $3, '.'), $5, $6);2066 | primary_value '[' opt_call_args ']' tOP_ASGN arg_rhs 2067 { 2068 $$ = new_op_asgn(p, new_call(p, $1, intern_lit("[]"), $3, '.'), $5, $6); 1771 2069 } 1772 2070 | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs … … 1925 2223 $$ = new_if(p, cond($1), $3, $6); 1926 2224 } 2225 | arg '?' arg opt_nl tLABEL_TAG arg 2226 { 2227 $$ = new_if(p, cond($1), $3, $6); 2228 } 1927 2229 | primary 1928 2230 { … … 1939 2241 | args comma assocs trailer 1940 2242 { 1941 $$ = push($1, new_ hash(p, $3));2243 $$ = push($1, new_kw_hash(p, $3)); 1942 2244 } 1943 2245 | assocs trailer 1944 2246 { 1945 $$ = cons(new_ hash(p, $1), 0);2247 $$ = cons(new_kw_hash(p, $1), 0); 1946 2248 NODE_LINENO($$, $1); 1947 2249 } … … 1960 2262 ; 1961 2263 1962 paren_args : '(' opt_call_args rparen2264 paren_args : '(' opt_call_args ')' 1963 2265 { 1964 2266 $$ = $2; … … 1971 2273 1972 2274 opt_call_args : none 1973 | call_args 1974 | args ','2275 | call_args opt_terms 2276 | args comma 1975 2277 { 1976 2278 $$ = cons($1,0); 1977 2279 NODE_LINENO($$, $1); 1978 2280 } 1979 | args comma assocs ','1980 { 1981 $$ = cons(push($1, new_ hash(p, $3)), 0);2281 | args comma assocs comma 2282 { 2283 $$ = cons(push($1, new_kw_hash(p, $3)), 0); 1982 2284 NODE_LINENO($$, $1); 1983 2285 } 1984 | assocs ','1985 { 1986 $$ = cons(list1(new_ hash(p, $1)), 0);2286 | assocs comma 2287 { 2288 $$ = cons(list1(new_kw_hash(p, $1)), 0); 1987 2289 NODE_LINENO($$, $1); 1988 2290 } … … 2002 2304 | assocs opt_block_arg 2003 2305 { 2004 $$ = cons(list1(new_ hash(p, $1)), $2);2306 $$ = cons(list1(new_kw_hash(p, $1)), $2); 2005 2307 NODE_LINENO($$, $1); 2006 2308 } 2007 2309 | args comma assocs opt_block_arg 2008 2310 { 2009 $$ = cons(push($1, new_ hash(p, $3)), $4);2311 $$ = cons(push($1, new_kw_hash(p, $3)), $4); 2010 2312 NODE_LINENO($$, $1); 2011 2313 } … … 2045 2347 2046 2348 comma : ',' 2047 | ',' heredoc_bodies2349 | ',' opt_nl heredoc_bodies 2048 2350 ; 2049 2351 … … 2096 2398 | var_ref 2097 2399 | backref 2400 | tNUMPARAM 2401 { 2402 $$ = new_nvar(p, $1); 2403 } 2098 2404 | tFID 2099 2405 { … … 2248 2554 yyerror(p, "class definition in method body"); 2249 2555 $<nd>$ = local_switch(p); 2556 nvars_block(p); 2250 2557 } 2251 2558 bodystmt … … 2255 2562 SET_LINENO($$, $1); 2256 2563 local_resume(p, $<nd>4); 2564 nvars_unnest(p); 2257 2565 } 2258 2566 | keyword_class … … 2265 2573 { 2266 2574 $<nd>$ = cons(local_switch(p), nint(p->in_single)); 2575 nvars_block(p); 2267 2576 p->in_single = 0; 2268 2577 } … … 2273 2582 SET_LINENO($$, $1); 2274 2583 local_resume(p, $<nd>6->car); 2584 nvars_unnest(p); 2275 2585 p->in_def = $<num>4; 2276 2586 p->in_single = intn($<nd>6->cdr); … … 2282 2592 yyerror(p, "module definition in method body"); 2283 2593 $<nd>$ = local_switch(p); 2594 nvars_block(p); 2284 2595 } 2285 2596 bodystmt … … 2289 2600 SET_LINENO($$, $1); 2290 2601 local_resume(p, $<nd>3); 2602 nvars_unnest(p); 2291 2603 } 2292 2604 | keyword_def fname … … 2298 2610 p->in_def++; 2299 2611 $<nd>$ = local_switch(p); 2612 nvars_block(p); 2300 2613 } 2301 2614 f_arglist … … 2306 2619 SET_LINENO($$, $1); 2307 2620 local_resume(p, $<nd>4); 2621 nvars_unnest(p); 2308 2622 p->in_def--; 2309 2623 p->cmdarg_stack = $<stack>3; … … 2320 2634 p->lstate = EXPR_ENDFN; /* force for args */ 2321 2635 $<nd>$ = local_switch(p); 2636 nvars_block(p); 2322 2637 } 2323 2638 f_arglist … … 2328 2643 SET_LINENO($$, $1); 2329 2644 local_resume(p, $<nd>6); 2645 nvars_unnest(p); 2330 2646 p->in_single--; 2331 2647 p->cmdarg_stack = $<stack>4; … … 2388 2704 ; 2389 2705 2390 f_marg : f_norm_arg 2391 { 2392 $$ = new_arg(p, $1); 2393 } 2394 | tLPAREN f_margs rparen 2395 { 2396 $$ = new_masgn(p, $2, 0); 2397 } 2398 ; 2399 2400 f_marg_list : f_marg 2401 { 2402 $$ = list1($1); 2403 } 2404 | f_marg_list ',' f_marg 2405 { 2406 $$ = push($1, $3); 2407 } 2408 ; 2409 2410 f_margs : f_marg_list 2706 f_margs : f_arg 2411 2707 { 2412 2708 $$ = list3($1,0,0); 2413 2709 } 2414 | f_ marg_list',' tSTAR f_norm_arg2710 | f_arg ',' tSTAR f_norm_arg 2415 2711 { 2416 2712 $$ = list3($1, new_arg(p, $4), 0); 2417 2713 } 2418 | f_ marg_list ',' tSTAR f_norm_arg ',' f_marg_list2714 | f_arg ',' tSTAR f_norm_arg ',' f_arg 2419 2715 { 2420 2716 $$ = list3($1, new_arg(p, $4), $6); 2421 2717 } 2422 | f_marg_list ',' tSTAR 2423 { 2718 | f_arg ',' tSTAR 2719 { 2720 local_add_f(p, 0); 2424 2721 $$ = list3($1, (node*)-1, 0); 2425 2722 } 2426 | f_ marg_list ',' tSTAR ',' f_marg_list2723 | f_arg ',' tSTAR ',' f_arg 2427 2724 { 2428 2725 $$ = list3($1, (node*)-1, $5); … … 2432 2729 $$ = list3(0, new_arg(p, $2), 0); 2433 2730 } 2434 | tSTAR f_norm_arg ',' f_ marg_list2731 | tSTAR f_norm_arg ',' f_arg 2435 2732 { 2436 2733 $$ = list3(0, new_arg(p, $2), $4); … … 2438 2735 | tSTAR 2439 2736 { 2737 local_add_f(p, 0); 2440 2738 $$ = list3(0, (node*)-1, 0); 2441 2739 } 2442 | tSTAR ',' f_marg_list 2443 { 2444 $$ = list3(0, (node*)-1, $3); 2445 } 2446 ; 2447 2448 block_param : f_arg ',' f_block_optarg ',' f_rest_arg opt_f_block_arg 2740 | tSTAR ',' 2741 { 2742 local_add_f(p, 0); 2743 } 2744 f_arg 2745 { 2746 $$ = list3(0, (node*)-1, $4); 2747 } 2748 ; 2749 2750 block_args_tail : f_block_kwarg ',' f_kwrest opt_f_block_arg 2751 { 2752 $$ = new_args_tail(p, $1, $3, $4); 2753 } 2754 | f_block_kwarg opt_f_block_arg 2755 { 2756 $$ = new_args_tail(p, $1, 0, $2); 2757 } 2758 | f_kwrest opt_f_block_arg 2759 { 2760 $$ = new_args_tail(p, 0, $1, $2); 2761 } 2762 | f_block_arg 2763 { 2764 $$ = new_args_tail(p, 0, 0, $1); 2765 } 2766 ; 2767 2768 opt_block_args_tail : ',' block_args_tail 2769 { 2770 $$ = $2; 2771 } 2772 | /* none */ 2773 { 2774 $$ = new_args_tail(p, 0, 0, 0); 2775 } 2776 ; 2777 2778 block_param : f_arg ',' f_block_optarg ',' f_rest_arg opt_block_args_tail 2449 2779 { 2450 2780 $$ = new_args(p, $1, $3, $5, 0, $6); 2451 2781 } 2452 | f_arg ',' f_block_optarg ',' f_rest_arg ',' f_arg opt_ f_block_arg2782 | f_arg ',' f_block_optarg ',' f_rest_arg ',' f_arg opt_block_args_tail 2453 2783 { 2454 2784 $$ = new_args(p, $1, $3, $5, $7, $8); 2455 2785 } 2456 | f_arg ',' f_block_optarg opt_ f_block_arg2786 | f_arg ',' f_block_optarg opt_block_args_tail 2457 2787 { 2458 2788 $$ = new_args(p, $1, $3, 0, 0, $4); 2459 2789 } 2460 | f_arg ',' f_block_optarg ',' f_arg opt_ f_block_arg2790 | f_arg ',' f_block_optarg ',' f_arg opt_block_args_tail 2461 2791 { 2462 2792 $$ = new_args(p, $1, $3, 0, $5, $6); 2463 2793 } 2464 | f_arg ',' f_rest_arg opt_ f_block_arg2794 | f_arg ',' f_rest_arg opt_block_args_tail 2465 2795 { 2466 2796 $$ = new_args(p, $1, 0, $3, 0, $4); 2467 2797 } 2468 | f_arg ',' 2469 { 2470 $$ = new_args(p, $1, 0, 0, 0, 0);2471 } 2472 | f_arg ',' f_rest_arg ',' f_arg opt_ f_block_arg2798 | f_arg ',' opt_block_args_tail 2799 { 2800 $$ = new_args(p, $1, 0, 0, 0, $3); 2801 } 2802 | f_arg ',' f_rest_arg ',' f_arg opt_block_args_tail 2473 2803 { 2474 2804 $$ = new_args(p, $1, 0, $3, $5, $6); 2475 2805 } 2476 | f_arg opt_ f_block_arg2806 | f_arg opt_block_args_tail 2477 2807 { 2478 2808 $$ = new_args(p, $1, 0, 0, 0, $2); 2479 2809 } 2480 | f_block_optarg ',' f_rest_arg opt_ f_block_arg2810 | f_block_optarg ',' f_rest_arg opt_block_args_tail 2481 2811 { 2482 2812 $$ = new_args(p, 0, $1, $3, 0, $4); 2483 2813 } 2484 | f_block_optarg ',' f_rest_arg ',' f_arg opt_ f_block_arg2814 | f_block_optarg ',' f_rest_arg ',' f_arg opt_block_args_tail 2485 2815 { 2486 2816 $$ = new_args(p, 0, $1, $3, $5, $6); 2487 2817 } 2488 | f_block_optarg opt_ f_block_arg2818 | f_block_optarg opt_block_args_tail 2489 2819 { 2490 2820 $$ = new_args(p, 0, $1, 0, 0, $2); 2491 2821 } 2492 | f_block_optarg ',' f_arg opt_ f_block_arg2822 | f_block_optarg ',' f_arg opt_block_args_tail 2493 2823 { 2494 2824 $$ = new_args(p, 0, $1, 0, $3, $4); 2495 2825 } 2496 | f_rest_arg opt_ f_block_arg2826 | f_rest_arg opt_block_args_tail 2497 2827 { 2498 2828 $$ = new_args(p, 0, 0, $1, 0, $2); 2499 2829 } 2500 | f_rest_arg ',' f_arg opt_ f_block_arg2830 | f_rest_arg ',' f_arg opt_block_args_tail 2501 2831 { 2502 2832 $$ = new_args(p, 0, 0, $1, $3, $4); 2503 2833 } 2504 | f_block_arg2834 | block_args_tail 2505 2835 { 2506 2836 $$ = new_args(p, 0, 0, 0, 0, $1); … … 2509 2839 2510 2840 opt_block_param : none 2841 { 2842 local_add_blk(p, 0); 2843 $$ = 0; 2844 } 2511 2845 | block_param_def 2512 2846 { 2513 2847 p->cmd_start = TRUE; 2514 2848 $$ = $1; … … 2516 2850 ; 2517 2851 2518 block_param_def : '|' opt_bv_decl '|'2852 block_param_def : '|' {local_add_blk(p, 0);} opt_bv_decl '|' 2519 2853 { 2520 2854 $$ = 0; … … 2522 2856 | tOROP 2523 2857 { 2858 local_add_blk(p, 0); 2524 2859 $$ = 0; 2525 2860 } … … 2567 2902 $$ = $2; 2568 2903 } 2569 | keyword_do_LAMBDA compstmt keyword_end2904 | keyword_do_LAMBDA bodystmt keyword_end 2570 2905 { 2571 2906 $$ = $2; … … 2576 2911 { 2577 2912 local_nest(p); 2913 nvars_nest(p); 2578 2914 } 2579 2915 opt_block_param 2580 compstmt2916 bodystmt 2581 2917 keyword_end 2582 2918 { 2583 2919 $$ = new_block(p,$3,$4); 2584 2920 local_unnest(p); 2921 nvars_unnest(p); 2585 2922 } 2586 2923 ; … … 2630 2967 | primary_value call_op paren_args 2631 2968 { 2632 $$ = new_call(p, $1, intern ("call",4), $3, $2);2969 $$ = new_call(p, $1, intern_lit("call"), $3, $2); 2633 2970 } 2634 2971 | primary_value tCOLON2 paren_args 2635 2972 { 2636 $$ = new_call(p, $1, intern ("call",4), $3, tCOLON2);2973 $$ = new_call(p, $1, intern_lit("call"), $3, tCOLON2); 2637 2974 } 2638 2975 | keyword_super paren_args … … 2644 2981 $$ = new_zsuper(p); 2645 2982 } 2646 | primary_value '[' opt_call_args rbracket2647 { 2648 $$ = new_call(p, $1, intern ("[]",2), $3, '.');2983 | primary_value '[' opt_call_args ']' 2984 { 2985 $$ = new_call(p, $1, intern_lit("[]"), $3, '.'); 2649 2986 } 2650 2987 ; … … 2653 2990 { 2654 2991 local_nest(p); 2992 nvars_nest(p); 2655 2993 $<num>$ = p->lineno; 2656 2994 } … … 2661 2999 SET_LINENO($$, $<num>2); 2662 3000 local_unnest(p); 3001 nvars_unnest(p); 2663 3002 } 2664 3003 | keyword_do 2665 3004 { 2666 3005 local_nest(p); 3006 nvars_nest(p); 2667 3007 $<num>$ = p->lineno; 2668 3008 } 2669 3009 opt_block_param 2670 compstmt keyword_end3010 bodystmt keyword_end 2671 3011 { 2672 3012 $$ = new_block(p,$3,$4); 2673 3013 SET_LINENO($$, $<num>2); 2674 3014 local_unnest(p); 3015 nvars_unnest(p); 2675 3016 } 2676 3017 ; … … 2734 3075 ; 2735 3076 2736 string : tCHAR 3077 string : string_fragment 3078 | string string_fragment 3079 { 3080 $$ = concat_string(p, $1, $2); 3081 } 3082 ; 3083 3084 string_fragment : tCHAR 2737 3085 | tSTRING 2738 3086 | tSTRING_BEG tSTRING … … 2854 3202 symbol : basic_symbol 2855 3203 { 3204 p->lstate = EXPR_ENDARG; 2856 3205 $$ = new_sym(p, $1); 2857 3206 } 2858 3207 | tSYMBEG tSTRING_BEG string_rep tSTRING 2859 3208 { 2860 p->lstate = EXPR_END ;2861 $$ = new_dsym(p, push($3, $4));3209 p->lstate = EXPR_ENDARG; 3210 $$ = new_dsym(p, new_dstr(p, push($3, $4))); 2862 3211 } 2863 3212 ; … … 2865 3214 basic_symbol : tSYMBEG sym 2866 3215 { 2867 p->lstate = EXPR_END;2868 3216 $$ = $2; 2869 3217 } … … 2932 3280 assignable(p, $1); 2933 3281 } 3282 | tNUMPARAM 3283 { 3284 yyerror(p, "can't assign to numbered parameter"); 3285 } 2934 3286 ; 2935 3287 … … 2956 3308 | keyword__FILE__ 2957 3309 { 2958 const char *fn = p->filename;3310 const char *fn = mrb_sym_name_len(p->mrb, p->filename_sym, NULL); 2959 3311 if (!fn) { 2960 3312 fn = "(null)"; … … 2966 3318 char buf[16]; 2967 3319 2968 snprintf(buf, sizeof(buf), "%d", p->lineno); 2969 $$ = new_int(p, buf, 10); 3320 dump_int(p->lineno, buf); 3321 $$ = new_int(p, buf, 10, 0); 3322 } 3323 | keyword__ENCODING__ 3324 { 3325 #ifdef MRB_UTF8_STRING 3326 const char *enc = "UTF-8"; 3327 #else 3328 const char *enc = "ASCII-8BIT"; 3329 #endif 3330 $$ = new_str(p, enc, strlen(enc)); 2970 3331 } 2971 3332 ; … … 3007 3368 ; 3008 3369 3009 f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg 3370 f_label : tIDENTIFIER tLABEL_TAG 3371 { 3372 local_nest(p); 3373 } 3374 ; 3375 3376 f_kw : f_label arg 3377 { 3378 void_expr_error(p, $2); 3379 $$ = new_kw_arg(p, $1, cons($2, locals_node(p))); 3380 local_unnest(p); 3381 } 3382 | f_label 3383 { 3384 $$ = new_kw_arg(p, $1, 0); 3385 local_unnest(p); 3386 } 3387 ; 3388 3389 f_block_kw : f_label primary_value 3390 { 3391 $$ = new_kw_arg(p, $1, cons($2, locals_node(p))); 3392 local_unnest(p); 3393 } 3394 | f_label 3395 { 3396 $$ = new_kw_arg(p, $1, 0); 3397 local_unnest(p); 3398 } 3399 ; 3400 3401 f_block_kwarg : f_block_kw 3402 { 3403 $$ = list1($1); 3404 } 3405 | f_block_kwarg ',' f_block_kw 3406 { 3407 $$ = push($1, $3); 3408 } 3409 ; 3410 3411 f_kwarg : f_kw 3412 { 3413 $$ = list1($1); 3414 } 3415 | f_kwarg ',' f_kw 3416 { 3417 $$ = push($1, $3); 3418 } 3419 ; 3420 3421 kwrest_mark : tPOW 3422 | tDSTAR 3423 ; 3424 3425 f_kwrest : kwrest_mark tIDENTIFIER 3426 { 3427 $$ = cons((node*)NODE_KW_REST_ARGS, nsym($2)); 3428 } 3429 | kwrest_mark 3430 { 3431 $$ = cons((node*)NODE_KW_REST_ARGS, 0); 3432 } 3433 ; 3434 3435 args_tail : f_kwarg ',' f_kwrest opt_f_block_arg 3436 { 3437 $$ = new_args_tail(p, $1, $3, $4); 3438 } 3439 | f_kwarg opt_f_block_arg 3440 { 3441 $$ = new_args_tail(p, $1, 0, $2); 3442 } 3443 | f_kwrest opt_f_block_arg 3444 { 3445 $$ = new_args_tail(p, 0, $1, $2); 3446 } 3447 | f_block_arg 3448 { 3449 $$ = new_args_tail(p, 0, 0, $1); 3450 } 3451 ; 3452 3453 opt_args_tail : ',' args_tail 3454 { 3455 $$ = $2; 3456 } 3457 | /* none */ 3458 { 3459 $$ = new_args_tail(p, 0, 0, 0); 3460 } 3461 ; 3462 3463 f_args : f_arg ',' f_optarg ',' f_rest_arg opt_args_tail 3010 3464 { 3011 3465 $$ = new_args(p, $1, $3, $5, 0, $6); 3012 3466 } 3013 | f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_ f_block_arg3467 | f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_args_tail 3014 3468 { 3015 3469 $$ = new_args(p, $1, $3, $5, $7, $8); 3016 3470 } 3017 | f_arg ',' f_optarg opt_ f_block_arg3471 | f_arg ',' f_optarg opt_args_tail 3018 3472 { 3019 3473 $$ = new_args(p, $1, $3, 0, 0, $4); 3020 3474 } 3021 | f_arg ',' f_optarg ',' f_arg opt_ f_block_arg3475 | f_arg ',' f_optarg ',' f_arg opt_args_tail 3022 3476 { 3023 3477 $$ = new_args(p, $1, $3, 0, $5, $6); 3024 3478 } 3025 | f_arg ',' f_rest_arg opt_ f_block_arg3479 | f_arg ',' f_rest_arg opt_args_tail 3026 3480 { 3027 3481 $$ = new_args(p, $1, 0, $3, 0, $4); 3028 3482 } 3029 | f_arg ',' f_rest_arg ',' f_arg opt_ f_block_arg3483 | f_arg ',' f_rest_arg ',' f_arg opt_args_tail 3030 3484 { 3031 3485 $$ = new_args(p, $1, 0, $3, $5, $6); 3032 3486 } 3033 | f_arg opt_ f_block_arg3487 | f_arg opt_args_tail 3034 3488 { 3035 3489 $$ = new_args(p, $1, 0, 0, 0, $2); 3036 3490 } 3037 | f_optarg ',' f_rest_arg opt_ f_block_arg3491 | f_optarg ',' f_rest_arg opt_args_tail 3038 3492 { 3039 3493 $$ = new_args(p, 0, $1, $3, 0, $4); 3040 3494 } 3041 | f_optarg ',' f_rest_arg ',' f_arg opt_ f_block_arg3495 | f_optarg ',' f_rest_arg ',' f_arg opt_args_tail 3042 3496 { 3043 3497 $$ = new_args(p, 0, $1, $3, $5, $6); 3044 3498 } 3045 | f_optarg opt_ f_block_arg3499 | f_optarg opt_args_tail 3046 3500 { 3047 3501 $$ = new_args(p, 0, $1, 0, 0, $2); 3048 3502 } 3049 | f_optarg ',' f_arg opt_ f_block_arg3503 | f_optarg ',' f_arg opt_args_tail 3050 3504 { 3051 3505 $$ = new_args(p, 0, $1, 0, $3, $4); 3052 3506 } 3053 | f_rest_arg opt_ f_block_arg3507 | f_rest_arg opt_args_tail 3054 3508 { 3055 3509 $$ = new_args(p, 0, 0, $1, 0, $2); 3056 3510 } 3057 | f_rest_arg ',' f_arg opt_ f_block_arg3511 | f_rest_arg ',' f_arg opt_args_tail 3058 3512 { 3059 3513 $$ = new_args(p, 0, 0, $1, $3, $4); 3060 3514 } 3061 | f_block_arg3515 | args_tail 3062 3516 { 3063 3517 $$ = new_args(p, 0, 0, 0, 0, $1); … … 3065 3519 | /* none */ 3066 3520 { 3067 local_add_f(p, 0);3521 local_add_f(p, mrb_intern_lit(p->mrb, "&")); 3068 3522 $$ = new_args(p, 0, 0, 0, 0, 0); 3069 3523 } … … 3090 3544 $$ = 0; 3091 3545 } 3546 | tNUMPARAM 3547 { 3548 yyerror(p, "formal argument cannot be a numbered parameter"); 3549 $$ = 0; 3550 } 3092 3551 ; 3093 3552 … … 3107 3566 $$ = new_arg(p, $1); 3108 3567 } 3109 | tLPAREN f_margs rparen 3110 { 3111 $$ = new_masgn(p, $2, 0); 3568 | tLPAREN 3569 { 3570 $<nd>$ = local_switch(p); 3571 } 3572 f_margs rparen 3573 { 3574 $$ = new_masgn_param(p, $3, p->locals->car); 3575 local_resume(p, $<nd>2); 3576 local_add_f(p, 0); 3112 3577 } 3113 3578 ; … … 3126 3591 { 3127 3592 local_add_f(p, $1); 3593 local_nest(p); 3128 3594 $$ = $1; 3129 3595 } … … 3133 3599 { 3134 3600 void_expr_error(p, $2); 3135 $$ = cons(nsym($1), $2); 3601 $$ = cons(nsym($1), cons($2, locals_node(p))); 3602 local_unnest(p); 3136 3603 } 3137 3604 ; … … 3140 3607 { 3141 3608 void_expr_error(p, $2); 3142 $$ = cons(nsym($1), $2); 3609 $$ = cons(nsym($1), cons($2, locals_node(p))); 3610 local_unnest(p); 3143 3611 } 3144 3612 ; … … 3175 3643 | restarg_mark 3176 3644 { 3177 local_add_f(p, 0);3645 local_add_f(p, mrb_intern_lit(p->mrb, "*")); 3178 3646 $$ = -1; 3179 3647 } … … 3186 3654 f_block_arg : blkarg_mark tIDENTIFIER 3187 3655 { 3188 local_add_f(p, $2);3189 3656 $$ = $2; 3190 3657 } … … 3197 3664 | none 3198 3665 { 3199 local_add_f(p, 0);3200 3666 $$ = 0; 3201 3667 } … … 3244 3710 NODE_LINENO($$, $1); 3245 3711 } 3246 | assocs ','assoc3712 | assocs comma assoc 3247 3713 { 3248 3714 $$ = push($1, $3); 3249 3715 } 3716 ; 3717 3718 label_tag : tLABEL_TAG 3719 | tLABEL_TAG heredoc_bodies 3250 3720 ; 3251 3721 … … 3256 3726 $$ = cons($1, $3); 3257 3727 } 3258 | tLABEL arg 3728 | tIDENTIFIER label_tag arg 3729 { 3730 void_expr_error(p, $3); 3731 $$ = cons(new_sym(p, $1), $3); 3732 } 3733 | string_fragment label_tag arg 3734 { 3735 void_expr_error(p, $3); 3736 if ($1->car == (node*)NODE_DSTR) { 3737 $$ = cons(new_dsym(p, $1), $3); 3738 } 3739 else { 3740 $$ = cons(new_sym(p, new_strsym(p, $1)), $3); 3741 } 3742 } 3743 | tDSTAR arg 3259 3744 { 3260 3745 void_expr_error(p, $2); 3261 $$ = cons(new_sym(p, $1), $2); 3262 } 3263 | tLABEL_END arg 3264 { 3265 void_expr_error(p, $2); 3266 $$ = cons(new_sym(p, new_strsym(p, $1)), $2); 3267 } 3268 | tSTRING_BEG tLABEL_END arg 3269 { 3270 void_expr_error(p, $3); 3271 $$ = cons(new_sym(p, new_strsym(p, $2)), $3); 3272 } 3273 | tSTRING_BEG string_rep tLABEL_END arg 3274 { 3275 void_expr_error(p, $4); 3276 $$ = cons(new_dsym(p, push($2, $3)), $4); 3746 $$ = cons(cons((node*)NODE_KW_REST_ARGS, 0), $2); 3277 3747 } 3278 3748 ; … … 3323 3793 ; 3324 3794 3325 rparen : opt_nl ')' 3326 ; 3327 3328 rbracket : opt_nl ']' 3795 rparen : opt_terms ')' 3329 3796 ; 3330 3797 3331 3798 trailer : /* none */ 3332 | nl3799 | terms 3333 3800 | comma 3334 3801 ; … … 3362 3829 { 3363 3830 char* c; 3364 int n;3831 size_t n; 3365 3832 3366 3833 if (! p->capture_errors) { 3367 3834 #ifndef MRB_DISABLE_STDIO 3368 if (p->filename) { 3369 fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s); 3835 if (p->filename_sym) { 3836 const char *filename = mrb_sym_name_len(p->mrb, p->filename_sym, NULL); 3837 fprintf(stderr, "%s:%d:%d: %s\n", filename, p->lineno, p->column, s); 3370 3838 } 3371 3839 else { … … 3386 3854 3387 3855 static void 3388 yyerror_ i(parser_state *p, const char *fmt, int i)3856 yyerror_c(parser_state *p, const char *msg, char c) 3389 3857 { 3390 3858 char buf[256]; 3391 3859 3392 snprintf(buf, sizeof(buf), fmt, i); 3860 strncpy(buf, msg, sizeof(buf) - 2); 3861 buf[sizeof(buf) - 2] = '\0'; 3862 strncat(buf, &c, 1); 3393 3863 yyerror(p, buf); 3394 3864 } … … 3398 3868 { 3399 3869 char* c; 3400 int n;3870 size_t n; 3401 3871 3402 3872 if (! p->capture_errors) { 3403 3873 #ifndef MRB_DISABLE_STDIO 3404 if (p->filename) { 3405 fprintf(stderr, "%s:%d:%d: %s\n", p->filename, p->lineno, p->column, s); 3874 if (p->filename_sym) { 3875 const char *filename = mrb_sym_name_len(p->mrb, p->filename_sym, NULL); 3876 fprintf(stderr, "%s:%d:%d: warning: %s\n", filename, p->lineno, p->column, s); 3406 3877 } 3407 3878 else { 3408 fprintf(stderr, "line %d:%d: %s\n", p->lineno, p->column, s);3879 fprintf(stderr, "line %d:%d: warning: %s\n", p->lineno, p->column, s); 3409 3880 } 3410 3881 #endif … … 3428 3899 3429 3900 static void 3430 yywarning_s(parser_state *p, const char * fmt, const char *s)3901 yywarning_s(parser_state *p, const char *msg, const char *s) 3431 3902 { 3432 3903 char buf[256]; 3433 3904 3434 snprintf(buf, sizeof(buf), fmt, s); 3905 strncpy(buf, msg, sizeof(buf) - 1); 3906 buf[sizeof(buf) - 1] = '\0'; 3907 strncat(buf, ": ", sizeof(buf) - strlen(buf) - 1); 3908 strncat(buf, s, sizeof(buf) - strlen(buf) - 1); 3435 3909 yywarning(p, buf); 3436 3910 } … … 3441 3915 int c; 3442 3916 3443 c = (int)(intptr_t)n->car;3917 c = intn(n->car); 3444 3918 3445 3919 if (c == NODE_NTH_REF) { 3446 yyerror_ i(p, "can't set variable $%" MRB_PRId, (mrb_int)(intptr_t)n->cdr);3920 yyerror_c(p, "can't set variable $", (char)intn(n->cdr)+'0'); 3447 3921 } 3448 3922 else if (c == NODE_BACK_REF) { 3449 yyerror_ i(p, "can't set variable $%c", (int)(intptr_t)n->cdr);3923 yyerror_c(p, "can't set variable $", (char)intn(n->cdr)); 3450 3924 } 3451 3925 else { 3452 mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == % S", mrb_fixnum_value(c));3926 mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == %d", c); 3453 3927 } 3454 3928 } … … 3460 3934 3461 3935 if (n == NULL) return; 3462 c = (int)(intptr_t)n->car;3936 c = intn(n->car); 3463 3937 switch (c) { 3464 3938 case NODE_BREAK: … … 3471 3945 case NODE_AND: 3472 3946 case NODE_OR: 3473 void_expr_error(p, n->cdr->car); 3474 void_expr_error(p, n->cdr->cdr); 3947 if (n->cdr) { 3948 void_expr_error(p, n->cdr->car); 3949 void_expr_error(p, n->cdr->cdr); 3950 } 3475 3951 break; 3476 3952 case NODE_BEGIN: … … 3492 3968 3493 3969 static inline int 3970 nextc0(parser_state *p) 3971 { 3972 int c; 3973 #ifndef MRB_DISABLE_STDIO 3974 if (p->f) { 3975 if (feof(p->f)) return -1; 3976 c = fgetc(p->f); 3977 if (c == EOF) return -1; 3978 } 3979 else 3980 #endif 3981 if (!p->s || p->s >= p->send) { 3982 return -1; 3983 } 3984 else { 3985 c = (unsigned char)*p->s++; 3986 } 3987 return c; 3988 } 3989 3990 static inline int 3494 3991 nextc(parser_state *p) 3495 3992 { … … 3499 3996 node *tmp; 3500 3997 3501 c = (int)(intptr_t)p->pb->car;3998 c = intn(p->pb->car); 3502 3999 tmp = p->pb; 3503 4000 p->pb = p->pb->cdr; … … 3505 4002 } 3506 4003 else { 3507 #ifndef MRB_DISABLE_STDIO 3508 if (p->f) { 3509 if (feof(p->f)) goto eof; 3510 c = fgetc(p->f); 3511 if (c == EOF) goto eof; 3512 } 3513 else 3514 #endif 3515 if (!p->s || p->s >= p->send) { 3516 goto eof; 3517 } 3518 else { 3519 c = (unsigned char)*p->s++; 3520 } 4004 c = nextc0(p); 4005 if (c < 0) goto eof; 3521 4006 } 3522 4007 if (c >= 0) { … … 3524 4009 } 3525 4010 if (c == '\r') { 3526 c = nextc(p); 3527 if (c != '\n') { 3528 pushback(p, c); 3529 return '\r'; 3530 } 3531 return c; 4011 const int lf = nextc0(p); 4012 if (lf == '\n') { 4013 return '\n'; 4014 } 4015 if (lf > 0) pushback(p, lf); 3532 4016 } 3533 4017 return c; … … 3548 4032 p->column--; 3549 4033 } 3550 p->pb = cons( (node*)(intptr_t)c, p->pb);4034 p->pb = cons(nint(c), p->pb); 3551 4035 } 3552 4036 … … 3573 4057 if (c0 == -1) return c0; /* do not skip partial EOF */ 3574 4058 if (c0 >= 0) --p->column; 3575 list = push(list, (node*)(intptr_t)c0);4059 list = push(list, nint(c0)); 3576 4060 } while(n--); 3577 4061 if (p->pb) { … … 3594 4078 peeks(parser_state *p, const char *s) 3595 4079 { 3596 int len = strlen(s);4080 size_t len = strlen(s); 3597 4081 3598 4082 #ifndef MRB_DISABLE_STDIO … … 3630 4114 s++; 3631 4115 if (peeks(p, s)) { 3632 int len = strlen(s);4116 size_t len = strlen(s); 3633 4117 3634 4118 while (len--) { … … 3752 4236 #define IS_LABEL_SUFFIX(n) (peek_n(p, ':',(n)) && !peek_n(p, ':', (n)+1)) 3753 4237 3754 static int 4238 static int32_t 3755 4239 scan_oct(const int *start, int len, int *retlen) 3756 4240 { 3757 4241 const int *s = start; 3758 int retval = 0;4242 int32_t retval = 0; 3759 4243 3760 4244 /* mrb_assert(len <= 3) */ … … 3763 4247 retval |= *s++ - '0'; 3764 4248 } 3765 *retlen = s - start;4249 *retlen = (int)(s - start); 3766 4250 3767 4251 return retval; … … 3769 4253 3770 4254 static int32_t 3771 scan_hex( const int *start, int len, int *retlen)4255 scan_hex(parser_state *p, const int *start, int len, int *retlen) 3772 4256 { 3773 4257 static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF"; 3774 4258 const int *s = start; 3775 int32_t retval = 0;4259 uint32_t retval = 0; 3776 4260 char *tmp; 3777 4261 … … 3782 4266 s++; 3783 4267 } 3784 *retlen = s - start;3785 3786 return retval;4268 *retlen = (int)(s - start); 4269 4270 return (int32_t)retval; 3787 4271 } 3788 4272 … … 3790 4274 read_escape_unicode(parser_state *p, int limit) 3791 4275 { 3792 int32_t c;3793 4276 int buf[9]; 3794 4277 int i; 4278 int32_t hex; 3795 4279 3796 4280 /* Look for opening brace */ 3797 4281 i = 0; 3798 4282 buf[0] = nextc(p); 3799 if (buf[0] < 0) goto eof; 4283 if (buf[0] < 0) { 4284 eof: 4285 yyerror(p, "invalid escape character syntax"); 4286 return -1; 4287 } 3800 4288 if (ISXDIGIT(buf[0])) { 3801 4289 /* \uxxxx form */ … … 3812 4300 pushback(p, buf[0]); 3813 4301 } 3814 c = scan_hex(buf, i, &i); 3815 if (i == 0) { 3816 eof: 3817 yyerror(p, "Invalid escape character syntax"); 4302 hex = scan_hex(p, buf, i, &i); 4303 if (i == 0 || hex > 0x10FFFF || (hex & 0xFFFFF800) == 0xD800) { 4304 yyerror(p, "invalid Unicode code point"); 3818 4305 return -1; 3819 4306 } 3820 if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) { 3821 yyerror(p, "Invalid Unicode code point"); 3822 return -1; 3823 } 3824 return c; 4307 return hex; 3825 4308 } 3826 4309 … … 3888 4371 } 3889 4372 } 3890 c = scan_hex(buf, i, &i);3891 4373 if (i == 0) { 3892 yyerror(p, " Invalid escape character syntax");3893 return 0;3894 } 3895 }3896 return c;4374 yyerror(p, "invalid hex escape"); 4375 return -1; 4376 } 4377 return scan_hex(p, buf, i, &i); 4378 } 3897 4379 3898 4380 case 'u': /* Unicode */ … … 3961 4443 int c; 3962 4444 string_type type = (string_type)(intptr_t)p->lex_strterm->car; 3963 int nest_level = (intptr_t)p->lex_strterm->cdr->car;3964 int beg = (intptr_t)p->lex_strterm->cdr->cdr->car;3965 int end = (intptr_t)p->lex_strterm->cdr->cdr->cdr;4445 int nest_level = intn(p->lex_strterm->cdr->car); 4446 int beg = intn(p->lex_strterm->cdr->cdr->car); 4447 int end = intn(p->lex_strterm->cdr->cdr->cdr); 3966 4448 parser_heredoc_info *hinf = (type & STR_FUNC_HEREDOC) ? parsing_heredoc_inf(p) : NULL; 3967 int cmd_state = p->cmd_start;3968 4449 3969 4450 if (beg == 0) beg = -3; /* should never happen */ … … 3990 4471 } 3991 4472 if ((len-1 == hinf->term_len) && (strncmp(s, hinf->term, len-1) == 0)) { 3992 if (c < 0) { 3993 p->parsing_heredoc = NULL; 3994 } 3995 else { 3996 return tHEREDOC_END; 3997 } 4473 return tHEREDOC_END; 3998 4474 } 3999 4475 } 4000 4476 if (c < 0) { 4001 4477 char buf[256]; 4002 snprintf(buf, sizeof(buf), "can't find heredoc delimiter \"%s\" anywhere before EOF", hinf->term); 4003 yyerror(p, buf); 4478 const char s1[] = "can't find heredoc delimiter \""; 4479 const char s2[] = "\" anywhere before EOF"; 4480 4481 if (sizeof(s1)+sizeof(s2)+strlen(hinf->term)+1 >= sizeof(buf)) { 4482 yyerror(p, "can't find heredoc delimiter anywhere before EOF"); 4483 } else { 4484 strcpy(buf, s1); 4485 strcat(buf, hinf->term); 4486 strcat(buf, s2); 4487 yyerror(p, buf); 4488 } 4004 4489 return 0; 4005 4490 } … … 4013 4498 else if (c == beg) { 4014 4499 nest_level++; 4015 p->lex_strterm->cdr->car = (node*)(intptr_t)nest_level;4500 p->lex_strterm->cdr->car = nint(nest_level); 4016 4501 } 4017 4502 else if (c == end) { 4018 4503 nest_level--; 4019 p->lex_strterm->cdr->car = (node*)(intptr_t)nest_level;4504 p->lex_strterm->cdr->car = nint(nest_level); 4020 4505 } 4021 4506 else if (c == '\\') { … … 4119 4604 4120 4605 tokfix(p); 4121 p->lstate = EXPR_END ;4606 p->lstate = EXPR_ENDARG; 4122 4607 end_strterm(p); 4123 4608 … … 4145 4630 case 'u': f |= 16; break; 4146 4631 case 'n': f |= 32; break; 4632 case 'o': break; 4147 4633 default: tokadd(p, re_opt); break; 4148 4634 } … … 4151 4637 if (toklen(p)) { 4152 4638 char msg[128]; 4639 4640 strcpy(msg, "unknown regexp option"); 4153 4641 tokfix(p); 4154 snprintf(msg, sizeof(msg), "unknown regexp option%s - %s", 4155 toklen(p) > 1 ? "s" : "", tok(p)); 4642 if (toklen(p) > 1) { 4643 strcat(msg, "s"); 4644 } 4645 strcat(msg, " - "); 4646 strncat(msg, tok(p), sizeof(msg) - strlen(msg) - 1); 4156 4647 yyerror(p, msg); 4157 4648 } … … 4180 4671 } 4181 4672 pylval.nd = new_str(p, tok(p), toklen(p)); 4182 if (IS_LABEL_POSSIBLE()) {4183 if (IS_LABEL_SUFFIX(0)) {4184 p->lstate = EXPR_BEG;4185 nextc(p);4186 return tLABEL_END;4187 }4188 }4189 4673 4190 4674 return tSTRING; 4191 4675 } 4192 4676 4677 static int 4678 number_literal_suffix(parser_state *p) 4679 { 4680 int c, result = 0; 4681 node *list = 0; 4682 int column = p->column; 4683 int mask = NUM_SUFFIX_R|NUM_SUFFIX_I; 4684 4685 while ((c = nextc(p)) != -1) { 4686 list = push(list, (node*)(intptr_t)c); 4687 4688 if ((mask & NUM_SUFFIX_I) && c == 'i') { 4689 result |= (mask & NUM_SUFFIX_I); 4690 mask &= ~NUM_SUFFIX_I; 4691 /* r after i, rational of complex is disallowed */ 4692 mask &= ~NUM_SUFFIX_R; 4693 continue; 4694 } 4695 if ((mask & NUM_SUFFIX_R) && c == 'r') { 4696 result |= (mask & NUM_SUFFIX_R); 4697 mask &= ~NUM_SUFFIX_R; 4698 continue; 4699 } 4700 if (!ISASCII(c) || ISALPHA(c) || c == '_') { 4701 p->column = column; 4702 if (p->pb) { 4703 p->pb = append((node*)list, p->pb); 4704 } 4705 else { 4706 p->pb = list; 4707 } 4708 return 0; 4709 } 4710 pushback(p, c); 4711 break; 4712 } 4713 return result; 4714 } 4193 4715 4194 4716 static int … … 4311 4833 case -2: /* end of a file */ 4312 4834 case '\n': 4313 4835 maybe_heredoc: 4314 4836 heredoc_treat_nextline(p); 4315 switch (p->lstate) {4316 case EXPR_BEG:4317 case EXPR_FNAME:4318 case EXPR_DOT:4319 case EXPR_CLASS:4320 case EXPR_VALUE:4321 p->lineno++;4322 4837 p->column = 0; 4838 switch (p->lstate) { 4839 case EXPR_BEG: 4840 case EXPR_FNAME: 4841 case EXPR_DOT: 4842 case EXPR_CLASS: 4843 case EXPR_VALUE: 4844 p->lineno++; 4845 if (p->parsing_heredoc != NULL) { 4846 if (p->lex_strterm) { 4847 return parse_string(p); 4848 } 4849 } 4850 goto retry; 4851 default: 4852 break; 4853 } 4323 4854 if (p->parsing_heredoc != NULL) { 4324 if (p->lex_strterm) { 4325 return parse_string(p); 4326 } 4327 } 4328 goto retry; 4329 default: 4330 break; 4331 } 4332 if (p->parsing_heredoc != NULL) { 4855 return '\n'; 4856 } 4857 while ((c = nextc(p))) { 4858 switch (c) { 4859 case ' ': case '\t': case '\f': case '\r': 4860 case '\13': /* '\v' */ 4861 space_seen = 1; 4862 break; 4863 case '#': /* comment as a whitespace */ 4864 pushback(p, '#'); 4865 p->lineno++; 4866 goto retry; 4867 case '.': 4868 if (!peek(p, '.')) { 4869 pushback(p, '.'); 4870 p->lineno++; 4871 goto retry; 4872 } 4873 pushback(p, c); 4874 goto normal_newline; 4875 case '&': 4876 if (peek(p, '.')) { 4877 pushback(p, '&'); 4878 p->lineno++; 4879 goto retry; 4880 } 4881 pushback(p, c); 4882 goto normal_newline; 4883 case -1: /* EOF */ 4884 case -2: /* end of a file */ 4885 goto normal_newline; 4886 default: 4887 pushback(p, c); 4888 goto normal_newline; 4889 } 4890 } 4891 normal_newline: 4892 p->cmd_start = TRUE; 4893 p->lstate = EXPR_BEG; 4333 4894 return '\n'; 4334 }4335 while ((c = nextc(p))) {4336 switch (c) {4337 case ' ': case '\t': case '\f': case '\r':4338 case '\13': /* '\v' */4339 space_seen = 1;4340 break;4341 case '.':4342 if ((c = nextc(p)) != '.') {4343 pushback(p, c);4344 pushback(p, '.');4345 goto retry;4346 }4347 case -1: /* EOF */4348 case -2: /* end of a file */4349 goto normal_newline;4350 default:4351 pushback(p, c);4352 goto normal_newline;4353 }4354 }4355 normal_newline:4356 p->cmd_start = TRUE;4357 p->lstate = EXPR_BEG;4358 return '\n';4359 4895 4360 4896 case '*': 4361 4897 if ((c = nextc(p)) == '*') { 4362 4898 if ((c = nextc(p)) == '=') { 4363 pylval.id = intern ("**",2);4899 pylval.id = intern_lit("**"); 4364 4900 p->lstate = EXPR_BEG; 4365 4901 return tOP_ASGN; 4366 4902 } 4367 4903 pushback(p, c); 4368 c = tPOW; 4904 if (IS_SPCARG(c)) { 4905 yywarning(p, "'**' interpreted as argument prefix"); 4906 c = tDSTAR; 4907 } 4908 else if (IS_BEG()) { 4909 c = tDSTAR; 4910 } 4911 else { 4912 c = tPOW; /* "**", "argument prefix" */ 4913 } 4369 4914 } 4370 4915 else { 4371 4916 if (c == '=') { 4372 pylval.id = intern_ c('*');4917 pylval.id = intern_lit("*"); 4373 4918 p->lstate = EXPR_BEG; 4374 4919 return tOP_ASGN; … … 4486 5031 if (c == '<') { 4487 5032 if ((c = nextc(p)) == '=') { 4488 pylval.id = intern ("<<",2);5033 pylval.id = intern_lit("<<"); 4489 5034 p->lstate = EXPR_BEG; 4490 5035 return tOP_ASGN; … … 4508 5053 if (c == '>') { 4509 5054 if ((c = nextc(p)) == '=') { 4510 pylval.id = intern (">>",2);5055 pylval.id = intern_lit(">>"); 4511 5056 p->lstate = EXPR_BEG; 4512 5057 return tOP_ASGN; … … 4579 5124 if (c2) { 4580 5125 char buf[256]; 4581 snprintf(buf, sizeof(buf), "invalid character syntax; use ?\\%c", c2); 5126 char cc[] = { (char)c2, '\0' }; 5127 5128 strcpy(buf, "invalid character syntax; use ?\\"); 5129 strncat(buf, cc, 2); 4582 5130 yyerror(p, buf); 4583 5131 } … … 4590 5138 newtok(p); 4591 5139 /* need support UTF-8 if configured */ 4592 if (( isalnum(c) || c == '_')) {5140 if ((ISALNUM(c) || c == '_')) { 4593 5141 int c2 = nextc(p); 4594 5142 pushback(p, c2); 4595 if (( isalnum(c2) || c2 == '_')) {5143 if ((ISALNUM(c2) || c2 == '_')) { 4596 5144 goto ternary; 4597 5145 } … … 4606 5154 tokfix(p); 4607 5155 pylval.nd = new_str(p, tok(p), toklen(p)); 4608 p->lstate = EXPR_END ;5156 p->lstate = EXPR_ENDARG; 4609 5157 return tCHAR; 4610 5158 … … 4613 5161 p->lstate = EXPR_BEG; 4614 5162 if ((c = nextc(p)) == '=') { 4615 pylval.id = intern ("&&",2);5163 pylval.id = intern_lit("&&"); 4616 5164 p->lstate = EXPR_BEG; 4617 5165 return tOP_ASGN; … … 4625 5173 } 4626 5174 else if (c == '=') { 4627 pylval.id = intern_ c('&');5175 pylval.id = intern_lit("&"); 4628 5176 p->lstate = EXPR_BEG; 4629 5177 return tOP_ASGN; … … 4652 5200 p->lstate = EXPR_BEG; 4653 5201 if ((c = nextc(p)) == '=') { 4654 pylval.id = intern ("||",2);5202 pylval.id = intern_lit("||"); 4655 5203 p->lstate = EXPR_BEG; 4656 5204 return tOP_ASGN; … … 4660 5208 } 4661 5209 if (c == '=') { 4662 pylval.id = intern_ c('|');5210 pylval.id = intern_lit("|"); 4663 5211 p->lstate = EXPR_BEG; 4664 5212 return tOP_ASGN; … … 4684 5232 } 4685 5233 if (c == '=') { 4686 pylval.id = intern_ c('+');5234 pylval.id = intern_lit("+"); 4687 5235 p->lstate = EXPR_BEG; 4688 5236 return tOP_ASGN; … … 4712 5260 } 4713 5261 if (c == '=') { 4714 pylval.id = intern_ c('-');5262 pylval.id = intern_lit("-"); 4715 5263 p->lstate = EXPR_BEG; 4716 5264 return tOP_ASGN; … … 4753 5301 { 4754 5302 int is_float, seen_point, seen_e, nondigit; 5303 int suffix = 0; 4755 5304 4756 5305 is_float = seen_point = seen_e = nondigit = 0; 4757 p->lstate = EXPR_END ;5306 p->lstate = EXPR_ENDARG; 4758 5307 newtok(p); 4759 5308 if (c == '-' || c == '+') { … … 4786 5335 } 4787 5336 else if (nondigit) goto trailing_uc; 4788 pylval.nd = new_int(p, tok(p), 16); 5337 suffix = number_literal_suffix(p); 5338 pylval.nd = new_int(p, tok(p), 16, suffix); 4789 5339 return tINTEGER; 4790 5340 } … … 4810 5360 } 4811 5361 else if (nondigit) goto trailing_uc; 4812 pylval.nd = new_int(p, tok(p), 2); 5362 suffix = number_literal_suffix(p); 5363 pylval.nd = new_int(p, tok(p), 2, suffix); 4813 5364 return tINTEGER; 4814 5365 } … … 4834 5385 } 4835 5386 else if (nondigit) goto trailing_uc; 4836 pylval.nd = new_int(p, tok(p), 10); 5387 suffix = number_literal_suffix(p); 5388 pylval.nd = new_int(p, tok(p), 10, suffix); 4837 5389 return tINTEGER; 4838 5390 } … … 4867 5419 tokfix(p); 4868 5420 if (nondigit) goto trailing_uc; 4869 pylval.nd = new_int(p, tok(p), 8); 5421 suffix = number_literal_suffix(p); 5422 pylval.nd = new_int(p, tok(p), 8, suffix); 4870 5423 return tINTEGER; 4871 5424 } … … 4884 5437 else { 4885 5438 pushback(p, c); 4886 pylval.nd = new_int(p, "0", 10); 5439 suffix = number_literal_suffix(p); 5440 pylval.nd = new_int(p, "0", 10, suffix); 4887 5441 return tINTEGER; 4888 5442 } … … 4952 5506 if (nondigit) { 4953 5507 trailing_uc: 4954 yyerror_ i(p, "trailing '%c' in number",nondigit);5508 yyerror_c(p, "trailing non digit in number: ", (char)nondigit); 4955 5509 } 4956 5510 tokfix(p); 4957 5511 if (is_float) { 5512 #ifdef MRB_WITHOUT_FLOAT 5513 yywarning_s(p, "floating point numbers are not supported", tok(p)); 5514 pylval.nd = new_int(p, "0", 10, 0); 5515 return tINTEGER; 5516 #else 4958 5517 double d; 4959 5518 char *endp; … … 4962 5521 d = mrb_float_read(tok(p), &endp); 4963 5522 if (d == 0 && endp == tok(p)) { 4964 yywarning_s(p, "corrupted float value %s", tok(p));5523 yywarning_s(p, "corrupted float value", tok(p)); 4965 5524 } 4966 5525 else if (errno == ERANGE) { 4967 yywarning_s(p, "float %sout of range", tok(p));5526 yywarning_s(p, "float out of range", tok(p)); 4968 5527 errno = 0; 4969 5528 } 4970 pylval.nd = new_float(p, tok(p)); 5529 suffix = number_literal_suffix(p); 5530 pylval.nd = new_float(p, tok(p), suffix); 4971 5531 return tFLOAT; 4972 } 4973 pylval.nd = new_int(p, tok(p), 10); 5532 #endif 5533 } 5534 suffix = number_literal_suffix(p); 5535 pylval.nd = new_int(p, tok(p), 10, suffix); 4974 5536 return tINTEGER; 4975 5537 } … … 4985 5547 p->lstate = EXPR_ENDFN; 4986 5548 else 4987 p->lstate = EXPR_END ARG;5549 p->lstate = EXPR_END; 4988 5550 return c; 4989 5551 … … 4998 5560 return tCOLON2; 4999 5561 } 5000 if ( IS_END() || ISSPACE(c)) {5562 if (!space_seen && IS_END()) { 5001 5563 pushback(p, c); 5002 5564 p->lstate = EXPR_BEG; 5003 return ':'; 5565 return tLABEL_TAG; 5566 } 5567 if (!ISSPACE(c) || IS_BEG()) { 5568 pushback(p, c); 5569 p->lstate = EXPR_FNAME; 5570 return tSYMBEG; 5004 5571 } 5005 5572 pushback(p, c); 5006 p->lstate = EXPR_ FNAME;5007 return tSYMBEG;5573 p->lstate = EXPR_BEG; 5574 return ':'; 5008 5575 5009 5576 case '/': … … 5013 5580 } 5014 5581 if ((c = nextc(p)) == '=') { 5015 pylval.id = intern_ c('/');5582 pylval.id = intern_lit("/"); 5016 5583 p->lstate = EXPR_BEG; 5017 5584 return tOP_ASGN; … … 5032 5599 case '^': 5033 5600 if ((c = nextc(p)) == '=') { 5034 pylval.id = intern_ c('^');5601 pylval.id = intern_lit("^"); 5035 5602 p->lstate = EXPR_BEG; 5036 5603 return tOP_ASGN; … … 5070 5637 } 5071 5638 else if (IS_SPCARG(-1)) { 5639 c = tLPAREN_ARG; 5640 } 5641 else if (p->lstate == EXPR_END && space_seen) { 5072 5642 c = tLPAREN_ARG; 5073 5643 } … … 5147 5717 else { 5148 5718 term = nextc(p); 5149 if ( isalnum(term)) {5719 if (ISALNUM(term)) { 5150 5720 yyerror(p, "unknown type of %string"); 5151 5721 return 0; … … 5206 5776 } 5207 5777 if ((c = nextc(p)) == '=') { 5208 pylval.id = intern_ c('%');5778 pylval.id = intern_lit("%"); 5209 5779 p->lstate = EXPR_BEG; 5210 5780 return tOP_ASGN; … … 5260 5830 tokadd(p, c); 5261 5831 tokfix(p); 5262 pylval.id = intern _cstr(tok(p));5832 pylval.id = intern(tok(p), toklen(p)); 5263 5833 return tGVAR; 5264 5834 … … 5270 5840 gvar: 5271 5841 tokfix(p); 5272 pylval.id = intern _cstr(tok(p));5842 pylval.id = intern(tok(p), toklen(p)); 5273 5843 return tGVAR; 5274 5844 … … 5291 5861 tokadd(p, c); 5292 5862 c = nextc(p); 5293 } while (c >= 0 && isdigit(c));5863 } while (c >= 0 && ISDIGIT(c)); 5294 5864 pushback(p, c); 5295 5865 if (last_state == EXPR_FNAME) goto gvar; … … 5298 5868 unsigned long n = strtoul(tok(p), NULL, 10); 5299 5869 if (n > INT_MAX) { 5300 yyerror _i(p, "capture group index must be <= %d", INT_MAX);5870 yyerror(p, "capture group index must be <= " MRB_STRINGIZE(INT_MAX)); 5301 5871 return 0; 5302 5872 } … … 5333 5903 return 0; 5334 5904 } 5335 else if ( isdigit(c)) {5905 else if (ISDIGIT(c)) { 5336 5906 if (p->tidx == 1) { 5337 yyerror_ i(p, "'@%c' is not allowed as an instance variable name", c);5907 yyerror_c(p, "wrong instance variable name: @", c); 5338 5908 } 5339 5909 else { 5340 yyerror_ i(p, "'@@%c' is not allowed as a class variable name", c);5910 yyerror_c(p, "wrong class variable name: @@", c); 5341 5911 } 5342 5912 return 0; … … 5354 5924 default: 5355 5925 if (!identchar(c)) { 5356 yyerror_i(p, "Invalid char '\\x%02X' in expression", c); 5926 char buf[36]; 5927 const char s[] = "Invalid char in expression: 0x"; 5928 const char hexdigits[] = "0123456789ABCDEF"; 5929 5930 strcpy(buf, s); 5931 buf[sizeof(s)-1] = hexdigits[(c & 0xf0) >> 4]; 5932 buf[sizeof(s)] = hexdigits[(c & 0x0f)]; 5933 buf[sizeof(s)+1] = 0; 5934 yyerror(p, buf); 5357 5935 goto retry; 5358 5936 } … … 5400 5978 break; 5401 5979 5980 case '_': 5981 if (toklen(p) == 2 && ISDIGIT(tok(p)[1]) && p->nvars) { 5982 int n = tok(p)[1] - '0'; 5983 int nvar; 5984 5985 if (n > 0) { 5986 node *nvars = p->nvars->cdr; 5987 5988 while (nvars) { 5989 nvar = intn(nvars->car); 5990 if (nvar == -2) break; /* top of the scope */ 5991 if (nvar > 0) { 5992 yywarning(p, "numbered parameter used in outer block"); 5993 break; 5994 } 5995 nvars->car = nint(-1); 5996 nvars = nvars->cdr; 5997 } 5998 nvar = intn(p->nvars->car); 5999 if (nvar == -1) { 6000 yywarning(p, "numbered parameter used in inner block"); 6001 } 6002 if (nvar >= -1) { 6003 pylval.num = n; 6004 p->lstate = EXPR_END; 6005 return tNUMPARAM; 6006 } 6007 else { 6008 yywarning(p, "identifier for numbered parameter; consider another name"); 6009 } 6010 } 6011 } 6012 /* fall through */ 5402 6013 default: 5403 6014 if (toklast(p) == '!' || toklast(p) == '?') { … … 5406 6017 else { 5407 6018 if (p->lstate == EXPR_FNAME) { 6019 if ((c = nextc(p)) == '=' && !peek(p, '~') && !peek(p, '>') && 6020 (!peek(p, '=') || (peek_n(p, '>', 1)))) { 6021 result = tIDENTIFIER; 6022 tokadd(p, c); 6023 tokfix(p); 6024 } 6025 else { 6026 pushback(p, c); 6027 } 5408 6028 if ((c = nextc(p)) == '=' && !peek(p, '~') && !peek(p, '>') && 5409 6029 (!peek(p, '=') || (peek_n(p, '>', 1)))) { … … 5426 6046 if (IS_LABEL_POSSIBLE()) { 5427 6047 if (IS_LABEL_SUFFIX(0)) { 5428 p->lstate = EXPR_BEG; 5429 nextc(p); 6048 p->lstate = EXPR_END; 5430 6049 tokfix(p); 5431 pylval.id = intern _cstr(tok(p));5432 return t LABEL;6050 pylval.id = intern(tok(p), toklen(p)); 6051 return tIDENTIFIER; 5433 6052 } 5434 6053 } … … 5488 6107 } 5489 6108 { 5490 mrb_sym ident = intern _cstr(tok(p));6109 mrb_sym ident = intern(tok(p), toklen(p)); 5491 6110 5492 6111 pylval.id = ident; 5493 #if 0 5494 if (last_state != EXPR_DOT && islower(tok(p)[0]) && lvar_defined(ident)) { 6112 if (last_state != EXPR_DOT && ISLOWER(tok(p)[0]) && local_var_p(p, ident)) { 5495 6113 p->lstate = EXPR_END; 5496 6114 } 5497 #endif5498 6115 } 5499 6116 return result; … … 5524 6141 p->capture_errors = cxt->capture_errors; 5525 6142 p->no_optimize = cxt->no_optimize; 6143 p->on_eval = cxt->on_eval; 5526 6144 if (cxt->partial_hook) { 5527 6145 p->cxt = cxt; … … 5536 6154 5537 6155 if (!cxt) return; 5538 if ( (int)(intptr_t)p->tree->car!= NODE_SCOPE) return;6156 if (intn(p->tree->car) != NODE_SCOPE) return; 5539 6157 n0 = n = p->tree->cdr->car; 5540 6158 while (n) { … … 5559 6177 5560 6178 MRB_TRY(p->jmp) { 5561 int n ;6179 int n = 1; 5562 6180 5563 6181 p->cmd_start = TRUE; … … 5675 6293 { 5676 6294 if (s) { 5677 int len = strlen(s);6295 size_t len = strlen(s); 5678 6296 char *p = (char *)mrb_malloc(mrb, len + 1); 5679 6297 … … 5702 6320 5703 6321 sym = mrb_intern_cstr(p->mrb, f); 5704 p->filename = mrb_sym2name_len(p->mrb, sym, NULL);6322 p->filename_sym = sym; 5705 6323 p->lineno = (p->filename_table_length > 0)? 0 : 1; 5706 6324 5707 6325 for (i = 0; i < p->filename_table_length; ++i) { 5708 6326 if (p->filename_table[i] == sym) { 5709 p->current_filename_index = i;6327 p->current_filename_index = (int)i; 5710 6328 return; 5711 6329 } 5712 6330 } 5713 6331 6332 if (p->filename_table_length == UINT16_MAX) { 6333 yyerror(p, "too many files to compile"); 6334 return; 6335 } 5714 6336 p->current_filename_index = p->filename_table_length++; 5715 6337 5716 6338 new_table = (mrb_sym*)parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length); 5717 6339 if (p->filename_table) { 5718 memmove(new_table, p->filename_table, sizeof(mrb_sym) * p-> filename_table_length);6340 memmove(new_table, p->filename_table, sizeof(mrb_sym) * p->current_filename_index); 5719 6341 } 5720 6342 p->filename_table = new_table; … … 5722 6344 } 5723 6345 5724 MRB_API char const*6346 MRB_API mrb_sym 5725 6347 mrb_parser_get_filename(struct mrb_parser_state* p, uint16_t idx) { 5726 if (idx >= p->filename_table_length) { return NULL; }6348 if (idx >= p->filename_table_length) return 0; 5727 6349 else { 5728 return mrb_sym2name_len(p->mrb, p->filename_table[idx], NULL);6350 return p->filename_table[idx]; 5729 6351 } 5730 6352 } … … 5747 6369 5748 6370 MRB_API parser_state* 5749 mrb_parse_nstring(mrb_state *mrb, const char *s, int len, mrbc_context *c)6371 mrb_parse_nstring(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) 5750 6372 { 5751 6373 parser_state *p; … … 5778 6400 } 5779 6401 if (!p->tree || p->nerr) { 6402 if (c) c->parser_nerr = p->nerr; 5780 6403 if (p->capture_errors) { 5781 6404 char buf[256]; 5782 int n; 5783 5784 n = snprintf(buf, sizeof(buf), "line %d: %s\n", 5785 p->error_buffer[0].lineno, p->error_buffer[0].message); 5786 mrb->exc = mrb_obj_ptr(mrb_exc_new(mrb, E_SYNTAX_ERROR, buf, n)); 6405 6406 strcpy(buf, "line "); 6407 dump_int(p->error_buffer[0].lineno, buf+5); 6408 strcat(buf, ": "); 6409 strncat(buf, p->error_buffer[0].message, sizeof(buf) - strlen(buf) - 1); 6410 mrb->exc = mrb_obj_ptr(mrb_exc_new(mrb, E_SYNTAX_ERROR, buf, strlen(buf))); 5787 6411 mrb_parser_free(p); 5788 6412 return mrb_undef_value(); … … 5817 6441 } 5818 6442 } 5819 proc->target_class = target;6443 MRB_PROC_SET_TARGET_CLASS(proc, target); 5820 6444 if (mrb->c->ci) { 5821 6445 mrb->c->ci->target_class = target; … … 5841 6465 5842 6466 MRB_API mrb_value 5843 mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *c)6467 mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *c) 5844 6468 { 5845 6469 return mrb_load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c); … … 5847 6471 5848 6472 MRB_API mrb_value 5849 mrb_load_nstring(mrb_state *mrb, const char *s, int len)6473 mrb_load_nstring(mrb_state *mrb, const char *s, size_t len) 5850 6474 { 5851 6475 return mrb_load_nstring_cxt(mrb, s, len, NULL); … … 5885 6509 } 5886 6510 6511 static void 6512 dump_args(mrb_state *mrb, node *n, int offset) 6513 { 6514 if (n->car) { 6515 dump_prefix(n, offset+1); 6516 printf("mandatory args:\n"); 6517 dump_recur(mrb, n->car, offset+2); 6518 } 6519 n = n->cdr; 6520 if (n->car) { 6521 dump_prefix(n, offset+1); 6522 printf("optional args:\n"); 6523 { 6524 node *n2 = n->car; 6525 6526 while (n2) { 6527 dump_prefix(n2, offset+2); 6528 printf("%s=\n", mrb_sym_name(mrb, sym(n2->car->car))); 6529 mrb_parser_dump(mrb, n2->car->cdr, offset+3); 6530 n2 = n2->cdr; 6531 } 6532 } 6533 } 6534 n = n->cdr; 6535 if (n->car) { 6536 dump_prefix(n, offset+1); 6537 printf("rest=*%s\n", mrb_sym_name(mrb, sym(n->car))); 6538 } 6539 n = n->cdr; 6540 if (n->car) { 6541 dump_prefix(n, offset+1); 6542 printf("post mandatory args:\n"); 6543 dump_recur(mrb, n->car, offset+2); 6544 } 6545 6546 n = n->cdr; 6547 if (n) { 6548 mrb_assert(intn(n->car) == NODE_ARGS_TAIL); 6549 mrb_parser_dump(mrb, n, offset); 6550 } 6551 } 6552 6553 /* 6554 * This function restores the GC arena on return. 6555 * For this reason, if a process that further generates an object is 6556 * performed at the caller, the string pointer returned as the return 6557 * value may become invalid. 6558 */ 6559 static const char* 6560 str_dump(mrb_state *mrb, const char *str, int len) 6561 { 6562 mrb_int ai = mrb_gc_arena_save(mrb); 6563 mrb_value s; 6564 # if INT_MAX > MRB_INT_MAX / 4 6565 /* check maximum length with "\xNN" charactor */ 6566 if (len > MRB_INT_MAX / 4) { 6567 len = MRB_INT_MAX / 4; 6568 } 6569 # endif 6570 s = mrb_str_new(mrb, str, (mrb_int)len); 6571 s = mrb_str_dump(mrb, s); 6572 mrb_gc_arena_restore(mrb, ai); 6573 return RSTRING_PTR(s); 6574 } 5887 6575 #endif 5888 6576 … … 5896 6584 again: 5897 6585 dump_prefix(tree, offset); 5898 nodetype = (int)(intptr_t)tree->car;6586 nodetype = intn(tree->car); 5899 6587 tree = tree->cdr; 5900 6588 switch (nodetype) { … … 5956 6644 5957 6645 case NODE_LAMBDA: 5958 printf("NODE_BLOCK:\n"); 6646 printf("NODE_LAMBDA:\n"); 6647 dump_prefix(tree, offset); 5959 6648 goto block; 5960 6649 … … 5964 6653 tree = tree->cdr; 5965 6654 if (tree->car) { 5966 node *n = tree->car; 5967 5968 if (n->car) { 5969 dump_prefix(n, offset+1); 5970 printf("mandatory args:\n"); 5971 dump_recur(mrb, n->car, offset+2); 5972 } 5973 n = n->cdr; 5974 if (n->car) { 5975 dump_prefix(n, offset+1); 5976 printf("optional args:\n"); 5977 { 5978 node *n2 = n->car; 5979 5980 while (n2) { 5981 dump_prefix(n2, offset+2); 5982 printf("%s=", mrb_sym2name(mrb, sym(n2->car->car))); 5983 mrb_parser_dump(mrb, n2->car->cdr, 0); 5984 n2 = n2->cdr; 5985 } 5986 } 5987 } 5988 n = n->cdr; 5989 if (n->car) { 5990 dump_prefix(n, offset+1); 5991 printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car))); 5992 } 5993 n = n->cdr; 5994 if (n->car) { 5995 dump_prefix(n, offset+1); 5996 printf("post mandatory args:\n"); 5997 dump_recur(mrb, n->car, offset+2); 5998 } 5999 if (n->cdr) { 6000 dump_prefix(n, offset+1); 6001 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n->cdr))); 6002 } 6655 dump_args(mrb, tree->car, offset+1); 6003 6656 } 6004 6657 dump_prefix(tree, offset+1); … … 6123 6776 if (n2->car) { 6124 6777 if (!first_lval) printf(", "); 6125 printf("%s", mrb_sym 2name(mrb, sym(n2->car)));6778 printf("%s", mrb_sym_name(mrb, sym(n2->car))); 6126 6779 first_lval = FALSE; 6127 6780 } … … 6151 6804 dump_prefix(tree, offset+1); 6152 6805 printf("method='%s' (%d)\n", 6153 mrb_sym 2name(mrb, sym(tree->cdr->car)),6154 (int)(intptr_t)tree->cdr->car);6806 mrb_sym_dump(mrb, sym(tree->cdr->car)), 6807 intn(tree->cdr->car)); 6155 6808 tree = tree->cdr->cdr->car; 6156 6809 if (tree) { … … 6182 6835 mrb_parser_dump(mrb, tree->car, offset+1); 6183 6836 dump_prefix(tree, offset+1); 6184 printf("::%s\n", mrb_sym 2name(mrb, sym(tree->cdr)));6837 printf("::%s\n", mrb_sym_name(mrb, sym(tree->cdr))); 6185 6838 break; 6186 6839 6187 6840 case NODE_COLON3: 6188 printf("NODE_COLON3: ::%s\n", mrb_sym 2name(mrb, sym(tree)));6841 printf("NODE_COLON3: ::%s\n", mrb_sym_name(mrb, sym(tree))); 6189 6842 break; 6190 6843 … … 6196 6849 case NODE_HASH: 6197 6850 printf("NODE_HASH:\n"); 6851 while (tree) { 6852 dump_prefix(tree, offset+1); 6853 printf("key:\n"); 6854 mrb_parser_dump(mrb, tree->car->car, offset+2); 6855 dump_prefix(tree, offset+1); 6856 printf("value:\n"); 6857 mrb_parser_dump(mrb, tree->car->cdr, offset+2); 6858 tree = tree->cdr; 6859 } 6860 break; 6861 6862 case NODE_KW_HASH: 6863 printf("NODE_KW_HASH:\n"); 6198 6864 while (tree) { 6199 6865 dump_prefix(tree, offset+1); … … 6269 6935 tree = tree->cdr; 6270 6936 dump_prefix(tree, offset+1); 6271 printf("op='%s' (%d)\n", mrb_sym 2name(mrb, sym(tree->car)), (int)(intptr_t)tree->car);6937 printf("op='%s' (%d)\n", mrb_sym_name(mrb, sym(tree->car)), intn(tree->car)); 6272 6938 tree = tree->cdr; 6273 6939 mrb_parser_dump(mrb, tree->car, offset+1); … … 6321 6987 6322 6988 case NODE_LVAR: 6323 printf("NODE_LVAR %s\n", mrb_sym 2name(mrb, sym(tree)));6989 printf("NODE_LVAR %s\n", mrb_sym_name(mrb, sym(tree))); 6324 6990 break; 6325 6991 6326 6992 case NODE_GVAR: 6327 printf("NODE_GVAR %s\n", mrb_sym 2name(mrb, sym(tree)));6993 printf("NODE_GVAR %s\n", mrb_sym_name(mrb, sym(tree))); 6328 6994 break; 6329 6995 6330 6996 case NODE_IVAR: 6331 printf("NODE_IVAR %s\n", mrb_sym 2name(mrb, sym(tree)));6997 printf("NODE_IVAR %s\n", mrb_sym_name(mrb, sym(tree))); 6332 6998 break; 6333 6999 6334 7000 case NODE_CVAR: 6335 printf("NODE_CVAR %s\n", mrb_sym2name(mrb, sym(tree))); 7001 printf("NODE_CVAR %s\n", mrb_sym_name(mrb, sym(tree))); 7002 break; 7003 7004 case NODE_NVAR: 7005 printf("NODE_NVAR %d\n", intn(tree)); 6336 7006 break; 6337 7007 6338 7008 case NODE_CONST: 6339 printf("NODE_CONST %s\n", mrb_sym 2name(mrb, sym(tree)));7009 printf("NODE_CONST %s\n", mrb_sym_name(mrb, sym(tree))); 6340 7010 break; 6341 7011 … … 6351 7021 6352 7022 case NODE_BACK_REF: 6353 printf("NODE_BACK_REF: $%c\n", (int)(intptr_t)tree);7023 printf("NODE_BACK_REF: $%c\n", intn(tree)); 6354 7024 break; 6355 7025 6356 7026 case NODE_NTH_REF: 6357 printf("NODE_NTH_REF: $% " MRB_PRId "\n", (mrb_int)(intptr_t)tree);7027 printf("NODE_NTH_REF: $%d\n", intn(tree)); 6358 7028 break; 6359 7029 6360 7030 case NODE_ARG: 6361 printf("NODE_ARG %s\n", mrb_sym 2name(mrb, sym(tree)));7031 printf("NODE_ARG %s\n", mrb_sym_name(mrb, sym(tree))); 6362 7032 break; 6363 7033 … … 6368 7038 6369 7039 case NODE_INT: 6370 printf("NODE_INT %s base %d\n", (char*)tree->car, (int)(intptr_t)tree->cdr->car);7040 printf("NODE_INT %s base %d\n", (char*)tree->car, intn(tree->cdr->car)); 6371 7041 break; 6372 7042 … … 6376 7046 6377 7047 case NODE_NEGATE: 6378 printf("NODE_NEGATE \n");7048 printf("NODE_NEGATE:\n"); 6379 7049 mrb_parser_dump(mrb, tree, offset+1); 6380 7050 break; 6381 7051 6382 7052 case NODE_STR: 6383 printf("NODE_STR \"%s\" len %d\n", (char*)tree->car, (int)(intptr_t)tree->cdr);7053 printf("NODE_STR %s len %d\n", str_dump(mrb, (char*)tree->car, intn(tree->cdr)), intn(tree->cdr)); 6384 7054 break; 6385 7055 6386 7056 case NODE_DSTR: 6387 printf("NODE_DSTR \n");7057 printf("NODE_DSTR:\n"); 6388 7058 dump_recur(mrb, tree, offset+1); 6389 7059 break; 6390 7060 6391 7061 case NODE_XSTR: 6392 printf("NODE_XSTR \"%s\" len %d\n", (char*)tree->car, (int)(intptr_t)tree->cdr);7062 printf("NODE_XSTR %s len %d\n", str_dump(mrb, (char*)tree->car, intn(tree->cdr)), intn(tree->cdr)); 6393 7063 break; 6394 7064 6395 7065 case NODE_DXSTR: 6396 printf("NODE_DXSTR \n");7066 printf("NODE_DXSTR:\n"); 6397 7067 dump_recur(mrb, tree, offset+1); 6398 7068 break; … … 6403 7073 6404 7074 case NODE_DREGX: 6405 printf("NODE_DREGX \n");7075 printf("NODE_DREGX:\n"); 6406 7076 dump_recur(mrb, tree->car, offset+1); 6407 7077 dump_prefix(tree, offset); … … 6418 7088 6419 7089 case NODE_SYM: 6420 printf("NODE_SYM :%s (%d)\n", mrb_sym2name(mrb, sym(tree)), 6421 (int)(intptr_t)tree); 7090 printf("NODE_SYM :%s (%d)\n", mrb_sym_dump(mrb, sym(tree)), 7091 intn(tree)); 7092 break; 7093 7094 case NODE_DSYM: 7095 printf("NODE_DSYM:\n"); 7096 mrb_parser_dump(mrb, tree, offset+1); 7097 break; 7098 7099 case NODE_WORDS: 7100 printf("NODE_WORDS:\n"); 7101 dump_recur(mrb, tree, offset+1); 7102 break; 7103 7104 case NODE_SYMBOLS: 7105 printf("NODE_SYMBOLS:\n"); 7106 dump_recur(mrb, tree, offset+1); 7107 break; 7108 7109 case NODE_LITERAL_DELIM: 7110 printf("NODE_LITERAL_DELIM\n"); 6422 7111 break; 6423 7112 … … 6440 7129 case NODE_ALIAS: 6441 7130 printf("NODE_ALIAS %s %s:\n", 6442 mrb_sym 2name(mrb, sym(tree->car)),6443 mrb_sym 2name(mrb, sym(tree->cdr)));7131 mrb_sym_dump(mrb, sym(tree->car)), 7132 mrb_sym_dump(mrb, sym(tree->cdr))); 6444 7133 break; 6445 7134 … … 6449 7138 node *t = tree; 6450 7139 while (t) { 6451 printf(" %s", mrb_sym 2name(mrb, sym(t->car)));7140 printf(" %s", mrb_sym_dump(mrb, sym(t->car))); 6452 7141 t = t->cdr; 6453 7142 } … … 6460 7149 if (tree->car->car == (node*)0) { 6461 7150 dump_prefix(tree, offset+1); 6462 printf(":%s\n", mrb_sym 2name(mrb, sym(tree->car->cdr)));7151 printf(":%s\n", mrb_sym_name(mrb, sym(tree->car->cdr))); 6463 7152 } 6464 7153 else if (tree->car->car == (node*)1) { 6465 7154 dump_prefix(tree, offset+1); 6466 printf("::%s\n", mrb_sym 2name(mrb, sym(tree->car->cdr)));7155 printf("::%s\n", mrb_sym_name(mrb, sym(tree->car->cdr))); 6467 7156 } 6468 7157 else { 6469 7158 mrb_parser_dump(mrb, tree->car->car, offset+1); 6470 7159 dump_prefix(tree, offset+1); 6471 printf("::%s\n", mrb_sym 2name(mrb, sym(tree->car->cdr)));7160 printf("::%s\n", mrb_sym_name(mrb, sym(tree->car->cdr))); 6472 7161 } 6473 7162 if (tree->cdr->car) { … … 6485 7174 if (tree->car->car == (node*)0) { 6486 7175 dump_prefix(tree, offset+1); 6487 printf(":%s\n", mrb_sym 2name(mrb, sym(tree->car->cdr)));7176 printf(":%s\n", mrb_sym_name(mrb, sym(tree->car->cdr))); 6488 7177 } 6489 7178 else if (tree->car->car == (node*)1) { 6490 7179 dump_prefix(tree, offset+1); 6491 printf("::%s\n", mrb_sym 2name(mrb, sym(tree->car->cdr)));7180 printf("::%s\n", mrb_sym_name(mrb, sym(tree->car->cdr))); 6492 7181 } 6493 7182 else { 6494 7183 mrb_parser_dump(mrb, tree->car->car, offset+1); 6495 7184 dump_prefix(tree, offset+1); 6496 printf("::%s\n", mrb_sym 2name(mrb, sym(tree->car->cdr)));7185 printf("::%s\n", mrb_sym_name(mrb, sym(tree->car->cdr))); 6497 7186 } 6498 7187 dump_prefix(tree, offset+1); … … 6512 7201 printf("NODE_DEF:\n"); 6513 7202 dump_prefix(tree, offset+1); 6514 printf("%s\n", mrb_sym 2name(mrb, sym(tree->car)));7203 printf("%s\n", mrb_sym_dump(mrb, sym(tree->car))); 6515 7204 tree = tree->cdr; 6516 7205 { … … 6525 7214 if (n2->car) { 6526 7215 if (!first_lval) printf(", "); 6527 printf("%s", mrb_sym 2name(mrb, sym(n2->car)));7216 printf("%s", mrb_sym_name(mrb, sym(n2->car))); 6528 7217 first_lval = FALSE; 6529 7218 } … … 6535 7224 tree = tree->cdr; 6536 7225 if (tree->car) { 6537 node *n = tree->car; 6538 6539 if (n->car) { 6540 dump_prefix(n, offset+1); 6541 printf("mandatory args:\n"); 6542 dump_recur(mrb, n->car, offset+2); 6543 } 6544 n = n->cdr; 6545 if (n->car) { 6546 dump_prefix(n, offset+1); 6547 printf("optional args:\n"); 6548 { 6549 node *n2 = n->car; 6550 6551 while (n2) { 6552 dump_prefix(n2, offset+2); 6553 printf("%s=", mrb_sym2name(mrb, sym(n2->car->car))); 6554 mrb_parser_dump(mrb, n2->car->cdr, 0); 6555 n2 = n2->cdr; 6556 } 6557 } 6558 } 6559 n = n->cdr; 6560 if (n->car) { 6561 dump_prefix(n, offset+1); 6562 printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car))); 6563 } 6564 n = n->cdr; 6565 if (n->car) { 6566 dump_prefix(n, offset+1); 6567 printf("post mandatory args:\n"); 6568 dump_recur(mrb, n->car, offset+2); 6569 } 6570 if (n->cdr) { 6571 dump_prefix(n, offset+1); 6572 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n->cdr))); 6573 } 7226 dump_args(mrb, tree->car, offset); 6574 7227 } 6575 7228 mrb_parser_dump(mrb, tree->cdr->car, offset+1); … … 6581 7234 tree = tree->cdr; 6582 7235 dump_prefix(tree, offset+1); 6583 printf(":%s\n", mrb_sym 2name(mrb, sym(tree->car)));7236 printf(":%s\n", mrb_sym_dump(mrb, sym(tree->car))); 6584 7237 tree = tree->cdr->cdr; 6585 7238 if (tree->car) { 6586 node *n = tree->car; 6587 6588 if (n->car) { 6589 dump_prefix(n, offset+1); 6590 printf("mandatory args:\n"); 6591 dump_recur(mrb, n->car, offset+2); 6592 } 6593 n = n->cdr; 6594 if (n->car) { 6595 dump_prefix(n, offset+1); 6596 printf("optional args:\n"); 6597 { 6598 node *n2 = n->car; 6599 6600 while (n2) { 6601 dump_prefix(n2, offset+2); 6602 printf("%s=", mrb_sym2name(mrb, sym(n2->car->car))); 6603 mrb_parser_dump(mrb, n2->car->cdr, 0); 6604 n2 = n2->cdr; 6605 } 6606 } 6607 } 6608 n = n->cdr; 6609 if (n->car) { 6610 dump_prefix(n, offset+1); 6611 printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car))); 6612 } 6613 n = n->cdr; 6614 if (n->car) { 6615 dump_prefix(n, offset+1); 6616 printf("post mandatory args:\n"); 6617 dump_recur(mrb, n->car, offset+2); 6618 } 6619 n = n->cdr; 6620 if (n) { 6621 dump_prefix(n, offset+1); 6622 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n))); 6623 } 7239 dump_args(mrb, tree->car, offset+1); 6624 7240 } 6625 7241 tree = tree->cdr; … … 6637 7253 break; 6638 7254 7255 case NODE_ARGS_TAIL: 7256 printf("NODE_ARGS_TAIL:\n"); 7257 { 7258 node *kws = tree->car; 7259 7260 while (kws) { 7261 mrb_parser_dump(mrb, kws->car, offset+1); 7262 kws = kws->cdr; 7263 } 7264 } 7265 tree = tree->cdr; 7266 if (tree->car) { 7267 mrb_assert(intn(tree->car->car) == NODE_KW_REST_ARGS); 7268 mrb_parser_dump(mrb, tree->car, offset+1); 7269 } 7270 tree = tree->cdr; 7271 if (tree->car) { 7272 dump_prefix(tree, offset+1); 7273 printf("block='%s'\n", mrb_sym_name(mrb, sym(tree->car))); 7274 } 7275 break; 7276 7277 case NODE_KW_ARG: 7278 printf("NODE_KW_ARG %s:\n", mrb_sym_name(mrb, sym(tree->car))); 7279 mrb_parser_dump(mrb, tree->cdr->car, offset + 1); 7280 break; 7281 7282 case NODE_KW_REST_ARGS: 7283 printf("NODE_KW_REST_ARGS %s\n", mrb_sym_name(mrb, sym(tree))); 7284 break; 7285 6639 7286 default: 6640 7287 printf("node type: %d (0x%x)\n", nodetype, (unsigned)nodetype);
Note:
See TracChangeset
for help on using the changeset viewer.