From ee457d92c2d99d85f61346ccd7dd3a6c21b294b6 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 2 Jul 2007 12:49:35 +0000 Subject: [PATCH] * compile.c: rename iseq_translate_direct_threaded_code() to iseq_translate_threaded_code(). * eval_intern.h, yarvcore.h: mv EXEC_EVENT_HOOK() and exec_event_hooks() to yarvcore.h. * insnhelper.ci, vm.c: mv yarv_finish_insn_seq to vm.c. * insns.def (opt_call_c_function): fix to use RESTORE_REGS(). * iseq.c (rb_iseq_build_for_ruby2cext): fix to allocate iseq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++++++++ compile.c | 8 ++++---- eval_intern.h | 33 +-------------------------------- insnhelper.ci | 8 -------- insns.def | 6 ++++-- iseq.c | 10 ++++++++++ vm.c | 13 ++++++++++--- yarvcore.h | 28 ++++++++++++++++++++++++++++ 8 files changed, 71 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index 877d98c06b..4060c0be34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Mon Jul 2 21:45:53 2007 Koichi Sasada + + * compile.c: rename iseq_translate_direct_threaded_code() + to iseq_translate_threaded_code(). + + * eval_intern.h, yarvcore.h: mv EXEC_EVENT_HOOK() and + exec_event_hooks() to yarvcore.h. + + * insnhelper.ci, vm.c: mv yarv_finish_insn_seq to vm.c. + + * insns.def (opt_call_c_function): fix to use RESTORE_REGS(). + + * iseq.c (rb_iseq_build_for_ruby2cext): fix to allocate iseq. + Mon Jul 2 11:59:34 2007 Nobuyoshi Nakada * insns.def (defineclass): suppress a warning. diff --git a/compile.c b/compile.c index dadbcaddff..3bcce2871c 100644 --- a/compile.c +++ b/compile.c @@ -218,8 +218,8 @@ rb_iseq_compile(VALUE self, NODE *node) VALUE vm_eval(void *); -static int -iseq_translate_direct_threaded_code(rb_iseq_t *iseq) +int +iseq_translate_threaded_code(rb_iseq_t *iseq) { #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE @@ -690,8 +690,8 @@ iseq_setup(rb_iseq_t *iseq, LINK_ANCHOR *anchor) debugs("[compile step 4.3 (set_optargs_table)] \n"); set_optargs_table(iseq); - debugs("[compile step 5 (iseq_translate_direct_threaded_code)] \n"); - iseq_translate_direct_threaded_code(iseq); + debugs("[compile step 5 (iseq_translate_threaded_code)] \n"); + iseq_translate_threaded_code(iseq); if (CPDEBUG > 1) { VALUE str = ruby_iseq_disasm(iseq->self); diff --git a/eval_intern.h b/eval_intern.h index 9e03d789a8..03281863a6 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -227,39 +227,8 @@ VALUE rb_obj_is_proc(VALUE); void rb_vm_check_redefinition_opt_method(NODE *node); VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, rb_block_t *blockptr, VALUE filename); void rb_thread_terminate_all(void); - -VALUE rb_vm_set_eval_stack(rb_thread_t *, VALUE iseq); +void rb_vm_set_eval_stack(rb_thread_t *, VALUE iseq); #define ruby_cbase() vm_get_cbase(GET_THREAD()) - -/* tracer */ -static void inline -exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass) -{ - while (hook) { - if (flag & hook->flag) { - (*hook->func)(flag, hook->data, self, id, klass); - } - hook = hook->next; - } -} - -#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \ - rb_event_flag_t wait_event__ = th->event_flags; \ - if (UNLIKELY(wait_event__)) { \ - if (wait_event__ & (flag | RUBY_EVENT_VM)) { \ - VALUE self__ = (self), klass__ = (klass); \ - ID id__ = (id); \ - if (wait_event__ & flag) { \ - exec_event_hooks(th->event_hooks, flag, self__, id__, klass__); \ - } \ - if (wait_event__ & RUBY_EVENT_VM) { \ - exec_event_hooks(th->vm->event_hooks, flag, self__, id__, klass__); \ - } \ - } \ - } \ -} while (0) - - #endif /* EVAL_INTERN_H_INCLUDED */ diff --git a/insnhelper.ci b/insnhelper.ci index efa3bccbe9..92e88e9632 100644 --- a/insnhelper.ci +++ b/insnhelper.ci @@ -14,14 +14,6 @@ #include "insns.inc" -#if OPT_STACK_CACHING -static VALUE yarv_finish_insn_seq[1] = { BIN(finish_SC_ax_ax) }; -#elif OPT_CALL_THREADED_CODE -static VALUE const yarv_finish_insn_seq[1] = { 0 }; -#else -static VALUE yarv_finish_insn_seq[1] = { BIN(finish) }; -#endif - /* control stack frame */ static inline rb_control_frame_t * diff --git a/insns.def b/insns.def index 9de8591053..6dbfd09db1 100644 --- a/insns.def +++ b/insns.def @@ -379,11 +379,11 @@ putobject DEFINE_INSN putstring -(VALUE val) +(VALUE str) () (VALUE val) { - val = rb_str_new3(val); + val = rb_str_new3(str); } /** @@ -2337,6 +2337,7 @@ opt_call_c_function () { rb_insn_func_t funcptr = (rb_insn_func_t) func; + reg_cfp = (funcptr)(th, reg_cfp); if (reg_cfp == 0) { @@ -2345,6 +2346,7 @@ opt_call_c_function THROW_EXCEPTION(err); } + RESTORE_REGS(); NEXT_INSN(); } diff --git a/iseq.c b/iseq.c index 2647dd1521..da0652092f 100644 --- a/iseq.c +++ b/iseq.c @@ -1372,6 +1372,7 @@ rb_iseq_build_for_ruby2cext( const char *name, const char *filename) { + int i; VALUE iseqval = iseq_alloc(rb_cISeq); rb_iseq_t *iseq; GetISeqPtr(iseqval, iseq); @@ -1382,6 +1383,15 @@ rb_iseq_build_for_ruby2cext( iseq->filename = rb_str_new2(filename); iseq->mark_ary = rb_ary_new(); + iseq->iseq = ALLOC_N(VALUE, iseq->iseq_size); + + for (i=0; iiseq_size; i+=2) { + iseq->iseq[i] = BIN(opt_call_c_function); + iseq->iseq[i+1] = (VALUE)func; + } + + iseq_translate_threaded_code(iseq); + #define ALLOC_AND_COPY(dst, src, type, size) do { \ if (size) { \ (dst) = ALLOC_N(type, (size)); \ diff --git a/vm.c b/vm.c index 0cc2483917..81e6ee2f81 100644 --- a/vm.c +++ b/vm.c @@ -38,6 +38,14 @@ static NODE *lfp_set_special_cref(VALUE *lfp, NODE * cref); static inline int block_proc_is_lambda(VALUE procval); +#if OPT_STACK_CACHING +static VALUE yarv_finish_insn_seq[1] = { BIN(finish_SC_ax_ax) }; +#elif OPT_CALL_THREADED_CODE +static VALUE const yarv_finish_insn_seq[1] = { 0 }; +#else +static VALUE yarv_finish_insn_seq[1] = { BIN(finish) }; +#endif + void rb_vm_change_state(void) { @@ -56,7 +64,7 @@ rb_vm_set_finish_env(rb_thread_t *th) return Qtrue; } -static void +void rb_vm_set_top_stack(rb_thread_t *th, VALUE iseqval) { rb_iseq_t *iseq; @@ -74,7 +82,7 @@ rb_vm_set_top_stack(rb_thread_t *th, VALUE iseqval) th->cfp->sp, 0, iseq->local_size); } -VALUE +void rb_vm_set_eval_stack(rb_thread_t *th, VALUE iseqval) { rb_iseq_t *iseq; @@ -86,7 +94,6 @@ rb_vm_set_eval_stack(rb_thread_t *th, VALUE iseqval) vm_push_frame(th, iseq, FRAME_MAGIC_EVAL, block->self, GC_GUARDED_PTR(block->dfp), iseq->iseq_encoded, th->cfp->sp, block->lfp, iseq->local_size); - return 0; } /* Env */ diff --git a/yarvcore.h b/yarvcore.h index 3fdb7417ff..d72ed96951 100644 --- a/yarvcore.h +++ b/yarvcore.h @@ -719,4 +719,32 @@ void rb_thread_execute_interrupts(rb_thread_t *); #define RUBY_VM_CHECK_INTS() \ RUBY_VM_CHECK_INTS_TH(GET_THREAD()) +/* tracer */ +static void inline +exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass) +{ + while (hook) { + if (flag & hook->flag) { + (*hook->func)(flag, hook->data, self, id, klass); + } + hook = hook->next; + } +} + +#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \ + rb_event_flag_t wait_event__ = th->event_flags; \ + if (UNLIKELY(wait_event__)) { \ + if (wait_event__ & (flag | RUBY_EVENT_VM)) { \ + VALUE self__ = (self), klass__ = (klass); \ + ID id__ = (id); \ + if (wait_event__ & flag) { \ + exec_event_hooks(th->event_hooks, flag, self__, id__, klass__); \ + } \ + if (wait_event__ & RUBY_EVENT_VM) { \ + exec_event_hooks(th->vm->event_hooks, flag, self__, id__, klass__); \ + } \ + } \ + } \ +} while (0) + #endif /* _YARVCORE_H_INCLUDED_ */