mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_core.h: define vm_svar_index.
* vm_insnhelper.c, vm.c, compile.c: use vm_svar_index names. * iseq.h: remove DEFAULT_SPECIAL_VAR_COUNT. use VM_SVAR_FLIPFLOP_START instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
689df4ae2a
commit
ca6b174078
6 changed files with 36 additions and 21 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Fri Feb 27 17:06:44 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* vm_core.h: define vm_svar_index.
|
||||||
|
|
||||||
|
* vm_insnhelper.c, vm.c, compile.c: use vm_svar_index names.
|
||||||
|
|
||||||
|
* iseq.h: remove DEFAULT_SPECIAL_VAR_COUNT.
|
||||||
|
use VM_SVAR_FLIPFLOP_START instead.
|
||||||
|
|
||||||
Fri Feb 27 13:57:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Feb 27 13:57:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (setup_narg): wipe away expanded part of buffer to get rid
|
* io.c (setup_narg): wipe away expanded part of buffer to get rid
|
||||||
|
|
|
@ -5288,7 +5288,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
||||||
rb_num_t cnt;
|
rb_num_t cnt;
|
||||||
VALUE key;
|
VALUE key;
|
||||||
|
|
||||||
cnt = local_iseq->flip_cnt++ + DEFAULT_SPECIAL_VAR_COUNT;
|
cnt = local_iseq->flip_cnt++ + VM_SVAR_FLIPFLOP_START;
|
||||||
key = INT2FIX(cnt);
|
key = INT2FIX(cnt);
|
||||||
|
|
||||||
ADD_INSN2(ret, line, getspecial, key, INT2FIX(0));
|
ADD_INSN2(ret, line, getspecial, key, INT2FIX(0));
|
||||||
|
|
2
iseq.h
2
iseq.h
|
@ -151,8 +151,6 @@ enum defined_type {
|
||||||
|
|
||||||
VALUE rb_iseq_defined_string(enum defined_type type);
|
VALUE rb_iseq_defined_string(enum defined_type type);
|
||||||
|
|
||||||
#define DEFAULT_SPECIAL_VAR_COUNT 2
|
|
||||||
|
|
||||||
RUBY_SYMBOL_EXPORT_END
|
RUBY_SYMBOL_EXPORT_END
|
||||||
|
|
||||||
#endif /* RUBY_COMPILE_H */
|
#endif /* RUBY_COMPILE_H */
|
||||||
|
|
8
vm.c
8
vm.c
|
@ -943,25 +943,25 @@ vm_svar_set(VALUE key, VALUE val)
|
||||||
VALUE
|
VALUE
|
||||||
rb_backref_get(void)
|
rb_backref_get(void)
|
||||||
{
|
{
|
||||||
return vm_svar_get(1);
|
return vm_svar_get(VM_SVAR_BACKREF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_backref_set(VALUE val)
|
rb_backref_set(VALUE val)
|
||||||
{
|
{
|
||||||
vm_svar_set(1, val);
|
vm_svar_set(VM_SVAR_BACKREF, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_lastline_get(void)
|
rb_lastline_get(void)
|
||||||
{
|
{
|
||||||
return vm_svar_get(0);
|
return vm_svar_get(VM_SVAR_LASTLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_lastline_set(VALUE val)
|
rb_lastline_set(VALUE val)
|
||||||
{
|
{
|
||||||
vm_svar_set(0, val);
|
vm_svar_set(VM_SVAR_LASTLINE, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* misc */
|
/* misc */
|
||||||
|
|
|
@ -838,6 +838,14 @@ enum vm_special_object_type {
|
||||||
VM_SPECIAL_OBJECT_CONST_BASE
|
VM_SPECIAL_OBJECT_CONST_BASE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum vm_svar_index {
|
||||||
|
VM_SVAR_LASTLINE = 0, /* $_ */
|
||||||
|
VM_SVAR_BACKREF = 1, /* $~ */
|
||||||
|
|
||||||
|
VM_SVAR_EXTRA_START = 2,
|
||||||
|
VM_SVAR_FLIPFLOP_START = 2 /* flipflop */
|
||||||
|
};
|
||||||
|
|
||||||
#define VM_FRAME_MAGIC_METHOD 0x11
|
#define VM_FRAME_MAGIC_METHOD 0x11
|
||||||
#define VM_FRAME_MAGIC_BLOCK 0x21
|
#define VM_FRAME_MAGIC_BLOCK 0x21
|
||||||
#define VM_FRAME_MAGIC_CLASS 0x31
|
#define VM_FRAME_MAGIC_CLASS 0x31
|
||||||
|
|
|
@ -140,11 +140,11 @@ rb_error_arity(int argc, int min, int max)
|
||||||
/* svar */
|
/* svar */
|
||||||
|
|
||||||
static inline NODE **
|
static inline NODE **
|
||||||
lep_svar_place(rb_thread_t *th, VALUE *lep)
|
lep_svar_place(rb_thread_t *th, const VALUE *lep)
|
||||||
{
|
{
|
||||||
VALUE *svar;
|
const VALUE *svar;
|
||||||
|
|
||||||
if (lep && th->root_lep != lep) {
|
if (lep && (th == NULL || th->root_lep != lep)) {
|
||||||
svar = &lep[-1];
|
svar = &lep[-1];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -155,17 +155,17 @@ lep_svar_place(rb_thread_t *th, VALUE *lep)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
lep_svar_get(rb_thread_t *th, VALUE *lep, rb_num_t key)
|
lep_svar_get(rb_thread_t *th, const VALUE *lep, rb_num_t key)
|
||||||
{
|
{
|
||||||
NODE **svar_place = lep_svar_place(th, lep);
|
NODE ** const svar_place = lep_svar_place(th, lep);
|
||||||
NODE *svar = *svar_place;
|
const NODE * const svar = *svar_place;
|
||||||
|
|
||||||
if (NIL_P((VALUE)svar)) return Qnil;
|
if (NIL_P((VALUE)svar)) return Qnil;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 0:
|
case VM_SVAR_LASTLINE:
|
||||||
return svar->u1.value;
|
return svar->u1.value;
|
||||||
case 1:
|
case VM_SVAR_BACKREF:
|
||||||
return svar->u2.value;
|
return svar->u2.value;
|
||||||
default: {
|
default: {
|
||||||
const VALUE ary = svar->u3.value;
|
const VALUE ary = svar->u3.value;
|
||||||
|
@ -174,7 +174,7 @@ lep_svar_get(rb_thread_t *th, VALUE *lep, rb_num_t key)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_ary_entry(ary, key - DEFAULT_SPECIAL_VAR_COUNT);
|
return rb_ary_entry(ary, key - VM_SVAR_EXTRA_START);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ lep_svar_get(rb_thread_t *th, VALUE *lep, rb_num_t key)
|
||||||
static void
|
static void
|
||||||
lep_svar_set(rb_thread_t *th, VALUE *lep, rb_num_t key, VALUE val)
|
lep_svar_set(rb_thread_t *th, VALUE *lep, rb_num_t key, VALUE val)
|
||||||
{
|
{
|
||||||
NODE **svar_place = lep_svar_place(th, lep);
|
NODE **svar_place = (NODE **)lep_svar_place(th, lep);
|
||||||
NODE *svar = *svar_place;
|
NODE *svar = *svar_place;
|
||||||
|
|
||||||
if (NIL_P((VALUE)svar)) {
|
if (NIL_P((VALUE)svar)) {
|
||||||
|
@ -191,10 +191,10 @@ lep_svar_set(rb_thread_t *th, VALUE *lep, rb_num_t key, VALUE val)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 0:
|
case VM_SVAR_LASTLINE:
|
||||||
svar->u1.value = val;
|
svar->u1.value = val;
|
||||||
return;
|
return;
|
||||||
case 1:
|
case VM_SVAR_BACKREF:
|
||||||
svar->u2.value = val;
|
svar->u2.value = val;
|
||||||
return;
|
return;
|
||||||
default: {
|
default: {
|
||||||
|
@ -203,7 +203,7 @@ lep_svar_set(rb_thread_t *th, VALUE *lep, rb_num_t key, VALUE val)
|
||||||
if (NIL_P(ary)) {
|
if (NIL_P(ary)) {
|
||||||
svar->u3.value = ary = rb_ary_new();
|
svar->u3.value = ary = rb_ary_new();
|
||||||
}
|
}
|
||||||
rb_ary_store(ary, key - DEFAULT_SPECIAL_VAR_COUNT, val);
|
rb_ary_store(ary, key - VM_SVAR_EXTRA_START, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ vm_getspecial(rb_thread_t *th, VALUE *lep, rb_num_t key, rb_num_t type)
|
||||||
val = lep_svar_get(th, lep, key);
|
val = lep_svar_get(th, lep, key);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE backref = lep_svar_get(th, lep, 1);
|
VALUE backref = lep_svar_get(th, lep, VM_SVAR_BACKREF);
|
||||||
|
|
||||||
if (type & 0x01) {
|
if (type & 0x01) {
|
||||||
switch (type >> 1) {
|
switch (type >> 1) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue