mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6ffeed5c89
commit
a122fce476
8 changed files with 56 additions and 76 deletions
|
@ -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>
|
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
|
* gc.c (gc_sweep): defer finalization in GC during compilation or
|
||||||
interrupt prohibit section.
|
interrupt prohibit section.
|
||||||
|
|
||||||
|
|
35
eval.c
35
eval.c
|
@ -1735,7 +1735,7 @@ is_defined(self, node, buf)
|
||||||
case NODE_GASGN:
|
case NODE_GASGN:
|
||||||
case NODE_CDECL:
|
case NODE_CDECL:
|
||||||
case NODE_CVDECL:
|
case NODE_CVDECL:
|
||||||
case NODE_CVASGN2:
|
case NODE_CVASGN:
|
||||||
return "assignment";
|
return "assignment";
|
||||||
|
|
||||||
case NODE_LVAR:
|
case NODE_LVAR:
|
||||||
|
@ -1768,9 +1768,10 @@ is_defined(self, node, buf)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
self = rb_iv_get(ruby_cbase, "__attached__");
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case NODE_CVAR2:
|
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";
|
return "class variable";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2255,6 +2256,7 @@ rb_eval(self, n)
|
||||||
if (state == TAG_RAISE) {
|
if (state == TAG_RAISE) {
|
||||||
NODE * volatile resq = node->nd_resq;
|
NODE * volatile resq = node->nd_resq;
|
||||||
|
|
||||||
|
ruby_sourceline = nd_line(node);
|
||||||
while (resq) {
|
while (resq) {
|
||||||
if (handle_rescue(self, resq)) {
|
if (handle_rescue(self, resq)) {
|
||||||
state = 0;
|
state = 0;
|
||||||
|
@ -2598,15 +2600,18 @@ rb_eval(self, n)
|
||||||
if (NIL_P(ruby_cbase)) {
|
if (NIL_P(ruby_cbase)) {
|
||||||
rb_raise(rb_eTypeError, "no class/module to define class variable");
|
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);
|
result = rb_eval(self, node->nd_value);
|
||||||
rb_cvar_declare(ruby_cbase, node->nd_vid, result);
|
if (FL_TEST(ruby_cbase, FL_SINGLETON)) {
|
||||||
|
rb_cvar_declare(rb_cvar_singleton(rb_iv_get(ruby_cbase, "__attached__")),
|
||||||
|
node->nd_vid, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fall through */
|
rb_cvar_declare(ruby_cbase, node->nd_vid, result);
|
||||||
case NODE_CVASGN2:
|
break;
|
||||||
|
|
||||||
|
case NODE_CVASGN:
|
||||||
result = rb_eval(self, node->nd_value);
|
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;
|
break;
|
||||||
|
|
||||||
case NODE_LVAR:
|
case NODE_LVAR:
|
||||||
|
@ -2632,14 +2637,15 @@ rb_eval(self, n)
|
||||||
result = ev_const_get(RNODE(ruby_frame->cbase), node->nd_vid);
|
result = ev_const_get(RNODE(ruby_frame->cbase), node->nd_vid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_CVAR:
|
case NODE_CVAR: /* normal method */
|
||||||
if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
|
if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
|
||||||
result = rb_cvar_get(ruby_cbase, node->nd_vid);
|
result = rb_cvar_get(ruby_cbase, node->nd_vid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
self = rb_iv_get(ruby_cbase, "__attached__");
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case NODE_CVAR2:
|
case NODE_CVAR2: /* singleton method */
|
||||||
result = rb_cvar_get_singleton(self, node->nd_vid);
|
result = rb_cvar_get(rb_cvar_singleton(self), node->nd_vid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_BLOCK_ARG:
|
case NODE_BLOCK_ARG:
|
||||||
|
@ -3634,11 +3640,14 @@ assign(self, lhs, val, check)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_CVDECL:
|
case NODE_CVDECL:
|
||||||
|
if (!FL_TEST(ruby_cbase, FL_SINGLETON)) {
|
||||||
rb_cvar_declare(ruby_cbase, lhs->nd_vid, val);
|
rb_cvar_declare(ruby_cbase, lhs->nd_vid, val);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case NODE_CVASGN2:
|
self = rb_iv_get(ruby_cbase, "__attached__");
|
||||||
rb_cvar_set(CLASS_OF(self), lhs->nd_vid, val);
|
/* fall through */
|
||||||
|
case NODE_CVASGN:
|
||||||
|
rb_cvar_set(rb_cvar_singleton(self), lhs->nd_vid, val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_MASGN:
|
case NODE_MASGN:
|
||||||
|
|
4
gc.c
4
gc.c
|
@ -486,7 +486,7 @@ rb_gc_mark(ptr)
|
||||||
case NODE_IASGN:
|
case NODE_IASGN:
|
||||||
case NODE_CDECL:
|
case NODE_CDECL:
|
||||||
case NODE_CVDECL:
|
case NODE_CVDECL:
|
||||||
case NODE_CVASGN2:
|
case NODE_CVASGN:
|
||||||
case NODE_MODULE:
|
case NODE_MODULE:
|
||||||
case NODE_COLON3:
|
case NODE_COLON3:
|
||||||
case NODE_OPT_N:
|
case NODE_OPT_N:
|
||||||
|
@ -661,7 +661,7 @@ gc_sweep()
|
||||||
int i, used = heaps_used;
|
int i, used = heaps_used;
|
||||||
|
|
||||||
if (ruby_in_compile) {
|
if (ruby_in_compile) {
|
||||||
/* sould not reclaim nodes during compilation */
|
/* should not reclaim nodes during compilation */
|
||||||
for (i = 0; i < used; i++) {
|
for (i = 0; i < used; i++) {
|
||||||
p = heaps[i]; pend = p + HEAP_SLOTS;
|
p = heaps[i]; pend = p + HEAP_SLOTS;
|
||||||
while (p < pend) {
|
while (p < pend) {
|
||||||
|
|
4
intern.h
4
intern.h
|
@ -371,9 +371,7 @@ void rb_cvar_declare _((VALUE, ID, VALUE));
|
||||||
int rb_cvar_defined _((VALUE, ID));
|
int rb_cvar_defined _((VALUE, ID));
|
||||||
void rb_cvar_set _((VALUE, ID, VALUE));
|
void rb_cvar_set _((VALUE, ID, VALUE));
|
||||||
VALUE rb_cvar_get _((VALUE, ID));
|
VALUE rb_cvar_get _((VALUE, ID));
|
||||||
int rb_cvar_defined_singleton _((VALUE, ID));
|
VALUE rb_cvar_singleton _((VALUE));
|
||||||
void rb_cvar_set_singleton _((VALUE, ID, VALUE));
|
|
||||||
VALUE rb_cvar_get_singleton _((VALUE, ID));
|
|
||||||
VALUE rb_mod_class_variables _((VALUE));
|
VALUE rb_mod_class_variables _((VALUE));
|
||||||
/* version.c */
|
/* version.c */
|
||||||
void ruby_show_version _((void));
|
void ruby_show_version _((void));
|
||||||
|
|
4
node.h
4
node.h
|
@ -49,7 +49,7 @@ enum node_type {
|
||||||
NODE_GASGN,
|
NODE_GASGN,
|
||||||
NODE_IASGN,
|
NODE_IASGN,
|
||||||
NODE_CDECL,
|
NODE_CDECL,
|
||||||
NODE_CVASGN2,
|
NODE_CVASGN,
|
||||||
NODE_CVDECL,
|
NODE_CVDECL,
|
||||||
NODE_OP_ASGN1,
|
NODE_OP_ASGN1,
|
||||||
NODE_OP_ASGN2,
|
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_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_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_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_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_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))
|
#define NEW_OP_ASGN2(r,i,o,val) rb_node_newnode(NODE_OP_ASGN2,r,val,NEW_OP_ASGN22(i,o))
|
||||||
|
|
4
parse.y
4
parse.y
|
@ -4089,7 +4089,7 @@ assignable(id, val)
|
||||||
return NEW_CDECL(id, val);
|
return NEW_CDECL(id, val);
|
||||||
}
|
}
|
||||||
else if (is_class_id(id)) {
|
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);
|
return NEW_CVDECL(id, val);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -4179,7 +4179,7 @@ node_assign(lhs, rhs)
|
||||||
case NODE_MASGN:
|
case NODE_MASGN:
|
||||||
case NODE_CDECL:
|
case NODE_CDECL:
|
||||||
case NODE_CVDECL:
|
case NODE_CVDECL:
|
||||||
case NODE_CVASGN2:
|
case NODE_CVASGN:
|
||||||
lhs->nd_value = rhs;
|
lhs->nd_value = rhs;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
63
variable.c
63
variable.c
|
@ -1327,6 +1327,20 @@ rb_define_global_const(name, val)
|
||||||
rb_define_const(rb_cObject, 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
|
void
|
||||||
rb_cvar_set(klass, id, val)
|
rb_cvar_set(klass, id, val)
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
|
@ -1411,55 +1425,6 @@ rb_cvar_defined(klass, id)
|
||||||
return Qfalse;
|
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
|
void
|
||||||
rb_cv_set(klass, name, val)
|
rb_cv_set(klass, name, val)
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#define RUBY_VERSION "1.6.2"
|
#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_VERSION_CODE 162
|
||||||
#define RUBY_RELEASE_CODE 20001120
|
#define RUBY_RELEASE_CODE 20001121
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue