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; }
internal static Class rb_struct_define(string name, Frame caller, params string[] members) { Array ary = new Array(); foreach (string mem in members) ary.Add(new Symbol(mem)); return make_struct(name, ary, Ruby.Runtime.Init.rb_cStruct, caller); }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Array ary = new Array(); foreach (uint id in Symbol.sym_tbl.Values) { ary.Add(new Symbol(id)); } return ary; }
public RubyException raise(Frame caller) { Array backtrace = new Array(); Frame frame = caller; while (frame != null) { backtrace.Add(new String(frame.callPoint())); frame = frame.caller; } this.instance_variable_set("bt", backtrace); return rubyException; }
public override object Call0(Class last_class, object group, Frame caller, Proc block) { ThreadGroup data; Array ary; data = (ThreadGroup)group; ary = new Array(); foreach(Thread th in Thread.thread_list){ if (th.thGroup == data.group) { ary.Add(th.thread); } } return ary; }
public override object Call1(Class last_class, object recv, Frame caller, Proc block, object level) { Array list = new Array(); int skip = (int)level; int i = 0; while (caller != null) { if (i >= skip) list.Add(new String(caller.callPoint())); caller = caller.caller; i++; } return list; }
public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest) { System.Collections.ArrayList list; if (Class.rb_scan_args(caller, rest, 0, 1, false) == 0) rest.Add(true); if (Marshal.RTEST(rest[0])) { list = new System.Collections.ArrayList(); Class.CLASS_OF(recv).get_all_specified_methods(list, Access.Public, Eval.Test(rest[0])); return Array.CreateUsing(list); } else { list = new System.Collections.ArrayList(); Class.CLASS_OF(recv).public_methods(list); return new Array(list); } }
public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest) { String str = (String)recv; Class.rb_scan_args(caller, rest, 0, 2, false); object limit = null; int lim = 0; int i = 0; if (rest.Count == 2) { limit = rest[1]; lim = Numeric.rb_num2long(limit, caller); if (lim <= 0) limit = null; else if (lim == 1) { if (str.value.Length == 0) return new Array(); return new Array(str); } i = 1; } bool awk_split = false; object spat = null; if (rest.Count > 0) spat = rest[0]; if (spat == null) { if (String.rb_fs != null && String.rb_fs.value != null) spat = String.rb_fs.value; else awk_split = true; } if (!awk_split) { if (spat is String && ((String)spat).value.Length == 1) { if (((String)spat).value[0] == ' ') awk_split = true; else spat = new Regexp(Regexp.rb_reg_quote((String)spat).value, 0); } else spat = String.get_pat(spat, true, caller); } Array result = new Array(); int beg = 0; if (awk_split) { string[] strings; if (limit != null) strings = str.value.Split(new char[] { ' ' }, lim, System.StringSplitOptions.RemoveEmptyEntries); else strings = str.value.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); foreach (string s in strings) { String s1 = new String(s); Object.obj_infect(s1, str); result.Add(s1); if (limit != null) i++; } beg = str.value.Length; } else { Regexp pat = (Regexp)spat; int start = beg; int end; bool last_null = false; while ((end = pat.rb_reg_search(str, start, false, caller)) >= 0) { Match regs = Regexp.rb_backref_get(caller); if (start == end && regs.value.Length == 0) { if (str.value.Length == 0) { result.Add(new String()); break; } else if (last_null) { String s = new String(str.value.Substring(beg, 1)); Object.obj_infect(s, str); result.Add(s); beg = start; } else { start += 1; last_null = true; continue; } } else if (start == end && last_null && pat.value.ToString().Equals(regs.value.Value)) { beg = start = regs.value.Index + regs.value.Length; } else { String s = new String(str.value.Substring(beg, end - beg)); Object.obj_infect(s, str); result.Add(s); beg = start = regs.value.Index + regs.value.Length; } last_null = false; for (int idx = 1; idx < regs.value.Groups.Count; idx++) { String tmp; if (regs.value.Groups[idx].Length == 0) tmp = new String(); else tmp = new String(regs.value.Groups[idx].Value); Object.obj_infect(tmp, str); result.Add(tmp); } if (limit != null && lim <= ++i) break; } } if (str.value.Length > 0 && (limit != null || str.value.Length > beg || lim < 0)) { String tmp; if (str.value.Length == beg) tmp = new String(); else tmp = new String(str.value.Substring(beg)); Object.obj_infect(tmp, str); result.Add(tmp); } if (limit == null && lim == 0) while (result.Count > 0 && ((String)result.value[result.Count - 1]).value.Length == 0) result.value.RemoveAt(result.value.Count - 1); return result; }
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; }
public override object Call(Class last_class, object recv, Frame caller, Proc block, object p1, Array rest) { object read, write = null, except = null, timeout = null; Array res, list; fd_set rset = new fd_set(), wset = new fd_set(), eset = new fd_set(), pset = new fd_set(); object rp, wp, ep; System.TimeSpan tp; IO fptr; int i; int max = 0; int interrupt_flag = 0; int pending = 0; Class.rb_scan_args(caller, rest, 1, 3, false); read = (Array)p1; if (rest.Count > 0) write = rest[0]; if (rest.Count > 1) except = rest[1]; if (rest.Count > 2) timeout = rest[2]; if (timeout == null) tp = System.TimeSpan.Zero; else tp = Time.rb_time_interval(timeout, caller); rset.fd_array = new int[64]; FD_ZERO(pset); if (read != null) { Object.CheckType<Array>(caller, read); rp = rset; FD_ZERO((fd_set)rp); for (i = 0; i < ((Array)read).Count; i++) { fptr = IO.GetOpenFile(caller, IO.rb_io_get_io(((Array)read)[i], caller)); FD_SET(IO.fileno(fptr.f), (fd_set)rp); if (IO.READ_DATA_PENDING(fptr.f)) { /* check for buffered data */ pending++; FD_SET(IO.fileno(fptr.f), pset); } if (max < IO.fileno(fptr.f)) max = IO.fileno(fptr.f); } if (pending > 0) { /* no blocking if there's buffered data */ tp = System.TimeSpan.Zero; } } else rp = null; if (write != null) { Object.CheckType<Array>(caller, write); wp = wset; FD_ZERO((fd_set)wp); for (i = 0; i < ((Array)write).Count; i++) { fptr = IO.GetOpenFile(caller, IO.rb_io_get_io(((Array)write)[i], caller)); FD_SET(IO.fileno(fptr.f), (fd_set)wp); if (max < IO.fileno(fptr.f)) max = IO.fileno(fptr.f); if (fptr.f2 != null) { FD_SET(IO.fileno(fptr.f2), (fd_set)wp); if (max < IO.fileno(fptr.f2)) max = IO.fileno(fptr.f2); } } } else wp = null; if (except != null) { Object.CheckType<Array>(caller, except); ep = eset; FD_ZERO((fd_set)ep); for (i = 0; i < ((Array)except).Count; i++) { fptr = IO.GetOpenFile(caller, IO.rb_io_get_io(((Array)except)[i], caller)); FD_SET(IO.fileno(fptr.f), (fd_set)ep); if (max < IO.fileno(fptr.f)) max = IO.fileno(fptr.f); if (fptr.f2 != null) { FD_SET(IO.fileno(fptr.f2), (fd_set)ep); if (max < IO.fileno(fptr.f2)) max = IO.fileno(fptr.f2); } } } else ep = null; max++; //n = rb_thread_select(max, rp, wp, ep, tp); //if (n < 0) //{ // rb_sys_fail(0); //} if (pending == 0) //&& n == 0) return null; /* returns nil on timeout */ res = new Array(); res.Tainted = true; Array rparr = new Array(), wparr = new Array(), eparr = new Array(); if (rp == null) rparr.Tainted = true; if (wp == null) wparr.Tainted = true; if (ep == null) eparr.Tainted = true; res.Add(rparr); res.Add(wparr); res.Add(eparr); if (interrupt_flag == 0) { if (rp != null) { list = rparr; for (i = 0; i < ((Array)read).Count; i++) { fptr = IO.GetOpenFile(caller, IO.rb_io_get_io(((Array)read)[i], caller)); if (FD_ISSET(IO.fileno(fptr.f), (fd_set)rp) || FD_ISSET(IO.fileno(fptr.f), pset)) { list.Add(((Array)read)[i]); } } } if (wp != null) { list = wparr; for (i = 0; i < ((Array)write).Count; i++) { fptr = IO.GetOpenFile(caller, IO.rb_io_get_io(((Array)write)[i], caller)); if (FD_ISSET(IO.fileno(fptr.f), (fd_set)wp)) { list.Add(((Array)write)[i]); } else if (fptr.f2 != null && FD_ISSET(IO.fileno(fptr.f2), (fd_set)wp)) { list.Add(((Array)write)[i]); } } } if (ep != null) { list = eparr; for (i = 0; i < ((Array)except).Count; i++) { fptr = IO.GetOpenFile(caller, IO.rb_io_get_io(((Array)except)[i], caller)); if (FD_ISSET(IO.fileno(fptr.f), (fd_set)ep)) { list.Add(((Array)except)[i]); } else if (fptr.f2 != null && FD_ISSET(IO.fileno(fptr.f2), (fd_set)ep)) { list.Add(((Array)except)[i]); } } } } return res; /* returns an empty array on interrupt */ }
public override object Call(Class last_class, object recv, Frame caller, Proc block, Array argv) { int argc = argv.Count; if (argc > 0) { throw new ArgumentError(string.Format(CultureInfo.InvariantCulture, "wrong number of arguments ({0} for 0)", argc)).raise(caller); } else { Match match = (Match)recv; Array result = new Array(); bool taint = match.Tainted; System.Text.RegularExpressions.Match m = match.value; while (m.Success) { String str = new String(m.Value); if (taint) str.Tainted = true; if (Eval.Test(Proc.rb_yield(block, caller, new object[] { str }))) { result.Add(str); } m = m.NextMatch(); } return result; } }
public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest) { Class klass0 = Class.CLASS_OF(recv); System.Collections.ArrayList list = new System.Collections.ArrayList(); bool recur = true; if (Class.rb_scan_args(caller, rest, 0, 1, false) == 0) rest.Add(true); recur = Eval.Test(rest[0]); if (klass0 != null && klass0._type == Class.Type.Singleton) klass0.get_specified_methods(list, Access.notPrivate); // force "all but private" case if (recur) for (Class cls = klass0.super; cls != null && (cls._type == Class.Type.Singleton || cls._type == Class.Type.IClass); cls = cls.super) cls.get_specified_methods(list, Access.notPrivate); return Array.CreateUsing(list); }
public override object Call(Class last_class, object recv, Frame caller, Proc block, Array rest) { System.Collections.ArrayList list; if (Class.rb_scan_args(caller, rest, 0, 1, false) == 0) rest.Add(true); if (!Eval.Test(rest[0])) return rb_obj_singleton_methods.singleton.Call(last_class, recv, caller, block, rest); else // arg-length check already done => inline remaining body of rb_class_instance_methods { list = new System.Collections.ArrayList(); Class.CLASS_OF(recv).get_all_specified_methods(list, Access.notPrivate, true); return Array.CreateUsing(list); } }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Data data = (Data)recv; object mesg = data.instance_vars["0"]; object obj = null; if (mesg == null) return null; else { string desc = null; String d = null; obj = data.instance_vars["0"]; if (obj == null) desc = "nil"; else if (obj.Equals(true)) desc = "true"; else if (obj.Equals(false)) desc = "false"; else { try { d = Object.Inspect(obj, caller); } catch (RubyException) { } if (d == null) { d = (String)rb_any_to_s.singleton.Call0(last_class, obj, caller, null); } desc = d.value; } if (desc != null && desc.Length > 0 && desc[0] != '#') d = new String(string.Format(CultureInfo.InvariantCulture, "{0}:{1}", desc, ((Object)obj).my_class._name)); Array args = new Array(); args.Add(mesg); args.Add(data.instance_vars["2"]); args.Add(d); mesg = rb_f_sprintf.singleton.Call(last_class, recv, caller, null, args); } if (((Object)obj).Tainted) ((Object)mesg).Tainted = true; return mesg; }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Array tuples = new Array(); Eval.CallPrivate(recv, caller, "each", new Proc(null, block, new sort_by_i(tuples), 1)); rb_ary_sort_bang.singleton.Call0(last_class, tuples, caller, new Proc(null, null, new sort_by_cmp(), 1)); Array ary = new Array(); foreach (Array tuple in tuples) { ary.Add(tuple[1]); } return ary; }
public override object Call1(Class last_class, object recv, Frame caller, Proc block, object val) { Array tmp; int i; tmp = new Array(); tmp.Add(val); for (i = 0; i < memo.args.Count; i++) { if (memo.args[i].Count > memo.index) tmp.Add(memo.args[i][memo.index]); else tmp.Add(null); } if (block != null) { block.yield(caller, tmp); } else { result.Add(tmp); } memo.index++; return null; }
public override object Calln(Class last_class, object recv, Frame caller, ArgList args) { IO.NEXT_ARGF_FORWARD(caller); Array ary = new Array(); String line; while ((line = IO.argf_getline(args.ToArray(), caller)) != null) //rb_ary_push.singleton.Call1(last_class, ary, caller, null, line); ary.Add(line); return ary; }
private object scan_once(String str, Regexp pat, ref int start, Frame caller) { Match match; if (pat.rb_reg_search(str, start, false, caller) >= 0) { match = Regexp.rb_backref_get(caller); if (match.value.Length == 0) /* * Always consume at least one character of the input string */ start = match.value.Index + 1; else start = match.value.Index + match.value.Length; if (match.value.Groups.Count == 1) return Regexp.rb_reg_nth_match(0, match); else { Array result = new Array(); for (int i = 1; i < match.value.Groups.Count; i++) result = result.Add(Regexp.rb_reg_nth_match(i, match)); return result; } } else return null; }
public override object Call1(Class last_class, object recv, Frame caller, Proc block, object p1) { String str = (String)recv; Regexp pat = String.get_pat(p1, true, caller); object result; int start = 0; Match match = null; if (block == null) { Array ary = new Array(); while ((result = scan_once(str, pat, ref start, caller)) != null) { match = Regexp.rb_backref_get(caller); ary = ary.Add(result); } Regexp.rb_backref_set(match, caller); return ary; } while ((result = scan_once(str, pat, ref start, caller)) != null) { match = Regexp.rb_backref_get(caller); match.busy = true; Proc.rb_yield(block, caller, new object[] { result }); Regexp.rb_backref_set(match, caller); /* restore $~ value */ } Regexp.rb_backref_set(match, caller); return str; }
public override object Call0(Class klass, object recv, Frame caller, Proc block) { if (block == null) throw new LocalJumpError("no block given").raise(caller); Array ary = new Array(); foreach (System.Collections.DictionaryEntry pair in System.Environment.GetEnvironmentVariables()) { String key = Env.env_str_new(caller, (string)pair.Key); String val = Env.env_str_new2(caller, (string)pair.Value); if ((bool)(Proc.rb_yield(block, caller, key, val))) ary.Add(new Array(key, val)); } return ary; }
internal static Array rb_push_glob(Frame caller, Proc block, object str, int flags) { Array ary = new Array(); string path = String.StringValue(str, caller); foreach (string file in glob(path)) { String s = new String(file); s.Tainted = true; ary.Add(s); } if (block != null) { Methods.rb_ary_each.singleton.Call0(null, ary, caller, block); return null; } return ary; }
public override object Call(Class klass, object recv, Frame caller, Proc block, Array rest) { Errors.rb_warn(string.Format(CultureInfo.InvariantCulture, "ENV#{0} is deprecated; use ENV#values_at", "indexes")); // rb_frame_last_func Array ary = new Array(); for (int i = 0; i < rest.Count; i++) { String tmp = String.rb_check_string_type(rest[i], caller); if (tmp == null) ary.Add(null); else ary.Add(Env.env_str_new2(caller, System.Environment.GetEnvironmentVariable(tmp.value))); } return ary; }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Array ary = new Array(); foreach (Thread th in Thread.thread_list) { switch (th._status) { case Thread.Thread_Status.THREAD_RUNNABLE: goto case Thread.Thread_Status.THREAD_TO_KILL; case Thread.Thread_Status.THREAD_STOPPED: goto case Thread.Thread_Status.THREAD_TO_KILL; case Thread.Thread_Status.THREAD_TO_KILL: ary.Add(th); break; default: // break; //TODO: this break was in the ruby code, // they must order their lists in some intelligent way? break; } } return ary; }
public override object Call(Class last_class, object recv, Frame caller, Proc block, Array argv) { String rs = null; int argc = argv.Count; if (argc == 0) { rs = (String)IO.rb_rs.value; } else { Class.rb_scan_args(caller, argv, 1, 0, false); if (argv[0] != null) rs = String.RStringValue(argv[0], caller); } Array ary = new Array(); String line; while ((line = IO.rb_io_getline(rs, recv, caller)) != null) { ary.Add(line); } return ary; }
public override object Call0(Class klass, object recv, Frame caller, Proc block) { Array ary = new Array(); foreach (System.Collections.DictionaryEntry pair in System.Environment.GetEnvironmentVariables()) { ary.Add(new Array(Env.env_str_new(caller, (string)pair.Key), Env.env_str_new2(caller, (string)pair.Value))); } return ary; }
private void fill(Array ary, object item, Proc block, int beg, int end, Frame caller) { Array.rb_ary_modify(caller, ary); while (ary.Count < end) ary.Add(null); for (int i = beg; i < end; i++) if (block != null) ary[i] = Proc.rb_yield(block, caller, i); else ary[i] = item; }
public override object Call0(Class klass, object recv, Frame caller, Proc block) { Array keys = new Array(); foreach (string key in System.Environment.GetEnvironmentVariables().Keys) keys.Add(Env.env_str_new(caller, key)); return keys; }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Array newarray = new Array(); foreach (object value in ((Hash)recv).value.Values) newarray.Add(value); return newarray; }
public override object Call(Class klass, object recv, Frame caller, Proc block, Array rest) { Array ary = new Array(); foreach (object key in rest) { object val = rb_f_getenv.singleton.Call1(klass, recv, caller, null, key); ary.Add(val); } return ary; }
public override object Call0(Class last_class, object recv, Frame caller, Proc block) { Array newarray = new Array(); foreach (Dictionary.Key key in ((Hash)recv).value.Keys) newarray.Add(key.key); return newarray; }