Exemplo n.º 1
0
        public override string ToString()
        {
            string s = ruby.ClassOf(this).Name;

            s = String.Format("#<{0}:0x{1:x8}>", s, GetHashCode());
            return(s);
        }
Exemplo n.º 2
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.º 3
0
 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);
 }
Exemplo n.º 4
0
 internal void Init(NetRuby rb)
 {
     rb.cFalseClass = rb.DefineClass("FalseClass", rb.cObject);
     rb.cFalseClass.DefineMethod("&", new RMethod(ruby_and), 1);
     rb.cFalseClass.DefineMethod("|", new RMethod(ruby_or), 1);
     rb.cFalseClass.DefineMethod("^", new RMethod(ruby_xor), 1);
     rb.ClassOf(rb.cFalseClass).UndefMethod("new");
     rb.DefineGlobalConst("FALSE", false);
 }
Exemplo n.º 5
0
        internal static new void Init(NetRuby rb)
        {
            RClass it = rb.DefineClass("Integer", rb.cNumeric);

            rb.cInteger = it;
            rb.ClassOf(it).UndefMethod("new");

            it.DefineMethod("upto", new RMethod(int_upto), 1);
            it.DefineMethod("downto", new RMethod(int_downto), 1);
            it.DefineMethod("step", new RMethod(int_step), 2);

            it.DefineMethod("to_int", new RMethod(num_to_i), 0);
            it.DefineMethod("floor", new RMethod(num_to_i), 0);
            it.DefineMethod("ceil", new RMethod(num_to_i), 0);
            it.DefineMethod("round", new RMethod(num_to_i), 0);
        }
Exemplo n.º 6
0
        internal void Init(NetRuby rb)
        {
            BindingFlags bf = BindingFlags.InvokeMethod
                              | BindingFlags.Static | BindingFlags.Public
                              | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy
                              | BindingFlags.Instance;

            rb.cNilClass = rb.DefineClass("NilClass", rb.cObject);
            Type obj = typeof(RNil);

            rb.cNilClass.DefineMethod("to_i", obj.GetMethod("ToInteger", bf));
            rb.cNilClass.DefineMethod("to_a", obj.GetMethod("ToArray", bf));
            rb.cNilClass.DefineMethod("to_s", new RMethod(nil_to_s), 0);
            rb.cNilClass.DefineMethod("&", new RMethod(ruby_and), 1);
            rb.cNilClass.DefineMethod("|", new RMethod(ruby_or), 1);
            rb.cNilClass.DefineMethod("^", new RMethod(ruby_xor), 1);
            rb.cNilClass.DefineMethod("nil?", new RMethod(ruby_true), 0);

            rb.ClassOf(rb.cNilClass).UndefMethod("new");
            rb.DefineGlobalConst("NIL", null);
        }
