示例#1
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            Class klass0 = Class.CLASS_OF(recv);

            return klass0.class_real();

        }
示例#2
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
        {
            if (Numeric.random == null)
                rb_f_srand.singleton.Call0(last_class, recv, caller, null);
                        
            int max;
            if (p1 == null)
                max = 0;
            else if (p1 is int)
                max = (int)p1;
            else if (p1 is Bignum)
                return rb_big_rand((Bignum)p1, Numeric.random.NextDouble());
            else if (p1 is Float)
            {
                if (((Float)p1).value <= int.MaxValue && ((Float)p1).value >= int.MinValue)
                    max = (int)((Float)p1).value;
                else
                    return rb_big_rand(new Bignum(((Float)p1).value), Numeric.random.NextDouble());
            }
            else
            {
                p1 = Integer.rb_Integer(p1, caller);
                if (p1 is Bignum)
                    return rb_big_rand((Bignum)p1, Numeric.random.NextDouble());
                max = (int)System.Math.Abs(Numeric.rb_num2long(p1, caller));
            }

            if (max == 0)
                return new Float(Numeric.random.NextDouble());
            else if (max < 0)
                max = -max;

            return (int)(max * Numeric.random.NextDouble());
        }
示例#3
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
        {
            string path = String.StringValue(p1, caller);

            Eval.rb_secure(2, caller);
            return new FileStat(path);
        }
 public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
 {
     if (recv == p1)
         return true;
     else
         return Object.Equals(((ProcessStatus)recv).st, p1);
 }
示例#5
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object param0)
        {
            if (param0 is bool)
                return (bool)param0;

            return param0 != null;
        }
示例#6
0
        public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest)
        {
            object time, t;            
            long seconds = 0;
            long uSeconds = 0;

            if (Class.rb_scan_args(caller, rest, 1, 1, false) == 2)
            {
                time = rest[0];
                t = rest[1];
                seconds = Numeric.rb_num2long(rest[0], caller);
                uSeconds = Numeric.rb_num2long(rest[1], caller);
            }
            else 
            {
                time = rest[0];
                Time.rb_time_timeval(rest[0], out seconds, out uSeconds, caller);
            }

            if (time is Time)
            {
                bool gmt = ((Time)time).gmt;
                t = Time.time_new_internal(seconds, uSeconds, gmt, caller);
            }
            else
            {
                t = Time.time_new_internal(seconds, uSeconds, false, caller);
                ((Time)t).value = ((Time)t).value.ToLocalTime();
            }

            return t;
        }
示例#7
0
 public override object Call0(Class last_class, object recv, Frame caller, Proc block)
 {
     // this functionality seems to be getting done in another method
     // could not find a testing sequence that made this fail. Although
     // Eval.getConst only calls it under certain circumstances. 
     return Init.rb_cObject.get_constants();
 }
示例#8
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
        {
            Object.CheckType<Class>(caller, p1);

            Class.rb_define_singleton_method(p1, "induced_from", prec_induced_from.singleton, 1, caller);
            return recv;
        }
示例#9
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            bool old = GC.dont_gc;

            GC.dont_gc = true;
            return old;
        }
示例#10
0
 public override object Call0(Class last_class, object recv, Frame caller, Proc block)
 {
     Match md = (Match)recv;
     String str = new String(md.matched.Substring(0, md.value.Index));
     if (md.Tainted) str.Tainted = true;
     return str;
 }
示例#11
0
        internal static void gvar_trace(string gvar_name, Proc cmd)
        {
            if (global_vars[gvar_name].trace == null)
                global_vars[gvar_name].trace = new List<Proc>();

            global_vars[gvar_name].trace.Add(cmd);
        }
示例#12
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            ProcessStatus status = ((ProcessStatus)recv);

            System.Text.StringBuilder buf = new System.Text.StringBuilder();

            buf.Append(string.Format(CultureInfo.InvariantCulture, "#<{0}: pid={1}", status.my_class._name, status.pid));
            if (status.WIFSTOPPED())
            {
                int stopsig = status.WSTOPSIG();
                string signame = Signal.ruby_signal_name(stopsig);
                if (signame != null)
                    buf.Append(string.Format(CultureInfo.InvariantCulture, ",stopped(SIG{0}={1})", signame, stopsig));
                else
                    buf.Append(string.Format(CultureInfo.InvariantCulture, ",stopped({0})", stopsig));
            }
            if (status.WIFSIGNALED())
            {
                int termsig = status.WTERMSIG();
                string signame = Signal.ruby_signal_name(termsig);
                if (signame != null)
                    buf.Append(string.Format(CultureInfo.InvariantCulture, ",signaled(SIG{0}={1})", signame, termsig));
                else
                    buf.Append(string.Format(CultureInfo.InvariantCulture, ",signaled({0})", termsig));
            }
            if (status.WIFEXITED())
            {
                buf.Append(string.Format(CultureInfo.InvariantCulture, ",exited({0})", status.WEXITSTATUS()));
            }
            buf.Append(">");

            return new String(buf.ToString());
        }
示例#13
0
        public override object Call1(Class last_class, object from, Frame caller, Proc block, object to)
        {
            if (from is int && to is int)
            {
                int end = (int)to;

                if (block == null)
                    throw new LocalJumpError("no block given").raise(caller);

                for (int i = (int)from; i <= end; i++)
                    Proc.rb_yield(block, caller, i);
            }
            else
            {
                object i = from;
                while (!(bool)Eval.CallPrivate(i, caller, ">", null, to))
                {
                    if (block == null)
                        throw new LocalJumpError("no block given").raise(caller);

                    Proc.rb_yield(block, caller, i);
                    i = Eval.CallPrivate(i, caller, "+", null, 1);
                }
            }

            return from;
        }
