Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add basic support for __method__ and __callee__

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4559 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 00b147f04fe2b6579257233c14dafac63a43fd0e 1 parent 5a12405
Laurent Sansonetti authored
View
21 compiler.cpp
@@ -208,6 +208,7 @@ RoxorCompiler::RoxorCompiler(bool _debug_mode)
newRangeFunc = NULL;
newRegexpFunc = NULL;
strInternFunc = NULL;
+ selToSymFunc = NULL;
keepVarsFunc = NULL;
masgnGetElemBeforeSplatFunc =
get_function("vm_masgn_get_elem_before_splat");
@@ -2367,6 +2368,26 @@ RoxorCompiler::compile_optimized_dispatch_call(SEL sel, int argc,
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;
}
View
1  compiler.h
@@ -198,6 +198,7 @@ class RoxorCompiler {
Function *newRangeFunc;
Function *newRegexpFunc;
Function *strInternFunc;
+ Function *selToSymFunc;
Function *keepVarsFunc;
Function *masgnGetElemBeforeSplatFunc;
Function *masgnGetElemAfterSplatFunc;
View
9 eval.c
@@ -805,14 +805,7 @@ rb_f_local_variables(VALUE rcv, SEL sel)
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);
View
3  id.c
@@ -107,6 +107,9 @@ Init_id(void)
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("[]");
View
2  id.h
@@ -117,6 +117,8 @@ extern SEL selInherited;
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;
View
9 symbol.c
@@ -843,3 +843,12 @@ rb_sym_str(VALUE sym)
{
return RSYM(sym)->str;
}
+
+VALUE
+rb_sel_to_sym(SEL sel)
+{
+ if (sel == 0) {
+ return Qnil;
+ }
+ return ID2SYM(rb_intern(sel_getName(sel)));
+}
Please sign in to comment.
Something went wrong with that request. Please try again.