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

* yarvcore.h: some refactoring on rb_iseq_t.

rename some variable names, add comments, etc.
* compile.c, iseq.c, proc.c, vm.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-06-30 18:04:35 +00:00
parent eb9aaa4c4f
commit 6a69ad4df1
6 changed files with 70 additions and 59 deletions

View file

@ -1,3 +1,10 @@
Sun Jul 1 03:02:29 2007 Koichi Sasada <ko1@atdot.net>
* yarvcore.h: some refactoring on rb_iseq_t.
rename some variable names, add comments, etc.
* compile.c, iseq.c, proc.c, vm.c: ditto.
Sun Jul 1 02:57:57 2007 Koichi Sasada <ko1@atdot.net> Sun Jul 1 02:57:57 2007 Koichi Sasada <ko1@atdot.net>
* vm.h: rename insn_func_type to rb_insn_func_type. * vm.h: rename insn_func_type to rb_insn_func_type.

View file

@ -227,10 +227,10 @@ iseq_translate_direct_threaded_code(rb_iseq_t *iseq)
#endif #endif
int i; int i;
iseq->iseq_encoded = ALLOC_N(VALUE, iseq->size); iseq->iseq_encoded = ALLOC_N(VALUE, iseq->iseq_size);
MEMCPY(iseq->iseq_encoded, iseq->iseq, VALUE, iseq->size); MEMCPY(iseq->iseq_encoded, iseq->iseq, VALUE, iseq->iseq_size);
for (i = 0; i < iseq->size; /* */ ) { for (i = 0; i < iseq->iseq_size; /* */ ) {
int insn = iseq->iseq_encoded[i]; int insn = iseq->iseq_encoded[i];
int len = insn_len(insn); int len = insn_len(insn);
iseq->iseq_encoded[i] = (VALUE)table[insn]; iseq->iseq_encoded[i] = (VALUE)table[insn];
@ -950,7 +950,7 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
{ {
LABEL *lobj; LABEL *lobj;
INSN *iobj; INSN *iobj;
struct insn_info_struct *insn_info_tbl; struct insn_info_struct *insn_info_table;
LINK_ELEMENT *list; LINK_ELEMENT *list;
VALUE *generated_iseq; VALUE *generated_iseq;
@ -992,7 +992,7 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
/* make instruction sequence */ /* make instruction sequence */
generated_iseq = ALLOC_N(VALUE, pos); generated_iseq = ALLOC_N(VALUE, pos);
insn_info_tbl = ALLOC_N(struct insn_info_struct, k); insn_info_table = ALLOC_N(struct insn_info_struct, k);
list = FIRST_ELEMENT(anchor); list = FIRST_ELEMENT(anchor);
k = pos = sp = 0; k = pos = sp = 0;
@ -1122,8 +1122,8 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
return 0; return 0;
} }
} }
insn_info_tbl[k].line_no = iobj->line_no; insn_info_table[k].line_no = iobj->line_no;
insn_info_tbl[k].position = pos; insn_info_table[k].position = pos;
pos += len; pos += len;
k++; k++;
break; break;
@ -1146,13 +1146,12 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
list = list->next; list = list->next;
} }
{ iseq->iseq = (void *)generated_iseq;
iseq->iseq = (void *)generated_iseq; iseq->iseq_size = pos;
iseq->size = pos; iseq->insn_info_table = insn_info_table;
iseq->insn_info_tbl = insn_info_tbl; iseq->insn_info_size = k;
iseq->insn_info_size = k; iseq->stack_max = stack_max;
iseq->stack_max = stack_max;
}
return COMPILE_OK; return COMPILE_OK;
} }

10
iseq.c
View file

