Example #1
0
        private RArray MethodList(bool inherited_too, InsMethods ins)
        {
            ArrayList ary = new ArrayList();

            lock (this)
            {
                for (RMetaObject klass = this; klass != null; klass = klass.super)
                {
                    foreach (DictionaryEntry entry in klass.m_tbl)
                    {
                        ////string s = ins.Inspect(ruby, (uint)entry.Key, (RNode)entry.Value);
                        RCMethod m = (RCMethod)entry.Value;
                        string   s = m.Name;
                        if (s != null && ary.Contains(s) == false)
                        {
                            ary.Add(s);
                        }
                    }
                    if (inherited_too == false)
                    {
                        break;
                    }
                }
            }
            return(new RArray(ruby, ary));
        }
Example #2
0
        internal RMetaObject PushClass(RMetaObject klass)
        {
            RMetaObject old = rClass;

            rClass = klass;
            return(old);
        }
Example #3
0
 internal RMetaObject(RMetaObject o) :
     base(o)
 {
     if (o.m_tbl != null)
     {
         m_tbl = (st_table)o.m_tbl.Clone();
     }
 }
Example #4
0
 internal RMetaObject(RMetaObject o) :
     base(o)
 {
     if (o.m_tbl != null)
     {
         m_tbl = (st_table)o.m_tbl.Clone();
     }
 }
Example #5
0
        static public RBasic NewThreadGroup(object[] argv, RMetaObject meta)
        {
            NetRuby      ruby = meta.ruby;
            RThreadGroup tg   = new RThreadGroup(ruby, meta);

            ruby.CallInit(tg, argv);
            return(tg);
        }
Example #6
0
        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));
        }
Example #7
0
 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);
     }
 }
Example #8
0
        public object ruby_s_new(RBasic r, params object[] o)
        {
            object[] args = new object[1];
            if (ruby.ScanArgs(o, "01", args) == 0)
            {
                args[0] = ruby.cObject;
            }
            RMetaObject spr = (RMetaObject)args[0];

            return(RClass.ClassNew(ruby, spr, o));
        }
Example #9
0
 internal RMetaObject(NetRuby rb, string name, RMetaObject sp, RMetaObject meta)
     : base(rb, meta)
 {
     super = sp;
     m_tbl = new st_table();
     if (name != null)
     {
         uint id = rb.intern(name);
         IVarSet("__classid__", Symbol.ID2SYM(id));
     }
 }
Example #10
0
        public override object Inspect()
        {
            RMetaObject klass = ruby.ClassOf(this);
            string      s     = ToString();

            if (s.Length == 0)
            {
                return(klass.ClassPath);
            }
            return(String.Format("#<{0}: {1}>", klass.ClassPath, s));
        }
Example #11
0
 internal RClass DefineClass(string name, RMetaObject spr)
 {
     klass = new RSingletonClass(spr.klass);
     klass.AttachSingleton(this);
     ruby.Funcall(spr, "inherited", this);
     lock (ruby.class_tbl.SyncRoot)
     {
         ruby.class_tbl[ruby.intern(name)] = this;
     }
     return(this);
 }
Example #12
0
        static public RBasic NewThread(object[] argv, RMetaObject meta)
        {
            NetRuby ruby   = meta.ruby;
            RThread parent = ruby.GetCurrentContext();
            RThread thrd   = (RThread)parent.Clone();

            thrd.thread = null;
            thrd.klass  = meta;
            ruby.CallInit(thrd, argv);
            return(thrd);
        }
Example #13
0
        internal void SetClassPath(RMetaObject under, string name)
        {
            string str = name;

            if (under != ruby.cObject)
            {
                str  = under.ClassPath;
                str += "::" + name;
            }
            IVarSet("__classpath__", str);
        }
Example #14
0
 internal RMetaObject(NetRuby rb, string name, RMetaObject sp, RMetaObject meta)
     : base(rb, meta)
 {
     super = sp;
     m_tbl = new st_table();
     if (name != null)
     {
         uint id = rb.intern(name);
         IVarSet("__classid__", Symbol.ID2SYM(id));
     }
 }
