Beispiel #1
0
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     if (args.Length == 0)
         return Call1(last_class, recv, caller, args.block, 1);
     else
         return Call1(last_class, recv, caller, args.block, args[0]);
 }
Beispiel #2
0
 public object yield(Frame caller, ArgList args)
 {
     args.block = this.block;
     // return body.Calln(my_class, self, caller, args); // BBTAG: last_class should be nearest lexical class definition rather than Proc
     Class last_class = Init.rb_cObject;
     if (caller != null && caller.nesting().Length > 0)
         last_class = caller.nesting()[0];
     return body.Calln(last_class, self, caller, args);
 }
Beispiel #3
0
        internal object yield(Frame caller, params object[] args)
        {
            ArgList list = new ArgList(block, args);
            if (args.Length == 1)
                list.single_arg = true;

            return yield(caller, list);
            
        }
Beispiel #4
0
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     if (args.Length >= 1)
     {
         string path = String.StringValue(args[0], caller);
         if (path.StartsWith("|"))
         {
             String newpath = new String(path.Remove(0, 1));
             args[0] = newpath;
             return rb_io_s_popen.singleton.Calln(last_class, Ruby.Runtime.Init.rb_cIO, caller, args);
         }
     }
     return rb_io_s_open.singleton.Calln(last_class, Ruby.Runtime.Init.rb_cFile, caller, args);
 }
Beispiel #5
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            Proc proc = (Proc)recv;
            switch (proc.kind)
            {
                case ProcKind.Method:
                case ProcKind.Lambda:
                    {
                        args.single_arg = false;

                        if (!proc.HasCorrectArgs(args.Length))
                            throw new ArgumentError(string.Format(CultureInfo.InvariantCulture, "wrong number of arguments ({0} for {1})", args.Length, System.Math.Abs(proc._arity))).raise(caller);

                        try
                        {
                            return Proc.rb_yield(proc, caller, args);
                        }
                        catch (ReturnException exception)
                        {
                            return exception.return_value;
                        }
                        catch (BreakException exception)
                        {
                            return exception.return_value;
                        }
                    }
                case ProcKind.RawProc:
                    {
                        try
                        {
                            return Proc.rb_yield(proc, caller, args);
                        }
                        catch (BreakException)
                        {
                            throw new LocalJumpError("break from proc-closure").raise(caller);
                        }
                    }
                default:
                case ProcKind.Block:
                    {
                        return Proc.rb_yield(proc, caller, args);
                    }
            }
        }
Beispiel #6
0
        public override object Calln(Class last_class, object self, Frame caller, ArgList args)
        {
            int safe = -1;
            Method method = (Method)self;
            object result = null;

            if (method.recv == null)
                throw new TypeError("you cannot call unbound method; bind first").raise(caller);

            if (method.Tainted)
            {
                safe = Eval.ruby_safe_level;
                if (Eval.ruby_safe_level < 4)
                    Eval.ruby_safe_level = 4;
            }

            result = method.body.body.Calln(last_class, method.recv, caller, args);

            if (safe >= 0)
                Eval.ruby_safe_level = safe;

            return result;
        }
Beispiel #7
0
        internal static object method_missing(object recv, Frame caller, string methodId, ArgList args) {
            ArgList newargs = new ArgList(args.block);
            newargs.Add(new Symbol(methodId));
            newargs.AddRange(args);

            Class origin;
            RubyMethod method = FindPrivateMethod(recv, caller, "method_missing", out origin);
            if (method != null)
                return method.body.Calln(origin, recv, caller, newargs);
            else
                throw new NoMethodError("method_missing method missing").raise(caller);
        }
