ruby-changes:10108
From: ko1 <ko1@a...>
Date: Mon, 19 Jan 2009 09:14:08 +0900 (JST)
Subject: [ruby-changes:10108] Ruby:r21651 (trunk): * eval.c, vm_eval.c (rb_f_local_variables): move definition from eval.c
ko1 2009-01-19 09:13:44 +0900 (Mon, 19 Jan 2009) New Revision: 21651 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21651 Log: * eval.c, vm_eval.c (rb_f_local_variables): move definition from eval.c to vm_eval.c because vm_collect_local_variables_in_heap() should be static function. * vm.c (vm_collect_local_variables_in_heap): make it static. Modified files: trunk/ChangeLog trunk/eval.c trunk/vm.c trunk/vm_eval.c Index: ChangeLog =================================================================== --- ChangeLog (revision 21650) +++ ChangeLog (revision 21651) @@ -1,3 +1,11 @@ +Mon Jan 19 08:56:53 2009 Koichi Sasada <ko1@a...> + + * eval.c, vm_eval.c (rb_f_local_variables): move definition from eval.c + to vm_eval.c because vm_collect_local_variables_in_heap() should + be static function. + + * vm.c (vm_collect_local_variables_in_heap): make it static. + Mon Jan 19 04:06:10 2009 Nobuyoshi Nakada <nobu@r...> * iseq.c (rb_iseq_load): renamed from ruby_iseq_load, since it is Index: vm_eval.c =================================================================== --- vm_eval.c (revision 21650) +++ vm_eval.c (revision 21651) @@ -19,6 +19,7 @@ static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex); static VALUE vm_exec(rb_thread_t *th); static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref); +static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary); static inline VALUE vm_call0(rb_thread_t * th, VALUE klass, VALUE recv, VALUE id, ID oid, @@ -1322,10 +1323,67 @@ return vm_backtrace(GET_THREAD(), -1); } +/* + * call-seq: + * local_variables => array + * + * Returns the names of the current local variables. + * + * fred = 1 + * for i in 1..10 + * # ... + * end + * local_variables #=> ["fred", "i"] + */ + +static VALUE +rb_f_local_variables(void) +{ + VALUE ary = rb_ary_new(); + rb_thread_t *th = GET_THREAD(); + rb_control_frame_t *cfp = + vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)); + int i; + + while (cfp) { + if (cfp->iseq) { + for (i = 0; i < cfp->iseq->local_table_size; i++) { + ID lid = cfp->iseq->local_table[i]; + if (lid) { + const char *vname = rb_id2name(lid); + /* should skip temporary variable */ + if (vname) { + rb_ary_push(ary, ID2SYM(lid)); + } + } + } + } + if (cfp->lfp != cfp->dfp) { + /* block */ + VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]); + + if (vm_collect_local_variables_in_heap(th, dfp, ary)) { + break; + } + else { + while (cfp->dfp != dfp) { + cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); + } + } + } + else { + break; + } + } + return ary; +} + void Init_vm_eval(void) { rb_define_global_function("eval", rb_f_eval, -1); + rb_define_global_function("local_variables", rb_f_local_variables, 0); + rb_define_global_function("catch", rb_f_catch, -1); rb_define_global_function("throw", rb_f_throw, -1); Index: eval.c =================================================================== --- eval.c (revision 21650) +++ eval.c (revision 21651) @@ -1040,66 +1040,8 @@ set_backtrace(err, val); } -int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary); - /* * call-seq: - * local_variables => array - * - * Returns the names of the current local variables. - * - * fred = 1 - * for i in 1..10 - * # ... - * end - * local_variables #=> ["fred", "i"] - */ - -static VALUE -rb_f_local_variables(void) -{ - VALUE ary = rb_ary_new(); - rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = - vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)); - int i; - - while (cfp) { - if (cfp->iseq) { - for (i = 0; i < cfp->iseq->local_table_size; i++) { - ID lid = cfp->iseq->local_table[i]; - if (lid) { - const char *vname = rb_id2name(lid); - /* should skip temporary variable */ - if (vname) { - rb_ary_push(ary, ID2SYM(lid)); - } - } - } - } - if (cfp->lfp != cfp->dfp) { - /* block */ - VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]); - - if (vm_collect_local_variables_in_heap(th, dfp, ary)) { - break; - } - else { - while (cfp->dfp != dfp) { - cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); - } - } - } - else { - break; - } - } - return ary; -} - - -/* - * call-seq: * __method__ => symbol * __callee__ => symbol * @@ -1134,7 +1076,6 @@ rb_define_global_function("fail", rb_f_raise, -1); rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */ - rb_define_global_function("local_variables", rb_f_local_variables, 0); rb_define_global_function("__method__", rb_f_method_name, 0); rb_define_global_function("__callee__", rb_f_method_name, 0); Index: vm.c =================================================================== --- vm.c (revision 21650) +++ vm.c (revision 21651) @@ -373,9 +373,8 @@ return 0; } -int -vm_collect_local_variables_in_heap(rb_thread_t * const th, - VALUE * const dfp, const VALUE ary) +static int +vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary) { if (ENV_IN_HEAP_P(th, dfp)) { rb_env_t *env; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/