Example #15
0
        static public RBasic NewInstance(object[] argv, RMetaObject meta)
        {
            if (meta is RSingletonClass)
            {
                throw new eTypeError("can't create instance of virtual class");
            }
            NetRuby ruby = meta.ruby;
            RObject obj  = new RObject(ruby, meta);

            ruby.CallInit(obj, argv);
            return(obj);
        }
Example #16
0
 /*
 internal RBasic(NetRuby rb)
 {
 }
 */
 internal RBasic(NetRuby rb, RMetaObject meta)
 {
     klass = meta;
     ruby = rb;
     /*
     if (rb.SafeLevel >= 3)
     {
         flags |= FL.TAINT;
     }
     */
     GetHashCode();        // define ID
 }
Example #17
0
        public RArray IncludedModules()
        {
            ArrayList a = new ArrayList();

            for (RMetaObject p = super; p != null; p = p.super)
            {
                if (p is RIncClass)
                {
                    a.Add(p.klass);
                }
            }
            return(new RArray(ruby, a));
        }
Example #18
0
        /*
         * internal RBasic(NetRuby rb)
         * {
         * }
         */
        internal RBasic(NetRuby rb, RMetaObject meta)
        {
            klass = meta;
            ruby  = rb;

            /*
             * if (rb.SafeLevel >= 3)
             * {
             *  flags |= FL.TAINT;
             * }
             */
            GetHashCode();        // define ID
        }
Example #19
0
        static public RProc NewProc(object[] argv, RMetaObject meta)
        {
/*
 *          NetRuby ruby = meta.ruby;
 *          if (ruby.IsBlockGiven == false && (bool)ruby.ruby_block_given_p(null) == false)
 *          {
 *              throw new ArgumentException("tried to create Proc object without a block");
 *          }
 *          RProc proc = new RProc(ruby, meta);
 *          ruby.CallInit(proc, argv);
 *          return proc;
 */
            return(null); //PH
        }
Example #20
0
        public int CompareTo(object o)
        {
            if (this == o)
            {
                return(0);
            }
            RMetaObject r = ModCheck(o);

            if (le(r))
            {
                return(-1);
            }
            return(1);
        }
Example #21
0
        public bool le(object o)
        {
            RMetaObject arg = ModCheck(o);
            RMetaObject mod = this;

            while (mod != null)
            {
                if (mod.m_tbl == arg.m_tbl)
                {
                    return(true);
                }
                mod = mod.super;
            }
            return(false);
        }
Example #22
0
        internal void Init(NetRuby rb)
        {
            if (klass == null)
            {
                klass = rb.cThread;
            }
            rClass = rb.cObject;
            ////frame.self = rb.topSelf;
            ////cRef = rb.topCRef;
            abortOnException = rb.cThread.abortOnException;

            RThreadGroup tg = (RThreadGroup)rb.cThreadGroup.ConstGetAt(rb.intern("Default"));

            tg.Add(this);
        }
Example #23
0
        public object CVarGet(uint id)
        {
            RMetaObject tmp    = this;
            object      result = null;

            while (tmp != null)
            {
                if (tmp.iv_tbl != null && tmp.iv_tbl.lookup(id, out result))
                {
                    return(result);
                }
                tmp = tmp.super;
            }
            throw new eNameError(String.Format("uninitialized class variable {0} in {1}",
                                               ruby.id2name(id), ClassName));
        }
Example #24
0
        public virtual object InstanceEval(params object[] argv)
        {
            RMetaObject klass;

            if (IsSpecialConst)
            {
                klass = null;
            }
            else
            {
                klass = SingletonClass(this, ruby);
            }

            ////return ruby.SpecificEval(klass, this, argv);
            return(null); //PH
        }
Example #25
0
        internal object SearchMethod(string id, out RMetaObject origin)
        {
            origin = null;
            RMetaObject klass = this;
            object      o;

            while (klass.m_tbl.lookup(id, out o) == false)
            {
                klass = klass.super;
                if (klass == null)
                {
                    return(null);
                }
            }
            origin = klass;
            return(o);
        }
Example #26
0
 internal RIncClass(RMetaObject module, RMetaObject sp) :
     base(module.ruby, sp)
 {
     if (module.iv_tbl == null)
     {
         module.iv_tbl = new st_table();
     }
     iv_tbl = module.iv_tbl;
     m_tbl  = module.m_tbl;
     if (module is RIncClass)
     {
         klass = module.klass;
     }
     else
     {
         klass = module;
     }
 }
