1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* yarvcore.h:

rename:
  rb_iseq_t#file_name -> filename
  rb_iseq_t#local_tbl -> local_table
  add:
  rb_iseq_t#local_table_size
* compile.c: separate local_table_size and local_size
  (local variable size)
* blockinlining.c: apply above rename.
* compile.h: ditto.
* eval.c: ditto.
* iseq.c: ditto.
* proc.c: ditto.
* vm.c: ditto.
* vm_dump.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-02-25 01:34:33 +00:00
parent 9c9b619799
commit 71986ef6bc
11 changed files with 136 additions and 103 deletions

View file

@ -1,3 +1,29 @@
Sun Feb 25 09:39:50 2007 Koichi Sasada <ko1@atdot.net>
* yarvcore.h:
rename:
rb_iseq_t#file_name -> filename
rb_iseq_t#local_tbl -> local_table
add:
rb_iseq_t#local_table_size
* compile.c: separate local_table_size and local_size
(local variable size)
* blockinlining.c: apply above rename.
* compile.h: ditto.
* eval.c: ditto.
* iseq.c: ditto.
* proc.c: ditto.
* vm.c: ditto.
* vm_dump.c: ditto.
Sun Feb 25 10:27:17 2007 Minero Aoki <aamine@loveruby.net>
* bootstraptest/runner.rb: add lib/ to load path.

View file

