summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-21 14:26:25 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-21 14:26:25 +0000
commita122fce4768ab91c8aab8a4ca3734554c8f1d939 (patch)
tree92742b1be493679024a2e5987f1b9ca64df36efe
parent6ffeed5c898cb5dd43d917d3f90459fbc31f8d3f (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--eval.c41
-rw-r--r--gc.c4
-rw-r--r--intern.h4
-rw-r--r--node.h4
-rw-r--r--parse.y4
-rw-r--r--variable.c63
-rw-r--r--version.h4
8 files changed, 56 insertions, 76 deletions
diff --git a/ChangeLog b/ChangeLog
index 53c5355c6a4..88c239efc23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
+Tue Nov 21 03:39:41 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (is_defined): clarify class variable behavior for
+ singleton classes.
+
Mon Nov 20 13:45:21 2000 Yukihiro Matsumoto <matz@ruby-lang.org>
+ * eval.c (rb_eval): set ruby_sourceline before evaluating
+ exceptions.
+
* gc.c (gc_sweep): defer finalization in GC during compilation or
interrupt prohibit section.
diff --git a/eval.c b/eval.c
index 03ae3775e52..6d300b62445 100644
--- a/eval.c
+++ b/eval.c
@@ -1735,7 +1735,7 @@ is_defined(self, node, buf)
case NODE_GASGN:
case NODE_CDECL:
case NODE_CVDECL:
- case NODE_CVASGN2:
+ case NODE_CVASGN:
return "assignment";
case NODE_LVAR:
@@ -1768,9 +1768,10 @@ is_defined(self, node, buf)
}
break;
}
+ self = rb_iv_get(ruby_cbase, "__attached__");
/* fall through */
case NODE_CVAR2:
- if (rb_cvar_defined_singleton(self, node->nd_vid)) {
+ if (rb_cvar_defined(rb_cvar_singleton(self), node->nd_vid)) {
return "class variable";
}
break;
@@ -2255,6 +2256,7 @@ rb_eval(self, n)
if (state == TAG_RAISE) {
NODE * volatile resq = node->nd_resq;
+ ruby_sourceline = nd_line(node);
while (resq) {
if (handle_rescue(self, resq)) {
state = 0;
@@ -2598,15 +2600,18 @@ rb_eval(self, n)
if (NIL_P(ruby_cbase)) {
rb_raise(rb_eTypeError, "no class/module to define class variable");
}
- if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
- result = rb_eval(self, node->nd_value);
- rb_cvar_declare(ruby_cbase, node->nd_vid, result);
+ result = rb_eval(self, node->nd_value);
+ if (FL_TEST(ruby_cbase, FL_SINGLETON)) {
+ rb_cvar_declare(rb_cvar_singleton(rb_iv_get(ruby_cbase, "__attached__")),
+ node->nd_vid, result);
break;
}
- /* fall through */
- case NODE_CVASGN2:
+ rb_cvar_declare(ruby_cbase, node->nd_vid, result);
+ break;
+
+ case NODE_CVASGN:
result = rb_eval(self, node->nd_value);
- rb_cvar_set_singleton(self, node->nd_vid, result);
+ rb_cvar_set(rb_cvar_singleton(self), node->nd_vid, result);
break;
case NODE_LVAR:
@@ -2632,14 +2637,15 @@ rb_eval(self, n)
result = ev_const_get(RNODE(ruby_frame->cbase), node->nd_vid);
break;
- case NODE_CVAR:
+ case NODE_CVAR: /* normal method */
if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
result = rb_cvar_get(ruby_cbase, node->nd_vid);
break;
}
+ self = rb_iv_get(ruby_cbase, "__attached__");
/* fall through */
- case NODE_CVAR2:
- result = rb_cvar_get_singleton(self, node->nd_vid);
+ case NODE_CVAR2: /* singleton method */
+ result = rb_cvar_get(rb_cvar_singleton(self), node->nd_vid);
break;
case NODE_BLOCK_ARG:
@@ -3634,11 +3640,14 @@ assign(self, lhs, val, check)
break;
case NODE_CVDECL:
- rb_cvar_declare(ruby_cbase, lhs->nd_vid, val);
- break;
-
- case NODE_CVASGN2:
- rb_cvar_set(CLASS_OF(self), lhs->nd_vid, val);
+ if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
+ rb_cvar_declare(ruby_cbase, lhs->nd_vid, val);
+ break;
+ }
+ self = rb_iv_get(ruby_cbase, "__attached__");
+ /* fall through */
+ case NODE_CVASGN:
+ rb_cvar_set(rb_cvar_singleton(self), lhs->nd_vid, val);
break;
case NODE_MASGN:
diff --git a/gc.c b/gc.c
index 8af89c922d0..097cd9c1c0a 100644
--- a/gc.c
+++ b/gc.c
@@ -486,7 +486,7 @@ rb_gc_mark(ptr)
case NODE_IASGN:
case NODE_CDECL:
case NODE_CVDECL:
- case NODE_CVASGN2:
+ case NODE_CVASGN:
case NODE_MODULE:
case NODE_COLON3:
case NODE_OPT_N:
@@ -661,7 +661,7 @@ gc_sweep()
int i, used = heaps_used;
if (ruby_in_compile) {
- /* sould not reclaim nodes during compilation */
+ /* should not reclaim nodes during compilation */
for (i = 0; i < used; i++) {
p = heaps[i]; pend = p + HEAP_SLOTS;
while (p < pend) {
diff --git a/intern.h b/intern.h
index 2edddd87c69..f36067b0ca9 100644
--- a/intern.h
+++ b/intern.h
@@ -371,9 +371,7 @@ void rb_cvar_declare _((VALUE, ID, VALUE));
int rb_cvar_defined _((VALUE, ID));
void rb_cvar_set _((VALUE, ID, VALUE));
VALUE rb_cvar_get _((VALUE, ID));
-int rb_cvar_defined_singleton _((VALUE, ID));
-void rb_cvar_set_singleton _((VALUE, ID, VALUE));
-VALUE rb_cvar_get_singleton _((VALUE, ID));
+VALUE rb_cvar_singleton _((VALUE));
VALUE rb_mod_class_variables _((VALUE));
/* version.c */
void ruby_show_version _((void));
diff --git a/node.h b/node.h
index 016e2d4f0a6..8140d669cbc 100644
--- a/node.h
+++ b/node.h
@@ -49,7 +49,7 @@ enum node_type {
NODE_GASGN,
NODE_IASGN,
NODE_CDECL,
- NODE_CVASGN2,
+ NODE_CVASGN,
NODE_CVDECL,
NODE_OP_ASGN1,
NODE_OP_ASGN2,
@@ -266,7 +266,7 @@ typedef struct RNode {
#define NEW_DASGN_CURR(v,val) rb_node_newnode(NODE_DASGN_CURR,v,val,0);
#define NEW_IASGN(v,val) rb_node_newnode(NODE_IASGN,v,val,0)
#define NEW_CDECL(v,val) rb_node_newnode(NODE_CDECL,v,val,0)
-#define NEW_CVASGN2(v,val) rb_node_newnode(NODE_CVASGN2,v,val,0)
+#define NEW_CVASGN(v,val) rb_node_newnode(NODE_CVASGN,v,val,0)
#define NEW_CVDECL(v,val) rb_node_newnode(NODE_CVDECL,v,val,0)
#define NEW_OP_ASGN1(p,id,a) rb_node_newnode(NODE_OP_ASGN1,p,id,a)
#define NEW_OP_ASGN2(r,i,o,val) rb_node_newnode(NODE_OP_ASGN2,r,val,NEW_OP_ASGN22(i,o))
diff --git a/parse.y b/parse.y
index 19def2f79a5..29cd1a4a274 100644
--- a/parse.y
+++ b/parse.y
@@ -4089,7 +4089,7 @@ assignable(id, val)
return NEW_CDECL(id, val);
}
else if (is_class_id(id)) {
- if (in_single) return NEW_CVASGN2(id, val);
+ if (in_single) return NEW_CVASGN(id, val);
return NEW_CVDECL(id, val);
}
else {
@@ -4179,7 +4179,7 @@ node_assign(lhs, rhs)
case NODE_MASGN:
case NODE_CDECL:
case NODE_CVDECL:
- case NODE_CVASGN2:
+ case NODE_CVASGN:
lhs->nd_value = rhs;
break;
diff --git a/variable.c b/variable.c
index 871f715d03e..dbc1967d028 100644
--- a/variable.c
+++ b/variable.c
@@ -1327,6 +1327,20 @@ rb_define_global_const(name, val)
rb_define_const(rb_cObject, name, val);
}
+VALUE
+rb_cvar_singleton(obj)
+ VALUE obj;
+{
+ switch (TYPE(obj)) {
+ case T_MODULE:
+ case T_CLASS:
+ return obj;
+ default:
+ break;
+ }
+ return CLASS_OF(obj);
+}
+
void
rb_cvar_set(klass, id, val)
VALUE klass;
@@ -1411,55 +1425,6 @@ rb_cvar_defined(klass, id)
return Qfalse;
}
-int
-rb_cvar_defined_singleton(obj, id)
- VALUE obj;
- ID id;
-{
- switch (TYPE(obj)) {
- case T_MODULE:
- case T_CLASS:
- break;
- default:
- obj = CLASS_OF(obj);
- break;
- }
- return rb_cvar_defined(obj, id);
-}
-
-void
-rb_cvar_set_singleton(obj, id, value)
- VALUE obj;
- ID id;
- VALUE value;
-{
- switch (TYPE(obj)) {
- case T_MODULE:
- case T_CLASS:
- break;
- default:
- obj = CLASS_OF(obj);
- break;
- }
- rb_cvar_set(obj, id, value);
-}
-
-VALUE
-rb_cvar_get_singleton(obj, id)
- VALUE obj;
- ID id;
-{
- switch (TYPE(obj)) {
- case T_MODULE:
- case T_CLASS:
- break;
- default:
- obj = CLASS_OF(obj);
- break;
- }
- return rb_cvar_get(obj, id);
-}
-
void
rb_cv_set(klass, name, val)
VALUE klass;
diff --git a/version.h b/version.h
index 9a9bd8ed6b6..cf50770ad14 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.6.2"
-#define RUBY_RELEASE_DATE "2000-11-20"
+#define RUBY_RELEASE_DATE "2000-11-21"
#define RUBY_VERSION_CODE 162
-#define RUBY_RELEASE_CODE 20001120
+#define RUBY_RELEASE_CODE 20001121