Exemplo n.º 1
0
        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);
             * }
             */
        }
Exemplo n.º 2
0
        public override RArray DivMod(object o)
        {
            RBignum z;
            RBignum y = divmod(o, out z);

            return(RArray.AssocNew(ruby, y.Normalize, z.Normalize));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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(".");
            /*
            }
            */
        }
Exemplo n.º 5
0
        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(".");

            /*
             * }
             */
        }
Exemplo n.º 6
0
        public RArray Concat(object o)
        {
            RArray ary = ToRArrayWith(o);

            ptr.AddRange(ary.ptr);
            return(this);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 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()));
 }
Exemplo n.º 10
0
 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");
 }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
        public object Clone()
        {
            RArray ra = new RArray(ruby, (ArrayList)ptr.Clone());

            if (Test(FL.TAINT))
            {
                ra.Set(FL.TAINT);
            }
            return(ra);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
 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));
     }
 }
Exemplo n.º 18
0
        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)));
        }
Exemplo n.º 19
0
        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)));
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
 public object Clone()
 {
     RArray ra = new RArray(ruby, (ArrayList)ptr.Clone());
     if (Test(FL.TAINT)) ra.Set(FL.TAINT);
     return ra;
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 internal static RArray Create(NetRuby rb, object[] args)
 {
     RArray a = new RArray(rb, args);
     return a;
 }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
 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;
 }
Exemplo n.º 26
0
 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;
             }
         }
     }
 }
Exemplo n.º 27
0
        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;        
        }
Exemplo n.º 28
0
        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));
        }
Exemplo n.º 29
0
        public RArray Reverse()
        {
            RArray ary = (RArray)Clone();

            return(ary.ReverseAt());
        }
Exemplo n.º 30
0
        public RArray Sort()
        {
            RArray ary = (RArray)Clone();

            return(ary.SortAt());
        }
Exemplo n.º 31
0
 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;
 }
Exemplo n.º 32
0
        internal static RArray Create(NetRuby rb, object[] args)
        {
            RArray a = new RArray(rb, args);

            return(a);
        }