diff options
author | Mike Pall <mike> | 2013-04-21 01:01:33 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-04-21 01:01:33 +0200 |
commit | 5f1781a1277508c2b7bec527f722da98d8556e26 (patch) | |
tree | e1bbc8b5b4af7c7b374a0139225a585aa0009fdf /src/lj_record.c | |
parent | 7b629b7bcf6bca3bd7733db601722c551098557e (diff) | |
download | luajit-5f1781a1277508c2b7bec527f722da98d8556e26.tar.gz luajit-5f1781a1277508c2b7bec527f722da98d8556e26.tar.bz2 luajit-5f1781a1277508c2b7bec527f722da98d8556e26.zip |
Compile string concatenations (BC_CAT).
Diffstat (limited to 'src/lj_record.c')
-rw-r--r-- | src/lj_record.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/lj_record.c b/src/lj_record.c index 003910a9..bbabd3ce 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #if LJ_HASJIT | 11 | #if LJ_HASJIT |
12 | 12 | ||
13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
14 | #include "lj_buf.h" | ||
14 | #include "lj_str.h" | 15 | #include "lj_str.h" |
15 | #include "lj_tab.h" | 16 | #include "lj_tab.h" |
16 | #include "lj_meta.h" | 17 | #include "lj_meta.h" |
@@ -1599,6 +1600,33 @@ static TRef rec_tnew(jit_State *J, uint32_t ah) | |||
1599 | return emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits); | 1600 | return emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits); |
1600 | } | 1601 | } |
1601 | 1602 | ||
1603 | /* -- Concatenation ------------------------------------------------------- */ | ||
1604 | |||
1605 | static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot) | ||
1606 | { | ||
1607 | TRef *top = &J->base[topslot], tr = *top; | ||
1608 | lua_assert(baseslot < topslot); | ||
1609 | if (tref_isnumber_str(tr) && tref_isnumber_str(*(top-1))) { | ||
1610 | TRef hdr, *trp, *xbase, *base = &J->base[baseslot]; | ||
1611 | /* First convert number consts to string consts to simplify FOLD rules. */ | ||
1612 | for (trp = top; trp >= base && tref_isnumber_str(*trp); trp--) | ||
1613 | if (tref_isk(*trp) && tref_isnumber(*trp)) | ||
1614 | *trp = emitir(IRT(IR_TOSTR, IRT_STR), *trp, 0); | ||
1615 | xbase = ++trp; | ||
1616 | tr = hdr = emitir(IRT(IR_BUFHDR, IRT_P32), | ||
1617 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
1618 | do { | ||
1619 | tr = emitir(IRT(IR_BUFPUT, IRT_P32), tr, *trp++); | ||
1620 | } while (trp <= top); | ||
1621 | tr = emitir(IRT(IR_BUFSTR, IRT_STR), hdr, tr); | ||
1622 | J->maxslot = (BCReg)(xbase - J->base); | ||
1623 | if (xbase == base) return tr; | ||
1624 | } | ||
1625 | setintV(&J->errinfo, BC_CAT); | ||
1626 | lj_trace_err_info(J, LJ_TRERR_NYIBC); /* __concat metamethod. */ | ||
1627 | return 0; | ||
1628 | } | ||
1629 | |||
1602 | /* -- Record bytecode ops ------------------------------------------------- */ | 1630 | /* -- Record bytecode ops ------------------------------------------------- */ |
1603 | 1631 | ||
1604 | /* Prepare for comparison. */ | 1632 | /* Prepare for comparison. */ |
@@ -1901,6 +1929,12 @@ void lj_record_ins(jit_State *J) | |||
1901 | rc = rec_mm_arith(J, &ix, MM_pow); | 1929 | rc = rec_mm_arith(J, &ix, MM_pow); |
1902 | break; | 1930 | break; |
1903 | 1931 | ||
1932 | /* -- Miscellaneous ops ------------------------------------------------- */ | ||
1933 | |||
1934 | case BC_CAT: | ||
1935 | rc = rec_cat(J, rb, rc); | ||
1936 | break; | ||
1937 | |||
1904 | /* -- Constant and move ops --------------------------------------------- */ | 1938 | /* -- Constant and move ops --------------------------------------------- */ |
1905 | 1939 | ||
1906 | case BC_MOV: | 1940 | case BC_MOV: |
@@ -2082,7 +2116,6 @@ void lj_record_ins(jit_State *J) | |||
2082 | /* fallthrough */ | 2116 | /* fallthrough */ |
2083 | case BC_ITERN: | 2117 | case BC_ITERN: |
2084 | case BC_ISNEXT: | 2118 | case BC_ISNEXT: |
2085 | case BC_CAT: | ||
2086 | case BC_UCLO: | 2119 | case BC_UCLO: |
2087 | case BC_FNEW: | 2120 | case BC_FNEW: |
2088 | case BC_TSETM: | 2121 | case BC_TSETM: |