Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/bintest/mrbc.rb
r321 r331 11 11 assert_equal 0, $?.exitstatus 12 12 end 13 14 assert('parsing function with void argument') do 15 a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb') 16 a.write('f ()') 17 a.flush 18 result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1` 19 assert_equal "#{cmd('mrbc')}:#{a.path}:Syntax OK", result.chomp 20 assert_equal 0, $?.exitstatus 21 end 22 23 assert('embedded document with invalid terminator') do 24 a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb') 25 a.write("=begin\n=endx\n") 26 a.flush 27 result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1` 28 assert_equal "#{a.path}:3:0: embedded document meets end of file", result.chomp 29 assert_equal 1, $?.exitstatus 30 end -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/core/codegen.c
r321 r331 9 9 #include <stdlib.h> 10 10 #include <string.h> 11 #include "mruby.h"12 #include "mruby/compile.h"13 #include "mruby/proc.h"14 #include "mruby/numeric.h"15 #include "mruby/string.h"16 #include "mruby/debug.h"11 #include <mruby.h> 12 #include <mruby/compile.h> 13 #include <mruby/proc.h> 14 #include <mruby/numeric.h> 15 #include <mruby/string.h> 16 #include <mruby/debug.h> 17 17 #include "node.h" 18 #include "mruby/opcode.h" 19 #include "mruby/re.h" 20 #include "mruby/throw.h" 18 #include <mruby/opcode.h> 19 #include <mruby/re.h> 20 #include <mruby/throw.h> 21 22 #ifndef MRB_CODEGEN_LEVEL_MAX 23 #define MRB_CODEGEN_LEVEL_MAX 1024 24 #endif 21 25 22 26 typedef mrb_ast_node node; … … 74 78 uint16_t filename_index; 75 79 parser_state* parser; 80 81 int rlev; /* recursion levels */ 76 82 } codegen_scope; 77 83 … … 94 100 while (s->prev) { 95 101 codegen_scope *tmp = s->prev; 102 mrb_free(s->mrb, s->iseq); 96 103 mrb_pool_close(s->mpool); 97 104 s = tmp; 98 105 } 99 #ifndef M BB_DISABLE_STDIO106 #ifndef MRB_DISABLE_STDIO 100 107 if (s->filename && s->lineno) { 101 108 fprintf(stderr, "codegen error:%s:%d: %s\n", s->filename, s->lineno, message); … … 340 347 } 341 348 } 349 if (c0 == OP_LOADNIL) { 350 if (GETARG_B(i) == GETARG_A(i0)) { 351 s->pc--; 352 return 0; 353 } 354 } 342 355 break; 343 356 case OP_JMPIF: … … 381 394 scope_error(s); 382 395 break; 396 } 397 if (diff > MAXARG_sBx) { 398 codegen_error(s, "too distant jump address"); 383 399 } 384 400 s->iseq[pc] = MKOP_AsBx(c, GETARG_A(i), diff); … … 495 511 } 496 512 497 static inline int 513 /* method symbols should be fit in 9 bits */ 514 #define MAXMSYMLEN 512 515 /* maximum symbol numbers */ 516 #define MAXSYMLEN 65536 517 518 static int 498 519 new_msym(codegen_scope *s, mrb_sym sym) 499 520 { … … 503 524 504 525 len = s->irep->slen; 505 if (len > 256) len = 256;526 if (len > MAXMSYMLEN) len = MAXMSYMLEN; 506 527 for (i=0; i<len; i++) { 507 528 if (s->irep->syms[i] == sym) return i; 508 529 if (s->irep->syms[i] == 0) break; 509 530 } 510 if (i == 256) {511 codegen_error(s, "too many symbols (max 256)");531 if (i == MAXMSYMLEN) { 532 codegen_error(s, "too many symbols (max " MRB_STRINGIZE(MAXMSYMLEN) ")"); 512 533 } 513 534 s->irep->syms[i] = sym; … … 516 537 } 517 538 518 static in line int539 static int 519 540 new_sym(codegen_scope *s, mrb_sym sym) 520 541 { … … 524 545 if (s->irep->syms[i] == sym) return i; 525 546 } 526 if (s->irep->slen > 125 && s->irep->slen < 256) { 527 s->irep->syms = (mrb_sym *)codegen_realloc(s, s->irep->syms, sizeof(mrb_sym)*65536); 528 for (i = 0; i < 256 - s->irep->slen; i++) { 547 if (s->irep->slen == MAXSYMLEN) { 548 codegen_error(s, "too many symbols (max " MRB_STRINGIZE(MAXSYMLEN) ")"); 549 } 550 551 if (s->irep->slen > MAXMSYMLEN/2 && s->scapa == MAXMSYMLEN) { 552 s->scapa = MAXSYMLEN; 553 s->irep->syms = (mrb_sym *)codegen_realloc(s, s->irep->syms, sizeof(mrb_sym)*MAXSYMLEN); 554 for (i = s->irep->slen; i < MAXMSYMLEN; i++) { 529 555 static const mrb_sym mrb_sym_zero = { 0 }; 530 s->irep->syms[i + s->irep->slen] = mrb_sym_zero;531 } 532 s->irep->slen = 256;556 s->irep->syms[i] = mrb_sym_zero; 557 } 558 s->irep->slen = MAXMSYMLEN; 533 559 } 534 560 s->irep->syms[s->irep->slen] = sym; … … 583 609 push(); /* push for a block parameter */ 584 610 585 lp = loop_push(s, LOOP_FOR);586 lp->pc1 = new_label(s);587 588 611 /* generate loop variable */ 589 612 n2 = tree->car; … … 595 618 gen_vmassignment(s, n2, 1, VAL); 596 619 } 620 /* construct loop */ 621 lp = loop_push(s, LOOP_FOR); 622 lp->pc2 = new_label(s); 623 624 /* loop body */ 597 625 codegen(s, tree->cdr->cdr->car, VAL); 598 626 pop(); … … 645 673 ba = tree->car->cdr->cdr->cdr->cdr ? 1 : 0; 646 674 675 if (ma > 0x1f || oa > 0x1f || pa > 0x1f || ka > 0x1f) { 676 codegen_error(s, "too many formal arguments"); 677 } 647 678 a = ((mrb_aspec)(ma & 0x1f) << 18) 648 679 | ((mrb_aspec)(oa & 0x1f) << 13) … … 765 796 } 766 797 798 #define CALL_MAXARGS 127 799 767 800 static int 768 gen_values(codegen_scope *s, node *t, int val )801 gen_values(codegen_scope *s, node *t, int val, int extra) 769 802 { 770 803 int n = 0; … … 773 806 while (t) { 774 807 is_splat = (intptr_t)t->car->car == NODE_SPLAT; /* splat mode */ 775 if (n >= 127 || is_splat) { 808 if ( 809 n+extra >= CALL_MAXARGS - 1 /* need to subtract one because vm.c expects an array if n == CALL_MAXARGS */ 810 || is_splat) { 776 811 if (val) { 777 pop_n(n); 778 genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), n)); 779 push(); 780 codegen(s, t->car, VAL); 781 pop(); pop(); 782 if (is_splat) { 783 genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1)); 812 if (is_splat && n == 0 && (intptr_t)t->car->cdr->car == NODE_ARRAY) { 813 codegen(s, t->car->cdr, VAL); 814 pop(); 784 815 } 785 816 else { 786 genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); 817 pop_n(n); 818 genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), n)); 819 push(); 820 codegen(s, t->car, VAL); 821 pop(); pop(); 822 if (is_splat) { 823 genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1)); 824 } 825 else { 826 genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); 827 } 787 828 } 788 829 t = t->cdr; … … 801 842 } 802 843 else { 803 codegen(s, t->car->cdr, NOVAL);804 t = t->cdr;805 844 while (t) { 806 845 codegen(s, t->car, NOVAL); … … 818 857 } 819 858 820 #define CALL_MAXARGS 127821 822 859 static void 823 gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val )860 gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe) 824 861 { 825 862 mrb_sym sym = name ? name : sym(tree->cdr->car); 826 int idx ;863 int idx, skip = 0; 827 864 int n = 0, noop = 0, sendv = 0, blk = 0; 828 865 829 866 codegen(s, tree->car, VAL); /* receiver */ 867 if (safe) { 868 int recv = cursp()-1; 869 genop(s, MKOP_A(OP_LOADNIL, cursp())); 870 push(); 871 genop(s, MKOP_AB(OP_MOVE, cursp(), recv)); 872 push(); pop(); /* space for a block */ 873 pop(); 874 idx = new_msym(s, mrb_intern_lit(s->mrb, "==")); 875 genop(s, MKOP_ABC(OP_EQ, cursp(), idx, 1)); 876 skip = genop(s, MKOP_AsBx(OP_JMPIF, cursp(), 0)); 877 } 830 878 idx = new_msym(s, sym); 831 879 tree = tree->cdr->cdr->car; 832 880 if (tree) { 833 n = gen_values(s, tree->car, VAL );881 n = gen_values(s, tree->car, VAL, sp?1:0); 834 882 if (n < 0) { 835 883 n = noop = sendv = 1; … … 863 911 const char *symname = mrb_sym2name_len(s->mrb, sym, &symlen); 864 912 865 if (!noop && symlen == 1 && symname[0] == '+' ) {913 if (!noop && symlen == 1 && symname[0] == '+' && n == 1) { 866 914 genop_peep(s, MKOP_ABC(OP_ADD, cursp(), idx, n), val); 867 915 } 868 else if (!noop && symlen == 1 && symname[0] == '-' ) {916 else if (!noop && symlen == 1 && symname[0] == '-' && n == 1) { 869 917 genop_peep(s, MKOP_ABC(OP_SUB, cursp(), idx, n), val); 870 918 } 871 else if (!noop && symlen == 1 && symname[0] == '*' ) {919 else if (!noop && symlen == 1 && symname[0] == '*' && n == 1) { 872 920 genop(s, MKOP_ABC(OP_MUL, cursp(), idx, n)); 873 921 } 874 else if (!noop && symlen == 1 && symname[0] == '/' ) {922 else if (!noop && symlen == 1 && symname[0] == '/' && n == 1) { 875 923 genop(s, MKOP_ABC(OP_DIV, cursp(), idx, n)); 876 924 } 877 else if (!noop && symlen == 1 && symname[0] == '<' ) {925 else if (!noop && symlen == 1 && symname[0] == '<' && n == 1) { 878 926 genop(s, MKOP_ABC(OP_LT, cursp(), idx, n)); 879 927 } 880 else if (!noop && symlen == 2 && symname[0] == '<' && symname[1] == '=' ) {928 else if (!noop && symlen == 2 && symname[0] == '<' && symname[1] == '=' && n == 1) { 881 929 genop(s, MKOP_ABC(OP_LE, cursp(), idx, n)); 882 930 } 883 else if (!noop && symlen == 1 && symname[0] == '>' ) {931 else if (!noop && symlen == 1 && symname[0] == '>' && n == 1) { 884 932 genop(s, MKOP_ABC(OP_GT, cursp(), idx, n)); 885 933 } 886 else if (!noop && symlen == 2 && symname[0] == '>' && symname[1] == '=' ) {934 else if (!noop && symlen == 2 && symname[0] == '>' && symname[1] == '=' && n == 1) { 887 935 genop(s, MKOP_ABC(OP_GE, cursp(), idx, n)); 888 936 } 889 else if (!noop && symlen == 2 && symname[0] == '=' && symname[1] == '=' ) {937 else if (!noop && symlen == 2 && symname[0] == '=' && symname[1] == '=' && n == 1) { 890 938 genop(s, MKOP_ABC(OP_EQ, cursp(), idx, n)); 891 939 } … … 900 948 } 901 949 } 950 if (safe) { 951 dispatch(s, skip); 952 } 902 953 if (val) { 903 954 push(); … … 912 963 913 964 tree = tree->cdr; 914 switch ( (intptr_t)type) {965 switch (type) { 915 966 case NODE_GVAR: 916 967 idx = new_sym(s, sym(tree)); … … 962 1013 963 1014 case NODE_CALL: 1015 case NODE_SCALL: 964 1016 push(); 965 gen_call(s, tree, attrsym(s, sym(tree->cdr->car)), sp, NOVAL); 1017 gen_call(s, tree, attrsym(s, sym(tree->cdr->car)), sp, NOVAL, 1018 type == NODE_SCALL); 966 1019 pop(); 967 1020 if (val) { … … 980 1033 default: 981 1034 #ifndef MRB_DISABLE_STDIO 982 printf("unknown lhs %d\n", type);1035 fprintf(stderr, "unknown lhs %d\n", type); 983 1036 #endif 984 1037 break; … … 1033 1086 } 1034 1087 } 1035 push(); 1088 if (!val) { 1089 push(); 1090 } 1036 1091 } 1037 1092 } … … 1176 1231 1177 1232 static void 1233 gen_retval(codegen_scope *s, node *tree) 1234 { 1235 if ((intptr_t)tree->car == NODE_SPLAT) { 1236 genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), 0)); 1237 push(); 1238 codegen(s, tree, VAL); 1239 pop(); pop(); 1240 genop(s, MKOP_AB(OP_ARYCAT, cursp(), cursp()+1)); 1241 } 1242 else { 1243 codegen(s, tree, VAL); 1244 pop(); 1245 } 1246 } 1247 1248 static void 1178 1249 codegen(codegen_scope *s, node *tree, int val) 1179 1250 { 1180 1251 int nt; 1181 1182 if (!tree) return; 1183 1252 int rlev = s->rlev; 1253 1254 if (!tree) { 1255 if (val) { 1256 genop(s, MKOP_A(OP_LOADNIL, cursp())); 1257 push(); 1258 } 1259 return; 1260 } 1261 1262 s->rlev++; 1263 if (s->rlev > MRB_CODEGEN_LEVEL_MAX) { 1264 codegen_error(s, "too complex expression"); 1265 } 1184 1266 if (s->irep && s->filename_index != tree->filename_index) { 1185 1267 s->irep->filename = mrb_parser_get_filename(s->parser, s->filename_index); … … 1210 1292 struct loopinfo *lp; 1211 1293 1294 if (tree->car == NULL) goto exit; 1212 1295 onerr = genop(s, MKOP_Bx(OP_ONERR, 0)); 1213 1296 lp = loop_push(s, LOOP_BEGIN); 1214 1297 lp->pc1 = onerr; 1215 if (tree->car) { 1216 codegen(s, tree->car, val); 1217 if (val) pop(); 1218 } 1298 codegen(s, tree->car, VAL); 1299 pop(); 1219 1300 lp->type = LOOP_RESCUE; 1220 1301 noexc = genop(s, MKOP_Bx(OP_JMP, 0)); … … 1227 1308 int exc = cursp(); 1228 1309 1229 genop(s, MKOP_A (OP_RESCUE, exc));1310 genop(s, MKOP_ABC(OP_RESCUE, exc, 0, 0)); 1230 1311 push(); 1231 1312 while (n2) { … … 1236 1317 pos2 = 0; 1237 1318 do { 1238 if (n4 ) {1319 if (n4 && n4->car && (intptr_t)n4->car->car == NODE_SPLAT) { 1239 1320 codegen(s, n4->car, VAL); 1240 } 1241 else { 1242 genop(s, MKOP_ABx(OP_GETCONST, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "StandardError")))); 1243 push(); 1244 } 1245 genop(s, MKOP_AB(OP_MOVE, cursp(), exc)); 1246 pop(); 1247 if (n4 && n4->car && (intptr_t)n4->car->car == NODE_SPLAT) { 1321 genop(s, MKOP_AB(OP_MOVE, cursp(), exc)); 1322 pop(); 1248 1323 genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1)); 1249 1324 } 1250 1325 else { 1251 genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1)); 1326 if (n4) { 1327 codegen(s, n4->car, VAL); 1328 } 1329 else { 1330 genop(s, MKOP_ABx(OP_GETCONST, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "StandardError")))); 1331 push(); 1332 } 1333 pop(); 1334 genop(s, MKOP_ABC(OP_RESCUE, exc, cursp(), 1)); 1252 1335 } 1253 1336 tmp = genop(s, MKOP_AsBx(OP_JMPIF, cursp(), pos2)); … … 1294 1377 1295 1378 case NODE_ENSURE: 1296 { 1379 if (!tree->cdr || !tree->cdr->cdr || 1380 ((intptr_t)tree->cdr->cdr->car == NODE_BEGIN && 1381 tree->cdr->cdr->cdr)) { 1297 1382 int idx; 1298 1383 int epush = s->pc; … … 1306 1391 genop_peep(s, MKOP_A(OP_EPOP, 1), NOVAL); 1307 1392 } 1393 else { /* empty ensure ignored */ 1394 codegen(s, tree->car, val); 1395 } 1308 1396 break; 1309 1397 1310 1398 case NODE_LAMBDA: 1311 {1399 if (val) { 1312 1400 int idx = lambda_body(s, tree, 1); 1313 1401 … … 1318 1406 1319 1407 case NODE_BLOCK: 1320 {1408 if (val) { 1321 1409 int idx = lambda_body(s, tree, 1); 1322 1410 … … 1331 1419 node *e = tree->cdr->cdr->car; 1332 1420 1421 if (!tree->car) { 1422 codegen(s, e, val); 1423 goto exit; 1424 } 1333 1425 switch ((intptr_t)tree->car->car) { 1334 1426 case NODE_TRUE: … … 1336 1428 case NODE_STR: 1337 1429 codegen(s, tree->cdr->car, val); 1338 return;1430 goto exit; 1339 1431 case NODE_FALSE: 1340 1432 case NODE_NIL: 1341 1433 codegen(s, e, val); 1342 return;1434 goto exit; 1343 1435 } 1344 1436 codegen(s, tree->car, VAL); … … 1347 1439 1348 1440 codegen(s, tree->cdr->car, val); 1349 if (val && !(tree->cdr->car)) {1350 genop(s, MKOP_A(OP_LOADNIL, cursp()));1351 push();1352 }1353 1441 if (e) { 1354 1442 if (val) pop(); … … 1485 1573 if (pos3) dispatch_linked(s, pos3); 1486 1574 if (head) pop(); 1487 genop(s, MKOP_AB(OP_MOVE, cursp(), pos)); 1575 if (cursp() != pos) { 1576 genop(s, MKOP_AB(OP_MOVE, cursp(), pos)); 1577 } 1488 1578 push(); 1489 1579 } … … 1505 1595 case NODE_FCALL: 1506 1596 case NODE_CALL: 1507 gen_call(s, tree, 0, 0, val); 1597 gen_call(s, tree, 0, 0, val, 0); 1598 break; 1599 case NODE_SCALL: 1600 gen_call(s, tree, 0, 0, val, 1); 1508 1601 break; 1509 1602 … … 1553 1646 int n; 1554 1647 1555 n = gen_values(s, tree, val );1648 n = gen_values(s, tree, val, 0); 1556 1649 if (n >= 0) { 1557 1650 if (val) { … … 1602 1695 1603 1696 case NODE_SPLAT: 1604 codegen(s, tree, VAL);1697 codegen(s, tree, val); 1605 1698 break; 1606 1699 … … 1617 1710 int rhs = cursp(); 1618 1711 1619 if ((intptr_t)t->car == NODE_ARRAY && nosplat(t->cdr)) {1712 if ((intptr_t)t->car == NODE_ARRAY && t->cdr && nosplat(t->cdr)) { 1620 1713 /* fixed rhs */ 1621 1714 t = t->cdr; … … 1630 1723 n = 0; 1631 1724 while (t) { 1632 gen_assignment(s, t->car, rhs+n, NOVAL); 1633 n++; 1725 if (n < len) { 1726 gen_assignment(s, t->car, rhs+n, NOVAL); 1727 n++; 1728 } 1729 else { 1730 genop(s, MKOP_A(OP_LOADNIL, rhs+n)); 1731 gen_assignment(s, t->car, rhs+n, NOVAL); 1732 } 1634 1733 t = t->cdr; 1635 1734 } … … 1688 1787 mrb_int len; 1689 1788 const char *name = mrb_sym2name_len(s->mrb, sym, &len); 1690 int idx; 1691 1692 codegen(s, tree->car, VAL); 1789 int idx, callargs = -1, vsp = -1; 1790 1791 if ((len == 2 && name[0] == '|' && name[1] == '|') && 1792 ((intptr_t)tree->car->car == NODE_CONST || 1793 (intptr_t)tree->car->car == NODE_CVAR)) { 1794 int onerr, noexc, exc; 1795 struct loopinfo *lp; 1796 1797 onerr = genop(s, MKOP_Bx(OP_ONERR, 0)); 1798 lp = loop_push(s, LOOP_BEGIN); 1799 lp->pc1 = onerr; 1800 exc = cursp(); 1801 codegen(s, tree->car, VAL); 1802 lp->type = LOOP_RESCUE; 1803 genop(s, MKOP_A(OP_POPERR, 1)); 1804 noexc = genop(s, MKOP_Bx(OP_JMP, 0)); 1805 dispatch(s, onerr); 1806 genop(s, MKOP_ABC(OP_RESCUE, exc, 0, 0)); 1807 genop(s, MKOP_A(OP_LOADF, exc)); 1808 dispatch(s, noexc); 1809 loop_pop(s, NOVAL); 1810 } 1811 else if ((intptr_t)tree->car->car == NODE_CALL) { 1812 node *n = tree->car->cdr; 1813 1814 if (val) { 1815 vsp = cursp(); 1816 push(); 1817 } 1818 codegen(s, n->car, VAL); /* receiver */ 1819 idx = new_msym(s, sym(n->cdr->car)); 1820 if (n->cdr->cdr->car) { 1821 int base = cursp()-1; 1822 int nargs = gen_values(s, n->cdr->cdr->car->car, VAL, 1); 1823 1824 /* copy receiver and arguments */ 1825 if (nargs >= 0) { 1826 int i; 1827 1828 genop(s, MKOP_AB(OP_MOVE, cursp(), base)); 1829 for (i=0; i<nargs; i++) { 1830 genop(s, MKOP_AB(OP_MOVE, cursp()+i+1, base+i+1)); 1831 } 1832 push_n(nargs+1); 1833 pop_n(nargs+1); 1834 callargs = nargs; 1835 } 1836 else { 1837 /* varargs */ 1838 push(); 1839 genop(s, MKOP_AB(OP_MOVE, cursp(), base)); 1840 genop(s, MKOP_AB(OP_MOVE, cursp()+1, base+1)); 1841 callargs = CALL_MAXARGS; 1842 } 1843 genop(s, MKOP_ABC(OP_SEND, cursp(), idx, callargs)); 1844 } 1845 else { 1846 genop(s, MKOP_AB(OP_MOVE, cursp(), cursp()-1)); 1847 genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 0)); 1848 callargs = 0; 1849 } 1850 push(); 1851 } 1852 else { 1853 codegen(s, tree->car, VAL); 1854 } 1693 1855 if (len == 2 && 1694 1856 ((name[0] == '|' && name[1] == '|') || … … 1697 1859 1698 1860 pop(); 1699 pos = genop_peep(s, MKOP_AsBx(name[0] == '|' ? OP_JMPIF : OP_JMPNOT, cursp(), 0), NOVAL); 1861 if (val) { 1862 if (vsp >= 0) { 1863 genop(s, MKOP_AB(OP_MOVE, vsp, cursp())); 1864 } 1865 pos = genop(s, MKOP_AsBx(name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0)); 1866 } 1867 else { 1868 pos = genop_peep(s, MKOP_AsBx(name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0), NOVAL); 1869 } 1700 1870 codegen(s, tree->cdr->cdr->car, VAL); 1701 1871 pop(); 1702 gen_assignment(s, tree->car, cursp(), val); 1872 if (val && vsp >= 0) { 1873 genop(s, MKOP_AB(OP_MOVE, vsp, cursp())); 1874 } 1875 if ((intptr_t)tree->car->car == NODE_CALL) { 1876 mrb_sym m = sym(tree->car->cdr->cdr->car); 1877 mrb_sym m2 = attrsym(s, m); 1878 1879 idx = new_msym(s, m2); 1880 pop(); 1881 if (callargs == CALL_MAXARGS) { 1882 genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); 1883 pop(); 1884 genop(s, MKOP_ABC(OP_SEND, cursp(), idx, callargs)); 1885 } 1886 else { 1887 pop_n(callargs); 1888 genop(s, MKOP_ABC(OP_SEND, cursp(), idx, callargs+1)); 1889 } 1890 } 1891 else { 1892 gen_assignment(s, tree->car, cursp(), val); 1893 } 1703 1894 dispatch(s, pos); 1704 break;1895 goto exit; 1705 1896 } 1706 1897 codegen(s, tree->cdr->cdr->car, VAL); … … 1736 1927 genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 1)); 1737 1928 } 1738 } 1739 gen_assignment(s, tree->car, cursp(), val); 1929 if (callargs < 0) { 1930 gen_assignment(s, tree->car, cursp(), val); 1931 } 1932 else { 1933 if (val && vsp >= 0) { 1934 genop(s, MKOP_AB(OP_MOVE, vsp, cursp())); 1935 } 1936 if (callargs == CALL_MAXARGS) { 1937 pop(); 1938 genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); 1939 } 1940 else { 1941 pop_n(callargs); 1942 callargs++; 1943 } 1944 pop(); 1945 idx = new_msym(s, attrsym(s,sym(tree->car->cdr->cdr->car))); 1946 genop(s, MKOP_ABC(OP_SEND, cursp(), idx, callargs)); 1947 } 1948 } 1740 1949 break; 1741 1950 1742 1951 case NODE_SUPER: 1743 1952 { 1953 codegen_scope *s2 = s; 1954 int lv = 0; 1744 1955 int n = 0, noop = 0, sendv = 0; 1745 1956 1746 1957 push(); /* room for receiver */ 1958 while (!s2->mscope) { 1959 lv++; 1960 s2 = s2->prev; 1961 if (!s2) break; 1962 } 1963 genop(s, MKOP_ABx(OP_ARGARY, cursp(), (lv & 0xf))); 1964 push(); push(); /* ARGARY pushes two values */ 1965 pop(); pop(); 1747 1966 if (tree) { 1748 1967 node *args = tree->car; 1749 1968 if (args) { 1750 n = gen_values(s, args, VAL );1969 n = gen_values(s, args, VAL, 0); 1751 1970 if (n < 0) { 1752 1971 n = noop = sendv = 1; … … 1796 2015 case NODE_RETURN: 1797 2016 if (tree) { 1798 codegen(s, tree, VAL); 1799 pop(); 2017 gen_retval(s, tree); 1800 2018 } 1801 2019 else { … … 1823 2041 } 1824 2042 if (s2) ainfo = s2->ainfo; 1825 genop(s, MKOP_ABx(OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf)));1826 2043 push(); 1827 2044 if (tree) { 1828 n = gen_values(s, tree, VAL );2045 n = gen_values(s, tree, VAL, 0); 1829 2046 if (n < 0) { 1830 2047 n = sendv = 1; … … 1833 2050 } 1834 2051 pop_n(n+1); 2052 genop(s, MKOP_ABx(OP_BLKPUSH, cursp(), (ainfo<<4)|(lv & 0xf))); 1835 2053 if (sendv) n = CALL_MAXARGS; 1836 2054 genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "call")), n)); … … 1869 2087 1870 2088 case NODE_REDO: 1871 if (!s->loop ) {2089 if (!s->loop || s->loop->type == LOOP_BEGIN || s->loop->type == LOOP_RESCUE) { 1872 2090 raise_error(s, "unexpected redo"); 1873 2091 } … … 1878 2096 genop(s, MKOP_sBx(OP_JMP, s->loop->pc2 - s->pc)); 1879 2097 } 2098 if (val) push(); 1880 2099 break; 1881 2100 … … 1912 2131 } 1913 2132 } 2133 if (val) push(); 1914 2134 } 1915 2135 break; … … 1984 2204 case NODE_BACK_REF: 1985 2205 if (val) { 1986 char buf[2] = { '$' }; 2206 char buf[3]; 2207 int sym; 2208 2209 buf[0] = '$'; 2210 buf[1] = (char)(intptr_t)tree; 2211 buf[2] = 0; 2212 sym = new_sym(s, mrb_intern_cstr(s->mrb, buf)); 2213 genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); 2214 push(); 2215 } 2216 break; 2217 2218 case NODE_NTH_REF: 2219 if (val) { 2220 mrb_state *mrb = s->mrb; 1987 2221 mrb_value str; 1988 2222 int sym; 1989 2223 1990 buf[1] = (char)(intptr_t)tree; 1991 str = mrb_str_new(s->mrb, buf, 2); 1992 sym = new_sym(s, mrb_intern_str(s->mrb, str)); 1993 genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); 1994 push(); 1995 } 1996 break; 1997 1998 case NODE_NTH_REF: 1999 if (val) { 2000 int sym; 2001 mrb_state *mrb = s->mrb; 2002 mrb_value fix = mrb_fixnum_value((intptr_t)tree); 2003 mrb_value str = mrb_str_buf_new(mrb, 4); 2004 2005 mrb_str_cat_lit(mrb, str, "$"); 2006 mrb_str_cat_str(mrb, str, mrb_fixnum_to_str(mrb, fix, 10)); 2224 str = mrb_format(mrb, "$%S", mrb_fixnum_value((mrb_int)(intptr_t)tree)); 2007 2225 sym = new_sym(s, mrb_intern_str(mrb, str)); 2008 2226 genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); … … 2051 2269 if (val) { 2052 2270 char *p = (char*)tree; 2053 mrb_float f = str_to_mrb_float(p);2271 mrb_float f = mrb_float_read(p, NULL); 2054 2272 int off = new_lit(s, mrb_float_value(s->mrb, f)); 2055 2273 … … 2065 2283 switch (nt) { 2066 2284 case NODE_FLOAT: 2067 {2285 if (val) { 2068 2286 char *p = (char*)tree; 2069 mrb_float f = str_to_mrb_float(p);2287 mrb_float f = mrb_float_read(p, NULL); 2070 2288 int off = new_lit(s, mrb_float_value(s->mrb, -f)); 2071 2289 … … 2076 2294 2077 2295 case NODE_INT: 2078 {2296 if (val) { 2079 2297 char *p = (char*)tree->car; 2080 2298 int base = (intptr_t)tree->cdr->car; … … 2105 2323 2106 2324 default: 2107 {2325 if (val) { 2108 2326 int sym = new_msym(s, mrb_intern_lit(s->mrb, "-")); 2109 2327 … … 2113 2331 pop(); pop(); 2114 2332 genop(s, MKOP_ABC(OP_SUB, cursp(), sym, 2)); 2333 } 2334 else { 2335 codegen(s, tree, NOVAL); 2115 2336 } 2116 2337 break; … … 2139 2360 node *n = tree; 2140 2361 2141 if (!n) break; 2362 if (!n) { 2363 genop(s, MKOP_A(OP_LOADNIL, cursp())); 2364 push(); 2365 break; 2366 } 2142 2367 codegen(s, n->car, VAL); 2143 2368 n = n->cdr; … … 2176 2401 int sym = new_sym(s, mrb_intern_lit(s->mrb, "Kernel")); 2177 2402 2178 if (val == NOVAL) { push(); } 2179 genop(s, MKOP_A(OP_OCLASS, cursp())); 2180 genop(s, MKOP_ABx(OP_GETMCNST, cursp(), sym)); 2403 genop(s, MKOP_A(OP_LOADSELF, cursp())); 2181 2404 push(); 2182 2405 codegen(s, tree->car, VAL); … … 2193 2416 n = n->cdr; 2194 2417 } 2195 p op();2196 pop ();2418 push(); /* for block */ 2419 pop_n(3); 2197 2420 sym = new_sym(s, mrb_intern_lit(s->mrb, "`")); 2198 2421 genop(s, MKOP_ABC(OP_SEND, cursp(), sym, 1)); 2199 if (val == NOVAL) { pop(); } 2200 else { push(); } 2422 if (val) push(); 2201 2423 mrb_gc_arena_restore(s->mrb, ai); 2202 2424 } … … 2208 2430 size_t len = (intptr_t)tree->cdr; 2209 2431 int ai = mrb_gc_arena_save(s->mrb); 2210 int sym = new_sym(s, mrb_intern_lit(s->mrb, "Kernel"));2211 2432 int off = new_lit(s, mrb_str_new(s->mrb, p, len)); 2212 2213 if (val == NOVAL) { push(); } 2214 genop(s, MKOP_A(OP_OCLASS, cursp())); 2215 genop(s, MKOP_ABx(OP_GETMCNST, cursp(), sym)); 2433 int sym; 2434 2435 genop(s, MKOP_A(OP_LOADSELF, cursp())); 2216 2436 push(); 2217 2437 genop(s, MKOP_ABx(OP_STRING, cursp(), off)); 2218 pop(); 2438 push(); push(); 2439 pop_n(3); 2219 2440 sym = new_sym(s, mrb_intern_lit(s->mrb, "`")); 2220 2441 genop(s, MKOP_ABC(OP_SEND, cursp(), sym, 1)); 2221 if (val == NOVAL) { pop(); } 2222 else { push(); } 2442 if (val) push(); 2223 2443 mrb_gc_arena_restore(s->mrb, ai); 2224 2444 } … … 2244 2464 off = new_lit(s, mrb_str_new_cstr(s->mrb, p2)); 2245 2465 genop(s, MKOP_ABx(OP_STRING, cursp(), off)); 2246 } else { 2466 } 2467 else { 2247 2468 genop(s, MKOP_A(OP_LOADNIL, cursp())); 2248 2469 } … … 2295 2516 genop_peep(s, MKOP_AB(OP_STRCAT, cursp(), cursp()+1), VAL); 2296 2517 } 2297 if (n->cdr ) {2298 char *p2 = (char*)n->cdr ;2518 if (n->cdr->car) { 2519 char *p2 = (char*)n->cdr->car; 2299 2520 2300 2521 push(); … … 2302 2523 genop(s, MKOP_ABx(OP_STRING, cursp(), off)); 2303 2524 argc++; 2304 pop(); 2305 } 2306 pop(); 2525 } 2526 if (n->cdr->cdr) { 2527 char *p2 = (char*)n->cdr->cdr; 2528 2529 push(); 2530 off = new_lit(s, mrb_str_new_cstr(s->mrb, p2)); 2531 genop(s, MKOP_ABx(OP_STRING, cursp(), off)); 2532 argc++; 2533 } 2534 pop_n(argc); 2307 2535 sym = new_sym(s, mrb_intern_lit(s->mrb, "compile")); 2308 2536 genop(s, MKOP_ABC(OP_SEND, cursp(), sym, argc)); … … 2379 2607 push(); 2380 2608 genop(s, MKOP_A(OP_LOADNIL, cursp())); 2381 pop_n(3); 2609 push(); 2610 pop_n(4); 2382 2611 genop(s, MKOP_ABC(OP_SEND, cursp(), c, 2)); 2383 2612 if (val) { … … 2396 2625 push(); 2397 2626 while (t) { 2398 int symbol = new_msym(s, sym(t->car)); 2627 int symbol; 2628 if (num >= CALL_MAXARGS - 1) { 2629 pop_n(num); 2630 genop(s, MKOP_ABC(OP_ARRAY, cursp(), cursp(), num)); 2631 while (t) { 2632 symbol = new_msym(s, sym(t->car)); 2633 push(); 2634 genop(s, MKOP_ABx(OP_LOADSYM, cursp(), symbol)); 2635 pop(); 2636 genop(s, MKOP_AB(OP_ARYPUSH, cursp(), cursp()+1)); 2637 t = t->cdr; 2638 } 2639 num = CALL_MAXARGS; 2640 break; 2641 } 2642 symbol = new_msym(s, sym(t->car)); 2399 2643 genop(s, MKOP_ABx(OP_LOADSYM, cursp(), symbol)); 2400 2644 push(); … … 2402 2646 num++; 2403 2647 } 2404 pop_n(num + 1); 2648 pop(); 2649 if (num < CALL_MAXARGS) { 2650 pop_n(num); 2651 } 2405 2652 genop(s, MKOP_ABC(OP_SEND, cursp(), undef, num)); 2406 2653 if (val) { … … 2529 2776 break; 2530 2777 } 2778 exit: 2779 s->rlev = rlev; 2531 2780 } 2532 2781 … … 2570 2819 p->icapa = 1024; 2571 2820 p->iseq = (mrb_code*)mrb_malloc(mrb, sizeof(mrb_code)*p->icapa); 2572 p->irep->iseq = p->iseq;2821 p->irep->iseq = NULL; 2573 2822 2574 2823 p->pcapa = 32; … … 2576 2825 p->irep->plen = 0; 2577 2826 2578 p->scapa = 256;2827 p->scapa = MAXMSYMLEN; 2579 2828 p->irep->syms = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*p->scapa); 2580 2829 p->irep->slen = 0; … … 2620 2869 p->filename_index = prev->filename_index; 2621 2870 2871 p->rlev = prev->rlev+1; 2872 2622 2873 return p; 2623 2874 } … … 2646 2897 irep->reps = (mrb_irep**)codegen_realloc(s, irep->reps, sizeof(mrb_irep*)*irep->rlen); 2647 2898 if (s->filename) { 2648 s->irep->filename = mrb_parser_get_filename(s->parser, s->filename_index);2649 mrb_debug_info_append_file(mrb, s->irep, s->debug_start_pos, s->pc);2899 irep->filename = mrb_parser_get_filename(s->parser, s->filename_index); 2900 mrb_debug_info_append_file(mrb, irep, s->debug_start_pos, s->pc); 2650 2901 2651 2902 fname_len = strlen(s->filename); … … 2654 2905 fname[fname_len] = '\0'; 2655 2906 irep->filename = fname; 2907 irep->own_filename = TRUE; 2656 2908 } 2657 2909 … … 2689 2941 2690 2942 if (tree) { 2691 codegen(s, tree, VAL); 2692 pop(); 2943 gen_retval(s, tree); 2693 2944 } 2694 2945 … … 2702 2953 } 2703 2954 if (!loop) { 2704 codegen_error(s, "unexpected break"); 2955 raise_error(s, "unexpected break"); 2956 return; 2705 2957 } 2706 2958 … … 2718 2970 } 2719 2971 else { 2972 if (!tree) { 2973 genop(s, MKOP_A(OP_LOADNIL, cursp())); 2974 } 2720 2975 genop(s, MKOP_AB(OP_RETURN, cursp(), OP_R_BREAK)); 2721 2976 } … … 2726 2981 loop_pop(codegen_scope *s, int val) 2727 2982 { 2983 dispatch_linked(s, s->loop->pc3); 2728 2984 if (val) { 2729 2985 genop(s, MKOP_A(OP_LOADNIL, cursp())); 2730 2986 } 2731 dispatch_linked(s, s->loop->pc3);2732 2987 s->loop = s->loop->prev; 2733 2988 if (val) push(); … … 2739 2994 codegen_scope *scope = scope_new(mrb, 0, 0); 2740 2995 struct RProc *proc; 2996 struct mrb_jmpbuf *prev_jmp = mrb->jmp; 2741 2997 2742 2998 if (!scope) { … … 2749 3005 2750 3006 MRB_TRY(&scope->jmp) { 3007 mrb->jmp = &scope->jmp; 2751 3008 /* prepare irep */ 2752 3009 codegen(scope, p->tree, NOVAL); … … 2754 3011 mrb_irep_decref(mrb, scope->irep); 2755 3012 mrb_pool_close(scope->mpool); 3013 proc->c = NULL; 3014 mrb->jmp = prev_jmp; 2756 3015 return proc; 2757 3016 } 2758 3017 MRB_CATCH(&scope->jmp) { 2759 if (scope->filename == scope->irep->filename) {2760 scope->irep->filename = NULL;2761 }2762 3018 mrb_irep_decref(mrb, scope->irep); 2763 3019 mrb_pool_close(scope->mpool); 3020 mrb->jmp = prev_jmp; 2764 3021 return NULL; 2765 3022 } -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/core/lex.def
- Property svn:keywords deleted
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/core/node.h
r321 r331 5 5 */ 6 6 7 #ifndef NODE_H8 #define NODE_H7 #ifndef MRUBY_COMPILER_NODE_H 8 #define MRUBY_COMPILER_NODE_H 9 9 10 10 enum node_type { … … 39 39 NODE_OP_ASGN, 40 40 NODE_CALL, 41 NODE_SCALL, 41 42 NODE_FCALL, 42 43 NODE_VCALL, … … 115 116 }; 116 117 117 #endif /* NODE_H */118 #endif /* MRUBY_COMPILER_NODE_H */ -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/core/parse.y
r270 r331 23 23 #include <stdlib.h> 24 24 #include <string.h> 25 #include "mruby.h" 26 #include "mruby/compile.h" 27 #include "mruby/proc.h" 28 #include "mruby/error.h" 25 #include <mruby.h> 26 #include <mruby/compile.h> 27 #include <mruby/proc.h> 28 #include <mruby/error.h> 29 #include <mruby/throw.h> 29 30 #include "node.h" 30 #include "mruby/throw.h"31 31 32 32 #define YYLEX_PARAM p … … 42 42 static void yywarning(parser_state *p, const char *s); 43 43 static void backref_error(parser_state *p, node *n); 44 static void void_expr_error(parser_state *p, node *n); 44 45 static void tokadd(parser_state *p, int32_t c); 45 46 … … 73 74 #define sym(x) ((mrb_sym)(intptr_t)(x)) 74 75 #define nsym(x) ((node*)(intptr_t)(x)) 76 #define nint(x) ((node*)(intptr_t)(x)) 77 #define intn(x) ((int)(intptr_t)(x)) 75 78 76 79 static inline mrb_sym … … 309 312 } 310 313 314 static node* 315 new_mod_rescue(parser_state *p, node *body, node *resq) 316 { 317 return new_rescue(p, body, list1(list3(0, 0, resq)), 0); 318 } 319 311 320 /* (:ensure body ensure) */ 312 321 static node* … … 348 357 new_if(parser_state *p, node *a, node *b, node *c) 349 358 { 359 void_expr_error(p, a); 350 360 return list4((node*)NODE_IF, a, b, c); 351 361 } … … 355 365 new_unless(parser_state *p, node *a, node *b, node *c) 356 366 { 367 void_expr_error(p, a); 357 368 return list4((node*)NODE_IF, a, c, b); 358 369 } … … 362 373 new_while(parser_state *p, node *a, node *b) 363 374 { 375 void_expr_error(p, a); 364 376 return cons((node*)NODE_WHILE, cons(a, b)); 365 377 } … … 369 381 new_until(parser_state *p, node *a, node *b) 370 382 { 383 void_expr_error(p, a); 371 384 return cons((node*)NODE_UNTIL, cons(a, b)); 372 385 } … … 376 389 new_for(parser_state *p, node *v, node *o, node *b) 377 390 { 391 void_expr_error(p, o); 378 392 return list4((node*)NODE_FOR, v, o, b); 379 393 } … … 386 400 node *n2 = n; 387 401 402 void_expr_error(p, a); 388 403 while (n2->cdr) { 389 404 n2 = n2->cdr; … … 409 424 /* (:call a b c) */ 410 425 static node* 411 new_call(parser_state *p, node *a, mrb_sym b, node *c) 412 { 413 node *n = list4((node*)NODE_CALL, a, nsym(b), c); 426 new_call(parser_state *p, node *a, mrb_sym b, node *c, int pass) 427 { 428 node *n = list4(nint(pass?NODE_CALL:NODE_SCALL), a, nsym(b), c); 429 void_expr_error(p, a); 414 430 NODE_LINENO(n, a); 415 431 return n; … … 507 523 new_colon2(parser_state *p, node *b, mrb_sym c) 508 524 { 525 void_expr_error(p, b); 509 526 return cons((node*)NODE_COLON2, cons(b, nsym(c))); 510 527 } … … 614 631 new_class(parser_state *p, node *c, node *s, node *b) 615 632 { 633 void_expr_error(p, s); 616 634 return list4((node*)NODE_CLASS, c, s, cons(locals_node(p), b)); 617 635 } … … 621 639 new_sclass(parser_state *p, node *o, node *b) 622 640 { 641 void_expr_error(p, o); 623 642 return list3((node*)NODE_SCLASS, o, cons(locals_node(p), b)); 624 643 } … … 642 661 new_sdef(parser_state *p, node *o, mrb_sym m, node *a, node *b) 643 662 { 663 void_expr_error(p, o); 644 664 return list6((node*)NODE_SDEF, o, nsym(m), locals_node(p), a, b); 645 665 } … … 694 714 new_asgn(parser_state *p, node *a, node *b) 695 715 { 716 void_expr_error(p, b); 696 717 return cons((node*)NODE_ASGN, cons(a, b)); 697 718 } … … 701 722 new_masgn(parser_state *p, node *a, node *b) 702 723 { 724 void_expr_error(p, b); 703 725 return cons((node*)NODE_MASGN, cons(a, b)); 704 726 } … … 708 730 new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b) 709 731 { 732 void_expr_error(p, b); 710 733 return list4((node*)NODE_OP_ASGN, a, nsym(op), b); 711 734 } … … 715 738 new_int(parser_state *p, const char *s, int base) 716 739 { 717 return list3((node*)NODE_INT, (node*)strdup(s), (node*)(intptr_t)base);740 return list3((node*)NODE_INT, (node*)strdup(s), nint(base)); 718 741 } 719 742 … … 729 752 new_str(parser_state *p, const char *s, int len) 730 753 { 731 return cons((node*)NODE_STR, cons((node*)strndup(s, len), (node*)(intptr_t)len));754 return cons((node*)NODE_STR, cons((node*)strndup(s, len), nint(len))); 732 755 } 733 756 … … 743 766 new_xstr(parser_state *p, const char *s, int len) 744 767 { 745 return cons((node*)NODE_XSTR, cons((node*)strndup(s, len), (node*)(intptr_t)len));768 return cons((node*)NODE_XSTR, cons((node*)strndup(s, len), nint(len))); 746 769 } 747 770 … … 760 783 } 761 784 762 /* (: str . (a . a)) */785 /* (:regx . (s . (opt . enc))) */ 763 786 static node* 764 787 new_regx(parser_state *p, const char *p1, const char* p2, const char* p3) … … 767 790 } 768 791 769 /* (:dregx . a) */792 /* (:dregx . (a . b)) */ 770 793 static node* 771 794 new_dregx(parser_state *p, node *a, node *b) … … 778 801 new_back_ref(parser_state *p, int n) 779 802 { 780 return cons((node*)NODE_BACK_REF, (node*)(intptr_t)n);803 return cons((node*)NODE_BACK_REF, nint(n)); 781 804 } 782 805 … … 785 808 new_nth_ref(parser_state *p, int n) 786 809 { 787 return cons((node*)NODE_NTH_REF, (node*)(intptr_t)n);810 return cons((node*)NODE_NTH_REF, nint(n)); 788 811 } 789 812 … … 827 850 call_uni_op(parser_state *p, node *recv, const char *m) 828 851 { 829 return new_call(p, recv, intern_cstr(m), 0); 852 void_expr_error(p, recv); 853 return new_call(p, recv, intern_cstr(m), 0, 1); 830 854 } 831 855 … … 834 858 call_bin_op(parser_state *p, node *recv, const char *m, node *arg1) 835 859 { 836 return new_call(p, recv, intern_cstr(m), list1(list1(arg1)) );860 return new_call(p, recv, intern_cstr(m), list1(list1(arg1)), 1); 837 861 } 838 862 … … 853 877 node *n; 854 878 855 if (a->car == (node*)NODE_SUPER || 856 a->car == (node*)NODE_ZSUPER) { 879 switch ((enum node_type)intn(a->car)) { 880 case NODE_SUPER: 881 case NODE_ZSUPER: 857 882 if (!a->cdr) a->cdr = cons(0, b); 858 883 else { 859 884 args_with_block(p, a->cdr, b); 860 885 } 861 } 862 else { 886 break; 887 case NODE_CALL: 888 case NODE_FCALL: 889 case NODE_SCALL: 863 890 n = a->cdr->cdr->cdr; 864 891 if (!n->car) n->car = cons(0, b); … … 866 893 args_with_block(p, n->car, b); 867 894 } 895 break; 896 default: 897 break; 868 898 } 869 899 } … … 895 925 assignable(parser_state *p, node *lhs) 896 926 { 897 if ( (int)(intptr_t)lhs->car== NODE_LVAR) {927 if (intn(lhs->car) == NODE_LVAR) { 898 928 local_add(p, sym(lhs->cdr)); 899 929 } … … 905 935 node *n; 906 936 907 if ( (int)(intptr_t)lhs->car== NODE_LVAR) {937 if (intn(lhs->car) == NODE_LVAR) { 908 938 if (!local_var_p(p, sym(lhs->cdr))) { 909 939 n = new_fcall(p, sym(lhs->cdr), 0); … … 921 951 new_strterm(parser_state *p, string_type type, int term, int paren) 922 952 { 923 return cons( (node*)(intptr_t)type, cons((node*)0, cons((node*)(intptr_t)paren, (node*)(intptr_t)term)));953 return cons(nint(type), cons((node*)0, cons(nint(paren), nint(term)))); 924 954 } 925 955 … … 1002 1032 else { 1003 1033 /* next heredoc */ 1004 p->lex_strterm->car = (node*)(intptr_t)parsing_heredoc_inf(p)->type;1005 } 1006 } 1007 #define is_strterm_type(p,str_func) ( (int)(intptr_t)((p)->lex_strterm->car) & (str_func))1034 p->lex_strterm->car = nint(parsing_heredoc_inf(p)->type); 1035 } 1036 } 1037 #define is_strterm_type(p,str_func) (intn((p)->lex_strterm->car) & (str_func)) 1008 1038 1009 1039 /* xxx ----------------------------- */ … … 1077 1107 %token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL 1078 1108 %token <nd> tINTEGER tFLOAT tCHAR tXSTRING tREGEXP 1079 %token <nd> tSTRING tSTRING_PART tSTRING_MID 1109 %token <nd> tSTRING tSTRING_PART tSTRING_MID tLABEL_END 1080 1110 %token <nd> tNTH_REF tBACK_REF 1081 1111 %token <num> tREGEXP_END … … 1085 1115 %type <nd> top_compstmt top_stmts top_stmt 1086 1116 %type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call 1087 %type <nd> expr_value arg_ valueprimary_value1117 %type <nd> expr_value arg_rhs primary_value 1088 1118 %type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure 1089 1119 %type <nd> args call_args opt_call_args 1090 1120 %type <nd> paren_args opt_paren_args variable 1091 1121 %type <nd> command_args aref_args opt_block_arg block_arg var_ref var_lhs 1092 %type <nd> command_asgn mrhs superclass block_call block_command1122 %type <nd> command_asgn command_rhs mrhs superclass block_call block_command 1093 1123 %type <nd> f_block_optarg f_block_opt 1094 1124 %type <nd> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs … … 1101 1131 %type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_opt_asgn 1102 1132 %type <nd> heredoc words symbols 1133 %type <num> call_op call_op2 /* 0:'&.', 1:'.', 2:'::' */ 1103 1134 1104 1135 %token tUPLUS /* unary+ */ … … 1129 1160 %token tAMPER /* & */ 1130 1161 %token tLAMBDA /* -> */ 1162 %token tANDDOT /* &. */ 1131 1163 %token tSYMBEG tREGEXP_BEG tWORDS_BEG tSYMBOLS_BEG 1132 1164 %token tSTRING_BEG tXSTRING_BEG tSTRING_DVAR tLAMBEG … … 1292 1324 | stmt modifier_rescue stmt 1293 1325 { 1294 $$ = new_ rescue(p, $1, list1(list3(0, 0, $3)), 0);1326 $$ = new_mod_rescue(p, $1, $3); 1295 1327 } 1296 1328 | keyword_END '{' compstmt '}' 1297 1329 { 1298 yyerror(p, "END not sup orted");1330 yyerror(p, "END not supported"); 1299 1331 $$ = new_postexe(p, $3); 1300 1332 } … … 1304 1336 $$ = new_masgn(p, $1, $3); 1305 1337 } 1306 | var_lhs tOP_ASGN command_call 1338 | lhs '=' mrhs 1339 { 1340 $$ = new_asgn(p, $1, new_array(p, $3)); 1341 } 1342 | mlhs '=' arg 1343 { 1344 $$ = new_masgn(p, $1, $3); 1345 } 1346 | mlhs '=' mrhs 1347 { 1348 $$ = new_masgn(p, $1, new_array(p, $3)); 1349 } 1350 | expr 1351 ; 1352 1353 command_asgn : lhs '=' command_rhs 1354 { 1355 $$ = new_asgn(p, $1, $3); 1356 } 1357 | var_lhs tOP_ASGN command_rhs 1307 1358 { 1308 1359 $$ = new_op_asgn(p, $1, $2, $3); 1309 1360 } 1310 | primary_value '[' opt_call_args rbracket tOP_ASGN command_ call1311 { 1312 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3 ), $5, $6);1313 } 1314 | primary_value '.' tIDENTIFIER tOP_ASGN command_call1315 { 1316 $$ = new_op_asgn(p, new_call(p, $1, $3, 0 ), $4, $5);1317 } 1318 | primary_value '.' tCONSTANT tOP_ASGN command_call1319 { 1320 $$ = new_op_asgn(p, new_call(p, $1, $3, 0 ), $4, $5);1361 | primary_value '[' opt_call_args rbracket tOP_ASGN command_rhs 1362 { 1363 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); 1364 } 1365 | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs 1366 { 1367 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1368 } 1369 | primary_value call_op tCONSTANT tOP_ASGN command_rhs 1370 { 1371 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1321 1372 } 1322 1373 | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call … … 1325 1376 $$ = 0; 1326 1377 } 1327 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_ call1328 { 1329 $$ = new_op_asgn(p, new_call(p, $1, $3, 0 ), $4, $5);1330 } 1331 | backref tOP_ASGN command_ call1378 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs 1379 { 1380 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); 1381 } 1382 | backref tOP_ASGN command_rhs 1332 1383 { 1333 1384 backref_error(p, $1); 1334 1385 $$ = new_begin(p, 0); 1335 1386 } 1336 | lhs '=' mrhs 1337 { 1338 $$ = new_asgn(p, $1, new_array(p, $3)); 1339 } 1340 | mlhs '=' arg_value 1341 { 1342 $$ = new_masgn(p, $1, $3); 1343 } 1344 | mlhs '=' mrhs 1345 { 1346 $$ = new_masgn(p, $1, new_array(p, $3)); 1347 } 1348 | expr 1349 ; 1350 1351 command_asgn : lhs '=' command_call 1352 { 1353 $$ = new_asgn(p, $1, $3); 1354 } 1355 | lhs '=' command_asgn 1356 { 1357 $$ = new_asgn(p, $1, $3); 1358 } 1387 ; 1388 1389 command_rhs : command_call %prec tOP_ASGN 1390 | command_call modifier_rescue stmt 1391 { 1392 $$ = new_mod_rescue(p, $1, $3); 1393 } 1394 | command_asgn 1359 1395 ; 1360 1396 … … 1383 1419 { 1384 1420 if (!$1) $$ = new_nil(p); 1385 else $$ = $1; 1421 else { 1422 $$ = $1; 1423 } 1386 1424 } 1387 1425 ; … … 1392 1430 1393 1431 block_command : block_call 1394 | block_call dot_or_colon operation2 command_args 1432 | block_call call_op2 operation2 command_args 1433 { 1434 $$ = new_call(p, $1, $3, $4, $2); 1435 } 1395 1436 ; 1396 1437 … … 1417 1458 $$ = new_fcall(p, $1, $2); 1418 1459 } 1419 | primary_value '.'operation2 command_args %prec tLOWEST1420 { 1421 $$ = new_call(p, $1, $3, $4 );1422 } 1423 | primary_value '.'operation2 command_args cmd_brace_block1460 | primary_value call_op operation2 command_args %prec tLOWEST 1461 { 1462 $$ = new_call(p, $1, $3, $4, $2); 1463 } 1464 | primary_value call_op operation2 command_args cmd_brace_block 1424 1465 { 1425 1466 args_with_block(p, $4, $5); 1426 $$ = new_call(p, $1, $3, $4 );1467 $$ = new_call(p, $1, $3, $4, $2); 1427 1468 } 1428 1469 | primary_value tCOLON2 operation2 command_args %prec tLOWEST 1429 1470 { 1430 $$ = new_call(p, $1, $3, $4 );1471 $$ = new_call(p, $1, $3, $4, tCOLON2); 1431 1472 } 1432 1473 | primary_value tCOLON2 operation2 command_args cmd_brace_block 1433 1474 { 1434 1475 args_with_block(p, $4, $5); 1435 $$ = new_call(p, $1, $3, $4 );1476 $$ = new_call(p, $1, $3, $4, tCOLON2); 1436 1477 } 1437 1478 | keyword_super command_args … … 1549 1590 | primary_value '[' opt_call_args rbracket 1550 1591 { 1551 $$ = new_call(p, $1, intern("[]",2), $3 );1552 } 1553 | primary_value '.'tIDENTIFIER1554 { 1555 $$ = new_call(p, $1, $3, 0 );1592 $$ = new_call(p, $1, intern("[]",2), $3, '.'); 1593 } 1594 | primary_value call_op tIDENTIFIER 1595 { 1596 $$ = new_call(p, $1, $3, 0, $2); 1556 1597 } 1557 1598 | primary_value tCOLON2 tIDENTIFIER 1558 1599 { 1559 $$ = new_call(p, $1, $3, 0 );1560 } 1561 | primary_value '.'tCONSTANT1562 { 1563 $$ = new_call(p, $1, $3, 0 );1600 $$ = new_call(p, $1, $3, 0, tCOLON2); 1601 } 1602 | primary_value call_op tCONSTANT 1603 { 1604 $$ = new_call(p, $1, $3, 0, $2); 1564 1605 } 1565 1606 | primary_value tCOLON2 tCONSTANT … … 1588 1629 | primary_value '[' opt_call_args rbracket 1589 1630 { 1590 $$ = new_call(p, $1, intern("[]",2), $3 );1591 } 1592 | primary_value '.'tIDENTIFIER1593 { 1594 $$ = new_call(p, $1, $3, 0 );1631 $$ = new_call(p, $1, intern("[]",2), $3, '.'); 1632 } 1633 | primary_value call_op tIDENTIFIER 1634 { 1635 $$ = new_call(p, $1, $3, 0, $2); 1595 1636 } 1596 1637 | primary_value tCOLON2 tIDENTIFIER 1597 1638 { 1598 $$ = new_call(p, $1, $3, 0 );1599 } 1600 | primary_value '.'tCONSTANT1601 { 1602 $$ = new_call(p, $1, $3, 0 );1639 $$ = new_call(p, $1, $3, 0, tCOLON2); 1640 } 1641 | primary_value call_op tCONSTANT 1642 { 1643 $$ = new_call(p, $1, $3, 0, $2); 1603 1644 } 1604 1645 | primary_value tCOLON2 tCONSTANT … … 1638 1679 | primary_value tCOLON2 cname 1639 1680 { 1681 void_expr_error(p, $1); 1640 1682 $$ = cons($1, nsym($3)); 1641 1683 } … … 1716 1758 ; 1717 1759 1718 arg : lhs '=' arg 1760 arg : lhs '=' arg_rhs 1719 1761 { 1720 1762 $$ = new_asgn(p, $1, $3); 1721 1763 } 1722 | lhs '=' arg modifier_rescue arg 1723 { 1724 $$ = new_asgn(p, $1, new_rescue(p, $3, list1(list3(0, 0, $5)), 0)); 1725 } 1726 | var_lhs tOP_ASGN arg 1764 | var_lhs tOP_ASGN arg_rhs 1727 1765 { 1728 1766 $$ = new_op_asgn(p, $1, $2, $3); 1729 1767 } 1730 | var_lhs tOP_ASGN arg modifier_rescue arg 1731 { 1732 $$ = new_op_asgn(p, $1, $2, new_rescue(p, $3, list1(list3(0, 0, $5)), 0)); 1733 } 1734 | primary_value '[' opt_call_args rbracket tOP_ASGN arg 1735 { 1736 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3), $5, $6); 1737 } 1738 | primary_value '.' tIDENTIFIER tOP_ASGN arg 1739 { 1740 $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5); 1741 } 1742 | primary_value '.' tCONSTANT tOP_ASGN arg 1743 { 1744 $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5); 1745 } 1746 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg 1747 { 1748 $$ = new_op_asgn(p, new_call(p, $1, $3, 0), $4, $5); 1749 } 1750 | primary_value tCOLON2 tCONSTANT tOP_ASGN arg 1768 | primary_value '[' opt_call_args rbracket tOP_ASGN arg_rhs 1769 { 1770 $$ = new_op_asgn(p, new_call(p, $1, intern("[]",2), $3, '.'), $5, $6); 1771 } 1772 | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs 1773 { 1774 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1775 } 1776 | primary_value call_op tCONSTANT tOP_ASGN arg_rhs 1777 { 1778 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, $2), $4, $5); 1779 } 1780 | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs 1781 { 1782 $$ = new_op_asgn(p, new_call(p, $1, $3, 0, tCOLON2), $4, $5); 1783 } 1784 | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs 1751 1785 { 1752 1786 yyerror(p, "constant re-assignment"); 1753 1787 $$ = new_begin(p, 0); 1754 1788 } 1755 | tCOLON3 tCONSTANT tOP_ASGN arg 1789 | tCOLON3 tCONSTANT tOP_ASGN arg_rhs 1756 1790 { 1757 1791 yyerror(p, "constant re-assignment"); 1758 1792 $$ = new_begin(p, 0); 1759 1793 } 1760 | backref tOP_ASGN arg 1794 | backref tOP_ASGN arg_rhs 1761 1795 { 1762 1796 backref_error(p, $1); … … 1897 1931 ; 1898 1932 1899 arg_value : arg1900 {1901 $$ = $1;1902 if (!$$) $$ = new_nil(p);1903 }1904 ;1905 1906 1933 aref_args : none 1907 1934 | args trailer … … 1910 1937 NODE_LINENO($$, $1); 1911 1938 } 1912 | args ','assocs trailer1939 | args comma assocs trailer 1913 1940 { 1914 1941 $$ = push($1, new_hash(p, $3)); … … 1918 1945 $$ = cons(new_hash(p, $1), 0); 1919 1946 NODE_LINENO($$, $1); 1947 } 1948 ; 1949 1950 arg_rhs : arg %prec tOP_ASGN 1951 { 1952 $$ = $1; 1953 } 1954 | arg modifier_rescue arg 1955 { 1956 void_expr_error(p, $1); 1957 void_expr_error(p, $3); 1958 $$ = new_mod_rescue(p, $1, $3); 1920 1959 } 1921 1960 ; … … 1938 1977 NODE_LINENO($$, $1); 1939 1978 } 1940 | args ','assocs ','1979 | args comma assocs ',' 1941 1980 { 1942 1981 $$ = cons(push($1, new_hash(p, $3)), 0); … … 1952 1991 call_args : command 1953 1992 { 1993 void_expr_error(p, $1); 1954 1994 $$ = cons(list1($1), 0); 1955 1995 NODE_LINENO($$, $1); … … 1965 2005 NODE_LINENO($$, $1); 1966 2006 } 1967 | args ','assocs opt_block_arg2007 | args comma assocs opt_block_arg 1968 2008 { 1969 2009 $$ = cons(push($1, new_hash(p, $3)), $4); … … 1988 2028 ; 1989 2029 1990 block_arg : tAMPER arg _value2030 block_arg : tAMPER arg 1991 2031 { 1992 2032 $$ = new_block_arg(p, $2); … … 1994 2034 ; 1995 2035 1996 opt_block_arg : ','block_arg2036 opt_block_arg : comma block_arg 1997 2037 { 1998 2038 $$ = $2; … … 2004 2044 ; 2005 2045 2006 args : arg_value 2007 { 2046 comma : ',' 2047 | ',' heredoc_bodies 2048 ; 2049 2050 args : arg 2051 { 2052 void_expr_error(p, $1); 2008 2053 $$ = cons($1, 0); 2009 2054 NODE_LINENO($$, $1); 2010 2055 } 2011 | tSTAR arg_value 2012 { 2056 | tSTAR arg 2057 { 2058 void_expr_error(p, $2); 2013 2059 $$ = cons(new_splat(p, $2), 0); 2014 2060 NODE_LINENO($$, $2); 2015 2061 } 2016 | args ',' arg_value 2017 { 2062 | args comma arg 2063 { 2064 void_expr_error(p, $3); 2018 2065 $$ = push($1, $3); 2019 2066 } 2020 | args ',' tSTAR arg_value 2021 { 2067 | args comma tSTAR arg 2068 { 2069 void_expr_error(p, $4); 2022 2070 $$ = push($1, new_splat(p, $4)); 2023 2071 } 2024 | args ',' heredoc_bodies arg_value 2025 { 2026 $$ = push($1, $4); 2027 } 2028 | args ',' heredoc_bodies tSTAR arg_value 2029 { 2030 $$ = push($1, new_splat(p, $5)); 2031 } 2032 ; 2033 2034 mrhs : args ',' arg_value 2035 { 2072 ; 2073 2074 mrhs : args comma arg 2075 { 2076 void_expr_error(p, $3); 2036 2077 $$ = push($1, $3); 2037 2078 } 2038 | args ',' tSTAR arg_value 2039 { 2079 | args comma tSTAR arg 2080 { 2081 void_expr_error(p, $4); 2040 2082 $$ = push($1, new_splat(p, $4)); 2041 2083 } 2042 | tSTAR arg_value 2043 { 2084 | tSTAR arg 2085 { 2086 void_expr_error(p, $2); 2044 2087 $$ = list1(new_splat(p, $2)); 2045 2088 } … … 2073 2116 p->cmdarg_stack = 0; 2074 2117 } 2075 expr{p->lstate = EXPR_ENDARG;} rparen2118 stmt {p->lstate = EXPR_ENDARG;} rparen 2076 2119 { 2077 2120 p->cmdarg_stack = $<stack>2; … … 2080 2123 | tLPAREN_ARG {p->lstate = EXPR_ENDARG;} rparen 2081 2124 { 2082 $$ = 0;2125 $$ = new_nil(p); 2083 2126 } 2084 2127 | tLPAREN compstmt ')' … … 2108 2151 $$ = new_return(p, 0); 2109 2152 } 2110 | keyword_yield '(' call_args rparen 2111 { 2112 $$ = new_yield(p, $3); 2113 } 2114 | keyword_yield '(' rparen 2115 { 2116 $$ = new_yield(p, 0); 2117 } 2118 | keyword_yield 2119 { 2120 $$ = new_yield(p, 0); 2153 | keyword_yield opt_paren_args 2154 { 2155 $$ = new_yield(p, $2); 2121 2156 } 2122 2157 | keyword_not '(' expr rparen … … 2229 2264 term 2230 2265 { 2231 $<nd>$ = cons(local_switch(p), (node*)(intptr_t)p->in_single);2266 $<nd>$ = cons(local_switch(p), nint(p->in_single)); 2232 2267 p->in_single = 0; 2233 2268 } … … 2239 2274 local_resume(p, $<nd>6->car); 2240 2275 p->in_def = $<num>4; 2241 p->in_single = (int)(intptr_t)$<nd>6->cdr;2276 p->in_single = intn($<nd>6->cdr); 2242 2277 } 2243 2278 | keyword_module … … 2433 2468 | f_arg ',' 2434 2469 { 2435 $$ = new_args(p, $1, 0, 1, 0, 0);2470 $$ = new_args(p, $1, 0, 0, 0, 0); 2436 2471 } 2437 2472 | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg … … 2561 2596 $$ = $1; 2562 2597 } 2563 | block_call dot_or_colonoperation2 opt_paren_args2564 { 2565 $$ = new_call(p, $1, $3, $4 );2566 } 2567 | block_call dot_or_colonoperation2 opt_paren_args brace_block2568 { 2569 $$ = new_call(p, $1, $3, $4 );2598 | block_call call_op2 operation2 opt_paren_args 2599 { 2600 $$ = new_call(p, $1, $3, $4, $2); 2601 } 2602 | block_call call_op2 operation2 opt_paren_args brace_block 2603 { 2604 $$ = new_call(p, $1, $3, $4, $2); 2570 2605 call_with_block(p, $$, $5); 2571 2606 } 2572 | block_call dot_or_colonoperation2 command_args do_block2573 { 2574 $$ = new_call(p, $1, $3, $4 );2607 | block_call call_op2 operation2 command_args do_block 2608 { 2609 $$ = new_call(p, $1, $3, $4, $2); 2575 2610 call_with_block(p, $$, $5); 2576 2611 } … … 2581 2616 $$ = new_fcall(p, $1, $2); 2582 2617 } 2583 | primary_value '.'operation2 opt_paren_args2584 { 2585 $$ = new_call(p, $1, $3, $4 );2618 | primary_value call_op operation2 opt_paren_args 2619 { 2620 $$ = new_call(p, $1, $3, $4, $2); 2586 2621 } 2587 2622 | primary_value tCOLON2 operation2 paren_args 2588 2623 { 2589 $$ = new_call(p, $1, $3, $4 );2624 $$ = new_call(p, $1, $3, $4, tCOLON2); 2590 2625 } 2591 2626 | primary_value tCOLON2 operation3 2592 2627 { 2593 $$ = new_call(p, $1, $3, 0 );2594 } 2595 | primary_value '.'paren_args2596 { 2597 $$ = new_call(p, $1, intern("call",4), $3 );2628 $$ = new_call(p, $1, $3, 0, tCOLON2); 2629 } 2630 | primary_value call_op paren_args 2631 { 2632 $$ = new_call(p, $1, intern("call",4), $3, $2); 2598 2633 } 2599 2634 | primary_value tCOLON2 paren_args 2600 2635 { 2601 $$ = new_call(p, $1, intern("call",4), $3 );2636 $$ = new_call(p, $1, intern("call",4), $3, tCOLON2); 2602 2637 } 2603 2638 | keyword_super paren_args … … 2611 2646 | primary_value '[' opt_call_args rbracket 2612 2647 { 2613 $$ = new_call(p, $1, intern("[]",2), $3 );2648 $$ = new_call(p, $1, intern("[]",2), $3, '.'); 2614 2649 } 2615 2650 ; … … 2671 2706 ; 2672 2707 2673 exc_list : arg _value2708 exc_list : arg 2674 2709 { 2675 2710 $$ = list1($1); … … 2766 2801 ; 2767 2802 2768 opt_heredoc_bodies : /* none */2769 | heredoc_bodies2770 ;2771 2772 2803 heredoc_bodies : heredoc_body 2773 2804 | heredoc_bodies heredoc_body … … 2825 2856 $$ = new_sym(p, $1); 2826 2857 } 2827 | tSYMBEG tSTRING_BEG string_ interp tSTRING2858 | tSYMBEG tSTRING_BEG string_rep tSTRING 2828 2859 { 2829 2860 p->lstate = EXPR_END; … … 2925 2956 | keyword__FILE__ 2926 2957 { 2927 if (!p->filename) { 2928 p->filename = "(null)"; 2958 const char *fn = p->filename; 2959 if (!fn) { 2960 fn = "(null)"; 2929 2961 } 2930 $$ = new_str(p, p->filename, strlen(p->filename));2962 $$ = new_str(p, fn, strlen(fn)); 2931 2963 } 2932 2964 | keyword__LINE__ … … 2955 2987 { 2956 2988 $$ = $3; 2957 } /* 2989 } /* 2958 2990 | error term 2959 2991 { … … 3098 3130 ; 3099 3131 3100 f_opt : f_opt_asgn arg_value 3101 { 3132 f_opt : f_opt_asgn arg 3133 { 3134 void_expr_error(p, $2); 3102 3135 $$ = cons(nsym($1), $2); 3103 3136 } … … 3106 3139 f_block_opt : f_opt_asgn primary_value 3107 3140 { 3141 void_expr_error(p, $2); 3108 3142 $$ = cons(nsym($1), $2); 3109 3143 } … … 3179 3213 } 3180 3214 else { 3181 switch ((enum node_type) (int)(intptr_t)$3->car) {3215 switch ((enum node_type)intn($3->car)) { 3182 3216 case NODE_STR: 3183 3217 case NODE_DSTR: … … 3216 3250 ; 3217 3251 3218 assoc : arg_value tASSOC arg_value 3219 { 3252 assoc : arg tASSOC arg 3253 { 3254 void_expr_error(p, $1); 3255 void_expr_error(p, $3); 3220 3256 $$ = cons($1, $3); 3221 3257 } 3222 | tLABEL arg_value 3223 { 3258 | tLABEL arg 3259 { 3260 void_expr_error(p, $2); 3224 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); 3225 3277 } 3226 3278 ; … … 3246 3298 ; 3247 3299 3300 call_op : '.' 3301 { 3302 $$ = '.'; 3303 } 3304 | tANDDOT 3305 { 3306 $$ = 0; 3307 } 3308 ; 3309 3310 call_op2 : call_op 3311 | tCOLON2 3312 { 3313 $$ = tCOLON2; 3314 } 3315 ; 3316 3248 3317 opt_terms : /* none */ 3249 3318 | terms … … 3262 3331 trailer : /* none */ 3263 3332 | nl 3264 | ','3333 | comma 3265 3334 ; 3266 3335 3267 3336 term : ';' {yyerrok;} 3268 3337 | nl 3338 | heredoc_body 3269 3339 ; 3270 3340 … … 3274 3344 p->column = 0; 3275 3345 } 3276 opt_heredoc_bodies3346 ; 3277 3347 3278 3348 terms : term 3279 | terms ';' {yyerrok;}3349 | terms term 3280 3350 ; 3281 3351 … … 3286 3356 ; 3287 3357 %% 3288 #define yylval (*((YYSTYPE*)(p->ylval)))3358 #define pylval (*((YYSTYPE*)(p->ylval))) 3289 3359 3290 3360 static void … … 3374 3444 3375 3445 if (c == NODE_NTH_REF) { 3376 yyerror_i(p, "can't set variable $% d", (int)(intptr_t)n->cdr);3446 yyerror_i(p, "can't set variable $%" MRB_PRId, (mrb_int)(intptr_t)n->cdr); 3377 3447 } 3378 3448 else if (c == NODE_BACK_REF) { … … 3381 3451 else { 3382 3452 mrb_bug(p->mrb, "Internal error in backref_error() : n=>car == %S", mrb_fixnum_value(c)); 3453 } 3454 } 3455 3456 static void 3457 void_expr_error(parser_state *p, node *n) 3458 { 3459 int c; 3460 3461 if (n == NULL) return; 3462 c = (int)(intptr_t)n->car; 3463 switch (c) { 3464 case NODE_BREAK: 3465 case NODE_RETURN: 3466 case NODE_NEXT: 3467 case NODE_REDO: 3468 case NODE_RETRY: 3469 yyerror(p, "void value expression"); 3470 break; 3471 case NODE_AND: 3472 case NODE_OR: 3473 void_expr_error(p, n->cdr->car); 3474 void_expr_error(p, n->cdr->cdr); 3475 break; 3476 case NODE_BEGIN: 3477 if (n->cdr) { 3478 while (n->cdr) { 3479 n = n->cdr; 3480 } 3481 void_expr_error(p, n->car); 3482 } 3483 break; 3484 default: 3485 break; 3383 3486 } 3384 3487 } … … 3469 3572 c0 = nextc(p); 3470 3573 if (c0 == -1) return c0; /* do not skip partial EOF */ 3574 if (c0 >= 0) --p->column; 3471 3575 list = push(list, (node*)(intptr_t)c0); 3472 3576 } while(n--); … … 3517 3621 for (;;) { 3518 3622 c = nextc(p); 3519 if (c < 0) return c;3623 if (c < 0) return FALSE; 3520 3624 if (c == '\n') { 3521 3625 p->lineno++; … … 3547 3651 newtok(parser_state *p) 3548 3652 { 3549 p->bidx = 0; 3653 if (p->tokbuf != p->buf) { 3654 mrb_free(p->mrb, p->tokbuf); 3655 p->tokbuf = p->buf; 3656 p->tsiz = MRB_PARSER_TOKBUF_SIZE; 3657 } 3658 p->tidx = 0; 3550 3659 return p->column - 1; 3551 3660 } … … 3555 3664 { 3556 3665 char utf8[4]; 3557 unsignedlen;3666 int i, len; 3558 3667 3559 3668 /* mrb_assert(-0x10FFFF <= c && c <= 0xFF); */ … … 3589 3698 } 3590 3699 } 3591 if (p->bidx+len <= MRB_PARSER_BUF_SIZE) { 3592 unsigned i; 3593 for (i = 0; i < len; i++) { 3594 p->buf[p->bidx++] = utf8[i]; 3595 } 3700 if (p->tidx+len >= p->tsiz) { 3701 if (p->tsiz >= MRB_PARSER_TOKBUF_MAX) { 3702 p->tidx += len; 3703 return; 3704 } 3705 p->tsiz *= 2; 3706 if (p->tokbuf == p->buf) { 3707 p->tokbuf = (char*)mrb_malloc(p->mrb, p->tsiz); 3708 memcpy(p->tokbuf, p->buf, MRB_PARSER_TOKBUF_SIZE); 3709 } 3710 else { 3711 p->tokbuf = (char*)mrb_realloc(p->mrb, p->tokbuf, p->tsiz); 3712 } 3713 } 3714 for (i = 0; i < len; i++) { 3715 p->tokbuf[p->tidx++] = utf8[i]; 3596 3716 } 3597 3717 } … … 3600 3720 toklast(parser_state *p) 3601 3721 { 3602 return p-> buf[p->bidx-1];3722 return p->tokbuf[p->tidx-1]; 3603 3723 } 3604 3724 … … 3606 3726 tokfix(parser_state *p) 3607 3727 { 3608 int i = p->bidx, imax = MRB_PARSER_BUF_SIZE - 1; 3609 3610 if (i > imax) { 3611 i = imax; 3728 if (p->tidx >= MRB_PARSER_TOKBUF_MAX) { 3729 p->tidx = MRB_PARSER_TOKBUF_MAX-1; 3612 3730 yyerror(p, "string too long (truncated)"); 3613 3731 } 3614 p-> buf[i] = '\0';3732 p->tokbuf[p->tidx] = '\0'; 3615 3733 } 3616 3734 … … 3618 3736 tok(parser_state *p) 3619 3737 { 3620 return p-> buf;3738 return p->tokbuf; 3621 3739 } 3622 3740 … … 3624 3742 toklen(parser_state *p) 3625 3743 { 3626 return p-> bidx;3744 return p->tidx; 3627 3745 } 3628 3746 … … 3667 3785 3668 3786 return retval; 3787 } 3788 3789 static int32_t 3790 read_escape_unicode(parser_state *p, int limit) 3791 { 3792 int32_t c; 3793 int buf[9]; 3794 int i; 3795 3796 /* Look for opening brace */ 3797 i = 0; 3798 buf[0] = nextc(p); 3799 if (buf[0] < 0) goto eof; 3800 if (ISXDIGIT(buf[0])) { 3801 /* \uxxxx form */ 3802 for (i=1; i<limit; i++) { 3803 buf[i] = nextc(p); 3804 if (buf[i] < 0) goto eof; 3805 if (!ISXDIGIT(buf[i])) { 3806 pushback(p, buf[i]); 3807 break; 3808 } 3809 } 3810 } 3811 else { 3812 pushback(p, buf[0]); 3813 } 3814 c = scan_hex(buf, i, &i); 3815 if (i == 0) { 3816 eof: 3817 yyerror(p, "Invalid escape character syntax"); 3818 return -1; 3819 } 3820 if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) { 3821 yyerror(p, "Invalid Unicode code point"); 3822 return -1; 3823 } 3824 return c; 3669 3825 } 3670 3826 … … 3741 3897 3742 3898 case 'u': /* Unicode */ 3743 { 3744 int buf[9]; 3745 int i; 3746 3747 /* Look for opening brace */ 3748 i = 0; 3749 buf[0] = nextc(p); 3750 if (buf[0] < 0) goto eof; 3751 if (buf[0] == '{') { 3899 if (peek(p, '{')) { 3752 3900 /* \u{xxxxxxxx} form */ 3753 for (i=0; i<9; i++) { 3754 buf[i] = nextc(p); 3755 if (buf[i] < 0) goto eof; 3756 if (buf[i] == '}') { 3757 break; 3758 } 3759 else if (!ISXDIGIT(buf[i])) { 3760 yyerror(p, "Invalid escape character syntax"); 3761 pushback(p, buf[i]); 3762 return 0; 3763 } 3764 } 3765 } 3766 else if (ISXDIGIT(buf[0])) { 3767 /* \uxxxx form */ 3768 for (i=1; i<4; i++) { 3769 buf[i] = nextc(p); 3770 if (buf[i] < 0) goto eof; 3771 if (!ISXDIGIT(buf[i])) { 3772 pushback(p, buf[i]); 3773 break; 3774 } 3775 } 3901 nextc(p); 3902 c = read_escape_unicode(p, 8); 3903 if (c < 0) return 0; 3904 if (nextc(p) != '}') goto eof; 3776 3905 } 3777 3906 else { 3778 pushback(p, buf[0]); 3779 } 3780 c = scan_hex(buf, i, &i); 3781 if (i == 0) { 3782 yyerror(p, "Invalid escape character syntax"); 3783 return 0; 3784 } 3785 if (c < 0 || c > 0x10FFFF || (c & 0xFFFFF800) == 0xD800) { 3786 yyerror(p, "Invalid Unicode code point"); 3787 return 0; 3788 } 3789 } 3907 c = read_escape_unicode(p, 4); 3908 if (c < 0) return 0; 3909 } 3790 3910 return -c; 3791 3911 … … 3845 3965 int end = (intptr_t)p->lex_strterm->cdr->cdr->cdr; 3846 3966 parser_heredoc_info *hinf = (type & STR_FUNC_HEREDOC) ? parsing_heredoc_inf(p) : NULL; 3847 3967 int cmd_state = p->cmd_start; 3968 3969 if (beg == 0) beg = -3; /* should never happen */ 3970 if (end == 0) end = -3; 3848 3971 newtok(p); 3849 3972 while ((c = nextc(p)) != end || nest_level != 0) { … … 3867 3990 } 3868 3991 if ((len-1 == hinf->term_len) && (strncmp(s, hinf->term, len-1) == 0)) { 3869 return tHEREDOC_END; 3992 if (c < 0) { 3993 p->parsing_heredoc = NULL; 3994 } 3995 else { 3996 return tHEREDOC_END; 3997 } 3870 3998 } 3871 3999 } … … 3876 4004 return 0; 3877 4005 } 3878 yylval.nd = new_str(p, tok(p), toklen(p));4006 pylval.nd = new_str(p, tok(p), toklen(p)); 3879 4007 return tHD_STRING_MID; 3880 4008 } … … 3908 4036 tokadd(p, c); 3909 4037 } 4038 else if (c == 'u' && peek(p, '{')) { 4039 /* \u{xxxx xxxx xxxx} form */ 4040 nextc(p); 4041 while (1) { 4042 do c = nextc(p); while (ISSPACE(c)); 4043 if (c == '}') break; 4044 pushback(p, c); 4045 c = read_escape_unicode(p, 8); 4046 if (c < 0) break; 4047 tokadd(p, -c); 4048 } 4049 if (hinf) 4050 hinf->line_head = FALSE; 4051 } 3910 4052 else { 3911 4053 pushback(p, c); … … 3935 4077 p->lstate = EXPR_BEG; 3936 4078 p->cmd_start = TRUE; 3937 yylval.nd = new_str(p, tok(p), toklen(p));4079 pylval.nd = new_str(p, tok(p), toklen(p)); 3938 4080 if (hinf) { 3939 4081 hinf->line_head = FALSE; … … 3965 4107 pushback(p, c); 3966 4108 tokfix(p); 3967 yylval.nd = new_str(p, tok(p), toklen(p));4109 pylval.nd = new_str(p, tok(p), toklen(p)); 3968 4110 return tSTRING_MID; 3969 4111 } 4112 } 4113 if (c == '\n') { 4114 p->lineno++; 4115 p->column = 0; 3970 4116 } 3971 4117 tokadd(p, c); … … 3977 4123 3978 4124 if (type & STR_FUNC_XQUOTE) { 3979 yylval.nd = new_xstr(p, tok(p), toklen(p));4125 pylval.nd = new_xstr(p, tok(p), toklen(p)); 3980 4126 return tXSTRING; 3981 4127 } … … 4019 4165 if (flag > flags) { 4020 4166 dup = strndup(flags, (size_t)(flag - flags)); 4021 } else { 4167 } 4168 else { 4022 4169 dup = NULL; 4023 4170 } 4024 4171 if (enc) { 4025 4172 encp = strndup(&enc, 1); 4026 } else { 4173 } 4174 else { 4027 4175 encp = NULL; 4028 4176 } 4029 yylval.nd = new_regx(p, s, dup, encp);4177 pylval.nd = new_regx(p, s, dup, encp); 4030 4178 4031 4179 return tREGEXP; 4032 4180 } 4033 4034 yylval.nd = new_str(p, tok(p), toklen(p)); 4181 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 4035 4190 return tSTRING; 4036 4191 } … … 4102 4257 p->lstate = EXPR_END; 4103 4258 4104 yylval.nd = newnode;4259 pylval.nd = newnode; 4105 4260 return tHEREDOC_BEG; 4106 4261 } … … 4206 4361 if ((c = nextc(p)) == '*') { 4207 4362 if ((c = nextc(p)) == '=') { 4208 yylval.id = intern("**",2);4363 pylval.id = intern("**",2); 4209 4364 p->lstate = EXPR_BEG; 4210 4365 return tOP_ASGN; … … 4215 4370 else { 4216 4371 if (c == '=') { 4217 yylval.id = intern_c('*');4372 pylval.id = intern_c('*'); 4218 4373 p->lstate = EXPR_BEG; 4219 4374 return tOP_ASGN; … … 4331 4486 if (c == '<') { 4332 4487 if ((c = nextc(p)) == '=') { 4333 yylval.id = intern("<<",2);4488 pylval.id = intern("<<",2); 4334 4489 p->lstate = EXPR_BEG; 4335 4490 return tOP_ASGN; … … 4353 4508 if (c == '>') { 4354 4509 if ((c = nextc(p)) == '=') { 4355 yylval.id = intern(">>",2);4510 pylval.id = intern(">>",2); 4356 4511 p->lstate = EXPR_BEG; 4357 4512 return tOP_ASGN; … … 4450 4605 } 4451 4606 tokfix(p); 4452 yylval.nd = new_str(p, tok(p), toklen(p));4607 pylval.nd = new_str(p, tok(p), toklen(p)); 4453 4608 p->lstate = EXPR_END; 4454 4609 return tCHAR; … … 4458 4613 p->lstate = EXPR_BEG; 4459 4614 if ((c = nextc(p)) == '=') { 4460 yylval.id = intern("&&",2);4615 pylval.id = intern("&&",2); 4461 4616 p->lstate = EXPR_BEG; 4462 4617 return tOP_ASGN; … … 4465 4620 return tANDOP; 4466 4621 } 4622 else if (c == '.') { 4623 p->lstate = EXPR_DOT; 4624 return tANDDOT; 4625 } 4467 4626 else if (c == '=') { 4468 yylval.id = intern_c('&');4627 pylval.id = intern_c('&'); 4469 4628 p->lstate = EXPR_BEG; 4470 4629 return tOP_ASGN; … … 4493 4652 p->lstate = EXPR_BEG; 4494 4653 if ((c = nextc(p)) == '=') { 4495 yylval.id = intern("||",2);4654 pylval.id = intern("||",2); 4496 4655 p->lstate = EXPR_BEG; 4497 4656 return tOP_ASGN; … … 4501 4660 } 4502 4661 if (c == '=') { 4503 yylval.id = intern_c('|');4662 pylval.id = intern_c('|'); 4504 4663 p->lstate = EXPR_BEG; 4505 4664 return tOP_ASGN; … … 4525 4684 } 4526 4685 if (c == '=') { 4527 yylval.id = intern_c('+');4686 pylval.id = intern_c('+'); 4528 4687 p->lstate = EXPR_BEG; 4529 4688 return tOP_ASGN; … … 4553 4712 } 4554 4713 if (c == '=') { 4555 yylval.id = intern_c('-');4714 pylval.id = intern_c('-'); 4556 4715 p->lstate = EXPR_BEG; 4557 4716 return tOP_ASGN; … … 4627 4786 } 4628 4787 else if (nondigit) goto trailing_uc; 4629 yylval.nd = new_int(p, tok(p), 16);4788 pylval.nd = new_int(p, tok(p), 16); 4630 4789 return tINTEGER; 4631 4790 } … … 4651 4810 } 4652 4811 else if (nondigit) goto trailing_uc; 4653 yylval.nd = new_int(p, tok(p), 2);4812 pylval.nd = new_int(p, tok(p), 2); 4654 4813 return tINTEGER; 4655 4814 } … … 4675 4834 } 4676 4835 else if (nondigit) goto trailing_uc; 4677 yylval.nd = new_int(p, tok(p), 10);4836 pylval.nd = new_int(p, tok(p), 10); 4678 4837 return tINTEGER; 4679 4838 } … … 4708 4867 tokfix(p); 4709 4868 if (nondigit) goto trailing_uc; 4710 yylval.nd = new_int(p, tok(p), 8);4869 pylval.nd = new_int(p, tok(p), 8); 4711 4870 return tINTEGER; 4712 4871 } … … 4725 4884 else { 4726 4885 pushback(p, c); 4727 yylval.nd = new_int(p, "0", 10);4886 pylval.nd = new_int(p, "0", 10); 4728 4887 return tINTEGER; 4729 4888 } … … 4801 4960 4802 4961 errno = 0; 4803 d = strtod(tok(p), &endp);4962 d = mrb_float_read(tok(p), &endp); 4804 4963 if (d == 0 && endp == tok(p)) { 4805 4964 yywarning_s(p, "corrupted float value %s", tok(p)); … … 4809 4968 errno = 0; 4810 4969 } 4811 yylval.nd = new_float(p, tok(p));4970 pylval.nd = new_float(p, tok(p)); 4812 4971 return tFLOAT; 4813 4972 } 4814 yylval.nd = new_int(p, tok(p), 10);4973 pylval.nd = new_int(p, tok(p), 10); 4815 4974 return tINTEGER; 4816 4975 } … … 4854 5013 } 4855 5014 if ((c = nextc(p)) == '=') { 4856 yylval.id = intern_c('/');5015 pylval.id = intern_c('/'); 4857 5016 p->lstate = EXPR_BEG; 4858 5017 return tOP_ASGN; … … 4873 5032 case '^': 4874 5033 if ((c = nextc(p)) == '=') { 4875 yylval.id = intern_c('^');5034 pylval.id = intern_c('^'); 4876 5035 p->lstate = EXPR_BEG; 4877 5036 return tOP_ASGN; … … 5047 5206 } 5048 5207 if ((c = nextc(p)) == '=') { 5049 yylval.id = intern_c('%');5208 pylval.id = intern_c('%'); 5050 5209 p->lstate = EXPR_BEG; 5051 5210 return tOP_ASGN; … … 5101 5260 tokadd(p, c); 5102 5261 tokfix(p); 5103 yylval.id = intern_cstr(tok(p));5262 pylval.id = intern_cstr(tok(p)); 5104 5263 return tGVAR; 5105 5264 … … 5111 5270 gvar: 5112 5271 tokfix(p); 5113 yylval.id = intern_cstr(tok(p));5272 pylval.id = intern_cstr(tok(p)); 5114 5273 return tGVAR; 5115 5274 … … 5123 5282 goto gvar; 5124 5283 } 5125 yylval.nd = new_back_ref(p, c);5284 pylval.nd = new_back_ref(p, c); 5126 5285 return tBACK_REF; 5127 5286 … … 5142 5301 return 0; 5143 5302 } 5144 yylval.nd = new_nth_ref(p, (int)n);5303 pylval.nd = new_nth_ref(p, (int)n); 5145 5304 } 5146 5305 return tNTH_REF; … … 5166 5325 } 5167 5326 if (c < 0) { 5168 if (p-> bidx == 1) {5327 if (p->tidx == 1) { 5169 5328 yyerror(p, "incomplete instance variable syntax"); 5170 5329 } … … 5175 5334 } 5176 5335 else if (isdigit(c)) { 5177 if (p-> bidx == 1) {5336 if (p->tidx == 1) { 5178 5337 yyerror_i(p, "'@%c' is not allowed as an instance variable name", c); 5179 5338 } … … 5270 5429 nextc(p); 5271 5430 tokfix(p); 5272 yylval.id = intern_cstr(tok(p));5431 pylval.id = intern_cstr(tok(p)); 5273 5432 return tLABEL; 5274 5433 } … … 5281 5440 if (kw) { 5282 5441 enum mrb_lex_state_enum state = p->lstate; 5283 yylval.num = p->lineno;5442 pylval.num = p->lineno; 5284 5443 p->lstate = kw->state; 5285 5444 if (state == EXPR_FNAME) { 5286 yylval.id = intern_cstr(kw->name);5445 pylval.id = intern_cstr(kw->name); 5287 5446 return kw->id[0]; 5288 5447 } … … 5331 5490 mrb_sym ident = intern_cstr(tok(p)); 5332 5491 5333 yylval.id = ident;5492 pylval.id = ident; 5334 5493 #if 0 5335 5494 if (last_state != EXPR_DOT && islower(tok(p)[0]) && lvar_defined(ident)) { … … 5396 5555 mrb_parser_parse(parser_state *p, mrbc_context *c) 5397 5556 { 5398 struct mrb_jmpbuf buf ;5399 p->jmp = &buf ;5557 struct mrb_jmpbuf buf1; 5558 p->jmp = &buf1; 5400 5559 5401 5560 MRB_TRY(p->jmp) { 5561 int n; 5402 5562 5403 5563 p->cmd_start = TRUE; … … 5407 5567 5408 5568 parser_init_cxt(p, c); 5409 yyparse(p); 5569 5570 if (p->mrb->jmp) { 5571 n = yyparse(p); 5572 } 5573 else { 5574 struct mrb_jmpbuf buf2; 5575 5576 p->mrb->jmp = &buf2; 5577 MRB_TRY(p->mrb->jmp) { 5578 n = yyparse(p); 5579 } 5580 MRB_CATCH(p->mrb->jmp) { 5581 p->nerr++; 5582 } 5583 MRB_END_EXC(p->mrb->jmp); 5584 p->mrb->jmp = 0; 5585 } 5586 if (n != 0 || p->nerr > 0) { 5587 p->tree = 0; 5588 return; 5589 } 5410 5590 if (!p->tree) { 5411 5591 p->tree = new_nil(p); … … 5415 5595 mrb_parser_dump(p->mrb, p->tree, 0); 5416 5596 } 5417 5418 5597 } 5419 5598 MRB_CATCH(p->jmp) { … … 5443 5622 5444 5623 p->s = p->send = NULL; 5445 #ifndef MRB_DIS BLE_STDIO5624 #ifndef MRB_DISABLE_STDIO 5446 5625 p->f = NULL; 5447 5626 #endif … … 5456 5635 yydebug = 1; 5457 5636 #endif 5637 p->tsiz = MRB_PARSER_TOKBUF_SIZE; 5638 p->tokbuf = p->buf; 5458 5639 5459 5640 p->lex_strterm = NULL; … … 5470 5651 MRB_API void 5471 5652 mrb_parser_free(parser_state *p) { 5653 if (p->tokbuf != p->buf) { 5654 mrb_free(p->mrb, p->tokbuf); 5655 } 5472 5656 mrb_pool_close(p->pool); 5473 5657 } … … 5482 5666 mrbc_context_free(mrb_state *mrb, mrbc_context *cxt) 5483 5667 { 5668 mrb_free(mrb, cxt->filename); 5484 5669 mrb_free(mrb, cxt->syms); 5485 5670 mrb_free(mrb, cxt); … … 5491 5676 if (s) { 5492 5677 int len = strlen(s); 5493 char *p = (char *)mrb_ alloca(mrb, len + 1);5678 char *p = (char *)mrb_malloc(mrb, len + 1); 5494 5679 5495 5680 memcpy(p, s, len + 1); 5681 if (c->filename) { 5682 mrb_free(mrb, c->filename); 5683 } 5496 5684 c->filename = p; 5497 5685 } … … 5578 5766 } 5579 5767 5580 staticmrb_value5581 load_exec(mrb_state *mrb,parser_state *p, mrbc_context *c)5768 MRB_API mrb_value 5769 mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c) 5582 5770 { 5583 5771 struct RClass *target = mrb->object_class; … … 5601 5789 } 5602 5790 else { 5603 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error")); 5791 if (mrb->exc == NULL) { 5792 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SYNTAX_ERROR, "syntax error")); 5793 } 5604 5794 mrb_parser_free(p); 5605 5795 return mrb_undef_value(); … … 5609 5799 mrb_parser_free(p); 5610 5800 if (proc == NULL) { 5611 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error")); 5801 if (mrb->exc == NULL) { 5802 mrb->exc = mrb_obj_ptr(mrb_exc_new_str_lit(mrb, E_SCRIPT_ERROR, "codegen error")); 5803 } 5612 5804 return mrb_undef_value(); 5613 5805 } … … 5629 5821 mrb->c->ci->target_class = target; 5630 5822 } 5631 v = mrb_top level_run_keep(mrb, proc, keep);5823 v = mrb_top_run(mrb, proc, mrb_top_self(mrb), keep); 5632 5824 if (mrb->exc) return mrb_nil_value(); 5633 5825 return v; … … 5638 5830 mrb_load_file_cxt(mrb_state *mrb, FILE *f, mrbc_context *c) 5639 5831 { 5640 return load_exec(mrb, mrb_parse_file(mrb, f, c), c);5832 return mrb_load_exec(mrb, mrb_parse_file(mrb, f, c), c); 5641 5833 } 5642 5834 … … 5651 5843 mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *c) 5652 5844 { 5653 return load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c);5845 return mrb_load_exec(mrb, mrb_parse_nstring(mrb, s, len, c), c); 5654 5846 } 5655 5847 … … 5805 5997 dump_recur(mrb, n->car, offset+2); 5806 5998 } 5807 n = n->cdr; 5808 if (n) { 5999 if (n->cdr) { 5809 6000 dump_prefix(n, offset+1); 5810 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n )));6001 printf("blk=&%s\n", mrb_sym2name(mrb, sym(n->cdr))); 5811 6002 } 5812 6003 } … … 5946 6137 case NODE_FCALL: 5947 6138 case NODE_CALL: 5948 printf("NODE_CALL:\n"); 6139 case NODE_SCALL: 6140 switch (nodetype) { 6141 case NODE_FCALL: 6142 printf("NODE_FCALL:\n"); break; 6143 case NODE_CALL: 6144 printf("NODE_CALL(.):\n"); break; 6145 case NODE_SCALL: 6146 printf("NODE_SCALL(&.):\n"); break; 6147 default: 6148 break; 6149 } 5949 6150 mrb_parser_dump(mrb, tree->car, offset+1); 5950 6151 dump_prefix(tree, offset+1); … … 6154 6355 6155 6356 case NODE_NTH_REF: 6156 printf("NODE_NTH_REF: $% d\n", (int)(intptr_t)tree);6357 printf("NODE_NTH_REF: $%" MRB_PRId "\n", (mrb_int)(intptr_t)tree); 6157 6358 break; 6158 6359 … … 6206 6407 dump_prefix(tree, offset); 6207 6408 printf("tail: %s\n", (char*)tree->cdr->cdr->car); 6208 dump_prefix(tree, offset); 6209 printf("opt: %s\n", (char*)tree->cdr->cdr->cdr); 6409 if (tree->cdr->cdr->cdr->car) { 6410 dump_prefix(tree, offset); 6411 printf("opt: %s\n", (char*)tree->cdr->cdr->cdr->car); 6412 } 6413 if (tree->cdr->cdr->cdr->cdr) { 6414 dump_prefix(tree, offset); 6415 printf("enc: %s\n", (char*)tree->cdr->cdr->cdr->cdr); 6416 } 6210 6417 break; 6211 6418 6212 6419 case NODE_SYM: 6213 printf("NODE_SYM :%s\n", mrb_sym2name(mrb, sym(tree))); 6420 printf("NODE_SYM :%s (%d)\n", mrb_sym2name(mrb, sym(tree)), 6421 (int)(intptr_t)tree); 6214 6422 break; 6215 6423 … … 6425 6633 6426 6634 case NODE_HEREDOC: 6427 printf("NODE_HEREDOC :\n");6428 mrb_parser_dump(mrb, ((parser_heredoc_info*)tree)->doc, offset+1);6635 printf("NODE_HEREDOC (<<%s):\n", ((parser_heredoc_info*)tree)->term); 6636 dump_recur(mrb, ((parser_heredoc_info*)tree)->doc, offset+1); 6429 6637 break; 6430 6638 -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-compiler/mrbgem.rake
r321 r331 9 9 lex_def = "#{current_dir}/core/lex.def" 10 10 core_objs = Dir.glob("#{current_dir}/core/*.c").map { |f| 11 next nil if build.cxx_ abi_enabled? and f =~ /(codegen).c$/11 next nil if build.cxx_exception_enabled? and f =~ /(codegen).c$/ 12 12 objfile(f.pathmap("#{current_build_dir}/core/%n")) 13 13 }.compact 14 14 15 if build.cxx_ abi_enabled?15 if build.cxx_exception_enabled? 16 16 core_objs << 17 17 build.compile_as_cxx("#{current_build_dir}/core/y.tab.c", "#{current_build_dir}/core/y.tab.cxx",
Note:
See TracChangeset
for help on using the changeset viewer.