[macruby-changes] [2309] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 13 13:44:19 PDT 2009


Revision: 2309
          http://trac.macosforge.org/projects/ruby/changeset/2309
Author:   lsansonetti at apple.com
Date:     2009-08-13 13:44:16 -0700 (Thu, 13 Aug 2009)
Log Message:
-----------
fixed const lookup inside a module defined under an explicit (using ::) module

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	2009-08-13 19:26:58 UTC (rev 2308)
+++ MacRuby/trunk/compiler.cpp	2009-08-13 20:44:16 UTC (rev 2309)
@@ -1193,7 +1193,7 @@
     }
     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 @@
 }
 
 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 @@
 	    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 @@
 
 		    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);
 		}

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2009-08-13 19:26:58 UTC (rev 2308)
+++ MacRuby/trunk/compiler.h	2009-08-13 20:44:16 UTC (rev 2309)
@@ -242,7 +242,7 @@
 	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);

Modified: MacRuby/trunk/include/ruby/intern.h
===================================================================
--- MacRuby/trunk/include/ruby/intern.h	2009-08-13 19:26:58 UTC (rev 2308)
+++ MacRuby/trunk/include/ruby/intern.h	2009-08-13 20:44:16 UTC (rev 2309)
@@ -621,6 +621,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);
 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	2009-08-13 19:26:58 UTC (rev 2308)
+++ MacRuby/trunk/variable.c	2009-08-13 20:44:16 UTC (rev 2309)
@@ -259,7 +259,7 @@
 }
 
 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,9 +274,17 @@
     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
 rb_path2class(const char *path)
 {

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-08-13 19:26:58 UTC (rev 2308)
+++ MacRuby/trunk/vm.cpp	2009-08-13 20:44:16 UTC (rev 2309)
@@ -902,7 +902,7 @@
 
 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 @@
     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 @@
 	}
     }
     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 @@
 		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);
 	}

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2009-08-13 19:26:58 UTC (rev 2308)
+++ MacRuby/trunk/vm.h	2009-08-13 20:44:16 UTC (rev 2309)
@@ -483,6 +483,10 @@
     VALUE val;
 };
 
+// For rb_vm_define_class()
+#define DEFINE_MODULE	0x1
+#define DEFINE_OUTER 	0x2
+
 class RoxorCompiler;
 class RoxorJITManager;
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090813/275e578b/attachment-0001.html>


More information about the macruby-changes mailing list