示例#14
0
        public override object Call(Class last_class, object str, Frame caller, Proc block, Array argv)
        {
            int argc = argv.Count;
            object result;

            if (argc < 1 || 2 < argc)
            {
                throw new ArgumentError(string.Format(CultureInfo.InvariantCulture, "wrong number of arguments ({0} for 1)", argc)).raise(caller);
            }

            Array buf = new Array();
            int i;
            for (i = 0; i < argc; i++)
            {
                buf.Add(argv[i]);
            }
            result = rb_str_aref_m.singleton.Call(last_class, str, caller, null, buf);
            
            if (result != null)
            {
                buf.Add(new String());
                rb_str_aset_m.singleton.Call(last_class, str, caller, null, buf);
            }

            return result;
        }            
示例#15
0
        public override object Call(Class klass, object recv, Frame caller, Proc block, Array rest)
        {
            int count = Class.rb_scan_args(caller, rest, 1, 1, false);

            if (block != null && count == 2)
            {
                Errors.rb_warn("block supersedes default value argument");
            }

            object if_none = null;
            if (count == 2)
                if_none = rest[1];

            string name = String.StringValue(rest[0], caller);
            string val = System.Environment.GetEnvironmentVariable(name);

            if (val == null)
            {
                if (block != null)
                    return Proc.rb_yield(block, caller, rest[0]);

                if (if_none != null)
                    return if_none;

                throw new IndexError("key not found").raise(caller);
            }
            else if (Env.PATH_ENV.Equals(name, System.StringComparison.OrdinalIgnoreCase) && !Env.rb_env_path_tainted())
                return new String(val);
            else
                return Env.env_str_new2(caller, val);
        }
示例#16
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            if (Numeric.random == null)
                rb_f_srand.singleton.Call0(last_class, recv, caller, null);

            return new Float(Numeric.random.NextDouble());
        }
示例#17
0
        public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest)
        {
            if ((rest.Count == 0) || ((rest.Count == 0) && (rest.value[0].Equals(recv))))
                return recv;

            return Eval.CallPrivate(rest.value[0], caller, "new", block, rest);
        }
示例#18
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
        {
            string path = String.StringValue(p1, caller);

            FileStat st = new FileStat(path);

            return new Time(st.stat.st_atime);
        }
示例#19
0
 public override object Call1(Class last_class, object recv, Frame caller, Proc block, object param0)
 {
     String str = new String(((String)recv).value + String.StringValue(param0, caller));
     if (((recv is Basic) && (((Basic)recv).Tainted)) ||
         ((param0 is Basic) && (((Basic)param0).Tainted)))
         str.Tainted = true;
     return str;
 }
示例#20
0
 public override object Call0(Class last_class, object recv, Frame caller, Proc block)
 {
     string name = Symbol.rb_id2name((uint)(int)recv);
     if (name != null)
         return new Symbol(name);
     else
         return null;
 }
示例#21
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            Array ary = (Array)enum_to_a.singleton.Call0(last_class, recv, caller, null);

            rb_ary_sort_bang.singleton.Call0(last_class, ary, caller, block);

            return ary;
        }
示例#22
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            Array memo = new Array();

            Eval.CallPrivate(recv, caller, "each", new Proc(null, null, new to_a(memo), 1));

            return memo;
        }
示例#23
0
 public override object Call0(Class last_class, object recv, Frame caller, Proc block)
 {
     IO.argf_binmode = true;
     IO.next_argv(caller);
     IO.ARGF_FORWARD(caller);
     rb_io_binmode.singleton.Call0(last_class, IO.current_file, caller, null);
     return IO.argf;
 }
示例#24
0
 public override object Call0(Class last_class, object recv, Frame caller, Proc block)
 {
     Class[] nesting = caller.nesting();
     if (nesting == null)
         return new Array();
     else
         return new Array(nesting);
 }
示例#25
0
        public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest)
        {
            int i = Numeric.rb_num2long(recv, caller);
            if (rest.Count == 0)
                return new String(i.ToString(CultureInfo.InvariantCulture));

            return rb_big_to_s.singleton.Call(last_class, new Bignum(i), caller, block, rest);
        }
示例#26
0
 public override object Call0(Class last_class, object recv, Frame caller, Proc block)
 {
     Array ary = (Array)recv;
     if (ary.my_class == Ruby.Runtime.Init.rb_cArray)
         return ary;
     else
         return new Array(ary.value);
 }
示例#27
0
 public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
 {
     if (Options.ruby_verbose.value != null)
     {
         IO.rb_io_write(IO.rb_stderr.value, p1, caller);
         IO.rb_io_write(IO.rb_stderr.value, IO.rb_default_rs.value, caller);
     }
     return null;
 }
示例#28
0
        public override object Call0(Class last_class, object recv, Frame caller, Proc block)
        {
            int old = Numeric.seed;

            Numeric.seed = (int)System.DateTime.Now.Ticks ^ System.Diagnostics.Process.GetCurrentProcess().Id ^ n++;
            Numeric.random = new System.Random(Numeric.seed);
            
            return old;
        }
示例#29
0
        public override object Call0(Class last_class, object group, Frame caller, Proc block)
        {
            ThreadGroup data;

            data = (ThreadGroup)group;
            data.enclosed = 1;

            return group; 
        }
示例#30
0
        public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1)
        {
            int old = Numeric.seed;

            Numeric.seed = Numeric.rb_num2long(p1, caller);
            Numeric.random = new System.Random(Numeric.seed);

            return old;
        }