[macruby-changes] [4559] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Sep 29 16:44:28 PDT 2010
Revision: 4559
http://trac.macosforge.org/projects/ruby/changeset/4559
Author: lsansonetti at apple.com
Date: 2010-09-29 16:44:27 -0700 (Wed, 29 Sep 2010)
Log Message:
-----------
add basic support for __method__ and __callee__
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
MacRuby/trunk/compiler.h
MacRuby/trunk/eval.c
MacRuby/trunk/id.c
MacRuby/trunk/id.h
MacRuby/trunk/symbol.c
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2010-09-29 14:14:51 UTC (rev 4558)
+++ MacRuby/trunk/compiler.cpp 2010-09-29 23:44:27 UTC (rev 4559)
@@ -208,6 +208,7 @@
newRangeFunc = NULL;
newRegexpFunc = NULL;
strInternFunc = NULL;
+ selToSymFunc = NULL;
keepVarsFunc = NULL;
masgnGetElemBeforeSplatFunc =
get_function("vm_masgn_get_elem_before_splat");
@@ -2367,6 +2368,26 @@
return pn;
}
+ // __method__ or __callee__
+ else if (sel == sel__method__ || sel == sel__callee__) {
+
+ if (current_block_func != NULL || argc != 0) {
+ return NULL;
+ }
+
+ Function *f = bb->getParent();
+ Function::arg_iterator arg = f->arg_begin();
+ arg++; // skip self
+ Value *callee_sel = arg;
+
+ if (selToSymFunc == NULL) {
+ // VALUE rb_sel_to_sym(SEL sel);
+ selToSymFunc = cast<Function>(
+ module->getOrInsertFunction("rb_sel_to_sym",
+ RubyObjTy, PtrTy, NULL));
+ }
+ return CallInst::Create(selToSymFunc, callee_sel, "", bb);
+ }
return NULL;
}
Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h 2010-09-29 14:14:51 UTC (rev 4558)
+++ MacRuby/trunk/compiler.h 2010-09-29 23:44:27 UTC (rev 4559)
@@ -198,6 +198,7 @@
Function *newRangeFunc;
Function *newRegexpFunc;
Function *strInternFunc;
+ Function *selToSymFunc;
Function *keepVarsFunc;
Function *masgnGetElemBeforeSplatFunc;
Function *masgnGetElemAfterSplatFunc;
Modified: MacRuby/trunk/eval.c
===================================================================
--- MacRuby/trunk/eval.c 2010-09-29 14:14:51 UTC (rev 4558)
+++ MacRuby/trunk/eval.c 2010-09-29 23:44:27 UTC (rev 4559)
@@ -805,14 +805,7 @@
static VALUE
rb_f_method_name(VALUE rcv, SEL sel)
{
- ID fname = rb_frame_callee();
-
- if (fname) {
- return ID2SYM(fname);
- }
- else {
- return Qnil;
- }
+ return Qnil;
}
void Init_vm_eval(void);
Modified: MacRuby/trunk/id.c
===================================================================
--- MacRuby/trunk/id.c 2010-09-29 14:14:51 UTC (rev 4558)
+++ MacRuby/trunk/id.c 2010-09-29 23:44:27 UTC (rev 4559)
@@ -107,6 +107,9 @@
selLambda = sel_registerName("lambda");
selObjectForKey = sel_registerName("objectForKey:");
selSetObjectForKey = sel_registerName("setObject:forKey:");
+
+ sel__method__= sel_registerName("__method__");
+ sel__callee__ = sel_registerName("__callee__");
#endif
idAREF = rb_intern("[]");
Modified: MacRuby/trunk/id.h
===================================================================
--- MacRuby/trunk/id.h 2010-09-29 14:14:51 UTC (rev 4558)
+++ MacRuby/trunk/id.h 2010-09-29 23:44:27 UTC (rev 4559)
@@ -117,6 +117,8 @@
extern SEL selLambda;
extern SEL selObjectForKey;
extern SEL selSetObjectForKey;
+extern SEL sel__method__;
+extern SEL sel__callee__;
extern ID idIncludedModules;
extern ID idIncludedInClasses;
extern ID idAncestors;
Modified: MacRuby/trunk/symbol.c
===================================================================
--- MacRuby/trunk/symbol.c 2010-09-29 14:14:51 UTC (rev 4558)
+++ MacRuby/trunk/symbol.c 2010-09-29 23:44:27 UTC (rev 4559)
@@ -843,3 +843,12 @@
{
return RSYM(sym)->str;
}
+
+VALUE
+rb_sel_to_sym(SEL sel)
+{
+ if (sel == 0) {
+ return Qnil;
+ }
+ return ID2SYM(rb_intern(sel_getName(sel)));
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100929/dd8996ba/attachment.html>
More information about the macruby-changes
mailing list