Skip to content

Commit

Permalink
matz
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Nov 21, 2000
1 parent 6ffeed5 commit a122fce
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 76 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
41 changes: 25 additions & 16 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
63 changes: 14 additions & 49 deletions variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions version.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a122fce

Please sign in to comment.