Beispiel #8
0
 public static object CallPrivateA(object recv, Frame caller, string methodId, ArgList args) {
     Class origin;
     RubyMethod method = FindPrivateMethod(recv, caller, methodId, out origin);
     if (method != null)
         return method.body.Calln(origin, recv, caller, args);
     else
         return method_missing(recv, caller, methodId, args);
 }
 public abstract object Calln(Class last_class, Class ruby_class, object recv, Frame caller, ArgList args);
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     return Eval.CallSuperA(klass, caller, recv, methodId, args);
 }
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     return Call(last_class, recv, caller, args.block, Remaining(args, 0));
 }
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     if (args.Length == 9)
         return Call9(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
     else
         throw new ArgumentError("wrong number of arguments (" + args.Length + " for 9)").raise(caller);
 }
Beispiel #13
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            Errors.rb_warn(string.Format(CultureInfo.InvariantCulture, "Hash#{0} is deprecated; use Hash#values_at", "indexes")); //rb_frame_last_func

            System.Collections.ArrayList result = new System.Collections.ArrayList(args.Length);

            for (int i = 0; i < args.Length; i++)
                result.Add(rb_hash_aref.singleton.Call1(last_class, recv, caller, null, args[i]));

            return Array.CreateUsing(result);
        }
Beispiel #14
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            System.Collections.ArrayList result = new System.Collections.ArrayList(args.Length);

            for (int i = 0; i < args.Length; i++)
                result.Add(rb_hash_aref.singleton.Call1(last_class, recv, caller, null, args[i]));

            return Array.CreateUsing(result);
        }
Beispiel #15
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            ArrayList ary = ((Array)recv).value;

            try
            {
                for (int i = 0; i < ary.Count; i++)
                {
                    ArgList args = new ArgList(null, ary[i]);
                    args.single_arg = true;
                    Proc.rb_yield(block, caller, args);
                }
            }
            catch (BreakException)
            {
            }

            return recv;
        }
 public virtual object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     switch (args.Length)
     {
         case 0: return Call0(last_class, recv, caller, args.block);
         case 1: return Call1(last_class, recv, caller, args.block, args[0]);
         case 2: return Call2(last_class, recv, caller, args.block, args[0], args[1]);
         case 3: return Call3(last_class, recv, caller, args.block, args[0], args[1], args[2]);
         case 4: return Call4(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3]);
         case 5: return Call5(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3], args[4]);
         case 6: return Call6(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3], args[4], args[5]);
         case 7: return Call7(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
         case 8: return Call8(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
         case 9: return Call9(last_class, recv, caller, args.block, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
         default:
             throw new System.Exception("wrong number of arguments");
     }
 }
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     if (args.Length == 1)
         return Call1(last_class, recv, caller, args.block, args[0]);
     else
         throw new ArgumentError("wrong number of arguments (" + args.Length + " for 1)").raise(caller);
 }
Beispiel #18
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            char[] table = new char[256];
            int s, send;
            string sString;
            bool init = true;
            int i;

            if (args.Length < 1)
            {
                throw new ArgumentError("wrong number of arguments").raise(caller);
            }

            for (i = 0; i < args.Length; i++)
            {
                string sValue;

                sValue = String.StringValue(args[i], caller);
                String.SetupTable(sValue, table, init);
                init = false;
            }

            s = 0;
            sString = ((String)recv).value;
            if (sString == null || sString.Length == 0)
            {
                return 0;
            }
            send = s + sString.Length;
            i = 0;
            while (s < send)
            {
                if (table[(int)sString[s++]] > 0)
                {
                    i++;
                }
            }

            return i;
        }
 protected Array Remaining(ArgList args, int count)
 {
     object[] rest = new object[args.Length - count];
     for (int i = 0; i < args.Length - count; i++)
         rest[i] = args[i + count];
     return new Array(rest);
 }
Beispiel #20
0
        //needs retesting
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object arg)
        {
             if (arg is Array)
            {
                ArgList argv = new ArgList(block, new object[] { recv });
                argv.AddRange((Array)arg);
                return rb_f_sprintf.singleton.Calln(last_class, null, caller, argv);
            }

            return rb_f_sprintf.singleton.Call2(last_class, null, caller, block, recv, arg);
        }
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     if (args.Length < 3)
         throw new ArgumentError("wrong number of arguments (" + args.Length + " for 3)").raise(caller);
     return Call(last_class, recv, caller, args.block, args[0], args[1], args[2], Remaining(args, 3));
 }