Example #27
0
        public bool IsKindOf(object c)
        {
            RMetaObject cl = ruby.ClassOf(this);

            if (c is RMetaObject == false)
            {
                throw new eTypeError("class or module required");
            }
            while (cl != null)
            {
                if (cl == c || cl.m_tbl == ((RMetaObject)c).m_tbl)
                {
                    return(true);
                }
                cl = cl.super;
            }
            return(false);
        }
Example #28
0
        public void CVarSet(uint id, object val)
        {
            RMetaObject tmp = this;

            while (tmp != null)
            {
                lock (tmp.iv_tbl.SyncRoot)
                {
                    if (tmp.iv_tbl != null && tmp.iv_tbl.ContainsKey(id))
                    {
                        tmp.CVarCheck("class variable");
                        tmp.iv_tbl[id] = val;
                        return;
                    }
                }
                tmp = tmp.super;
            }
            throw new eNameError("uninitialized class variable " + ruby.id2name(id) + " in " + ClassName);
        }
Example #29
0
        public object IsKindOf(RBasic obj, params object[] o)
        {
            RMetaObject cl = ruby.ClassOf(obj);
            object      c  = o[0];

            if (c is RMetaObject == false)
            {
                throw new eTypeError("class or module required");
            }
            while (cl != null)
            {
                if (cl == c || cl.m_tbl == ((RMetaObject)c).m_tbl)
                {
                    return(true);
                }
                cl = cl.super;
            }
            return(false);
        }
