Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed const lookup inside a module defined under an explicit (using :…

…:) module

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2309 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit aca37fffc732fd1bd3e3cd87703ba0ab42ea318f 1 parent 19b6a62
Laurent Sansonetti authored
View
34 compiler.cpp
@@ -1193,7 +1193,7 @@ RoxorCompiler::compile_constant_declaration(NODE *node, Value *val)
}
else {
assert(node->nd_else != NULL);
- params.push_back(compile_class_path(node->nd_else));
+ params.push_back(compile_class_path(node->nd_else, NULL));
assert(node->nd_else->nd_mid > 0);
params.push_back(compile_id(node->nd_else->nd_mid));
}
@@ -1696,17 +1696,26 @@ RoxorCompiler::compile_jump(NODE *node)
}
Value *
-RoxorCompiler::compile_class_path(NODE *node)
+RoxorCompiler::compile_class_path(NODE *node, bool *outer)
{
if (nd_type(node) == NODE_COLON3) {
// ::Foo
+ if (outer != NULL) {
+ *outer = false;
+ }
return compile_nsobject();
}
else if (node->nd_head != NULL) {
// Bar::Foo
+ if (outer != NULL) {
+ *outer = false;
+ }
return compile_node(node->nd_head);
}
+ if (outer != NULL) {
+ *outer = true;
+ }
return compile_current_class();
}
@@ -2639,7 +2648,8 @@ RoxorCompiler::compile_literal(VALUE val)
params.push_back(load);
params.push_back(ConstantInt::get(Type::Int32Ty, str_len));
- return compile_protected_call(newString2Func, params);
+ return CallInst::Create(newString2Func, params.begin(),
+ params.end(), "", bb);
}
}
@@ -3618,20 +3628,28 @@ RoxorCompiler::compile_node(NODE *node)
if (defineClassFunc == NULL) {
// VALUE rb_vm_define_class(ID path, VALUE outer, VALUE super,
- // unsigned char is_module);
+ // int flags);
defineClassFunc = cast<Function>(module->getOrInsertFunction(
"rb_vm_define_class",
RubyObjTy, IntTy, RubyObjTy, RubyObjTy,
- Type::Int8Ty, NULL));
+ Type::Int32Ty, NULL));
}
std::vector<Value *> params;
+ bool outer = true;
params.push_back(compile_id(path));
- params.push_back(compile_class_path(node->nd_cpath));
+ params.push_back(compile_class_path(node->nd_cpath, &outer));
params.push_back(super == NULL ? zeroVal : compile_node(super));
- params.push_back(ConstantInt::get(Type::Int8Ty,
- nd_type(node) == NODE_MODULE ? 1 : 0));
+
+ int flags = 0;
+ if (nd_type(node) == NODE_MODULE) {
+ flags |= DEFINE_MODULE;
+ }
+ if (outer) {
+ flags |= DEFINE_OUTER;
+ }
+ params.push_back(ConstantInt::get(Type::Int32Ty, flags));
classVal = compile_protected_call(defineClassFunc, params);
}
View
2  compiler.h
@@ -242,7 +242,7 @@ class RoxorCompiler {
void compile_multiple_assignment_element(NODE *node, Value *val);
Value *compile_current_class(void);
virtual Value *compile_nsobject(void);
- Value *compile_class_path(NODE *node);
+ Value *compile_class_path(NODE *node, bool *outer);
Value *compile_const(ID id, Value *outer);
Value *compile_singleton_class(Value *obj);
Value *compile_defined_expression(NODE *node);
View
1  include/ruby/intern.h
@@ -621,6 +621,7 @@ struct timeval rb_time_interval(VALUE num);
//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);
VALUE rb_path2class(const char*);
void rb_name_class(VALUE, ID);
VALUE rb_class_name(VALUE);
View
12 variable.c
@@ -259,7 +259,7 @@ rb_class_path(VALUE klass)
}
void
-rb_set_class_path(VALUE klass, VALUE under, const char *name)
+rb_set_class_path2(VALUE klass, VALUE under, const char *name, bool set_outer)
{
VALUE str;
@@ -274,7 +274,15 @@ rb_set_class_path(VALUE klass, VALUE under, const char *name)
OBJ_FREEZE(str);
rb_ivar_set(klass, classpath, str);
- rb_vm_set_outer(klass, under);
+ if (set_outer) {
+ rb_vm_set_outer(klass, under);
+ }
+}
+
+void
+rb_set_class_path(VALUE klass, VALUE under, const char *name)
+{
+ return rb_set_class_path2(klass, under, name, true);
}
VALUE
View
12 vm.cpp
@@ -902,7 +902,7 @@ check_if_module(VALUE mod)
extern "C"
VALUE
-rb_vm_define_class(ID path, VALUE outer, VALUE super, unsigned char is_module)
+rb_vm_define_class(ID path, VALUE outer, VALUE super, int flags)
{
assert(path > 0);
check_if_module(outer);
@@ -915,7 +915,7 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, unsigned char is_module)
VALUE klass;
if (rb_const_defined_at(outer, path)) {
klass = rb_const_get_at(outer, path);
- if (!is_module && super != 0) {
+ if (!(flags & DEFINE_MODULE) && super != 0) {
check_if_module(klass);
if (RCLASS_SUPER(klass) != super) {
rb_raise(rb_eTypeError, "superclass mismatch for class %s",
@@ -924,10 +924,11 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, unsigned char is_module)
}
}
else {
- if (is_module) {
+ if (flags & DEFINE_MODULE) {
assert(super == 0);
klass = rb_define_module_id(path);
- rb_set_class_path(klass, outer, rb_id2name(path));
+ rb_set_class_path2(klass, outer, rb_id2name(path),
+ flags & DEFINE_OUTER);
rb_const_set(outer, path, klass);
}
else {
@@ -938,7 +939,8 @@ rb_vm_define_class(ID path, VALUE outer, VALUE super, unsigned char is_module)
check_if_module(super);
}
klass = rb_define_class_id(path, super);
- rb_set_class_path(klass, outer, rb_id2name(path));
+ rb_set_class_path2(klass, outer, rb_id2name(path),
+ flags & DEFINE_OUTER);
rb_const_set(outer, path, klass);
rb_class_inherited(super, klass);
}
View
4 vm.h
@@ -483,6 +483,10 @@ struct ccache {
VALUE val;
};
+// For rb_vm_define_class()
+#define DEFINE_MODULE 0x1
+#define DEFINE_OUTER 0x2
+
class RoxorCompiler;
class RoxorJITManager;
Please sign in to comment.
Something went wrong with that request. Please try again.