@ -43,7 +43,7 @@ yarv_iseq_special_block(rb_iseq_t *iseq, void *builder)
if (iseq->parent_iseq) {
parent = iseq->parent_iseq->self;
}
iseqval = rb_iseq_new_with_bopt(iseq->node, iseq->name, iseq->file_name,
iseqval = rb_iseq_new_with_bopt(iseq->node, iseq->name, iseq->filename,
parent, iseq->type,
GC_GUARDED_PTR(builder));
if (0) {

102
compile.c
View file

@ -773,9 +773,9 @@ set_exception_tbl(rb_iseq_t *iseq)
if (!id_dollar_bang) {
id_dollar_bang = rb_intern("#$!");
}
iseq->local_tbl = (ID *)ALLOC_N(ID *, 1);
iseq->local_size = 1;
iseq->local_tbl[0] = id_dollar_bang;
iseq->local_table = (ID *)ALLOC_N(ID *, 1);
iseq->local_table_size = iseq->local_size = 1;
iseq->local_table[0] = id_dollar_bang;
return COMPILE_OK;
}
@ -904,13 +904,13 @@ search_block_local_parameters(rb_iseq_t *iseq, NODE * lnode)
int i, size = RARRAY_LEN(local_vars);
if (size > 0) {
iseq->local_tbl = ALLOC_N(ID, size);
iseq->local_table = ALLOC_N(ID, size);
for (i = 0; i < size; i++) {
iseq->local_tbl[i] = SYM2ID(RARRAY_PTR(local_vars)[i]);
debugi("block local variable", iseq->local_tbl[i]);
iseq->local_table[i] = SYM2ID(RARRAY_PTR(local_vars)[i]);
debugi("block local variable", iseq->local_table[i]);
}
}
iseq->local_size = size;
iseq->local_table_size = iseq->local_size = size;
}
return node;
}
@ -1013,14 +1013,14 @@ set_block_local_tbl(rb_iseq_t *iseq, NODE * node, LINK_ANCHOR *anchor)
local_tbl[i] = id;
}
if (iseq->local_tbl) {
if (iseq->local_table) {
/* copy from old local tbl and delete it */
for (i=1; i<iseq->local_size; i++) {
local_tbl[argc + i - 1] = iseq->local_tbl[i];
local_tbl[argc + i - 1] = iseq->local_table[i];
}
ruby_xfree(iseq->local_tbl);
ruby_xfree(iseq->local_table);
}
iseq->local_tbl = local_tbl;
iseq->local_table = local_tbl;
iseq->local_size = local_size;
iseq->argc = argc;
break;
@ -1051,14 +1051,27 @@ static int
get_dyna_var_idx_at_raw(rb_iseq_t *iseq, ID id)
{
int i;
for (i = 0; i < iseq->local_size; i++) {
if (iseq->local_tbl[i] == id) {
for (i = 0; i < iseq->local_table_size; i++) {
if (iseq->local_table[i] == id) {
return i;
}
}
return -1;
}
static int
get_local_var_idx(rb_iseq_t *iseq, ID id)
{
int idx = get_dyna_var_idx_at_raw(iseq->local_iseq, id);
if (idx == -1) {
rb_bug("get_local_var_idx: -1");
}
return idx;
}
static int
get_dyna_var_idx(rb_iseq_t *iseq, ID id, int *level, int *ls)
{
@ -1073,6 +1086,8 @@ get_dyna_var_idx(rb_iseq_t *iseq, ID id, int *level, int *ls)
iseq = iseq->parent_iseq;
lv++;
}
rb_bug("get_dyna_var_idx: -1");
return -1;
}
@ -1089,6 +1104,7 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_arg)
ID post_start_id = 0;
int post_len = 0;
NODE *node_init = 0;
int d = iseq->local_size - iseq->local_table_size;
iseq->argc = node_arg->nd_frml;
node_opt = node_arg->nd_opt;
@ -1142,16 +1158,17 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_arg)
}
if ((long)rest_id == -1) {
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, 0 /* dummy var */);
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, 0 /* dummy var */) + d;
}
else if (rest_id) {
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, rest_id);
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, rest_id) + d;
}
if (iseq->arg_rest == -1) {
rb_bug("arg_rest: -1");
}
if (iseq->arg_rest == -1) rb_bug("arg_rest: -1");
if (block_id) {
iseq->arg_block = get_dyna_var_idx_at_raw(iseq, block_id);
iseq->arg_block = get_dyna_var_idx_at_raw(iseq, block_id) + d;
}
if (iseq->arg_rest != 0 || iseq->arg_opts != 0 || iseq->arg_block != 0) {
@ -1238,17 +1255,22 @@ static int
set_localtbl(rb_iseq_t *iseq, ID *tbl)
{
int size;
if (tbl) {
size = *tbl - 2 /* $~, $_ */ + 1 /* svar location */ ;
size = *tbl - 2 /* $~, $_ */;
}
else {
size = 1;
size = 0;
}
iseq->local_tbl = (ID *)ALLOC_N(ID *, size);
if (tbl && size > 1) {
MEMCPY(iseq->local_tbl + 1, tbl + 3, ID *, size - 1);
if (size > 0) {
iseq->local_table = (ID *)ALLOC_N(ID *, size);
MEMCPY(iseq->local_table, tbl + 3 /* size, $~, $_ */, ID *, size);
}
iseq->local_size = size;
iseq->local_table_size = size;
iseq->local_size = size + 1 /* svar */;
return COMPILE_OK;
}
@ -1263,10 +1285,10 @@ set_localtbl_eval(rb_iseq_t *iseq, ID *tbl)
size = 0;
}
if (tbl) {
iseq->local_tbl = (ID *)ALLOC_N(ID *, size);
MEMCPY(iseq->local_tbl, tbl + 1, ID *, size);
iseq->local_table = (ID *)ALLOC_N(ID *, size);
MEMCPY(iseq->local_table, tbl + 1, ID *, size);
}
iseq->local_size = size;
iseq->local_table_size = iseq->local_size = size;
return COMPILE_OK;
}
@ -3354,8 +3376,10 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
}
case NODE_LASGN:{
int idx = iseq->local_iseq->local_size + 2 - node->nd_cnt;
debugs("lvar: %d\n", idx);
ID id = node->nd_vid;
int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id);
debugs("lvar: %s idx: %d\n", rb_id2name(id), idx);
COMPILE(ret, "lvalue", node->nd_value);
if (!poped) {
@ -3962,8 +3986,10 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
}
case NODE_LVAR:{
if (!poped) {
int idx = iseq->local_iseq->local_size + 2 - node->nd_cnt;
debugs("idx: %d\n", idx);
ID id = node->nd_vid;
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));
}
break;
@ -4029,12 +4055,12 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
break;
}
case NODE_NTH_REF:{
ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(node->nd_cnt),
ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(1) /* '~' */,
INT2FIX(node->nd_nth << 1));
break;
}
case NODE_BACK_REF:{
ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(node->nd_cnt),
ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(1) /* '~' */,
INT2FIX(0x01 | (node->nd_nth << 1)));
break;
}
@ -4195,11 +4221,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
COMPILE_ERROR(("BUG: unknown node: NODE_TO_ARY"));
break;
}
case NODE_BLOCK_ARG:{
iseq->arg_block = node->nd_cnt - 2 + 1;
iseq->arg_simple = 0;
break;
}
case NODE_BLOCK_PASS:{
/* OK */
COMPILE_ERROR(("BUG: unknown node: NODE_BLOCK_PASS"));
@ -4987,8 +5008,9 @@ iseq_build_from_ary(rb_iseq_t *iseq, VALUE line,
}
iseq->local_size = opt + RARRAY_LEN(locals);
iseq->local_tbl = (ID *)ALLOC_N(ID *, iseq->local_size);
tbl = iseq->local_tbl + opt;
iseq->local_table_size = iseq->local_size;
iseq->local_table = (ID *)ALLOC_N(ID *, iseq->local_size);
tbl = iseq->local_table + opt;
for (i=0; i<RARRAY_LEN(locals); i++) {
tbl[i] = SYM2ID(RARRAY_PTR(locals)[i]);

View file

@ -103,7 +103,7 @@ r_value(VALUE value)
#define NEW_LABEL(l) new_label_body(iseq, l)
#define iseq_filename(iseq) \
(((rb_iseq_t*)DATA_PTR(iseq))->file_name)
(((rb_iseq_t*)DATA_PTR(iseq))->filename)
#define NEW_ISEQVAL(node, name, type) \
new_child_iseq(iseq, node, name, 0, type)

21
eval.c
View file

@ -1881,7 +1881,7 @@ rb_sourcefile(void)
{
rb_iseq_t *iseq = GET_THREAD()->cfp->iseq;
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
return RSTRING_PTR(iseq->file_name);
return RSTRING_PTR(iseq->filename);
}
return 0;
}
@ -1909,6 +1909,7 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
file = ruby_sourcefile;
line = ruby_sourceline;
}
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
rb_iseq_t *iseq;
@ -1935,7 +1936,6 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
th->base_block->iseq = cfp->iseq; /* TODO */
}
/* make eval iseq */
th->parse_in_eval++;
iseqval = th_compile(th, src, rb_str_new2(file), INT2FIX(line));
@ -1958,6 +1958,7 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
stored_cref_stack =
th_set_special_cref(th, env->block.lfp, stored_cref_stack);
}
/* kick */
result = th_eval_body(th);
}
@ -2797,12 +2798,8 @@ rb_f_local_variables(void)
while (1) {
if (cfp->iseq) {
int start = 0;
if (cfp->lfp == cfp->dfp) {
start = 1;
}
for (i = start; i < cfp->iseq->local_size; i++) {
ID lid = cfp->iseq->local_tbl[i];
for (i = 0; i < cfp->iseq->local_table_size; i++) {
ID lid = cfp->iseq->local_table[i];
if (lid) {
rb_ary_push(ary, rb_str_new2(rb_id2name(lid)));
}
@ -2942,10 +2939,11 @@ rb_dvar_defined(ID id)
iseq->type == ISEQ_TYPE_ENSURE ||
iseq->type == ISEQ_TYPE_EVAL) {
int i;
/* printf("local size: %d\n", iseq->local_size); */
for (i = 0; i < iseq->local_size; i++) {
for (i = 0; i < iseq->local_table_size; i++) {
/* printf("id (%4d): %s\n", i, rb_id2name(iseq->local_tbl[i])); */
if (iseq->local_tbl[i] == id) {
if (iseq->local_table[i] == id) {
return Qtrue;
}
}
@ -2994,8 +2992,7 @@ rb_scope_base_local_tbl_id(int i)
case 1:
return rb_intern("$~");
default:
return th->base_block->iseq->local_iseq->
local_tbl[i - 1 /* tbl[0] is reserved by svar */ ];
return th->base_block->iseq->local_iseq->local_table[i-2];
}
}

63
iseq.c
View file

@ -47,7 +47,7 @@ iseq_free(void *ptr)
iseq = ptr;
/* It's possible that strings are freed
* GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name),
* RSTRING_PTR(iseq->file_name));
* RSTRING_PTR(iseq->filename));
*/
if (iseq->iseq != iseq->iseq_encoded) {
FREE_UNLESS_NULL(iseq->iseq_encoded);
@ -55,7 +55,7 @@ iseq_free(void *ptr)
FREE_UNLESS_NULL(iseq->iseq);
FREE_UNLESS_NULL(iseq->insn_info_tbl);
FREE_UNLESS_NULL(iseq->local_tbl);
FREE_UNLESS_NULL(iseq->local_table);
FREE_UNLESS_NULL(iseq->catch_table);
FREE_UNLESS_NULL(iseq->arg_opt_tbl);
compile_data_free(iseq->compile_data);
@ -72,10 +72,10 @@ iseq_mark(void *ptr)
if (ptr) {
iseq = ptr;
GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->file_name));
GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
MARK_UNLESS_NULL(iseq->iseq_mark_ary);
MARK_UNLESS_NULL(iseq->name);
MARK_UNLESS_NULL(iseq->file_name);
MARK_UNLESS_NULL(iseq->filename);
MARK_UNLESS_NULL((VALUE)iseq->cref_stack);
MARK_UNLESS_NULL(iseq->klass);
MARK_UNLESS_NULL((VALUE)iseq->node);
@ -103,13 +103,13 @@ iseq_alloc(VALUE klass)
static VALUE
prepare_iseq_build(rb_iseq_t *iseq,
VALUE name, VALUE file_name,
VALUE name, VALUE filename,
VALUE parent, VALUE type, VALUE block_opt,
const rb_compile_option_t *option)
{
iseq->name = name;
iseq->defined_method_id = 0;
iseq->file_name = file_name;
iseq->filename = filename;
iseq->iseq_mark_ary = rb_ary_new();
RBASIC(iseq->iseq_mark_ary)->klass = 0;
@ -251,15 +251,15 @@ make_compile_option_value(rb_compile_option_t *option)
}
VALUE
rb_iseq_new(NODE *node, VALUE name, VALUE file_name,
rb_iseq_new(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type)
{
return rb_iseq_new_with_opt(node, name, file_name, parent, type,
return rb_iseq_new_with_opt(node, name, filename, parent, type,
&COMPILE_OPTION_DEFAULT);
}
static VALUE
rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE file_name,
rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type, VALUE bopt,
const rb_compile_option_t *option)
{
@ -269,26 +269,26 @@ rb_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE file_name,
GetISeqPtr(self, iseq);
iseq->self = self;
prepare_iseq_build(iseq, name, file_name, parent, type, bopt, option);
prepare_iseq_build(iseq, name, filename, parent, type, bopt, option);
iseq_compile(self, node);
cleanup_iseq_build(iseq);
return self;
}
VALUE
rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE file_name,
rb_iseq_new_with_opt(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type,
const rb_compile_option_t *option)
{
return rb_iseq_new_with_bopt_and_opt(node, name, file_name, parent, type,
return rb_iseq_new_with_bopt_and_opt(node, name, filename, parent, type,
Qfalse, option);
}
VALUE
rb_iseq_new_with_bopt(NODE *node, VALUE name, VALUE file_name,
rb_iseq_new_with_bopt(NODE *node, VALUE name, VALUE filename,
VALUE parent, VALUE type, VALUE bopt)
{
return rb_iseq_new_with_bopt_and_opt(node, name, file_name, parent, type,
return rb_iseq_new_with_bopt_and_opt(node, name, filename, parent, type,
bopt, &COMPILE_OPTION_DEFAULT);
}
@ -466,7 +466,7 @@ iseq_inspect(VALUE self)
rb_iseq_t *iseq = iseq_check(self);
snprintf(buff, sizeof(buff), "<ISeq:%s@%s>",
RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->file_name));
RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
return rb_str_new2(buff);
}
@ -542,8 +542,8 @@ insn_operand_intern(rb_iseq_t *iseq,
case TS_LINDEX:
{
rb_iseq_t *ip = iseq->local_iseq;
int lidx = ip->local_size - op + 1;
ID id = ip->local_tbl[lidx];
int lidx = ip->local_size - op;
ID id = ip->local_table[lidx];
if (id) {
ret = rb_str_new2(rb_id2name(id));
@ -561,9 +561,7 @@ insn_operand_intern(rb_iseq_t *iseq,
for (i = 0; i < level; i++) {
ip = ip->parent_iseq;
}
ret =
rb_str_new2(rb_id2name
(ip->local_tbl[ip->local_size - op]));
ret = rb_str_new2(rb_id2name(ip->local_table[ip->local_size - op]));
}
else {
ret = rb_inspect(INT2FIX(op));
@ -740,23 +738,16 @@ ruby_iseq_disasm(VALUE self)
}
/* show local table information */
tbl = iseqdat->local_tbl;
tbl = iseqdat->local_table;
if (tbl) {
int opt = 0;
if (iseqdat->type == ISEQ_TYPE_METHOD ||
iseqdat->type == ISEQ_TYPE_TOP ||
iseqdat->type == ISEQ_TYPE_CLASS) {
opt = 1;
}
snprintf(buff, sizeof(buff),
"local scope table (size: %d, argc: %d)\n",
iseqdat->local_size, iseqdat->argc);
rb_str_cat2(str, buff);
for (i = 0; i < iseqdat->local_size - opt; i++) {
const char *name = rb_id2name(tbl[i + opt]);
for (i = 0; i < iseqdat->local_table_size; i++) {
const char *name = rb_id2name(tbl[i]);
char info[0x100];
char argi[0x100] = "";
char opti[0x100] = "";
@ -1132,15 +1123,9 @@ iseq_data_to_ary(rb_iseq_t *iseq)
default: rb_bug("unsupported iseq type");
};
if (iseq->type == ISEQ_TYPE_METHOD ||
iseq->type == ISEQ_TYPE_TOP ||
iseq->type == ISEQ_TYPE_CLASS) {
opt = 1;
}
/* locals */
for (i=opt; i<iseq->local_size; i++) {
ID lid = iseq->local_tbl[i];
for (i=0; i<iseq->local_table_size; i++) {
ID lid = iseq->local_table[i];
if (lid) {
rb_ary_push(locals, ID2SYM(lid));
}
@ -1304,7 +1289,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
rb_ary_push(val, INT2FIX(1));
rb_ary_push(val, Qnil);
rb_ary_push(val, iseq->name);
rb_ary_push(val, iseq->file_name);
rb_ary_push(val, iseq->filename);
rb_ary_push(val, line);
rb_ary_push(val, type);
rb_ary_push(val, locals);

2
proc.c
View file

@ -526,7 +526,7 @@ proc_to_s(VALUE self)
line_no = iseq->insn_info_tbl[0].line_no;
}
str = rb_sprintf("#<%s:%lx@%s:%d>", cname, self,
RSTRING_PTR(iseq->file_name),
RSTRING_PTR(iseq->filename),
line_no);
}
else {

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-02-24"
#define RUBY_RELEASE_DATE "2007-02-25"
#define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070224
#define RUBY_RELEASE_CODE 20070225
#define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 24
#define RUBY_RELEASE_DAY 25
RUBY_EXTERN const char ruby_version[];
RUBY_EXTERN const char ruby_release_date[];

6
vm.c
View file

@ -376,8 +376,8 @@ collect_local_variables_in_env(rb_env_t *env, VALUE ary)
if (env->block.lfp == env->block.dfp) {
return 0;
}
for (i = 0; i < env->block.iseq->local_size; i++) {
ID lid = env->block.iseq->local_tbl[i];
for (i = 0; i < env->block.iseq->local_table_size; i++) {
ID lid = env->block.iseq->local_table[i];
if (lid) {
rb_ary_push(ary, rb_str_new2(rb_id2name(lid)));
}
@ -986,7 +986,7 @@ th_backtrace_each(rb_thread_t *th,
rb_iseq_t *iseq = cfp->iseq;
line_no = th_get_sourceline(cfp);
file = RSTRING_PTR(iseq->file_name);
file = RSTRING_PTR(iseq->filename);
str = rb_sprintf("%s:%d:in `%s'",
file, line_no, RSTRING_PTR(iseq->name));
rb_ary_push(ary, str);

View file

@ -103,7 +103,7 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
line = th_get_sourceline(cfp);
if (line) {
char fn[MAX_POSBUF+1];
snprintf(fn, MAX_POSBUF, "%s", RSTRING_PTR(cfp->iseq->file_name));
snprintf(fn, MAX_POSBUF, "%s", RSTRING_PTR(cfp->iseq->filename));
snprintf(posbuf, MAX_POSBUF, "%s:%d", fn, line);
}
}

View file

@ -240,9 +240,12 @@ struct rb_iseq_struct {
unsigned int insn_info_size;
/* file information where this sequence from */
VALUE file_name;
VALUE filename;
ID *local_tbl; /* must free */
ID *local_table; /* must free */
int local_table_size;
/* method, class frame: sizeof(vars) + 1, block frame: sizeof(vars) */
int local_size;
/* jit compiled or not */