Example #30
0
 private bool fc_i(uint key, object value, fc_result res)
 {
     if (Parser.is_const_id(key))
     {
         return(false);
     }
     if (value is RModule || value is RClass)
     {
         RMetaObject va = (RMetaObject)value;
         if (va == res.klass)
         {
             res.path = fc_path(res, key);
             return(true);
         }
         if (va.iv_tbl == null)
         {
             return(false);
         }
         fc_result list = res;
         while (list != null)
         {
             if (list.end(va))
             {
                 return(false);
             }
             list = list.prev;
         }
         fc_result arg = new fc_result(key, res.klass, va, res);
         lock (va.iv_tbl.SyncRoot)
         {
             foreach (DictionaryEntry ent in va.iv_tbl)
             {
                 if (fc_i((uint)ent.Key, ent.Value, arg))
                 {
                     res.path = arg.path;
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Example #31
0
        static public RClass ClassNew(NetRuby ruby, RMetaObject spr, object[] o)
        {
            if (spr == null)
            {
                spr = ruby.cObject;
            }
            else if (spr is RSingletonClass)
            {
                throw new eTypeError("can't make subclass of virtual class");
            }
            RClass klass = new RClass(ruby, spr);

            klass.klass = new RSingletonClass(spr.klass);
            klass.klass.AttachSingleton(klass);
            ruby.CallInit(klass, o);
            ruby.Funcall(spr, "inherited", new object[1] {
                klass
            });
            return(klass);
        }
Example #32
0
        internal RBasic(RBasic o)
        {
            ruby = o.ruby;
            if (o.klass is RSingletonClass)
            {
                RMetaObject org  = o.klass;
                RMetaObject meta = (RMetaObject)org.Clone();
                if (meta.m_tbl == null)
                {
                    meta.m_tbl = new st_table();
                }
                else
                {
                    meta.m_tbl.Clear();
                }

/*
 *              foreach (DictionaryEntry ent in org.m_tbl)
 *              {
 *                  RNMethod m = (RNMethod)ent.Value;
 *                  meta.m_tbl.Add(ent.Key, new RNMethod(m));
 *              }
 */
                klass = meta;
            }
            else
            {
                klass = o.klass;
            }
            flags = o.flags;

/*
 *          if (o.Test(FL.EXIVAR))
 *          {
 *              ruby.CloneGenericIVar(this, o);
 *          }
 */
            GetHashCode();        // define ID
        }
Example #33
0
        static internal object exc_exception(RBasic r, params object[] args)
        {
            if (args.Length == 0)
            {
                return(r);
            }
            if (args.Length == 1 && args[0] == r)
            {
                return(r);
            }
            NetRuby     rb    = r.ruby;
            RMetaObject etype = rb.ClassOf(r);

            while (etype is RSingletonClass)
            {
                etype = etype.super;
            }
            RException ex = new RException(rb, etype);

            r.ruby.CallInit(ex, args);
            return(ex);
        }
Example #34
0
 internal RObject(NetRuby rb, RMetaObject meta)
     : base(rb, meta)
 {
 }
Example #35
0
 internal RObjectBase(NetRuby rb, RMetaObject meta)
     : base(rb, meta)
 {
     iv_tbl = null;
 }
Example #36
0
 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);
     }
 }
Example #37
0
 static public RClass ClassNew(NetRuby ruby, RMetaObject spr, object[] o)
 {
     if (spr == null)
     {
         spr = ruby.cObject;
     }
     else if (spr is RSingletonClass)
     {
         throw new eTypeError("can't make subclass of virtual class");
     }
     RClass klass = new RClass(ruby, spr);
     klass.klass = new RSingletonClass(spr.klass);
     klass.klass.AttachSingleton(klass);
     ruby.CallInit(klass, o);
     ruby.Funcall(spr, "inherited", new object[1] { klass });
     return klass;
 }
Example #38
0
 internal void PopClass(RMetaObject org)
 {
     rClass = org;
 }
Example #39
0
 public void PushClassScope(RMetaObject cls)
 {
     class_scopes.Push(cls);
 }
Example #40
0
 internal RThreadGroup(NetRuby rb, RMetaObject meta) :
     base(rb, meta)
 {
     gid = GetHashCode();
 }
Example #41
0
 static public RBasic NewInstance(object[] argv, RMetaObject meta)
 {
     if (meta is RSingletonClass)
     {
         throw new eTypeError("can't create instance of virtual class");
     }
     NetRuby ruby = meta.ruby;
     RObject obj = new RObject(ruby, meta);
     ruby.CallInit(obj, argv);
     return obj;
 }
Example #42
0
 internal RIncClass(RMetaObject module, RMetaObject sp) :
     base(module.ruby, sp)
 {
     if (module.iv_tbl == null)
     {
         module.iv_tbl = new st_table();
     }
     iv_tbl = module.iv_tbl;
     m_tbl = module.m_tbl;
     if (module is RIncClass)
     {
         klass = module.klass;
     }
     else
     {
         klass = module;
     }
 }
Example #43
0
 public RHash(NetRuby rb, RMetaObject meta) :
     base(rb, meta)
 {
     hash = new Hashtable();
     ifnone = null;
 }
Example #44
0
 public RHash(NetRuby rb, RHash org, RMetaObject meta) :
     base(rb, meta)
 {
     hash = (Hashtable)org.hash.Clone();
     ifnone = null;
 }
Example #45
0
 public RClass(NetRuby rb, RMetaObject spr)
     : base(rb, null, spr, rb.cClass)
 {
 }
Example #46
0
 public RClass(NetRuby rb, string name, RMetaObject spr)
     : base(rb, name, spr, rb.cClass)
 {
 }
Example #47
0
        internal void Init(NetRuby rb)
        {
            if (klass == null)
                klass = rb.cThread;
            rClass = rb.cObject;
            ////frame.self = rb.topSelf;
            ////cRef = rb.topCRef;
            abortOnException = rb.cThread.abortOnException;

            RThreadGroup tg = (RThreadGroup)rb.cThreadGroup.ConstGetAt(rb.intern("Default"));
            tg.Add(this);
        }
Example #48
0
        public static void IncludeModule(RMetaObject klass, RMetaObject module)
        {
            bool changed = false;
            if (module == null) return;
            if (module == klass) return;
            // call Check_Type if need

            // what is the syncroot ?
            RMetaObject c = klass;
            while (module != null)
            {
                for (RMetaObject r = klass.super; r != null; r = r.super)
                {
                    if (r is RIncClass &&
                        r.m_tbl == module.m_tbl)
                    {
                        c = r;
                        goto skip;
                    }
                }
                c.super = new RIncClass(module, c.super);
                c = c.super;
                changed = true;
            skip:
                module = module.super;
            }
            ////if (changed) klass.ruby.ClearCache();
        }
Example #49
0
 static public RBasic NewThread(object[] argv, RMetaObject meta)
 {
     NetRuby ruby = meta.ruby;
     RThread parent = ruby.GetCurrentContext();
     RThread thrd = (RThread)parent.Clone();
     thrd.thread = null;
     thrd.klass = meta;
     ruby.CallInit(thrd, argv);
     return thrd;
 }
Example #50
0
 public static void ExtendObject(RBasic klass, RMetaObject module)
 {
     IncludeModule(SingletonClass(klass, klass.ruby), module);
 }
Example #51
0
 static public RBasic NewThreadGroup(object[] argv, RMetaObject meta)
 {
     NetRuby ruby = meta.ruby;
     RThreadGroup tg = new RThreadGroup(ruby, meta);
     ruby.CallInit(tg, argv);
     return tg;
 }
Example #52
0
 internal void SetClassPath(RMetaObject under, string name)
 {
     string str = name;
     if (under != ruby.cObject)
     {
         str = under.ClassPath;
         str += "::" + name;
     }
     IVarSet("__classpath__", str);
 }
Example #53
0
 internal RMetaObject PushClass(RMetaObject klass)
 {
     RMetaObject old = rClass;
     rClass = klass;
     return old;
 }
Example #54
0
 public virtual object InstanceEval(params object[] argv)
 {
     RMetaObject klass;
     if (IsSpecialConst)
         klass = null;
     else
         klass = SingletonClass(this, ruby);
 
     ////return ruby.SpecificEval(klass, this, argv);
     return null; //PH
 }
Example #55
0
 internal RClass DefineClass(string name, RMetaObject spr)
 {
     klass = new RSingletonClass(spr.klass);
     klass.AttachSingleton(this);
     ruby.Funcall(spr, "inherited", this);
     lock (ruby.class_tbl.SyncRoot)
     {
         ruby.class_tbl[ruby.intern(name)] = this;
     }
     return this;
 }
Example #56
0
 static internal RClass SingletonClass(object obj, NetRuby ruby)
 {
     if (obj is int || obj is long || obj is double || Symbol.IsSymbol(obj))
     {
         throw new eTypeError("can't define singleton");
     }
     if (RBasic.IsSpecialConstType(obj))
     {
         if (obj == null)
         {
             if (ruby.cNilClass.IsSingleton == false)
             {
                 ruby.cNilClass = new RSingletonClass(ruby.cNilClass);
                 return ruby.cNilClass;
             }
         }
         bool b = (bool)obj;
         RClass o = (b) ? ruby.cTrueClass : ruby.cFalseClass;
         if (o.IsSingleton == false)
         {
             if (b)
                 o = ruby.cTrueClass = new RSingletonClass(o);
             else
                 o = ruby.cFalseClass = new RSingletonClass(o);
         }
         return o;
     }
     if (obj is RBasic == false)
     {
         ruby.bug("Unknown object " + obj.ToString());
     }
     RBasic bas = (RBasic)obj;
     RClass klass = null;
     if (bas is RSingletonClass)
     {
         klass = (RClass)bas.klass;
     }
     else
     {
         klass = new RSingletonClass(bas.klass);
         bas.klass = klass;
         klass.AttachSingleton((RObjectBase)obj);
     }
     if (bas.Test(FL.TAINT))
     {
         klass.Set(FL.TAINT);
     }
     else
     {
         klass.Unset(FL.TAINT);
     }
     if (bas.Test(FL.FREEZE))
     {
         klass.Set(FL.FREEZE);
     }
 
     return klass;
 }
Example #57
0
 internal RTime(NetRuby rb, RMetaObject meta) :
     base(rb, meta)
 {
     utc = false;
     time = DateTime.Now;
 }
Example #58
0
 internal object SearchMethod(string id, out RMetaObject origin)
 {
     origin = null;
     RMetaObject klass = this;
     object o;
     while (klass.m_tbl.lookup(id, out o) == false)
     {
         klass = klass.super;
         if (klass == null) return null;
     }
     origin = klass;
     return o;
 }
Example #59
0
 public RArray(NetRuby rb, bool newobj, RMetaObject spr) :
     base(rb, spr)
 {
     ptr = (newobj) ? new ArrayList() : null;
 }
Example #60
0
 internal RSingletonClass(RMetaObject o)
     : base(o.ruby, o)
 {
 }