Exemplo n.º 1
0
        public virtual RBasic BasicSend(string name, RBasic[] args, RCBlock block)
        {
            RMetaObject origin;
            RCMethod    m = (RCMethod)klass.SearchMethod(name, out origin);

            /*
             * Console.WriteLine("sending");
             * Console.WriteLine("self " + this.ToString());
             * Console.WriteLine("send " + name + " found " + m.ToString());
             * foreach(RBasic ro in args) {
             *  Console.WriteLine("arg " + ro.ToString());
             * }
             */
            if (m == null)
            {
                Console.WriteLine("Available methods:");

                foreach (object o in klass.ClassInstanceMethods(new object[] { ruby.oTrue }))
                {
                    Console.WriteLine(o.ToString());
                }

                throw new Exception("Method not found: " + name);
            }
            return(m.Call(ruby.GetCurrentContext(), this, args, block));
        }
Exemplo n.º 2
0
        static internal RThread Start(NetRuby ruby, object[] args)
        {
            RThread parent = ruby.GetCurrentContext();
            RThread thrd   = (RThread)parent.Clone();

            return(thrd.Start(args));
        }
Exemplo n.º 3
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.º 4
0
        static private void matchSetter(object val, uint id, GlobalEntry gb, NetRuby rb)
        {
            rb.CheckType(val, typeof(RMatchData));
            RThread th = rb.GetCurrentContext();

            th.BackRef = val;
        }
Exemplo n.º 5
0
        static private object matchGetter(uint id, GlobalEntry gb, NetRuby rb)
        {
            RThread th = rb.GetCurrentContext();
            object  o  = th.BackRef;

            matchBusy(o);
            return(o);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        internal static void Init(NetRuby rb)
        {
            RThreadGroupClass t = new RThreadGroupClass(rb);

            t.DefineClass("ThreadGroup", rb.cObject);
            rb.cThreadGroup = t;
            t.DefineSingletonMethod("new", new RMethod(tg_new), -1);
            t.DefineMethod("list", new RMethod(list), 0);
            t.DefineMethod("add", new RMethod(add), 1);
            RThreadGroup rg = (RThreadGroup)tg_new(t);

            t.ConstSet(rb.intern("Default"), rg);
            rg.Add(rb.GetCurrentContext());
        }
Exemplo n.º 8
0
        static private object lastParenGetter(uint id, GlobalEntry gb, NetRuby rb)
        {
            RThread    th = rb.GetCurrentContext();
            RMatchData m  = (RMatchData)th.BackRef;

            if (m == null)
            {
                return(null);
            }
            string s = m.Last;

            if (m.IsTainted)
            {
                return(new RString(rb, s, true));
            }
            return(s);
        }
Exemplo n.º 9
0
        internal bool Require(string s)
        {
            RThread th = ruby.GetCurrentContext();

            ////ruby.CheckSafeString(th, s);
            s = s.Replace('/', Path.DirectorySeparatorChar);
            string fname  = null;
            bool   script = true;
            string ext    = Path.GetExtension(s);

            if (ext != String.Empty)
            {
                if (String.Compare(ext, ".rb", true) == 0)
                {
                    fname = FindFile(s);
                }
                else if (String.Compare(ext, ".dll", true) == 0 ||
                         String.Compare(ext, ".so", true) == 0)
                {
                    fname  = FindFile(s);
                    script = false;
                }
            }
            else
            {
                for (int i = 0; i < exts.Length; i++)
                {
                    fname = FindFile(s + exts[i]);
                    if (fname != null)
                    {
                        if (i != 0)
                        {
                            script = false;
                        }
                        break;
                    }
                }
            }
            if (fname == null)
            {
                throw new eLoadError("No such file to load -- " + s);
            }

            string fileName = Path.GetFileName(fname);

            if (featureCheck(fileName))
            {
                return(false);
            }

            if (script == false)
            {
                try
                {
                    AssemblyName asm = AssemblyName.GetAssemblyName(fname);
                    Assembly     a   = Assembly.Load(asm);
                    Type[]       tps = a.GetTypes();
                    foreach (Type t in tps)
                    {
                        AddType(t, th);
                    }
                    features.Add(fileName);
                }
                catch (FileLoadException)
                {
                    return(false);
                }
                catch (BadImageFormatException)
                {
                    throw new eLoadError("Not valid file image to load -- " + fname);
                }
            }
            else
            {
                ////int oldSafeLevel = th.safeLevel;
                ////th.safeLevel = 0;
                ////th.PushTag(Tag.TAG.PROT_NONE);
                try
                {
                    ruby.Load(fname, false);
                    features.Add(fileName);
                }
                catch (Exception e)
                {
#if _DEBUG
                    System.Console.Error.WriteLine(e.Message);
                    System.Console.Error.WriteLine(e.StackTrace);
#endif
                    throw e;
                }
                finally
                {
                    ////th.PopTag(true);
                    ////th.safeLevel = oldSafeLevel;
                }
            }
            return(true);
        }