Exemplo n.º 7
0
        static internal new void Init(NetRuby rb)
        {
            BindingFlags bf = BindingFlags.InvokeMethod
                              | BindingFlags.Static | BindingFlags.Public
                              | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy
                              | BindingFlags.Instance;
            RClass flo = rb.DefineClass("Float", rb.cNumeric);

            rb.cFloat = flo;
            rb.oFloat = new RFloat(rb, 0.0);
            Type obj = typeof(RFloat);

            rb.ClassOf(flo).UndefMethod("new");

            flo.DefineMethod("floor", obj.GetMethod("get_Floor", bf));
            flo.DefineMethod("ceil", obj.GetMethod("get_Ceil", bf));
            flo.DefineMethod("round", obj.GetMethod("get_Round", bf));
            flo.DefineMethod("nan?", obj.GetMethod("get_IsNaN", bf));
            flo.DefineMethod("infinite?", obj.GetMethod("get_IsInfinite", bf));
            flo.DefineMethod("finite?", obj.GetMethod("get_IsFinite", bf));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        internal void Init(NetRuby rb)
        {
            BindingFlags bf = BindingFlags.InvokeMethod
                              | BindingFlags.Static | BindingFlags.Public
                              | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy
                              | BindingFlags.Instance;

            RMethod rmDummy = new RMethod(ruby_dummy);

            rb.cObject.DefinePrivateMethod("initialize", rmDummy, 0);
            rb.cClass.DefinePrivateMethod("inherited", rmDummy, 1);

            DefineMethod("nil?", new RMethod(ruby_isnil), 0);
            DefineMethod("==", new RMethod(ruby_equals), 1);
            DefineAlias("equal?", "==");
            DefineAlias("===", "==");
            DefineMethod("=~", new RMethod(ruby_false), 1);
            DefineMethod("eql?", new RMethod(ruby_eql), 1);

            Type obj = GetType();

            RMethod rm = new RMethod(ruby_id);

            DefineMethod("hash", rm, 0);
            DefineMethod("id", rm, 0);
            DefineMethod("__id__", rm, 0);
            rm = new RMethod(ruby_class);
            DefineMethod("type", rm, 0);
            DefineMethod("class", rm, 0);

            DefineMethod("clone", new RMethod(ruby_clone), 0);
            DefineMethod("dup", new RMethod(ruby_dup), 0);
            DefineMethod("taint", new RMethod(ruby_taint), 0);
            DefineMethod("tainted?", new RMethod(ruby_istainted), 0);

            DefineMethod("Untaint", new RMethod(ruby_untaint), 0);
            DefineMethod("freeze", new RMethod(ruby_freeze), 0);
            DefineMethod("frozen?", new RMethod(ruby_isfrozen), 0);

            DefineMethod("to_a", new RMethod(ruby_to_a), 0);
            DefineMethod("to_s", new RMethod(ruby_to_s), 0);
            DefineMethod("inspect", new RMethod(ruby_inspect), 0);
            rm = new RMethod(ruby_methods);
            DefineMethod("methods", rm, 0);
            DefineMethod("public_methods", rm, 0);
            DefineMethod("singleton_methods", new RMethod(ruby_singleton_methods), 0);
            DefineMethod("protected_methods", new RMethod(ruby_protected_methods), 0);
            DefineMethod("private_methods", new RMethod(ruby_private_methods), 0);
            DefineMethod("instance_variables", new RMethod(ruby_instance_variables), 0);
            DefinePrivateMethod("remove_instance_variable",
                                new RMethod(ruby_remove_instance_variable), 1);
            DefineMethod("instance_of?", new RMethod(IsInstanceOf), 1);
            rm = new RMethod(IsKindOf);
            DefineMethod("kind_of?", rm, 1);
            DefineMethod("is_a?", rm, 1);

            rb.DefineGlobalFunction("singleton_method_added", rmDummy, 1);
            rb.DefineGlobalFunction("sprintf", new RMethod(sprintf), -1);
            rb.DefineGlobalFunction("format", new RMethod(sprintf), -1);

            rb.DefineGlobalFunction("Integer", new RMethod(ruby_integer), 1);
            rb.DefineGlobalFunction("Float", new RMethod(ruby_float), 1);
            rb.DefineGlobalFunction("String", new RMethod(ruby_string), 1);
            rb.DefineGlobalFunction("Array", new RMethod(ruby_array), 1);

            rb.DefineGlobalFunction("sleep", new RMethod(ruby_sleep), -1);

            rb.oNil = new RNil(rb);
            rb.oNil.Init(rb);

            Symbol.Init(rb);

            obj = typeof(RMetaObject);
            rb.cModule.DefineMethod("===", obj.GetMethod("Eqq"));
            rb.cModule.DefineMethod("<=>", obj.GetMethod("CompareTo"));
            rb.cModule.DefineMethod("<", obj.GetMethod("lt"));
            rb.cModule.DefineMethod("<=", obj.GetMethod("le"));
            rb.cModule.DefineMethod(">", obj.GetMethod("gt"));
            rb.cModule.DefineMethod(">=", obj.GetMethod("ge"));

            rb.cModule.DefineMethod("included_modules", obj.GetMethod("IncludedModules"));
            rb.cModule.DefineMethod("name", obj.GetMethod("get_ModuleName"));

            rb.cModule.DefineMethod("attr", new RMethod(attr), -1);
            rb.cModule.DefineMethod("attr_reader", new RMethod(attr_reader), -1);
            rb.cModule.DefineMethod("attr_writer", new RMethod(attr_writer), -1);
            rb.cModule.DefineMethod("attr_accessor", new RMethod(attr_accessor), -1);

            rb.cModule.DefineSingletonMethod("new", new RMethod(s_new), 0);
            rb.cModule.DefineMethod("initialize", new RMethod(initialize), -1);

            rb.cModule.DefineMethod("instance_methods", obj.GetMethod("ClassInstanceMethods", bf));
            rb.cModule.DefineMethod("public_instance_methods", obj.GetMethod("ClassInstanceMethods", bf));
            rb.cModule.DefineMethod("protected_instance_methods", obj.GetMethod("ClassProtectedInstanceMethods", bf));
            rb.cModule.DefineMethod("private_instance_methods", obj.GetMethod("ClassPrivateInstanceMethods", bf));

            rb.cModule.DefineMethod("constants", new RMethod(rb.cModule.constants), 0);
            rb.cModule.DefineMethod("const_get", new RMethod(rb.cModule.const_get), 1);
            rb.cModule.DefineMethod("const_set", new RMethod(rb.cModule.const_set), 2);
            rb.cModule.DefineMethod("const_defined?", new RMethod(rb.cModule.is_const_defined), 1);
            rb.cModule.DefineMethod("remove_const", new RMethod(rb.cModule.remove_const), 1);
            rb.cModule.DefineMethod("method_added", rmDummy, 1);

            obj = rb.cClass.GetType();
            rb.cClass.DefineMethod("new", new RMethod(ruby_new), -1);
            rb.cClass.DefineMethod("superclass", new RMethod(ruby_superclass), 0);
            rb.cClass.DefineSingletonMethod("new", new RMethod(ruby_s_new), -1);
            rb.cClass.UndefMethod("extend_object");
            rb.cClass.UndefMethod("append_feartures");
            rb.cClass.DefineSingletonMethod("inherited", new RMethod(RClass.Inherited), 1);

            rb.cData = rb.DefineClass("Data", rb.cObject);
            rb.ClassOf(rb.cData).UndefMethod("new");

            rb.topSelf = new RMainObject(rb);

            rb.oTrue = new RTrue(rb);
            rb.oTrue.Init(rb);
            rb.oFalse = new RFalse(rb);
            rb.oFalse.Init(rb);
        }
Exemplo n.º 10
0
        static internal void Init(NetRuby rb)
        {
            rb.eRegexpError = rb.DefineClass("RegexpError", rb.eStandardError);

            rb.DefineVirtualVariable("$~",
                                     new GlobalEntry.Getter(matchGetter),
                                     new GlobalEntry.Setter(matchSetter));
            rb.DefineVirtualVariable("$&",
                                     new GlobalEntry.Getter(lastMatchGetter), null);
            rb.DefineVirtualVariable("$`",
                                     new GlobalEntry.Getter(preMatchGetter), null);
            rb.DefineVirtualVariable("$'",
                                     new GlobalEntry.Getter(postMatchGetter), null);
            rb.DefineVirtualVariable("$+",
                                     new GlobalEntry.Getter(lastParenGetter), null);
            rb.DefineVirtualVariable("$=",
                                     new GlobalEntry.Getter(iCaseGetter),
                                     new GlobalEntry.Setter(iCaseSetter));
            rb.DefineVirtualVariable("$KCODE",
                                     new GlobalEntry.Getter(kCodeGetter),
                                     new GlobalEntry.Setter(kCodeSetter));
            rb.DefineVirtualVariable("$-K",
                                     new GlobalEntry.Getter(kCodeGetter),
                                     new GlobalEntry.Setter(kCodeSetter));

            RRegexpClass reg = new RRegexpClass(rb);

            reg.DefineClass("Regexp", rb.cObject);
            rb.cRegexp = reg;

            reg.DefineSingletonMethod("new", new RMethod(s_new), -1);
            reg.DefineSingletonMethod("compile", new RMethod(s_new), -1);
            reg.DefineSingletonMethod("quote", new RMethod(s_quote), -1);
            reg.DefineSingletonMethod("escape", new RMethod(s_quote), -1);
            reg.DefineSingletonMethod("last_match", new RMethod(s_lastmatch), 0);

            reg.DefineMethod("initialize", new RMethod(initialize), -1);
            reg.DefineMethod("=~", new RMethod(match), 1);
            reg.DefineMethod("===", new RMethod(match), 1);
            reg.DefineMethod("~", new RMethod(match2), 0);
            reg.DefineMethod("match", new RMethod(match_m), 1);
            reg.DefineMethod("source", new RMethod(source), 0);
            reg.DefineMethod("casefold?", new RMethod(casefold_p), 0);
            reg.DefineMethod("kcode", new RMethod(kcode_m), 0);

            reg.DefineConst("IGNORECASE", RegexOptions.IgnoreCase);
            reg.DefineConst("EXTENDED", RegexOptions.IgnorePatternWhitespace);
            reg.DefineConst("MULTILINE", RegexOptions.Multiline);

            RClass md = rb.DefineClass("MatchData", rb.cObject);

            rb.DefineGlobalConst("MatchingData", md);
            rb.cMatch = md;
            rb.ClassOf(md).UndefMethod("new");
            md.DefineMethod("size", new RMethod(match_size), 0);
            md.DefineMethod("length", new RMethod(match_size), 0);
            md.DefineMethod("offset", new RMethod(match_offset), 1);
            md.DefineMethod("begin", new RMethod(match_begin), 1);
            md.DefineMethod("end", new RMethod(match_end), 1);
            md.DefineMethod("to_a", new RMethod(match_to_a), 0);
            md.DefineMethod("[]", new RMethod(match_aref), -1);
            md.DefineMethod("pre_match", new RMethod(match_pre), 0);
            md.DefineMethod("post_match", new RMethod(match_post), 0);
            md.DefineMethod("to_s", new RMethod(match_to_s), 0);
            md.DefineMethod("string", new RMethod(match_string), 0);
        }