[macruby-changes] [4844] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 28 14:53:39 PDT 2010


Revision: 4844
          http://trac.macosforge.org/projects/ruby/changeset/4844
Author:   lsansonetti at apple.com
Date:     2010-10-28 14:53:38 -0700 (Thu, 28 Oct 2010)
Log Message:
-----------
add implementation of MRI rb_call_super() method (note: untested)

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/compiler.h
    MacRuby/trunk/dispatcher.cpp
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm.h

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-10-28 20:50:29 UTC (rev 4843)
+++ MacRuby/trunk/compiler.cpp	2010-10-28 21:53:38 UTC (rev 4844)
@@ -270,6 +270,7 @@
     rvalToSelFunc = get_function("vm_rval_to_sel");
     rvalToCharPtrFunc = get_function("vm_rval_to_charptr");
     initBlockFunc = get_function("vm_init_c_block");
+    setCurrentMRIMethodContext = NULL;
 
     VoidTy = Type::getVoidTy(context);
     Int1Ty = Type::getInt1Ty(context);
@@ -6569,8 +6570,20 @@
     bb = BasicBlock::Create(context, "EntryBlock", f);
     Function::arg_iterator arg = f->arg_begin();
     Value *rcv = arg++;
-    arg++; // skip SEL
+    Value *sel = arg++;
 
+    // Register the receiver and selector to the VM (for rb_call_super()).
+    if (setCurrentMRIMethodContext == NULL) {
+	// void rb_vm_prepare_method(Class klass, unsigned char dynamic_class,
+	//	SEL sel, Function *func, rb_vm_arity_t arity, int flags)
+	setCurrentMRIMethodContext = 
+	    cast<Function>(module->getOrInsertFunction(
+			"rb_vm_set_current_mri_method_context",
+			VoidTy, RubyObjTy, Int8Ty, NULL));
+    }
+    Value *args[2] = { rcv, sel };
+    CallInst::Create(setCurrentMRIMethodContext, args, args + 2, "", bb);
+
     // Prepare function types for the MRI implementation and arguments.
     std::vector<const Type *> imp_types;
     std::vector<Value *> params;

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2010-10-28 20:50:29 UTC (rev 4843)
+++ MacRuby/trunk/compiler.h	2010-10-28 21:53:38 UTC (rev 4844)
@@ -259,6 +259,7 @@
 	Function *rvalToSelFunc;
 	Function *rvalToCharPtrFunc;
 	Function *initBlockFunc;
+	Function *setCurrentMRIMethodContext;
 
 	Constant *zeroVal;
 	Constant *oneVal;

Modified: MacRuby/trunk/dispatcher.cpp
===================================================================
--- MacRuby/trunk/dispatcher.cpp	2010-10-28 20:50:29 UTC (rev 4843)
+++ MacRuby/trunk/dispatcher.cpp	2010-10-28 21:53:38 UTC (rev 4844)
@@ -1586,4 +1586,28 @@
 	bool check_override)
 {
     return respond_to(obj, klass, sel, priv, check_override);
+}
+
+// Note: rb_call_super() MUST always be called from methods registered using
+// the MRI API (such as rb_define_method() & friends). It must NEVER be used
+// internally inside MacRuby core.
+extern "C"
+VALUE
+rb_call_super(int argc, const VALUE *argv)
+{
+    RoxorVM *vm = GET_VM();
+    VALUE self = vm->get_current_mri_method_self();
+    SEL sel = vm->get_current_mri_method_sel();
+    assert(self != 0 && sel != 0);
+
+    return rb_vm_call_super(self, sel, argc, argv);
+}
+
+extern "C"
+void
+rb_vm_set_current_mri_method_context(VALUE self, SEL sel)
+{
+    RoxorVM *vm = GET_VM();
+    vm->set_current_mri_method_self(self);
+    vm->set_current_mri_method_sel(sel);
 } 

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2010-10-28 20:50:29 UTC (rev 4843)
+++ MacRuby/trunk/vm.cpp	2010-10-28 21:53:38 UTC (rev 4844)
@@ -401,6 +401,8 @@
     special_exc = NULL;
     current_super_class = NULL;
     current_super_sel = 0;
+    current_mri_method_self = Qnil;
+    current_mri_method_sel = 0;
 
     mcache = (struct mcache *)calloc(VM_MCACHE_SIZE, sizeof(struct mcache));
     assert(mcache != NULL);

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2010-10-28 20:50:29 UTC (rev 4843)
+++ MacRuby/trunk/vm.h	2010-10-28 21:53:38 UTC (rev 4844)
@@ -1033,7 +1033,9 @@
 	bool has_ensure;
 	int return_from_block;
 	Class current_super_class;
-	SEL current_super_sel;	
+	SEL current_super_sel;
+	VALUE current_mri_method_self;
+	SEL current_mri_method_sel;
 
 	RoxorSpecialException *special_exc;
 
@@ -1061,6 +1063,8 @@
 	ACCESSOR(current_super_class, Class);
 	ACCESSOR(current_super_sel, SEL);
 	READER(mcache, struct mcache *);
+	ACCESSOR(current_mri_method_self, VALUE);
+	ACCESSOR(current_mri_method_sel, SEL);
 
 	std::string debug_blocks(void);
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101028/da2512e8/attachment-0001.html>


More information about the macruby-changes mailing list