mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* insns.def (getlocal, setlocal): remove old getlocal/setlocal
instructions and rename getdaynmic/setdynamic instructions to getlocal/setlocal. * compile.c: ditto. * iseq.c: remove TS_DINDEX. * vm_exec.h (dindex_t): remove type definition of `dindex_t'. * tool/instruction.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
326e22e14a
commit
08c8605de9
6 changed files with 69 additions and 88 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Thu Oct 4 22:39:27 2012 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* insns.def (getlocal, setlocal): remove old getlocal/setlocal
|
||||
instructions and rename getdaynmic/setdynamic instructions
|
||||
to getlocal/setlocal.
|
||||
|
||||
* compile.c: ditto.
|
||||
|
||||
* iseq.c: remove TS_DINDEX.
|
||||
|
||||
* vm_exec.h (dindex_t): remove type definition of `dindex_t'.
|
||||
|
||||
* tool/instruction.rb: ditto.
|
||||
|
||||
Thu Oct 4 21:44:17 2012 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm.c (vm_analysis_insn|operand|register): use st_insert
|
||||
|
|
50
compile.c
50
compile.c
|
@ -535,7 +535,7 @@ rb_iseq_compile_node(VALUE self, NODE *node)
|
|||
}
|
||||
|
||||
if (iseq->type == ISEQ_TYPE_RESCUE || iseq->type == ISEQ_TYPE_ENSURE) {
|
||||
ADD_INSN2(ret, 0, getdynamic, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN2(ret, 0, getlocal, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN1(ret, 0, throw, INT2FIX(0) /* continue throw */ );
|
||||
}
|
||||
else {
|
||||
|
@ -1031,6 +1031,17 @@ iseq_set_exception_local_table(rb_iseq_t *iseq)
|
|||
return COMPILE_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
get_lvar_level(rb_iseq_t *iseq)
|
||||
{
|
||||
int lev = 0;
|
||||
while (iseq != iseq->local_iseq) {
|
||||
lev++;
|
||||
iseq = iseq->parent_iseq;
|
||||
}
|
||||
return lev;
|
||||
}
|
||||
|
||||
static int
|
||||
get_dyna_var_idx_at_raw(rb_iseq_t *iseq, ID id)
|
||||
{
|
||||
|
@ -1458,7 +1469,6 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
|
|||
break;
|
||||
}
|
||||
case TS_LINDEX:
|
||||
case TS_DINDEX:
|
||||
case TS_NUM: /* ulong */
|
||||
generated_iseq[pos + 1 + j] = FIX2INT(operands[j]);
|
||||
break;
|
||||
|
@ -3686,7 +3696,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
switch (nd_type(narg)) {
|
||||
case NODE_ARRAY:
|
||||
while (narg) {
|
||||
ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(2), INT2FIX(0));
|
||||
COMPILE(ret, "rescue arg", narg->nd_head);
|
||||
ADD_INSN1(ret, nd_line(node), checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
|
||||
ADD_INSNL(ret, nd_line(node), branchif, label_hit);
|
||||
|
@ -3696,7 +3706,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
case NODE_SPLAT:
|
||||
case NODE_ARGSCAT:
|
||||
case NODE_ARGSPUSH:
|
||||
ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(2), INT2FIX(0));
|
||||
COMPILE(ret, "rescue/cond splat", narg);
|
||||
ADD_INSN1(ret, nd_line(node), checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_RESCUE | VM_CHECKMATCH_ARRAY));
|
||||
ADD_INSNL(ret, nd_line(node), branchif, label_hit);
|
||||
|
@ -3707,7 +3717,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
}
|
||||
}
|
||||
else {
|
||||
ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN1(ret, nd_line(node), putobject, rb_eStandardError);
|
||||
ADD_INSN1(ret, nd_line(node), checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
|
||||
ADD_INSNL(ret, nd_line(node), branchif, label_hit);
|
||||
|
@ -3804,7 +3814,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
if (!poped) {
|
||||
ADD_INSN(ret, nd_line(node), dup);
|
||||
}
|
||||
ADD_INSN1(ret, nd_line(node), setlocal, INT2FIX(idx));
|
||||
ADD_INSN2(ret, nd_line(node), setlocal, INT2FIX(idx), INT2FIX(get_lvar_level(iseq)));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -3824,8 +3834,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
rb_bug("NODE_DASGN(_CURR): unknown id (%s)", rb_id2name(node->nd_vid));
|
||||
}
|
||||
|
||||
ADD_INSN2(ret, nd_line(node), setdynamic,
|
||||
INT2FIX(ls - idx), INT2FIX(lv));
|
||||
ADD_INSN2(ret, nd_line(node), setlocal, INT2FIX(ls - idx), INT2FIX(lv));
|
||||
break;
|
||||
}
|
||||
case NODE_GASGN:{
|
||||
|
@ -4277,13 +4286,14 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
/* NODE_ZSUPER */
|
||||
int i;
|
||||
rb_iseq_t *liseq = iseq->local_iseq;
|
||||
int lvar_level = get_lvar_level(iseq);
|
||||
|
||||
argc = INT2FIX(liseq->argc);
|
||||
|
||||
/* normal arguments */
|
||||
for (i = 0; i < liseq->argc; i++) {
|
||||
int idx = liseq->local_size - i;
|
||||
ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx));
|
||||
ADD_INSN2(args, nd_line(node), getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
}
|
||||
|
||||
if (!liseq->arg_simple) {
|
||||
|
@ -4292,7 +4302,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
int j;
|
||||
for (j = 0; j < liseq->arg_opts - 1; j++) {
|
||||
int idx = liseq->local_size - (i + j);
|
||||
ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx));
|
||||
ADD_INSN2(args, nd_line(node), getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
}
|
||||
i += j;
|
||||
argc = INT2FIX(i);
|
||||
|
@ -4301,7 +4311,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
if (liseq->arg_rest != -1) {
|
||||
/* rest argument */
|
||||
int idx = liseq->local_size - liseq->arg_rest;
|
||||
ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx));
|
||||
ADD_INSN2(args, nd_line(node), getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
argc = INT2FIX(liseq->arg_rest + 1);
|
||||
flag |= VM_CALL_ARGS_SPLAT_BIT;
|
||||
}
|
||||
|
@ -4315,7 +4325,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
int j;
|
||||
for (j=0; j<post_len; j++) {
|
||||
int idx = liseq->local_size - (post_start + j);
|
||||
ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx));
|
||||
ADD_INSN2(args, nd_line(node), getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
}
|
||||
ADD_INSN1(args, nd_line(node), newarray, INT2FIX(j));
|
||||
ADD_INSN (args, nd_line(node), concatarray);
|
||||
|
@ -4325,7 +4335,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
int j;
|
||||
for (j=0; j<post_len; j++) {
|
||||
int idx = liseq->local_size - (post_start + j);
|
||||
ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx));
|
||||
ADD_INSN2(args, nd_line(node), getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
}
|
||||
argc = INT2FIX(post_len + post_start);
|
||||
}
|
||||
|
@ -4460,7 +4470,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id);
|
||||
|
||||
debugs("id: %s idx: %d\n", rb_id2name(id), idx);
|
||||
ADD_INSN1(ret, nd_line(node), getlocal, INT2FIX(idx));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(idx), INT2FIX(get_lvar_level(iseq)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -4472,7 +4482,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
if (idx < 0) {
|
||||
rb_bug("unknown dvar (%s)", rb_id2name(node->nd_vid));
|
||||
}
|
||||
ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(ls - idx), INT2FIX(lv));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(ls - idx), INT2FIX(lv));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -4976,7 +4986,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
case NODE_ERRINFO:{
|
||||
if (!poped) {
|
||||
if (iseq->type == ISEQ_TYPE_RESCUE) {
|
||||
ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(2), INT2FIX(0));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(2), INT2FIX(0));
|
||||
}
|
||||
else {
|
||||
rb_iseq_t *ip = iseq;
|
||||
|
@ -4989,7 +4999,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
level++;
|
||||
}
|
||||
if (ip) {
|
||||
ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(2), INT2FIX(level));
|
||||
ADD_INSN2(ret, nd_line(node), getlocal, INT2FIX(2), INT2FIX(level));
|
||||
}
|
||||
else {
|
||||
ADD_INSN(ret, nd_line(node), putnil);
|
||||
|
@ -5050,12 +5060,12 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
switch (nd_type(node->nd_body)) {
|
||||
case NODE_LASGN:
|
||||
idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id);
|
||||
ADD_INSN1(ret, nd_line(node), setlocal, INT2FIX(idx));
|
||||
ADD_INSN2(ret, nd_line(node), setlocal, INT2FIX(idx), INT2FIX(get_lvar_level(iseq)));
|
||||
break;
|
||||
case NODE_DASGN:
|
||||
case NODE_DASGN_CURR:
|
||||
idx = get_dyna_var_idx(iseq, id, &lv, &ls);
|
||||
ADD_INSN2(ret, nd_line(node), setdynamic, INT2FIX(ls - idx), INT2FIX(lv));
|
||||
ADD_INSN2(ret, nd_line(node), setlocal, INT2FIX(ls - idx), INT2FIX(lv));
|
||||
break;
|
||||
default:
|
||||
rb_bug("iseq_compile_each (NODE_KW_ARG): unknown node: %s", ruby_node_name(nd_type(node->nd_body)));
|
||||
|
@ -5211,7 +5221,6 @@ insn_data_to_s_detail(INSN *iobj)
|
|||
}
|
||||
break;
|
||||
case TS_LINDEX:
|
||||
case TS_DINDEX:
|
||||
case TS_NUM: /* ulong */
|
||||
case TS_VALUE: /* VALUE */
|
||||
rb_str_concat(str, rb_inspect(OPERAND_AT(iobj, j)));
|
||||
|
@ -5458,7 +5467,6 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor,
|
|||
break;
|
||||
}
|
||||
case TS_LINDEX:
|
||||
case TS_DINDEX:
|
||||
case TS_NUM:
|
||||
(void)NUM2INT(op);
|
||||
argv[j] = op;
|
||||
|
|
72
insns.def
72
insns.def
|
@ -46,30 +46,44 @@ nop
|
|||
|
||||
/**
|
||||
@c variable
|
||||
@e Get value of local variable (pointed to by idx).
|
||||
@j idx で指定されたローカル変数をスタックに置く。
|
||||
@e Get local variable (pointed by `idx' and `level').
|
||||
'level' indicates the nesting depth from the current block.
|
||||
@j level, idx で指定されたローカル変数の値をスタックに置く。
|
||||
level はブロックのネストレベルで、何段上かを示す。
|
||||
*/
|
||||
DEFINE_INSN
|
||||
getlocal
|
||||
(lindex_t idx)
|
||||
(lindex_t idx, rb_num_t level)
|
||||
()
|
||||
(VALUE val)
|
||||
{
|
||||
val = *(GET_LEP() - idx);
|
||||
rb_num_t i;
|
||||
VALUE *ep = GET_EP();
|
||||
for (i = 0; i < level; i++) {
|
||||
ep = GET_PREV_EP(ep);
|
||||
}
|
||||
val = *(ep - idx);
|
||||
}
|
||||
|
||||
/**
|
||||
@c variable
|
||||
@e Set value of local variable (pointed to by idx) to val.
|
||||
@j idx で指定されたローカル変数を val に設定する。
|
||||
@e Set a local variable (pointed to by 'idx') as val.
|
||||
'level' indicates the nesting depth from the current block.
|
||||
@j level, idx で指定されたローカル変数の値を val にする。
|
||||
level はブロックのネストレベルで、何段上かを示す。
|
||||
*/
|
||||
DEFINE_INSN
|
||||
setlocal
|
||||
(lindex_t idx)
|
||||
(lindex_t idx, rb_num_t level)
|
||||
(VALUE val)
|
||||
()
|
||||
{
|
||||
*(GET_LEP() - idx) = val;
|
||||
rb_num_t i;
|
||||
VALUE *ep = GET_EP();
|
||||
for (i = 0; i < level; i++) {
|
||||
ep = GET_PREV_EP(ep);
|
||||
}
|
||||
*(ep - idx) = val;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,48 +114,6 @@ setspecial
|
|||
lep_svar_set(th, GET_LEP(), key, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@c variable
|
||||
@e Get value of block local variable (pointed to by idx and level).
|
||||
'level' indicates the nesting depth from the current block.
|
||||
@j level, idx で指定されたブロックローカル変数の値をスタックに置く。
|
||||
level はブロックのネストレベルで、何段上かを示す。
|
||||
*/
|
||||
DEFINE_INSN
|
||||
getdynamic
|
||||
(dindex_t idx, rb_num_t level)
|
||||
()
|
||||
(VALUE val)
|
||||
{
|
||||
rb_num_t i;
|
||||
VALUE *ep = GET_EP();
|
||||
for (i = 0; i < level; i++) {
|
||||
ep = GET_PREV_EP(ep);
|
||||
}
|
||||
val = *(ep - idx);
|
||||
}
|
||||
|
||||
/**
|
||||
@c variable
|
||||
@e Set block local variable (pointed to by 'idx') as val.
|
||||
'level' indicates the nesting depth from the current block.
|
||||
@j level, idx で指定されたブロックローカル変数の値を val にする。
|
||||
level はブロックのネストレベルで、何段上かを示す。
|
||||
*/
|
||||
DEFINE_INSN
|
||||
setdynamic
|
||||
(dindex_t idx, rb_num_t level)
|
||||
(VALUE val)
|
||||
()
|
||||
{
|
||||
rb_num_t i;
|
||||
VALUE *ep = GET_EP();
|
||||
for (i = 0; i < level; i++) {
|
||||
ep = GET_PREV_EP(ep);
|
||||
}
|
||||
*(ep - idx) = val;
|
||||
}
|
||||
|
||||
/**
|
||||
@c variable
|
||||
@e Get value of instance variable id of self.
|
||||
|
|
15
iseq.c
15
iseq.c
|
@ -981,16 +981,8 @@ insn_operand_intern(rb_iseq_t *iseq,
|
|||
ret = rb_sprintf("%"PRIuVALUE, op);
|
||||
break;
|
||||
|
||||
case TS_LINDEX:
|
||||
{
|
||||
rb_iseq_t *liseq = iseq->local_iseq;
|
||||
int lidx = liseq->local_size - (int)op;
|
||||
|
||||
ret = id_to_name(liseq->local_table[lidx], INT2FIX('*'));
|
||||
break;
|
||||
}
|
||||
case TS_DINDEX:{
|
||||
if (insn == BIN(getdynamic) || insn == BIN(setdynamic)) {
|
||||
case TS_LINDEX:{
|
||||
if (insn == BIN(getlocal) || insn == BIN(setlocal)) {
|
||||
if (pnop) {
|
||||
rb_iseq_t *diseq = iseq;
|
||||
VALUE level = *pnop, i;
|
||||
|
@ -1312,7 +1304,7 @@ rb_iseq_disasm(VALUE self)
|
|||
* 0004 putobject 2
|
||||
* 0006 opt_plus <ic:1>
|
||||
* 0008 dup
|
||||
* 0009 setdynamic num, 0
|
||||
* 0009 setlocal num, 0
|
||||
* 0012 leave
|
||||
*
|
||||
*/
|
||||
|
@ -1516,7 +1508,6 @@ iseq_data_to_ary(rb_iseq_t *iseq)
|
|||
break;
|
||||
}
|
||||
case TS_LINDEX:
|
||||
case TS_DINDEX:
|
||||
case TS_NUM:
|
||||
rb_ary_push(ary, INT2FIX(*seq));
|
||||
break;
|
||||
|
|
|
@ -930,8 +930,6 @@ class RubyVM
|
|||
"TS_NUM"
|
||||
when /^lindex_t/
|
||||
"TS_LINDEX"
|
||||
when /^dindex_t/
|
||||
"TS_DINDEX"
|
||||
when /^VALUE/
|
||||
"TS_VALUE"
|
||||
when /^ID/
|
||||
|
@ -957,7 +955,6 @@ class RubyVM
|
|||
'TS_OFFSET' => 'O',
|
||||
'TS_NUM' => 'N',
|
||||
'TS_LINDEX' => 'L',
|
||||
'TS_DINDEX' => 'D',
|
||||
'TS_VALUE' => 'V',
|
||||
'TS_ID' => 'I',
|
||||
'TS_GENTRY' => 'G',
|
||||
|
@ -1064,7 +1061,7 @@ class RubyVM
|
|||
val = op[1]
|
||||
|
||||
case type
|
||||
when /^long/, /^rb_num_t/, /^lindex_t/, /^dindex_t/
|
||||
when /^long/, /^rb_num_t/, /^lindex_t/
|
||||
"INT2FIX(#{val})"
|
||||
when /^VALUE/
|
||||
val
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
typedef long OFFSET;
|
||||
typedef unsigned long lindex_t;
|
||||
typedef unsigned long dindex_t;
|
||||
typedef rb_num_t GENTRY;
|
||||
typedef rb_iseq_t *ISEQ;
|
||||
|
||||
|
|
Loading…
Reference in a new issue