public static RBignum Dbl2Big(NetRuby ruby, double d) { if (Double.IsInfinity(d)) { throw new eFloatDomainError((d < 0) ? "-Infinity" : "Infinity"); } if (Double.IsNaN(d)) { throw new eFloatDomainError("NaN"); } int i = 0; double u = (d < 0) ? -d : d; while (u <= Int32.MaxValue == false || 0 != (int)u) { u /= (double)BIGRAD; i++; } uint[] dg = new uint[i]; while (i-- != 0) { u *= BIGRAD; dg[i] = (uint)u; u -= dg[i]; } return(new RBignum(ruby, dg, (d >= 0))); }
public EmitContext(NetRuby r, string name, string fn) { filename = fn; save = filename != null; ruby = r; AppDomain domain = AppDomain.CurrentDomain; AssemblyName assembly_name = new AssemblyName(); assembly_name.Name = name; assembly_builder = domain.DefineDynamicAssembly(assembly_name, save ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run); string module_name = name + "Module"; if (save) { module_builder = assembly_builder.DefineDynamicModule(module_name, filename); } else { module_builder = assembly_builder.DefineDynamicModule(module_name); } }
internal static void Init(NetRuby rb) { RClass ex = rb.DefineClass("Exception", rb.cObject); rb.eException = ex; ex.DefineSingletonMethod("exception", new RMethod(exc_new), -1); ex.DefineMethod("exception", new RMethod(exc_exception), -1); ex.DefineMethod("initialize", new RMethod(exc_initialize), -1); ex.DefineMethod("message", new RMethod(exc_to_s), 0); ex.DefineMethod("backtrace", new RMethod(exc_backtrace), 0); ex.DefineMethod("set_backtrace", new RMethod(exc_set_backtrace), 0); rb.eSystemExit = rb.DefineClass("SystemExit", ex); rb.eFatal = rb.DefineClass("Fatal", ex); rb.eInterrupt = rb.DefineClass("Interrupt", ex); rb.eSignal = rb.DefineClass("SignalException", ex); rb.eStandardError = rb.DefineClass("StandardError", ex); rb.eTypeError = rb.DefineClass("TypeError", rb.eStandardError); rb.eArgError = rb.DefineClass("ArgumentError", rb.eStandardError); rb.eIndexError = rb.DefineClass("IndexError", rb.eStandardError); rb.eRangeError = rb.DefineClass("RangeError", rb.eStandardError); rb.eScriptError = rb.DefineClass("ScriptError", ex); rb.eSyntaxError = rb.DefineClass("SyntaxError", rb.eScriptError); rb.eNameError = rb.DefineClass("NameError", rb.eScriptError); rb.eLoadError = rb.DefineClass("LoadError", rb.eScriptError); rb.eNotImpError = rb.DefineClass("NotImplementedError", rb.eScriptError); rb.eRuntimeError = rb.DefineClass("RuntimeError", rb.eStandardError); rb.eSecurityError = rb.DefineClass("SecurityError", rb.eStandardError); rb.eNoMemError = rb.DefineClass("NoMemoryError", ex); }
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 static long ToLong(NetRuby ruby, object o) { if (o == null) { throw new eTypeError("no implicit conversion from nil"); } if (o is int) { return((long)(int)o); } if (o is uint) { return((long)(uint)o); } if (o is long) { return((long)o); } if (o is RNumeric) { return(((RNumeric)o).ToLong()); } if (o is string || o is RString) { throw new eTypeError("no implicit conversion from string"); } if (o is bool || o is RBool) { throw new eTypeError("no implicit conversion from boolean"); } RFixnum f = (RFixnum)ruby.ConvertType(o, typeof(RFixnum), "Integer", "to_int"); return((long)f.ToLong()); }
static internal void Init(NetRuby ruby) { RClass num = ruby.DefineClass("Numeric", ruby.cObject); ruby.cNumeric = num; num.DefineMethod("coerce", new RMethod(num_coerce), 1); num.DefineMethod("to_i", new RMethod(num_to_i), 0); num.DefineMethod("truncate", new RMethod(num_to_i), 0); num.DefineMethod("+@", new RMethod(num_uplus), 0); num.DefineMethod("-@", new RMethod(num_uminus), 0); num.DefineMethod("===", new RMethod(num_equal), 1); num.DefineMethod("+", new RMethod(num_plus), 1); num.DefineMethod("-", new RMethod(num_minus), 1); num.DefineMethod("*", new RMethod(num_mul), 1); num.DefineMethod("/", new RMethod(num_div), 1); num.DefineMethod("%", new RMethod(num_mod), 1); num.DefineMethod("modulo", new RMethod(num_mod), 1); num.DefineMethod("divmod", new RMethod(num_divmod), 1); num.DefineMethod("remainder", new RMethod(num_remainder), 1); num.DefineMethod("<=>", new RMethod(num_cmp), 1); num.DefineMethod(">", new RMethod(num_gt), 1); num.DefineMethod(">=", new RMethod(num_ge), 1); num.DefineMethod("<", new RMethod(num_lt), 1); num.DefineMethod("<=", new RMethod(num_le), 1); }
internal RException(NetRuby ruby, Exception ex) : base(ruby, ruby.eException) { innerException = ex; IVarSet("mesg", ex.Message); Backtrace = ruby.Backtrace(-1); }
internal static RString New(NetRuby rb, object[] args) { RString rs = new RString(rb, String.Empty); rb.CallInit(rs, args); return(rs); }
public Scope(NetRuby r) : base(r, null) { flag = 0; local_tbl = null; local_vars = null; }
static internal RThread Start(NetRuby ruby, object[] args) { RThread parent = ruby.GetCurrentContext(); RThread thrd = (RThread)parent.Clone(); return(thrd.Start(args)); }
public static RBasic ConvertToRuby(NetRuby ruby, object v) { if (v is RBasic) { return((RBasic)v); } else if (v is int) { return(new RFixnum(ruby, (int)v)); } else if (v is bool) { if ((bool)v) { return(new RTrue(ruby)); } else { return(new RFalse(ruby)); } } else if (v is string) { return(new RString(ruby, (string)v)); } else if (v == null) { return(ruby.oNil); } else { throw new Exception("Illegal type to convert to Ruby object: " + v.GetType().Name); } }
static private RBignum to_big(NetRuby ruby, object o) { RBignum y = null; if (o is RFixnum) { o = ((RFixnum)o).GetData(); } if (o is RBignum) { y = (RBignum)o; } if (o is int) { y = Int2Big(ruby, (int)o); } else if (o is long) { y = Long2Big(ruby, (long)o); } else if (o is double) { y = Dbl2Big(ruby, (double)o); } else if (o is RFloat) { y = Dbl2Big(ruby, ((RFloat)o).Double); } return(y); }
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); }
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); * } */ }
private void CreateBlock(NetRuby rb) { /* * RThread th = rb.GetCurrentContext(); * block = th.block.Clone(); * block.origThread = th; * block.wrapper = th.wrapper; * block.iter = (block.prev != null) ? ITER.PRE : ITER.NOT; * block.frame = block.frame.Dup(); * if (th.frame.prev != null) * { * block.frame.lastFunc = th.frame.prev.lastFunc; * block.frame.lastClass = th.frame.prev.lastClass; * } * if (block.iter != 0) * { * block.DupPrev(); * } * else * { * block.prev = null; * } * block.scope.Dup(); * safeLevel = th.safeLevel; */ }
static internal object match_end(RBasic r, params object[] args) { NetRuby ruby = r.ruby; int i = RInteger.ToInt(r.ruby, args[0]); return(((RMatchData)r).End(i)); }
static private void matchSetter(object val, uint id, GlobalEntry gb, NetRuby rb) { rb.CheckType(val, typeof(RMatchData)); RThread th = rb.GetCurrentContext(); th.BackRef = val; }
internal static object alias_method(RBasic r, params object[] args) { NetRuby rb = r.ruby; ((RMetaObject)r).DefineAlias(rb.ToID(args[0]), rb.ToID(args[1])); return(r); }
static public RBasic NewThreadGroup(object[] argv, RMetaObject meta) { NetRuby ruby = meta.ruby; RThreadGroup tg = new RThreadGroup(ruby, meta); ruby.CallInit(tg, argv); return(tg); }
static internal object thread_s_abort_set(RBasic r, params object[] args) { NetRuby rb = r.ruby; bool b = RBasic.RTest(args[0]); rb.cThread.AbortOnException = b; return(b); }
internal override string Inspect(NetRuby ruby, uint key, RNode body) { if (body.body != null && (body.noex & (NOEX.PRIVATE)) != 0) { return(ruby.id2name(key)); } return(null); }
static private object matchGetter(uint id, GlobalEntry gb, NetRuby rb) { RThread th = rb.GetCurrentContext(); object o = th.BackRef; matchBusy(o); return(o); }
static public RArray AssocNew(NetRuby ruby, object car, object cdr) { ArrayList ar = new ArrayList(); ar.Add(car); ar.Add(cdr); return(new RArray(ruby, ar)); }
internal RBignum(NetRuby rb, uint u, bool sgn) : base(rb, rb.cBignum) { sign = sgn; len = 1; digits = new uint[1]; digits[0] = u; }
static internal void Init(NetRuby rb) { BindingFlags bf = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance; RClass ary = rb.DefineClass("Array", rb.cObject); RMetaObject.IncludeModule(ary, rb.mEnumerable); rb.cArray = ary; Type obj = typeof(RArray); ary.DefineSingletonMethod("new", new RMethod(s_new), -1); ary.DefineSingletonMethod("[]", obj.GetMethod("Create", bf)); ary.DefineMethod("initialize", obj.GetMethod("Initialize", bf)); ary.DefineMethod("to_ary", obj.GetMethod("ToArray", bf)); ary.DefineMethod("==", obj.GetMethod("ArrayEqual", bf)); ary.DefineMethod("eql?", obj.GetMethod("ArrayEql", bf)); ary.DefineMethod("[]", obj.GetMethod("ARef", bf)); ary.DefineMethod("[]=", obj.GetMethod("ASet", bf)); ary.DefineMethod("at", obj.GetMethod("At", bf)); ary.DefineMethod("first", obj.GetMethod("get_First", bf)); ary.DefineMethod("last", obj.GetMethod("get_Last", bf)); ary.DefineMethod("concat", obj.GetMethod("Concat", bf)); ary.DefineMethod("<<", obj.GetMethod("Push", bf)); ary.DefineMethod("push", obj.GetMethod("Push", bf)); ary.DefineMethod("pop", obj.GetMethod("Pop", bf)); ary.DefineMethod("shift", obj.GetMethod("Shift", bf)); ary.DefineMethod("unshift", obj.GetMethod("Unshift", bf)); ary.DefineMethod("each", obj.GetMethod("Each", bf)); ary.DefineMethod("each_index", obj.GetMethod("EachIndex", bf)); ary.DefineMethod("reverse_each", obj.GetMethod("ReverseEach", bf)); ary.DefineMethod("length", obj.GetMethod("get_Count", bf)); ary.DefineAlias("size", "length"); ary.DefineMethod("empty?", obj.GetMethod("get_IsEmpty", bf)); ary.DefineMethod("index", obj.GetMethod("Index", bf)); ary.DefineMethod("rindex", obj.GetMethod("RIndex", bf)); ary.DefineMethod("clone", obj.GetMethod("Clone", bf)); ary.DefineMethod("join", obj.GetMethod("JoinMethod", bf)); ary.DefineMethod("reverse", obj.GetMethod("Reverse", bf)); ary.DefineMethod("reverse!", obj.GetMethod("ReverseAt", bf)); ary.DefineMethod("sort", obj.GetMethod("Sort", bf)); ary.DefineMethod("sort!", obj.GetMethod("SortAt", bf)); ary.DefineMethod("collect", obj.GetMethod("Collect", bf)); ary.DefineMethod("collect!", obj.GetMethod("CollectAt", bf)); ary.DefineMethod("delete", obj.GetMethod("Delete", bf)); ary.DefineMethod("delete_at", obj.GetMethod("DeleteAt", bf)); ary.DefineMethod("clear", obj.GetMethod("Clear2", bf)); ary.DefineMethod("fill", obj.GetMethod("Fill", bf)); ary.DefineMethod("include", obj.GetMethod("Contains", bf)); }
public RModule(NetRuby rb, string name, RMetaObject spr) : base(rb, name, spr, rb.cModule) { if (name != null) { uint id = rb.intern(name); rb.class_tbl.Add(id, this); } }
internal RBignum(NetRuby rb, long l) : base(rb, rb.cBignum) { sign = (l < 0) ? false : true; len = 2; digits = new uint[2]; digits[0] = BIGLO(l); digits[1] = (uint)BIGDN(l); }
public RString(NetRuby rb, string s, bool taint) : base(rb, rb.cString) { ptr = s; if (taint) { flags |= FL.TAINT; } }
static private RThread check(NetRuby rb, object o) { if (o is RThread == false) { throw new eTypeError(String.Format("wrong argument type {0} (expected Thread)", rb.ClassOf(o).Name)); } return((RThread)o); }
public static RBignum Ulong2Big(NetRuby ruby, ulong n) { ulong num = (ulong)n; RBignum big = new RBignum(ruby, 2, true); big.digits[0] = (uint)n; big.digits[1] = (uint)(n >> 32); return(big); }
public Scanner(Parser psr, TextReader rdr, NetRuby rb, RThread th) { parser = psr; reader = rdr; ruby = rb; thread = th; thread.line = 0 - 1; thread.file = "(eval)"; rb.__end__seen = false; tokenbuf = new StringBuilder(128); }
public Scanner(Parser psr, TextReader rdr, string fname, int start, NetRuby rb, RThread th) { parser = psr; reader = rdr; ruby = rb; thread = th; thread.line = start - 1; thread.file = fname; rb.__end__seen = false; tokenbuf = new StringBuilder(128); }