diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-07 01:25:05 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-07 01:25:05 +0000 |
commit | 44aef0b53f3e73ec987a668a3284d5e28bdb8121 (patch) | |
tree | 4cbe7f49ca7c1b4be5f345870ef3d99126803a31 /vm.c | |
parent | 8ee7d0767f7940baeae60ffa95afde93f3378c93 (diff) | |
download | ruby-44aef0b53f3e73ec987a668a3284d5e28bdb8121.tar.gz |
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 80 |
1 files changed, 64 insertions, 16 deletions
@@ -508,7 +508,7 @@ th_call0(rb_thead_t *th, VALUE klass, VALUE recv, rb_block_t *blockptr = 0; if (0) printf("id: %s, nd: %s, argc: %d, passed: %p\n", - rb_id2name(id), node_name(nd_type(body)), + rb_id2name(id), ruby_node_name(nd_type(body)), argc, th->passed_block); //SDR2(th->cfp); @@ -798,13 +798,12 @@ th_invoke_proc(rb_thead_t *th, rb_proc_t *proc, VALUE val = Qundef; int state; volatile int stored_safe = th->safe_level; - volatile NODE *stored_special_cref_stack; + volatile NODE *stored_special_cref_stack = + lfp_set_special_cref(proc->block.lfp, proc->special_cref_stack); rb_control_frame_t * volatile cfp = th->cfp; TH_PUSH_TAG(th); if ((state = EXEC_TAG()) == 0) { - stored_special_cref_stack = - lfp_set_special_cref(proc->block.lfp, proc->special_cref_stack); th->safe_level = proc->safe_level; val = invoke_block(th, &proc->block, self, argc, argv, @@ -895,7 +894,7 @@ th_cfp_svar(rb_control_frame_t *cfp, int cnt) return lfp_svar(cfp->lfp, cnt); } -VALUE * +static VALUE * th_svar(rb_thead_t *th, int cnt) { rb_control_frame_t *cfp = th->cfp; @@ -903,11 +902,43 @@ th_svar(rb_thead_t *th, int cnt) } VALUE * -thread_svar(VALUE self, int cnt) +rb_svar(int cnt) { - rb_thead_t *th; - GetThreadPtr(self, th); - return th_svar(th, cnt); + return th_svar(GET_THREAD(), cnt); +} + +VALUE +rb_backref_get(void) +{ + VALUE *var = rb_svar(1); + if (var) { + return *var; + } + return Qnil; +} + +void +rb_backref_set(VALUE val) +{ + VALUE *var = rb_svar(1); + *var = val; +} + +VALUE +rb_lastline_get(void) +{ + VALUE *var = rb_svar(0); + if (var) { + return *var; + } + return Qnil; +} + +void +rb_lastline_set(VALUE val) +{ + VALUE *var = rb_svar(0); + *var = val; } int @@ -1387,14 +1418,14 @@ th_iter_break(rb_thead_t *th) } static VALUE yarv_redefined_flag = 0; -static st_table *yarv_opt_method_table = 0; +static st_table *vm_opt_method_table = 0; void -yarv_check_redefinition_opt_method(NODE *node) +rb_vm_check_redefinition_opt_method(NODE *node) { VALUE bop; - if (st_lookup(yarv_opt_method_table, (st_data_t)node, &bop)) { + if (st_lookup(vm_opt_method_table, (st_data_t)node, &bop)) { yarv_redefined_flag |= bop; } } @@ -1405,15 +1436,15 @@ add_opt_method(VALUE klass, ID mid, VALUE bop) NODE *node; if (st_lookup(RCLASS(klass)->m_tbl, mid, (void *)&node) && nd_type(node->nd_body->nd_body) == NODE_CFUNC) { - st_insert(yarv_opt_method_table, (st_data_t)node, (st_data_t)bop); + st_insert(vm_opt_method_table, (st_data_t)node, (st_data_t)bop); } else { - rb_bug("undefined optimized method", mid); + rb_bug("undefined optimized method: %s", rb_id2name(mid)); } } void -yarv_init_redefined_flag() +yarv_init_redefined_flag(void) { VALUE register_info[] = { idPLUS, BOP_PLUS, rb_cFixnum, rb_cFloat, rb_cString, rb_cArray, 0, @@ -1432,7 +1463,7 @@ yarv_init_redefined_flag() 0, }; VALUE *ptr = register_info; - yarv_opt_method_table = st_init_numtable(); + vm_opt_method_table = st_init_numtable(); while (*ptr) { ID mid = *ptr++; @@ -1758,3 +1789,20 @@ th_eval_body(rb_thead_t *th) TH_POP_TAG(); return result; } + +VALUE +rb_thread_eval(rb_thead_t *th, VALUE iseqval) +{ + VALUE val; + volatile VALUE tmp; + + th_set_top_stack(th, iseqval); + + if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) { + rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new()); + } + val = th_eval_body(th); + tmp = iseqval; /* prohibit tail call optimization */ + return val; +} + |