internal RubyMethod(MethodBody body, int arity, Access access, Class definingClass)
 {
     this.body = body;
     this.arity = arity;
     this.access = access;
     this.definingClass = definingClass;
 }
Beispiel #2
0
 internal Proc(object self, Proc block, MethodBody body, int arity, ProcKind kind)
     : base(Ruby.Runtime.Init.rb_cProc)
 {
     this.self = self;
     this.block = block;
     this.body = body;
     this.kind = kind;
     this._arity = arity;
 }
Beispiel #3
0
 internal static void rb_define_singleton_method(object obj, string name, MethodBody body, int arity, Frame caller)//status: done
 {
     singleton_class(caller, obj).define_method(name, body, arity, caller);
 }
Beispiel #4
0
 internal static void rb_define_global_function(string name, MethodBody body, int arity, Frame caller)//status: done
 {
     Ruby.Runtime.Init.rb_mKernel.define_module_function(name, body, arity, caller);
 }
Beispiel #5
0
 internal void define_module_function(string name, MethodBody body, int arity, Frame caller)//status: done
 {
     define_private_method(name, body, arity, caller);
     rb_define_singleton_method(this, name, body, arity, caller);
 }
Beispiel #6
0
        // BBTAG: corresponds to rb_add_method: complete implementation of method definition, 
        // including invocation tests
        internal void add_method(string name, MethodBody body, int arity, Access access, Frame caller)//author: Brian, status: done
        {
            Debug.Assert(_methods != null);

            if (Eval.rb_safe_level() >= 4 && (this == Ruby.Runtime.Init.rb_cObject || !Tainted))
                throw new SecurityError("Insecure: can't define method").raise(caller);

            if ((_type != Type.Singleton) && (name.Equals("initialize") || name.Equals("initialize_copy")))
                access = Access.Private;
            else if ((_type == Type.Singleton) && name.Equals("allocate"))
            {
                Errors.rb_warn((System.String.Format(CultureInfo.InvariantCulture, "defining {0}.allocate is deprecated; use define_alloc_func()", ((Class)attached)._name)));
                name = "allocator";
            }

            _methods[name] = new RubyMethod(body, arity, access, this);

            if (!name.Equals("allocator") && Eval.RubyRunning)
            {
                if (_type == Type.Singleton)
                    Eval.CallPrivate(attached, caller, "singleton_method_added", null, new Symbol(name));
                else
                    Eval.CallPrivate(this, caller, "method_added", null, new Symbol(name));
            }
        }
Beispiel #7
0
 internal void add_method(string name, MethodBody body, int arity, Frame caller)
 {
     if (caller != null && caller.scope_vmode == Access.ModuleFunction &&
         caller.nesting().Length > 0 && caller.nesting()[0] == this)
     {
         add_method(name, body, arity, Access.Private, caller);
         Class.rb_define_singleton_method(this, name, body, arity, caller);
     }
     else
     {
         add_method(name, body, arity, get_visibility_mode(caller), caller);
     }
 }
Beispiel #8
0
        public void define_method(string name, MethodBody body, int arity, Frame caller)
        {
            Debug.Assert(_methods != null);

            add_method(name, body, arity, caller);
        }
Beispiel #9
0
 public Proc(object self, Proc block, MethodBody body, int arity)
     : this(self, block, body, arity, ProcKind.RawProc)
 {
 }
Beispiel #10
0
        public void define_alloc_func(MethodBody body)
        {
            // Make sure the new allocator method generates objects that are subtypes of those
            // generated by the old allocator method - prevents compiler-generated CLR interop classes
            // overwriting Ruby built-in classes with incompatible allocator methods

            RubyMethod oldAlloc = null;
            Class c = this;

            //while (c != null)
            //{
                if (singleton_class(null, c)._methods.ContainsKey("allocator"))
                    oldAlloc = singleton_class(null, c)._methods["allocator"];

                if (oldAlloc != null && oldAlloc.body != null && body != null)
                {
                    object oldObj, newObj;

                    oldObj = oldAlloc.body.Call0(null, oldAlloc.definingClass, null, null);
                    newObj = body.Call0(null, oldAlloc.definingClass, null, null);

                    if (oldObj != null && newObj != null && !(newObj.GetType().IsInstanceOfType(oldObj)))
                    {
                    //    if (oldObj.GetType().FullName == "Ruby.Object" && newObj.GetType().FullName != "Ruby.Basic")
                            return;
                        //if ((oldObj.GetType().Equals(new Ruby.Object().GetType()) && !(newObj.GetType().Equals(new Ruby.Basic(null).GetType()))))
                        //    return;
                    }
                }

            //    c = c.super_real();
            //}
             
            rb_define_singleton_method(this, "allocator", body, 0, null);
        }
Beispiel #11
0
 internal static void rb_define_module_function(Class module, string name, MethodBody method, int arity, Frame caller)
 {
     module.define_module_function(name, method, arity, caller);
 }
Beispiel #12
0
 internal static void rb_define_private_method(Class klass, string name, MethodBody body, int arity, Frame caller)
 {
     klass.define_private_method(name, body, arity, caller);
 }
Beispiel #13
0
 internal static void rb_define_alloc_func(Class klass, MethodBody body)
 {
     klass.define_alloc_func(body);
 }
Beispiel #14
0
 internal static void rb_define_method(Class klass, string name, MethodBody method, int arity, Frame caller)
 {
     klass.define_public_method(name, method, arity, caller);
 }
Beispiel #15
0
 private static void define_filetest_function(string name, MethodBody body, int arity)
 {
     // BBTAG: someone may need to pass in a proper caller parameter here
     Ruby.Runtime.Init.rb_mFileTest.define_module_function(name, body, arity, null);
 }
Beispiel #16
0
 internal void define_public_method(string name, MethodBody body, int arity, Frame caller)//status: done
 {
     // methods[name] = new RubyMethod(body, arity, Access.Public);
     add_method(name, body, arity, Access.Public, caller);
 }
Beispiel #17
0
        // -------------------------------------------------------

        internal static void define_filetest_function(string name, MethodBody func, int argc)
        {
            //FIXME: Caller
            Class.rb_define_module_function(Ruby.Runtime.Init.rb_mFileTest, name, func, argc, null);
            Class.rb_define_singleton_method(Ruby.Runtime.Init.rb_cFile, name, func, argc, null);
        }