[macruby-changes] [3319] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 21 16:55:25 PST 2010
Revision: 3319
http://trac.macosforge.org/projects/ruby/changeset/3319
Author: lsansonetti at apple.com
Date: 2010-01-21 16:55:23 -0800 (Thu, 21 Jan 2010)
Log Message:
-----------
fix a const lookup bug inside Foo::Bar modules
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
MacRuby/trunk/compiler.h
MacRuby/trunk/include/ruby/intern.h
MacRuby/trunk/variable.c
MacRuby/trunk/vm.cpp
MacRuby/trunk/vm.h
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2010-01-21 20:23:25 UTC (rev 3318)
+++ MacRuby/trunk/compiler.cpp 2010-01-22 00:55:23 UTC (rev 3319)
@@ -1259,7 +1259,7 @@
}
std::vector<Value *> params;
- bool outer = true;
+ int flags = 0;
if (node->nd_vid > 0) {
params.push_back(compile_current_class());
@@ -1267,13 +1267,13 @@
}
else {
assert(node->nd_else != NULL);
- params.push_back(compile_class_path(node->nd_else, &outer));
+ params.push_back(compile_class_path(node->nd_else, &flags));
assert(node->nd_else->nd_mid > 0);
params.push_back(compile_id(node->nd_else->nd_mid));
}
params.push_back(val);
params.push_back(ConstantInt::get(Int8Ty,
- dynamic_class && outer ? 1 : 0));
+ dynamic_class && (flags & DEFINE_OUTER) ? 1 : 0));
CallInst::Create(setConstFunc, params.begin(), params.end(), "", bb);
@@ -1831,27 +1831,28 @@
}
Value *
-RoxorCompiler::compile_class_path(NODE *node, bool *outer)
+RoxorCompiler::compile_class_path(NODE *node, int *flags)
{
if (nd_type(node) == NODE_COLON3) {
// ::Foo
- if (outer != NULL) {
- *outer = false;
+ if (flags != NULL) {
+ *flags = 0;
}
return compile_nsobject();
}
else if (node->nd_head != NULL) {
// Bar::Foo
- if (outer != NULL) {
- *outer = false;
+ if (flags != NULL) {
+ *flags = DEFINE_SUB_OUTER;
}
return compile_node(node->nd_head);
}
-
- if (outer != NULL) {
- *outer = true;
+ else {
+ if (flags != NULL) {
+ *flags = DEFINE_OUTER;
+ }
+ return compile_current_class();
}
- return compile_current_class();
}
Value *
@@ -3961,22 +3962,21 @@
}
std::vector<Value *> params;
- bool outer = false;
+ int flags = 0;
params.push_back(compile_id(path));
- params.push_back(compile_class_path(node->nd_cpath, &outer));
- params.push_back(super == NULL ? zeroVal : compile_node(super));
+ params.push_back(compile_class_path(node->nd_cpath,
+ &flags));
+ params.push_back(super == NULL
+ ? zeroVal : compile_node(super));
- int flags = 0;
if (nd_type(node) == NODE_MODULE) {
flags |= DEFINE_MODULE;
}
- if (outer) {
- flags |= DEFINE_OUTER;
- }
params.push_back(ConstantInt::get(Int32Ty, flags));
params.push_back(ConstantInt::get(Int8Ty,
- outer && dynamic_class ? 1 : 0));
+ (flags & DEFINE_OUTER) && dynamic_class
+ ? 1 : 0));
classVal = compile_protected_call(defineClassFunc, params);
}
Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h 2010-01-21 20:23:25 UTC (rev 3318)
+++ MacRuby/trunk/compiler.h 2010-01-22 00:55:23 UTC (rev 3319)
@@ -279,7 +279,7 @@
Value *compile_current_class(void);
virtual Value *compile_nsobject(void);
virtual Value *compile_standarderror(void);
- Value *compile_class_path(NODE *node, bool *outer);
+ Value *compile_class_path(NODE *node, int *flags);
Value *compile_const(ID id, Value *outer);
Value *compile_singleton_class(Value *obj);
Value *compile_defined_expression(NODE *node);
Modified: MacRuby/trunk/include/ruby/intern.h
===================================================================
--- MacRuby/trunk/include/ruby/intern.h 2010-01-21 20:23:25 UTC (rev 3318)
+++ MacRuby/trunk/include/ruby/intern.h 2010-01-22 00:55:23 UTC (rev 3319)
@@ -633,7 +633,7 @@
//VALUE rb_mod_name(VALUE);
VALUE rb_class_path(VALUE);
void rb_set_class_path(VALUE, VALUE, const char*);
-void rb_set_class_path2(VALUE, VALUE, const char*, bool);
+void rb_set_class_path2(VALUE, VALUE, const char*, VALUE);
VALUE rb_path2class(const char*);
void rb_name_class(VALUE, ID);
VALUE rb_class_name(VALUE);
Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c 2010-01-21 20:23:25 UTC (rev 3318)
+++ MacRuby/trunk/variable.c 2010-01-22 00:55:23 UTC (rev 3319)
@@ -259,7 +259,7 @@
}
void
-rb_set_class_path2(VALUE klass, VALUE under, const char *name, bool set_outer)
+rb_set_class_path2(VALUE klass, VALUE under, const char *name, VALUE outer)
{
VALUE str;
@@ -274,13 +274,13 @@
OBJ_FREEZE(str);
rb_ivar_set(klass, classpath, str);
- rb_vm_set_outer(klass, set_outer ? under : rb_cObject);
+ rb_vm_set_outer(klass, outer);
}
void
rb_set_class_path(VALUE klass, VALUE under, const char *name)
{
- return rb_set_class_path2(klass, under, name, true);
+ return rb_set_class_path2(klass, under, name, under);
}
VALUE
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2010-01-21 20:23:25 UTC (rev 3318)
+++ MacRuby/trunk/vm.cpp 2010-01-22 00:55:23 UTC (rev 3319)
@@ -1298,6 +1298,7 @@
VALUE klass;
if (rb_const_defined_at(outer, path)) {
+ // Constant is already defined.
klass = rb_const_get_at(outer, path);
check_if_module(klass);
if (!(flags & DEFINE_MODULE) && super != 0) {
@@ -1308,11 +1309,30 @@
}
}
else {
+ // Prepare the constant outer.
+ VALUE const_outer;
+ if (flags & DEFINE_OUTER) {
+ const_outer = outer;
+ }
+ else if (flags & DEFINE_SUB_OUTER) {
+ // The Foo::Bar case, the outer here is the outer of the outer.
+ rb_vm_outer_t *o = GET_CORE()->get_outer((Class)outer);
+ if (o != NULL && o->outer != NULL) {
+ const_outer = (VALUE)o->outer->klass;
+ }
+ else {
+ const_outer = rb_cObject;
+ }
+ }
+ else {
+ const_outer = rb_cObject;
+ }
+
+ // Define the constant.
if (flags & DEFINE_MODULE) {
assert(super == 0);
klass = rb_define_module_id(path);
- rb_set_class_path2(klass, outer, rb_id2name(path),
- flags & DEFINE_OUTER);
+ rb_set_class_path2(klass, outer, rb_id2name(path), const_outer);
rb_const_set(outer, path, klass);
}
else {
@@ -1323,8 +1343,7 @@
check_if_module(super);
}
klass = rb_define_class_id(path, super);
- rb_set_class_path2(klass, outer, rb_id2name(path),
- flags & DEFINE_OUTER);
+ rb_set_class_path2(klass, outer, rb_id2name(path), const_outer);
rb_const_set(outer, path, klass);
rb_class_inherited(super, klass);
}
Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h 2010-01-21 20:23:25 UTC (rev 3318)
+++ MacRuby/trunk/vm.h 2010-01-22 00:55:23 UTC (rev 3319)
@@ -554,8 +554,9 @@
};
// For rb_vm_define_class()
-#define DEFINE_MODULE 0x1
-#define DEFINE_OUTER 0x2
+#define DEFINE_MODULE 0x1
+#define DEFINE_OUTER 0x2
+#define DEFINE_SUB_OUTER 0x4
class RoxorCompiler;
class RoxorJITManager;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100121/7a00e3ac/attachment.html>
More information about the macruby-changes
mailing list