@ -54,7 +54,7 @@ iseq_free(void *ptr)
} }
RUBY_FREE_UNLESS_NULL(iseq->iseq); RUBY_FREE_UNLESS_NULL(iseq->iseq);
RUBY_FREE_UNLESS_NULL(iseq->insn_info_tbl); RUBY_FREE_UNLESS_NULL(iseq->insn_info_table);
RUBY_FREE_UNLESS_NULL(iseq->local_table); RUBY_FREE_UNLESS_NULL(iseq->local_table);
RUBY_FREE_UNLESS_NULL(iseq->catch_table); RUBY_FREE_UNLESS_NULL(iseq->catch_table);
RUBY_FREE_UNLESS_NULL(iseq->arg_opt_tbl); RUBY_FREE_UNLESS_NULL(iseq->arg_opt_tbl);
@ -499,7 +499,7 @@ static unsigned short
find_line_no(rb_iseq_t *iseqdat, unsigned long pos) find_line_no(rb_iseq_t *iseqdat, unsigned long pos)
{ {
unsigned long i, size = iseqdat->insn_info_size; unsigned long i, size = iseqdat->insn_info_size;
struct insn_info_struct *iiary = iseqdat->insn_info_tbl; struct insn_info_struct *iiary = iseqdat->insn_info_table;
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
if (iiary[i].position == pos) { if (iiary[i].position == pos) {
@ -514,7 +514,7 @@ static unsigned short
find_prev_line_no(rb_iseq_t *iseqdat, unsigned long pos) find_prev_line_no(rb_iseq_t *iseqdat, unsigned long pos)
{ {
unsigned long i, size = iseqdat->insn_info_size; unsigned long i, size = iseqdat->insn_info_size;
struct insn_info_struct *iiary = iseqdat->insn_info_tbl; struct insn_info_struct *iiary = iseqdat->insn_info_table;
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
if (iiary[i].position == pos) { if (iiary[i].position == pos) {
@ -723,7 +723,7 @@ ruby_iseq_disasm(VALUE self)
char buff[0x200]; char buff[0x200];
iseq = iseqdat->iseq; iseq = iseqdat->iseq;
size = iseqdat->size; size = iseqdat->iseq_size;
rb_str_cat2(str, "== disasm: "); rb_str_cat2(str, "== disasm: ");
@ -1201,7 +1201,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
} }
/* body */ /* body */
for (seq = iseq->iseq; seq < iseq->iseq + iseq->size; ) { for (seq = iseq->iseq; seq < iseq->iseq + iseq->iseq_size; ) {
VALUE insn = *seq++; VALUE insn = *seq++;
int j, len = insn_len(insn); int j, len = insn_len(insn);
VALUE *nseq = seq + len - 1; VALUE *nseq = seq + len - 1;

4
proc.c
View file

@ -548,8 +548,8 @@ proc_to_s(VALUE self)
if (RUBY_VM_NORMAL_ISEQ_P(iseq)) { if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
int line_no = 0; int line_no = 0;
if (iseq->insn_info_tbl) { if (iseq->insn_info_table) {
line_no = iseq->insn_info_tbl[0].line_no; line_no = iseq->insn_info_table[0].line_no;
} }
str = rb_sprintf("#<%s:%p@%s:%d%s>", cname, (void *)self, str = rb_sprintf("#<%s:%p@%s:%d%s>", cname, (void *)self,
RSTRING_PTR(iseq->filename), RSTRING_PTR(iseq->filename),

6
vm.c
View file

@ -699,12 +699,12 @@ vm_get_sourceline(rb_control_frame_t *cfp)
int pos = cfp->pc - cfp->iseq->iseq_encoded; int pos = cfp->pc - cfp->iseq->iseq_encoded;
for (i = 0; i < iseq->insn_info_size; i++) { for (i = 0; i < iseq->insn_info_size; i++) {
if (iseq->insn_info_tbl[i].position == pos) { if (iseq->insn_info_table[i].position == pos) {
line_no = iseq->insn_info_tbl[i - 1].line_no; line_no = iseq->insn_info_table[i - 1].line_no;
goto found; goto found;
} }
} }
line_no = iseq->insn_info_tbl[i - 1].line_no; line_no = iseq->insn_info_table[i - 1].line_no;
} }
found: found:
return line_no; return line_no;

View file

@ -234,26 +234,22 @@ typedef struct rb_iseq_profile_struct {
struct rb_iseq_struct; struct rb_iseq_struct;
struct rb_iseq_struct { struct rb_iseq_struct {
/* instruction sequence type */ /***************/
VALUE type; /* static data */
/***************/
VALUE self; VALUE type; /* instruction sequence type */
VALUE name; /* String: iseq name */ VALUE name; /* String: iseq name */
VALUE *iseq; /* iseq */ VALUE filename; /* file information where this sequence from */
VALUE *iseq_encoded; VALUE *iseq; /* iseq (insn number and openrads) */
VALUE *iseq_encoded; /* encoded iseq */
unsigned long iseq_size;
VALUE iseq_mark_ary; /* Array: includes operands which should be GC marked */ VALUE iseq_mark_ary; /* Array: includes operands which should be GC marked */
/* sequence size */
unsigned long size;
/* insn info, must be freed */ /* insn info, must be freed */
struct insn_info_struct *insn_info_tbl; struct insn_info_struct *insn_info_table;
unsigned long insn_info_size;
/* insn info size, this value shows also instruction count */
unsigned int insn_info_size;
/* file information where this sequence from */
VALUE filename;
ID *local_table; /* must free */ ID *local_table; /* must free */
int local_table_size; int local_table_size;
@ -261,23 +257,27 @@ struct rb_iseq_struct {
/* method, class frame: sizeof(vars) + 1, block frame: sizeof(vars) */ /* method, class frame: sizeof(vars) + 1, block frame: sizeof(vars) */
int local_size; int local_size;
/* jit compiled or not */
void *jit_compiled;
void *iseq_orig;
/** /**
* argument information * argument information
* *
* def m(a1, a2, ..., aM, b1=(...), b2=(...), ..., bN=(...), *c, &d) * def m(a1, a2, ..., aM, # mandatory
* b1=(...), b2=(...), ..., bN=(...), # optinal
* *c, # rest
* d1, d2, ..., dO, # post
* &e) # block
* => * =>
* *
* argc = M * argc = M
* arg_rest = M+N + 1 // if no rest arguments, rest is 0 * arg_rest = M+N+1 // or -1 if no rest arg
* arg_opts = N * arg_opts = N
* arg_opts_tbl = [ (N entries) ] * arg_opts_tbl = [ (N entries) ]
* arg_block = M+N + 1 (rest) + 1 (block) * arg_post_len = O // 0 if no post arguments
* check: * arg_post_start = M+N+2
* M <= num * arg_block = M+N + 1 + O + 1 // -1 if no block arg
* arg_simple = 0 if not simple arguments.
* = 1 if no opt, rest, post, block.
* = 2 if ambiguos block parameter ({|a|}).
* arg_size = argument size.
*/ */
int argc; int argc;
@ -288,15 +288,9 @@ struct rb_iseq_struct {
int arg_post_len; int arg_post_len;
int arg_post_start; int arg_post_start;
int arg_size; int arg_size;
VALUE *arg_opt_tbl; VALUE *arg_opt_tbl;
/* for stack overflow check */ int stack_max; /* for stack overflow check */
int stack_max;
/* klass/module nest information stack (cref) */
NODE *cref_stack;
VALUE klass;
/* catch table */ /* catch table */
struct catch_table_entry *catch_table; struct catch_table_entry *catch_table;
@ -306,16 +300,27 @@ struct rb_iseq_struct {
struct rb_iseq_struct *parent_iseq; struct rb_iseq_struct *parent_iseq;
struct rb_iseq_struct *local_iseq; struct rb_iseq_struct *local_iseq;
/****************/
/* dynamic data */
/****************/
VALUE self;
/* block inlining */ /* block inlining */
NODE *node; NODE *node;
void *special_block_builder; void *special_block_builder;
void *cached_special_block_builder; void *cached_special_block_builder;
VALUE cached_special_block; VALUE cached_special_block;
/* klass/module nest information stack (cref) */
NODE *cref_stack;
VALUE klass;
/* misc */ /* misc */
ID defined_method_id; /* for define_method */ ID defined_method_id; /* for define_method */
rb_iseq_profile_t profile; rb_iseq_profile_t profile;
/* used at compile time */
struct iseq_compile_data *compile_data; struct iseq_compile_data *compile_data;
}; };