[#26488] Add Standard Deviation Function to Math Module — Daniel Cohen <danielc2017@...>

This patch adds a Standard Deviation function to the Math Module. It takes

25 messages 2009/11/02
[#26489] Re: Add Standard Deviation Function to Math Module — Yukihiro Matsumoto <matz@...> 2009/11/03

Hi,

[#26490] Re: Add Standard Deviation Function to Math Module — Daniel Cohen <danielc2017@...> 2009/11/03

OK,

[#26493] Re: Add Standard Deviation Function to Math Module — Yukihiro Matsumoto <matz@...> 2009/11/03

Hi,

[#26511] Re: Add Standard Deviation Function to Math Module — Yusuke ENDOH <mame@...> 2009/11/03

Hi,

[#26492] HashWithIndifferentAccess to core — Urabe Shyouhei <shyouhei@...>

Hello,

35 messages 2009/11/03
[#26496] Re: HashWithIndifferentAccess to core — Yukihiro Matsumoto <matz@...> 2009/11/03

Hi,

[#26507] Re: HashWithIndifferentAccess to core — Jeremy Kemper <jeremy@...> 2009/11/03

On Tue, Nov 3, 2009 at 6:48 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wro=

[#26514] Re: HashWithIndifferentAccess to core — "Martin J. Dst" <duerst@...> 2009/11/04

Just a thought: What about implementing this with an option on Hash:new,

[#26522] Re: HashWithIndifferentAccess to core — Yusuke ENDOH <mame@...> 2009/11/04

Hi,

[#26555] Re: HashWithIndifferentAccess to core — Yukihiro Matsumoto <matz@...> 2009/11/05

Hi,

[#26584] Re: HashWithIndifferentAccess to core — Yugui <yugui@...> 2009/11/07

2009/11/6 Yukihiro Matsumoto <matz@ruby-lang.org>:

[#26589] Re: HashWithIndifferentAccess to core — Yukihiro Matsumoto <matz@...> 2009/11/07

Hi,

[#26593] Re: HashWithIndifferentAccess to core — Lourens Naud<lourens@...> 2009/11/07

Hi,

[#26523] [Bug #2330] Non systematic segmentation fault with autoload rubyspec — Marc-Andre Lafortune <redmine@...>

Bug #2330: Non systematic segmentation fault with autoload rubyspec

12 messages 2009/11/04

[#26560] [Feature #2340] Removing YAML/Syck — Yui NARUSE <redmine@...>

Feature #2340: Removing YAML/Syck

38 messages 2009/11/06
[#26562] [Feature #2340] Removing YAML/Syck — Yui NARUSE <redmine@...> 2009/11/06

Issue #2340 has been updated by Yui NARUSE.

[#26567] Re: [Feature #2340] Removing YAML/Syck — James Edward Gray II <james@...> 2009/11/06

On Nov 6, 2009, at 4:02 AM, Yui NARUSE wrote:

[#26568] Re: [Feature #2340] Removing YAML/Syck — Jon <jon.forums@...> 2009/11/06

> > Issue #2340 has been updated by Yui NARUSE.

[#26571] Re: [Feature #2340] Removing YAML/Syck — "NARUSE, Yui" <naruse@...> 2009/11/06

Jon wrote:

[#26574] Re: [Feature #2340] Removing YAML/Syck — Aaron Patterson <aaron@...> 2009/11/06

On Sat, Nov 07, 2009 at 12:59:25AM +0900, NARUSE, Yui wrote:

[#26635] [Feature #2348] RBTree Should be Added to the Standard Library — James Gray <redmine@...>

Feature #2348: RBTree Should be Added to the Standard Library

20 messages 2009/11/08
[#28842] [Feature #2348] RBTree Should be Added to the Standard Library — James Gray <redmine@...> 2010/03/21

Issue #2348 has been updated by James Gray.

[#26650] [Feature #2350] Unicode specific functionality on String in 1.9 — Manfred Stienstra <redmine@...>

Feature #2350: Unicode specific functionality on String in 1.9

12 messages 2009/11/09
[#28985] [Feature #2350](Rejected) Unicode specific functionality on String in 1.9 — Yusuke Endoh <redmine@...> 2010/03/25

Issue #2350 has been updated by Yusuke Endoh.

[#28993] Re: [Feature #2350](Rejected) Unicode specific functionality on String in 1.9 — Nikolai Weibull <now@...> 2010/03/25

On Thu, Mar 25, 2010 at 14:45, Yusuke Endoh <redmine@ruby-lang.org> wrote:

[#26704] Maintainer confirmation process done. — "Yugui (Yuki Sonoda)" <yugui@...>

I'm sorry for my closing the maintainer confirmation process so late.

13 messages 2009/11/12

[#26736] [Bug #2365] Matrix: poor handling of coercion errors [patch] — Marc-Andre Lafortune <redmine@...>

Bug #2365: Matrix: poor handling of coercion errors [patch]

12 messages 2009/11/14

[#26772] [Bug #2378] Regression in ParseDate.parsedate('nn-nn') — Vladimir Sizikov <redmine@...>

Bug #2378: Regression in ParseDate.parsedate('nn-nn')

10 messages 2009/11/16

[#26774] Ruby constant lookup — Yehuda Katz <wycats@...>

Over the past six months or so, I have been working with the new Ruby 1.9

22 messages 2009/11/16
[#26775] Re: Ruby constant lookup — Shugo Maeda <shugo@...> 2009/11/17

Hi,

[#26777] Re: Ruby constant lookup — Yehuda Katz <wycats@...> 2009/11/17

Shugo,

[#26778] Re: Ruby constant lookup — Shugo Maeda <shugo@...> 2009/11/17

Hi,

[#26869] Caching #to_s for immutables (and a possible future for constant-folding) — Kurt Stephens <ks@...>

I have a proof-of-concept patch to MRI that caches #to_s values for

16 messages 2009/11/23
[#26936] Re: Caching #to_s for immutables (and a possible future for constant-folding) — Roger Pack <rogerdpack@...> 2009/11/29

> =A0It reduces the number of #to_s Strings created during the MRI test sui=

[#26958] Re: Caching #to_s for immutables (and a possible future for constant-folding) [with patch] — Kurt Stephens <ks@...> 2009/11/30

The attached patch add caching of #to_s results to the main immutable

[#26960] Re: Caching #to_s for immutables (and a possible future for constant-folding) [with patch] — Roger Pack <rogerdpack@...> 2009/11/30

> Yes. =A0The MRI test suite runs at 45 sec with these changes and at 53 se=

[#26963] Re: Caching #to_s for immutables (and a possible future for constant-folding) [with patch] — Kurt Stephens <ks@...> 2009/11/30

I just ran rubyspec against it; ~ 5% time improvement.

[ruby-core:26824] Re: Ruby constant lookup

From: Shugo Maeda <shugo@...>
Date: 2009-11-19 06:38:27 UTC
List: ruby-core #26824
Hi,

2009/11/17 Shugo Maeda <shugo@ruby-lang.org>:
> I guess we have four options now:
>
> (1) As you suggested, revert to the behavior of Ruby 1.8, and add a
> =A0 =A0new method (or flag) to enable the new behavior.

My proposal is as follows:

(1) Revert instance_eval, class_eval, and module_eval back to the
behavior of 1.8.
(2) But do not revert instance_exec, class_exec, and module_exec.

I have attached a patch.
My patch also reverts the behavior of class variables, but it may be
unnecessary.

--=20
Shugo Maeda

Attachments (1)

class_eval_1119.diff (7.41 KB, text/x-diff)
diff --git a/compile.c b/compile.c
index 5581ea8..4f6ce21 100644
--- a/compile.c
+++ b/compile.c
@@ -2549,7 +2549,8 @@ compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath)
     }
     else {
 	/* class at cbase Foo */
-	ADD_INSN1(ret, nd_line(cpath), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE));
+	ADD_INSN1(ret, nd_line(cpath), putspecialobject,
+		  INT2FIX(VM_SPECIAL_OBJECT_CONST_CBASE));
 	return Qtrue;
     }
 }
@@ -3710,7 +3711,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
 	}
 
 	if (node->nd_vid) {
-	    ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE));
+	    ADD_INSN1(ret, nd_line(node), putspecialobject,
+		      INT2FIX(VM_SPECIAL_OBJECT_CONST_CBASE));
 	    ADD_INSN1(ret, nd_line(node), setconstant, ID2SYM(node->nd_vid));
 	}
 	else {
diff --git a/eval.c b/eval.c
index 9ac6388..c5a72dc 100644
--- a/eval.c
+++ b/eval.c
@@ -274,7 +274,8 @@ rb_mod_nesting(void)
 
     while (cref && cref->nd_next) {
 	VALUE klass = cref->nd_clss;
-	if (!NIL_P(klass)) {
+	if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) &&
+	    !NIL_P(klass)) {
 	    rb_ary_push(ary, klass);
 	}
 	cref = cref->nd_next;
diff --git a/insns.def b/insns.def
index 4952297..932dbcc 100644
--- a/insns.def
+++ b/insns.def
@@ -343,6 +343,9 @@ putspecialobject
       case VM_SPECIAL_OBJECT_CBASE:
 	val = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP());
 	break;
+      case VM_SPECIAL_OBJECT_CONST_CBASE:
+	val = vm_get_const_cbase(GET_ISEQ(), GET_LFP(), GET_DFP());
+	break;
       default:
 	rb_bug("putspecialobject insn: unknown value_type");
     }
@@ -944,7 +947,7 @@ defineclass
 	rb_bug("unknown defineclass type: %d", (int)define_type);
     }
 
-    COPY_CREF(class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC));
+    COPY_CREF(class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC, NULL));
 
     /* enter scope */
     vm_push_frame(th, class_iseq,
diff --git a/node.h b/node.h
index c0fb774..4eb3ded 100644
--- a/node.h
+++ b/node.h
@@ -262,6 +262,7 @@ typedef struct RNode {
 
 /* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_FL_NEWLINE */
 #define NODE_FL_NEWLINE (((VALUE)1)<<7)
+#define NODE_FL_CREF_PUSHED_BY_EVAL NODE_FL_NEWLINE
 
 #define NODE_TYPESHIFT 8
 #define NODE_TYPEMASK  (((VALUE)0x7f)<<NODE_TYPESHIFT)
diff --git a/vm_core.h b/vm_core.h
index 3d0f239..d275148 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -524,8 +524,9 @@ typedef struct {
 #define VM_CALL_SUPER_BIT          (0x01 << 7)
 #define VM_CALL_OPT_SEND_BIT       (0x01 << 8)
 
-#define VM_SPECIAL_OBJECT_VMCORE   0x01
-#define VM_SPECIAL_OBJECT_CBASE    0x02
+#define VM_SPECIAL_OBJECT_VMCORE       0x01
+#define VM_SPECIAL_OBJECT_CBASE        0x02
+#define VM_SPECIAL_OBJECT_CONST_CBASE  0x03
 
 #define VM_FRAME_MAGIC_METHOD 0x11
 #define VM_FRAME_MAGIC_BLOCK  0x21
diff --git a/vm_eval.c b/vm_eval.c
index d989353..adca839 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -17,7 +17,7 @@ static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *a
 static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
 static inline VALUE vm_backtrace(rb_thread_t *th, int lev);
 static int vm_backtrace_each(rb_thread_t *th, int lev, rb_backtrace_iter_func *iter, void *arg);
-static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex);
+static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr);
 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);
@@ -1142,17 +1142,21 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
 /* block eval under the class/module context */
 
 static VALUE
-yield_under(VALUE under, VALUE self, VALUE values)
+yield_under(VALUE under, VALUE self, VALUE values, int is_eval)
 {
     rb_thread_t *th = GET_THREAD();
     rb_block_t block, *blockptr;
-    NODE *cref = vm_cref_push(th, under, NOEX_PUBLIC);
+    NODE *cref;
 
     if ((blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0])) != 0) {
 	block = *blockptr;
 	block.self = self;
 	th->cfp->lfp[0] = GC_GUARDED_PTR(&block);
     }
+    cref = vm_cref_push(th, under, NOEX_PUBLIC, &block);
+    if (is_eval) {
+	cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL;
+    }
 
     if (values == Qundef) {
 	return vm_yield_with_cref(th, 0, 0, cref);
@@ -1166,7 +1170,7 @@ yield_under(VALUE under, VALUE self, VALUE values)
 static VALUE
 eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)
 {
-    NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC);
+    NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC, NULL);
 
     if (rb_safe_level() >= 4) {
 	StringValue(src);
@@ -1185,7 +1189,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
 	if (argc > 0) {
 	    rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
 	}
-	return yield_under(klass, self, Qundef);
+	return yield_under(klass, self, Qundef, TRUE);
     }
     else {
 	const char *file = "(eval)";
@@ -1283,7 +1287,7 @@ rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
     else {
 	klass = rb_singleton_class(self);
     }
-    return yield_under(klass, self, rb_ary_new4(argc, argv));
+    return yield_under(klass, self, rb_ary_new4(argc, argv), FALSE);
 }
 
 /*
@@ -1339,7 +1343,7 @@ rb_mod_module_eval(int argc, VALUE *argv, VALUE mod)
 VALUE
 rb_mod_module_exec(int argc, VALUE *argv, VALUE mod)
 {
-    return yield_under(mod, mod, rb_ary_new4(argc, argv));
+    return yield_under(mod, mod, rb_ary_new4(argc, argv), FALSE);
 }
 
 /*
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index a05574f..be9ff49 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1066,14 +1066,17 @@ vm_get_cref(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp)
 }
 
 static NODE *
-vm_cref_push(rb_thread_t *th, VALUE klass, int noex)
+vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr)
 {
     rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(th, th->cfp);
     NODE *cref = NEW_BLOCK(klass);
     cref->nd_file = 0;
     cref->nd_visi = noex;
 
-    if (cfp) {
+    if (blockptr) {
+	cref->nd_next = vm_get_cref(blockptr->iseq, blockptr->lfp, blockptr->dfp);
+    }
+    else if (cfp) {
 	cref->nd_next = vm_get_cref(cfp->iseq, cfp->lfp, cfp->dfp);
     }
 
@@ -1096,6 +1099,23 @@ vm_get_cbase(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp)
     return klass;
 }
 
+static inline VALUE
+vm_get_const_cbase(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp)
+{
+    NODE *cref = vm_get_cref(iseq, lfp, dfp);
+    VALUE klass = Qundef;
+
+    while (cref) {
+	if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) &&
+	    (klass = cref->nd_clss) != 0) {
+	    break;
+	}
+	cref = cref->nd_next;
+    }
+
+    return klass;
+}
+
 static inline void
 vm_check_if_namespace(VALUE klass)
 {
@@ -1122,7 +1142,8 @@ vm_get_ev_const(rb_thread_t *th, const rb_iseq_t *iseq,
 	VALUE klass = orig_klass;
 
 	while (cref && cref->nd_next) {
-	    klass = cref->nd_clss;
+	    if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL))
+		klass = cref->nd_clss;
 	    cref = cref->nd_next;
 
 	    if (!NIL_P(klass)) {
@@ -1178,7 +1199,8 @@ vm_get_cvar_base(NODE *cref)
     VALUE klass;
 
     while (cref && cref->nd_next &&
-	   (NIL_P(cref->nd_clss) || FL_TEST(cref->nd_clss, FL_SINGLETON))) {
+	   (NIL_P(cref->nd_clss) || FL_TEST(cref->nd_clss, FL_SINGLETON) ||
+	    (cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL))) {
 	cref = cref->nd_next;
 
 	if (!cref->nd_next) {

In This Thread