internal eTagJump(RException e) { state = Tag.TAG.RAISE; rex = e; NetRuby rb = e.ruby; RThread th = rb.GetCurrentContext(); if (th.file != null) { RArray at = e.Backtrace; if (at == null) { at = rb.Backtrace(-1); e.Backtrace = at; } } th.errInfo = e; if (rb.debug && e.IsKindOf(rb.eSystemExit) == false) { Console.Error.WriteLine("Exception `{0}' at {1}:{2} - {3}", rb.ClassOf(e).Name, th.file, th.line, e.ToString()); } /* * // trace * if (th.protTag.Count <= 1) * { * rb.errorPrint(th); * } */ }
public override RArray DivMod(object o) { RBignum z; RBignum y = divmod(o, out z); return(RArray.AssocNew(ruby, y.Normalize, z.Normalize)); }
static private RArray CheckBacktrace(NetRuby rb, object o) { RArray a = null; if (o != null) { if (o is string || o is RString) { return(new RArray(rb, new object[1] { o })); } if (o is RArray == false) { throw new eTypeError("backtrace must be Array of String"); } a = (RArray)o; foreach (object x in a) { if (x is string == false && x is RString == false) { throw new eTypeError("backtrace must be Array of String"); } } } return(a); }
private Loader(NetRuby rb) { ruby = rb; loadPath = new RArray(rb, true); features = new RArray(rb, true); string baseDir = AppDomain.CurrentDomain.BaseDirectory; loadPath.Add(baseDir); loadPath.Add(Path.Combine(baseDir, "lib")); loadPath.Add(AppDomain.CurrentDomain.BaseDirectory); string lp = Environment.GetEnvironmentVariable("RUBYLIB"); if (lp != null) { string[] sp = lp.Split(new char[] { Path.PathSeparator }); for (int i = 0; i < sp.Length; i++) { loadPath.Add(Environment.ExpandEnvironmentVariables(sp[i])); } } /* if (rb.SafeLevel == 0) { */ loadPath.Add("."); /* } */ }
private Loader(NetRuby rb) { ruby = rb; loadPath = new RArray(rb, true); features = new RArray(rb, true); string baseDir = AppDomain.CurrentDomain.BaseDirectory; loadPath.Add(baseDir); loadPath.Add(Path.Combine(baseDir, "lib")); loadPath.Add(AppDomain.CurrentDomain.BaseDirectory); string lp = Environment.GetEnvironmentVariable("RUBYLIB"); if (lp != null) { string[] sp = lp.Split(new char[] { Path.PathSeparator }); for (int i = 0; i < sp.Length; i++) { loadPath.Add(Environment.ExpandEnvironmentVariables(sp[i])); } } /* * if (rb.SafeLevel == 0) * { */ loadPath.Add("."); /* * } */ }
public RArray Concat(object o) { RArray ary = ToRArrayWith(o); ptr.AddRange(ary.ptr); return(this); }
internal bool ArrayEqual(object o) { if (this == o) { return(true); } if (o is RArray == false) { return(false); } RArray a = (RArray)o; if (ptr == a.ptr) { return(true); } if (ptr.Count != a.ptr.Count) { return(false); } for (int i = 0; i < ptr.Count; i++) { if (ruby.Equal(ptr[i], a.ptr[i]) == false) { return(false); } } return(true); }
internal object Subseq(int beg, int len) { if (beg > ptr.Count) { return(null); } if (beg < 0 || len < 0) { return(null); } if (beg + len > ptr.Count) { len = ptr.Count - beg; } if (len < 0) { len = 0; } if (len == 0) { return(new RArray(ruby, true)); } RArray ary2 = new RArray(ruby, ptr.GetRange(beg, len)); ary2.klass = Class; return(ary2); }
public virtual RArray Coerce(object o) { if (ruby.ClassOf(o) == Class) { return(RArray.AssocNew(ruby, Instanciate(o), this)); } return(RArray.AssocNew(ruby, RFloat.Float(ruby, o), ToFloat())); }
public override RArray Coerce(object y) { if (y is int || y is long || y is RFixnum) { return(RArray.AssocNew(ruby, to_big(ruby, y), this)); } throw new eTypeError("Can't create " + ruby.ClassOf(y).Name + " to Bignum"); }
public RArray Indices(object[] args) { RArray ary = new RArray(ruby, true); for (int i = 0; i < args.Length; i++) { ary.Add(hash[args[i]]); } return ary; }
public object Clone() { RArray ra = new RArray(ruby, (ArrayList)ptr.Clone()); if (Test(FL.TAINT)) { ra.Set(FL.TAINT); } return(ra); }
public RArray Indices(object[] args) { RArray ary = new RArray(ruby, true); for (int i = 0; i < args.Length; i++) { ary.Add(hash[args[i]]); } return(ary); }
internal static object s_new(RBasic r, params object[] args) { NetRuby rb = r.ruby; RArray a = new RArray(rb, false, (RMetaObject)r); rb.CallInit(a, args); if (a.ptr == null) { a.ptr = new ArrayList(); } return(a); }
public override RArray ToArray() { ArrayList a = new ArrayList(); lock (hash.SyncRoot) { foreach (DictionaryEntry ent in hash) { a.Add(RArray.AssocNew(ruby, ent.Key, ent.Value)); } } return(new RArray(ruby, a)); }
public RArray Collect() { if (ruby.IsBlockGiven == false) { return((RArray)Clone()); } RArray collect = new RArray(ruby, ptr.Count); lock (ptr.SyncRoot) { foreach (object o in ptr) { collect.Add(ruby.Yield(o)); } } return(collect); }
protected void DoCoerce(object o, out RNumeric x, out RNumeric y) { x = y = null; try { RArray a = (RArray)ruby.Funcall(o, "coerce", this); if (a == null || a.Count != 2) { throw new eTypeError("coerce must return [x, y]"); } x = (RNumeric)a[0]; y = (RNumeric)a[1]; } catch { throw new eTypeError(String.Format("{0} can't be coerced into {1}", IsSpecialConstType(o) ? ruby.Inspect(o) : ruby.ClassOf(o).Name, ruby.ClassOf(this).Name)); } }
public override RArray DivMod(object o) { int y; if (o is int) { y = (int)o; } else if (o is RFixnum) { y = (int)((RFixnum)o).iVal; } else { return((RArray)CoerceBin(o)); } int mod; int d = divmod(y, out mod); return(RArray.AssocNew(ruby, new RFixnum(ruby, d), new RFixnum(ruby, mod))); }
public override RArray DivMod(object o) { double y; if (o is int) { y = (int)o; } else if (o is long) { y = (long)o; } else if (o is RFixnum) { y = ((RFixnum)o).ToLong(); } else if (o is double) { y = (double)o; } else if (o is RFloat) { y = ((RFloat)o).dVal; } else if (o is RBignum) { y = ((RBignum)o).Big2Dbl(); } else { return((RArray)CoerceBin(o)); } if (y == 0.0) { throw new DivideByZeroException("divided by 0"); } return(RArray.AssocNew(ruby, new RFloat(ruby, dVal / y), Modulo(y))); }
public override RArray ToArray() { bool b = IsTainted; RArray a = new RArray(ruby, true); GroupCollection g = match.Groups; for (int i = 0; i < g.Count; i++) { string s = g[i].Value; if (b) { a.Add(new RString(ruby, s, b)); } else { a.Add(s); } } if (b) { a.Taint(); } return(a); }
public object Clone() { RArray ra = new RArray(ruby, (ArrayList)ptr.Clone()); if (Test(FL.TAINT)) ra.Set(FL.TAINT); return ra; }
internal object Subseq(int beg, int len) { if (beg > ptr.Count) return null; if (beg < 0 || len < 0) return null; if (beg + len > ptr.Count) { len = ptr.Count - beg; } if (len < 0) len = 0; if (len == 0) return new RArray(ruby, true); RArray ary2 = new RArray(ruby, ptr.GetRange(beg, len)); ary2.klass = Class; return ary2; }
internal static RArray Create(NetRuby rb, object[] args) { RArray a = new RArray(rb, args); return a; }
internal static object s_new(RBasic r, params object[] args) { NetRuby rb = r.ruby; RArray a = new RArray(rb, false, (RMetaObject)r); rb.CallInit(a, args); if (a.ptr == null) a.ptr = new ArrayList(); return a; }
public RArray Collect() { if (ruby.IsBlockGiven == false) return (RArray)Clone(); RArray collect = new RArray(ruby, ptr.Count); lock (ptr.SyncRoot) { foreach (object o in ptr) { collect.Add(ruby.Yield(o)); } } return collect; }
void printBacktrace(RArray errat) { if (errat != null) { for (int i = 1; i < errat.Count; i++) { if (errat[i] is string || errat[i] is RString) { System.Console.Error.WriteLine(String.Format("\tfrom {0}", errat[i])); } if (i == 8 && errat.Count > 18) { System.Console.Error.WriteLine(String.Format("\t ... {0} levels...", errat.Count - 8 - 5)); i = errat.Count - 5; } } } }
public RArray Backtrace(int lev) { /* RThread th = GetCurrentContext(); Frame frm = th.frame; string buf; */ RArray ary = new RArray(this, true); /* if (lev < 0) { if (frm.lastFunc != 0) { buf = String.Format("{0}:{1}:in `{2}'", th.file, th.line, id2name(frm.lastFunc)); } else if (th.line == 0) { buf = th.file; } else { buf = String.Format("{0}:{1}", th.file, th.line); } ary.Add(buf); } else { while (lev-- > 0) { frm = frm.prev; if (frm == null) { ary = null; break; } } } while (frm != null && frm.file != null) { if (frm.prev != null && frm.prev.lastFunc != 0) { buf = String.Format("{0}:{1}:in `{2}'", frm.file, frm.line, id2name(frm.prev.lastFunc)); } else { buf = String.Format("{0}:{1}", frm.file, frm.line); } ary.Add(buf); frm = frm.prev; } */ return ary; }
private void progInit() { DefineVirtualVariable("$VERBOSE", new GlobalEntry.Getter(verboseGetter), new GlobalEntry.Setter(verboseSetter)); DefineVariable("$-v", null, new GlobalEntry.Getter(verboseGetter), new GlobalEntry.Setter(verboseSetter)); DefineVariable("$-w", null, new GlobalEntry.Getter(verboseGetter), new GlobalEntry.Setter(verboseSetter)); DefineVariable("$DEBUG", null, new GlobalEntry.Getter(debugGetter), new GlobalEntry.Setter(debugSetter)); DefineVariable("$-d", null, new GlobalEntry.Getter(debugGetter), new GlobalEntry.Setter(debugSetter)); DefineReadonlyVariable("$-p", null, new GlobalEntry.Getter(printGetter)); DefineReadonlyVariable("$-l", null, new GlobalEntry.Getter(lineGetter)); progName = new RString(this, String.Empty, true); #if RUBY_ARG0 DefineVariable("$0", progName, null, new GlobalEntry.Setter(SetArg0)); #else DefineVariable("$0", progName); #endif argv = new RArray(this, true); DefineReadonlyVariable("$*", argv, new GlobalEntry.Getter(argvGetter)); DefineGlobalConst("ARGV", argv); DefineReadonlyVariable("$-a", argv, new GlobalEntry.Getter(splitGetter)); DefineVirtualVariable("$_", new GlobalEntry.Getter(lastLineGetter),new GlobalEntry.Setter(lastLineSetter)); }
public RArray Reverse() { RArray ary = (RArray)Clone(); return(ary.ReverseAt()); }
public RArray Sort() { RArray ary = (RArray)Clone(); return(ary.SortAt()); }
public override RArray ToArray() { bool b = IsTainted; RArray a = new RArray(ruby, true); GroupCollection g = match.Groups; for (int i = 0; i < g.Count; i++) { string s = g[i].Value; if (b) a.Add(new RString(ruby, s, b)); else a.Add(s); } if (b) a.Taint(); return a; }
internal static RArray Create(NetRuby rb, object[] args) { RArray a = new RArray(rb, args); return(a); }