Beispiel #22
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            System.Text.RegularExpressions.CaptureCollection captures
                = ((Match)recv).value.Captures;

            Array result = new Array();
            foreach (int index in args)
            {
                int i = (index < 0) ? captures.Count - index : index;
                result.value.Add(new String(captures[i].Value));
            }

            return result;
        }
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     Method bound = (Method)(Methods.umethod_bind.singleton.Call1(last_class, orig, caller, args.block, recv));
     return bound.body.body.Calln(last_class, recv, caller, args);
 }
Beispiel #24
0
        public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
        {
            object idx, rest = null;

            Array argv = args.ToRubyArray();

            if (Class.rb_scan_args(caller, argv, 1, 1, false) == 2)
                rest = args[1];
            idx = args[0];

            if (rest != null || !(idx is int) || ((int)idx) < 0)
            {
                return rb_ary_aref.singleton.Call(last_class, match_to_a.singleton.Call0(last_class, recv, caller, null), caller, null, argv);
            }

            return Regexp.rb_reg_nth_match((int)idx, (Match)recv);
        }
 public override object Calln(Class last_class, object recv, Frame caller, ArgList args)
 {
     return Calln(last_class, null, recv, caller, args);
 }
Beispiel #26
0
        public override object Calln(Class klass, object recv, Frame caller, ArgList args)
        {
            Eval.rb_secure(4, caller);
            
            Array keys = (Array)env_keys.singleton.Call0(klass, recv, caller, null);
            foreach (object key in keys)
            {
                object val = rb_f_getenv.singleton.Call1(klass, recv, caller, null, key);
                if (val != null)
                    Env.env_delete(caller, val);
            }

            return recv;
        }
Beispiel #27
0
        public static object CallSuperA(Class klass, Frame caller, object recv, string methodId, ArgList args) {
            Class origin;
            RubyMethod method = FindSuperMethod(klass, caller, methodId, out origin);

            if (method != null)
                return method.body.Calln(origin, recv, caller, args);
            else {
                caller.call_status = CallStatus.Super;
                return method_missing(recv, caller, methodId, args);
            }
        }
Beispiel #28
0
 public override object Calln(Class klass, object recv, Frame caller, ArgList args)
 {
     return new String("ENV");
 }
Beispiel #29
0
        internal static object specific_eval(Class last_class, object self, Class ruby_class, Frame caller, Proc block, Array args) //author: Brian, status: partial
        {
            if (block != null) {
                ArgList argList = new ArgList();
                argList.AddArray(args, caller);
                return block.yield_under(caller, argList, ruby_class, self);
            } else {
                string file = "eval";
                int line = 1;

                object scope = null;
                object vfile = null;
                object vline = null;
                String src = null;

                if (args.Count > 0) {
                    src = (String)(args[0]);
                    if (args.Count > 1) {
                        vfile = args[1];
                        file = ((String)vfile).value;
                        if (args.Count > 2) {
                            vline = args[2];
                            line = (int)vline;
                        }
                    }
                }

                scope = new Binding(caller, self);

                if (!(scope is IContext))
                    throw new TypeError(string.Format(CultureInfo.InvariantCulture, "wrong argument type {0} (expected Proc/Binding)", scope.GetType())).raise(caller);

                object ret = Eval.eval_under(ruby_class, self, (String)src, (IContext)scope, file, line, caller);

                return ret;
            }
        }
Beispiel #30
0
        public override object Calln(Class klass, object recv, Frame caller, ArgList args)
        {
            Array values = new Array();

            foreach (string val in System.Environment.GetEnvironmentVariables().Values)
                values.Add(Env.env_str_new2(caller, val));

            return values;
        }