diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-29 08:03:51 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-29 08:03:51 +0000 |
commit | d5c8ad535961968b40823512ccdb12e38f1ed529 (patch) | |
tree | ec9fda92b59a605bc0a836f625a71e871a23a6a7 /compile.c | |
parent | 65615986ec0cfc5971c990abe46643b0edbcab8d (diff) | |
download | ruby-d5c8ad535961968b40823512ccdb12e38f1ed529.tar.gz |
* insns.def (toregexp): generate a regexp from strings instead of one
string.
* re.c (rb_reg_new_ary): defined for toregexp. it concatenates
strings after each string is preprocessed.
* compile.c (compile_dstr_fragments): split from compile_dstr.
(compile_dstr): call compile_dstr_fragments.
(compile_dregx): defined for dynamic regexp.
(iseq_compile_each): use compile_dregx for dynamic regexp.
[ruby-dev:33400]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -1853,7 +1853,7 @@ iseq_set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor) static int -compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) +compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int *cntp) { NODE *list = node->nd_next; VALUE lit = node->nd_lit; @@ -1867,12 +1867,30 @@ compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) cnt++; list = list->nd_next; } + *cntp = cnt; + + return COMPILE_OK; +} +static int +compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) +{ + int cnt; + compile_dstr_fragments(iseq, ret, node, &cnt); ADD_INSN1(ret, nd_line(node), concatstrings, INT2FIX(cnt)); return COMPILE_OK; } static int +compile_dregx(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) +{ + int cnt; + compile_dstr_fragments(iseq, ret, node, &cnt); + ADD_INSN2(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag), INT2FIX(cnt)); + return COMPILE_OK; +} + +static int compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond, LABEL *then_label, LABEL *else_label) { @@ -4111,8 +4129,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) break; } case NODE_DREGX:{ - compile_dstr(iseq, ret, node); - ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); + compile_dregx(iseq, ret, node); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -4128,8 +4145,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN2(ret, nd_line(node), onceinlinecache, 0, lend); ADD_INSN(ret, nd_line(node), pop); - compile_dstr(iseq, ret, node); - ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); + compile_dregx(iseq, ret, node); ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); ADD_LABEL(ret, lend); |