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

* yarvcore.h, compile.c, insnhelper.ci, iseq.c, vm.c:

rename structure names and field names.
* insnhelper.h, insns.def: add GET_CONST_INLINE_CACHE().
* iseq.c: add rb_iseq_build_for_ruby2cext().
* yarvcore.h, vm.h: move declaration of rb_insn_func_t
  to yarvcore.h.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-07-01 18:16:02 +00:00
parent 061cce6d6f
commit 27013e71e4
10 changed files with 102 additions and 56 deletions

View file

@ -1,3 +1,15 @@
Mon Jul 2 03:09:36 2007 Koichi Sasada <ko1@atdot.net>
* yarvcore.h, compile.c, insnhelper.ci, iseq.c, vm.c:
rename structure names and field names.
* insnhelper.h, insns.def: add GET_CONST_INLINE_CACHE().
* iseq.c: add rb_iseq_build_for_ruby2cext().
* yarvcore.h, vm.h: move declaration of rb_insn_func_t
to yarvcore.h.
Sun Jul 1 03:25:53 2007 Koichi Sasada <ko1@atdot.net>
* insnhelper.h, vm.h: some refactoring.

View file

@ -115,14 +115,18 @@ static int set_optargs_table(rb_iseq_t *iseq);
static int
iseq_add_mark_object(rb_iseq_t *iseq, VALUE v)
{
rb_ary_push(iseq->iseq_mark_ary, v);
if (!SPECIAL_CONST_P(v)) {
rb_ary_push(iseq->mark_ary, v);
}
return COMPILE_OK;
}
static int
iseq_add_mark_object_compile_time(rb_iseq_t *iseq, VALUE v)
{
if (!SPECIAL_CONST_P(v)) {
rb_ary_push(iseq->compile_data->mark_ary, v);
}
return COMPILE_OK;
}
@ -837,10 +841,10 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
i += 1;
iseq->arg_opts = i;
iseq->arg_opt_tbl = ALLOC_N(VALUE, i);
MEMCPY(iseq->arg_opt_tbl, RARRAY_PTR(labels), VALUE, i);
iseq->arg_opt_table = ALLOC_N(VALUE, i);
MEMCPY(iseq->arg_opt_table, RARRAY_PTR(labels), VALUE, i);
for (j = 0; j < i; j++) {
iseq->arg_opt_tbl[j] &= ~1;
iseq->arg_opt_table[j] &= ~1;
}
}
else {
@ -950,7 +954,7 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
{
LABEL *lobj;
INSN *iobj;
struct insn_info_struct *insn_info_table;
struct iseq_insn_info_entry *insn_info_table;
LINK_ELEMENT *list;
VALUE *generated_iseq;
@ -992,7 +996,7 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
/* make instruction sequence */
generated_iseq = ALLOC_N(VALUE, pos);
insn_info_table = ALLOC_N(struct insn_info_struct, k);
insn_info_table = ALLOC_N(struct iseq_insn_info_entry, k);
list = FIRST_ELEMENT(anchor);
k = pos = sp = 0;
@ -1095,9 +1099,7 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor)
VALUE v = operands[j];
generated_iseq[pos + 1 + j] = v;
/* to mark ruby object */
if (!SPECIAL_CONST_P(v)) {
iseq_add_mark_object(iseq, v);
}
break;
}
case TS_IC: /* inline cache */
@ -1172,12 +1174,12 @@ set_exception_table(rb_iseq_t *iseq)
{
VALUE *tptr, *ptr;
int tlen, i;
struct catch_table_entry *entry;
struct iseq_catch_table_entry *entry;
tlen = RARRAY_LEN(iseq->compile_data->catch_table_ary);
tptr = RARRAY_PTR(iseq->compile_data->catch_table_ary);
iseq->catch_table = ALLOC_N(struct catch_table_entry, tlen);
iseq->catch_table = ALLOC_N(struct iseq_catch_table_entry, tlen);
iseq->catch_table_size = tlen;
for (i = 0; i < tlen; i++) {
@ -1232,8 +1234,8 @@ set_optargs_table(rb_iseq_t *iseq)
if (iseq->arg_opts != 0) {
for (i = 0; i < iseq->arg_opts; i++) {
iseq->arg_opt_tbl[i] =
label_get_position((LABEL *)iseq->arg_opt_tbl[i]);
iseq->arg_opt_table[i] =
label_get_position((LABEL *)iseq->arg_opt_table[i]);
}
}
return COMPILE_OK;
@ -4456,12 +4458,6 @@ dump_disasm_list(struct iseq_link_element *link)
printf("---------------------\n");
}
int
nd_line_debug(NODE * n)
{
return nd_line(n);
}
VALUE
insns_name_array(void)
{
@ -4608,9 +4604,7 @@ iseq_build_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor,
break;
case TS_VALUE:
argv[j] = op;
if (!SPECIAL_CONST_P(op)) {
iseq_add_mark_object(iseq, op);
}
break;
case TS_ISEQ:
{
@ -4730,10 +4724,10 @@ iseq_build_from_ary(rb_iseq_t *iseq, VALUE line,
iseq->arg_rest = FIX2INT(arg_rest);
iseq->arg_block = FIX2INT(arg_block);
iseq->arg_opt_tbl = (VALUE *)ALLOC_N(VALUE, iseq->arg_opts);
iseq->arg_opt_table = (VALUE *)ALLOC_N(VALUE, iseq->arg_opts);
for (i=0; i<RARRAY_LEN(arg_opt_labels); i++) {
iseq->arg_opt_tbl[i] =
iseq->arg_opt_table[i] =
(VALUE)register_label(iseq, labels_table,
rb_ary_entry(arg_opt_labels, i));
}

View file

@ -147,10 +147,10 @@ vm_callee_setup_arg(rb_thread_t *th, rb_iseq_t *iseq,
if (argc > opts) {
argc -= opts;
argv += opts;
opt_pc = iseq->arg_opt_tbl[opts]; /* no opt */
opt_pc = iseq->arg_opt_table[opts]; /* no opt */
}
else {
opt_pc = iseq->arg_opt_tbl[argc];
opt_pc = iseq->arg_opt_table[argc];
argc = 0;
}
}

View file

@ -96,6 +96,8 @@
#define GET_GLOBAL(entry) rb_gvar_get((struct global_entry*)entry)
#define SET_GLOBAL(entry, val) rb_gvar_set((struct global_entry*)entry, val)
#define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 1))
/**********************************************************/
/* deal with values */
/**********************************************************/

View file

@ -1560,7 +1560,7 @@ setinlinecache
(VALUE val)
(VALUE val)
{
IC ic = (IC) * (GET_PC() + dst + 1);
IC ic = GET_CONST_INLINE_CACHE(dst);
ic->ic_value = val;
ic->ic_vmstat = GET_VM_STATE_VERSION();

61
iseq.c
View file

@ -57,7 +57,7 @@ iseq_free(void *ptr)
RUBY_FREE_UNLESS_NULL(iseq->insn_info_table);
RUBY_FREE_UNLESS_NULL(iseq->local_table);
RUBY_FREE_UNLESS_NULL(iseq->catch_table);
RUBY_FREE_UNLESS_NULL(iseq->arg_opt_tbl);
RUBY_FREE_UNLESS_NULL(iseq->arg_opt_table);
compile_data_free(iseq->compile_data);
ruby_xfree(ptr);
}
@ -73,7 +73,7 @@ iseq_mark(void *ptr)
if (ptr) {
iseq = ptr;
RUBY_GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
RUBY_MARK_UNLESS_NULL(iseq->iseq_mark_ary);
RUBY_MARK_UNLESS_NULL(iseq->mark_ary);
RUBY_MARK_UNLESS_NULL(iseq->name);
RUBY_MARK_UNLESS_NULL(iseq->filename);
RUBY_MARK_UNLESS_NULL((VALUE)iseq->cref_stack);
@ -115,8 +115,8 @@ prepare_iseq_build(rb_iseq_t *iseq,
iseq->name = name;
iseq->filename = filename;
iseq->defined_method_id = 0;
iseq->iseq_mark_ary = rb_ary_new();
RBASIC(iseq->iseq_mark_ary)->klass = 0;
iseq->mark_ary = rb_ary_new();
RBASIC(iseq->mark_ary)->klass = 0;
iseq->type = type;
iseq->arg_rest = -1;
@ -499,7 +499,7 @@ static unsigned short
find_line_no(rb_iseq_t *iseqdat, unsigned long pos)
{
unsigned long i, size = iseqdat->insn_info_size;
struct insn_info_struct *iiary = iseqdat->insn_info_table;
struct iseq_insn_info_entry *iiary = iseqdat->insn_info_table;
for (i = 0; i < size; i++) {
if (iiary[i].position == pos) {
@ -514,7 +514,7 @@ static unsigned short
find_prev_line_no(rb_iseq_t *iseqdat, unsigned long pos)
{
unsigned long i, size = iseqdat->insn_info_size;
struct insn_info_struct *iiary = iseqdat->insn_info_table;
struct iseq_insn_info_entry *iiary = iseqdat->insn_info_table;
for (i = 0; i < size; i++) {
if (iiary[i].position == pos) {
@ -738,7 +738,7 @@ ruby_iseq_disasm(VALUE self)
rb_str_cat2(str, "== catch table\n");
}
for (i = 0; i < iseqdat->catch_table_size; i++) {
struct catch_table_entry *entry = &iseqdat->catch_table[i];
struct iseq_catch_table_entry *entry = &iseqdat->catch_table[i];
sprintf(buff,
"| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
catch_type((int)entry->type), (int)entry->start,
@ -777,7 +777,7 @@ ruby_iseq_disasm(VALUE self)
int opts = iseqdat->arg_opts;
if (i >= argc && i < argc + opts - 1) {
snprintf(opti, sizeof(opti), "Opt=%ld",
iseqdat->arg_opt_tbl[i - argc]);
iseqdat->arg_opt_table[i - argc]);
}
}
@ -1184,7 +1184,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
for (j=0; j<iseq->arg_opts; j++) {
rb_ary_push(arg_opt_labels,
register_label(labels_table, iseq->arg_opt_tbl[j]));
register_label(labels_table, iseq->arg_opt_table[j]));
}
/* commit */
@ -1277,7 +1277,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
/* exception */
for (i=0; i<iseq->catch_table_size; i++) {
VALUE ary = rb_ary_new();
struct catch_table_entry *entry = &iseq->catch_table[i];
struct iseq_catch_table_entry *entry = &iseq->catch_table[i];
rb_ary_push(ary, exception_type2symbol(entry->type));
if (entry->iseq) {
rb_iseq_t *eiseq;
@ -1347,6 +1347,47 @@ insn_make_insn_table(void)
return table;
}
/* ruby2cext */
VALUE
rb_iseq_build_for_ruby2cext(
const rb_iseq_t *iseq_template,
const rb_insn_func_t *func,
const struct iseq_insn_info_entry *insn_info_table,
const char **local_table,
const VALUE *arg_opt_table,
const struct iseq_catch_table_entry *catch_table,
const char *name,
const char *filename)
{
VALUE iseqval = iseq_alloc(rb_cISeq);
rb_iseq_t *iseq;
GetISeqPtr(iseqval, iseq);
/* copy iseq */
*iseq = *iseq_template;
iseq->name = rb_str_new2(name);
iseq->filename = rb_str_new2(filename);
iseq->mark_ary = rb_ary_new();
#define ALLOC_AND_COPY(dst, src, type, size) do { \
if (size) { \
(dst) = ALLOC_N(type, (size)); \
MEMCPY((dst), (src), type, (size)); \
} \
} while (0)
ALLOC_AND_COPY(iseq->insn_info_table, insn_info_table,
struct iseq_insn_info_entry, iseq->insn_info_size);
ALLOC_AND_COPY(iseq->catch_table, catch_table,
struct iseq_catch_table_entry, iseq->catch_table_size);
ALLOC_AND_COPY(iseq->arg_opt_table, arg_opt_table,
VALUE, iseq->arg_opts);
return iseqval;
}
void
Init_ISeq(void)

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-07-01"
#define RUBY_RELEASE_DATE "2007-07-02"
#define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070701
#define RUBY_RELEASE_CODE 20070702
#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 7
#define RUBY_RELEASE_DAY 1
#define RUBY_RELEASE_DAY 2
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];

2
vm.c
View file

@ -1156,7 +1156,7 @@ vm_eval_body(rb_thread_t *th)
}
else {
int i;
struct catch_table_entry *entry;
struct iseq_catch_table_entry *entry;
unsigned long epc, cont_pc, cont_sp;
VALUE catch_iseqval;
rb_control_frame_t *cfp;

7
vm.h
View file

@ -24,13 +24,6 @@ typedef unsigned long lindex_t;
typedef unsigned long dindex_t;
typedef rb_num_t GENTRY;
#ifndef FUNC_FASTCALL
#define FUNC_FASTCALL(x) x
#endif
typedef rb_control_frame_t *
(FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
extern VALUE rb_cEnv;
extern VALUE ruby_vm_global_state_version;
extern VALUE ruby_vm_redefined_flag;

View file

@ -140,7 +140,7 @@ extern ID idFuncall;
extern ID id__send_bang;
struct insn_info_struct {
struct iseq_insn_info_entry {
unsigned short position;
unsigned short line_no;
};
@ -161,7 +161,7 @@ struct insn_info_struct {
#define CATCH_TYPE_REDO INT2FIX(5)
#define CATCH_TYPE_NEXT INT2FIX(6)
struct catch_table_entry {
struct iseq_catch_table_entry {
VALUE type;
VALUE iseq;
unsigned long start;
@ -244,11 +244,10 @@ struct rb_iseq_struct {
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 mark_ary; /* Array: includes operands which should be GC marked */
/* insn info, must be freed */
struct insn_info_struct *insn_info_table;
struct iseq_insn_info_entry *insn_info_table;
unsigned long insn_info_size;
ID *local_table; /* must free */
@ -288,12 +287,12 @@ struct rb_iseq_struct {
int arg_post_len;
int arg_post_start;
int arg_size;
VALUE *arg_opt_tbl;
VALUE *arg_opt_table;
int stack_max; /* for stack overflow check */
/* catch table */
struct catch_table_entry *catch_table;
struct iseq_catch_table_entry *catch_table;
int catch_table_size;
/* for child iseq */
@ -607,7 +606,12 @@ void rb_vm_change_state(void);
typedef VALUE CDHASH;
#ifndef FUNC_FASTCALL
#define FUNC_FASTCALL(x) x
#endif
typedef rb_control_frame_t *
(FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
#define GC_GUARDED_PTR(p) ((VALUE)((VALUE)(p) | 0x01))
#define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)p) & ~0x03))