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); }
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); }
public override RBasic Call(RThread th, RBasic self, RBasic[] args, RCBlock block) { th.PushLegacyBlock(block); RBasic ret = RClass.ConvertToRuby(ruby, method(self, (object[])args)); th.PopLegacyBlock(); return(ret); }
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 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)); }
static internal void Init(NetRuby rb) { RClass sym = rb.DefineClass("Symbol", rb.cObject); rb.cSymbol = sym; rb.oSymbol = new Symbol(rb); sym.DefineMethod("to_i", new RMethod(to_i), 0); sym.DefineMethod("to_int", new RMethod(to_i), 0); sym.DefineMethod("inspect", new RMethod(inspect), 0); sym.DefineMethod("to_s", new RMethod(to_s), 0); sym.DefineMethod("id2name", new RMethod(to_s), 0); }
static internal void Init(NetRuby rb) { BindingFlags bf = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance; RClass str = rb.DefineClass("String", rb.cObject); rb.cString = str; rb.oString = new RString(rb, String.Empty); #if MIXIN RClass.IncludeModule(str, rb.mComparable); RClass.IncludeModule(str, rb.mEnumerable); #endif Type obj = typeof(RString); str.DefineSingletonMethod("new", obj.GetMethod("New", bf)); str.DefineMethod("initialize", obj.GetMethod("Initialize", bf)); str.DefineMethod("clone", obj.GetMethod("Clone", bf)); str.DefineMethod("dup", obj.GetMethod("Dup", new Type[0])); str.DefineMethod("<=>", obj.GetMethod("CompareMethod", bf)); str.DefineMethod("eql?", obj.GetMethod("Equals", bf & (~BindingFlags.Static))); str.DefineMethod("equal?", new RMethod(rb.oString.str_equal), 1); str.DefineMethod("+", obj.GetMethod("Plus", bf)); str.DefineMethod("length", obj.GetMethod("get_Length", bf)); str.DefineMethod("size", obj.GetMethod("get_Length", bf)); str.DefineMethod("empty?", obj.GetMethod("get_IsEmpty", bf)); str.DefineMethod("to_i", obj.GetMethod("ToInteger", new Type[0])); str.DefineMethod("to_f", obj.GetMethod("ToFloat", bf)); MethodInfo mi = obj.GetMethod("ToRString", bf); str.DefineMethod("to_s", mi); str.DefineMethod("to_str", mi); str.DefineMethod("inspect", obj.GetMethod("Inspect", bf)); str.DefineMethod("dump", obj.GetMethod("Dump", bf)); str.DefineMethod("upcase", obj.GetMethod("UpCase", bf)); str.DefineMethod("downcase", obj.GetMethod("DownCase", bf)); str.DefineMethod("capitalize", obj.GetMethod("Capitalize", bf)); str.DefineMethod("swapcase", obj.GetMethod("SwapCase", bf)); str.DefineMethod("upcase!", obj.GetMethod("UpCaseBang", bf)); str.DefineMethod("downcase!", obj.GetMethod("DownCaseBang", bf)); str.DefineMethod("capitalize!", obj.GetMethod("CapitalizeBang", bf)); str.DefineMethod("swapcase!", obj.GetMethod("SwapCaseBang", bf)); str.DefineMethod("sub", obj.GetMethod("Sub", bf)); str.DefineMethod("gsub", obj.GetMethod("Gsub", bf)); str.DefineMethod("sub!", obj.GetMethod("SubAt", bf)); str.DefineMethod("gsub!", obj.GetMethod("GsubAt", bf)); }
static internal new void Init(NetRuby rb) { RClass big = rb.DefineClass("Bignum", rb.cInteger); rb.cBignum = big; big.DefineMethod("~", new RMethod(ruby_neg), 0); RMethod rm = new RMethod(ruby_eq); big.DefineMethod("==", rm, 1); big.DefineMethod("===", rm, 1); big.DefineMethod("eql?", rm, 1); }
static internal new void Init(NetRuby rb) { RClass fix = rb.DefineClass("Fixnum", rb.cInteger); rb.cFixnum = fix; RFixnum o = new RFixnum(rb); rb.oFixnum = o; rb.oFixZero = new RFixnum(rb, 0); fix.DefineMethod("to_f", new RMethod(o.ruby_to_f), 0); fix.DefineMethod("to_c", new RMethod(o.ruby_to_c), 0); fix.DefineMethod("==", new RMethod(fix_equal), 1); }
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); }
public override RBasic Call(RThread th, RBasic self, RBasic[] args, RCBlock block) { th.PushLegacyBlock(block); /* * Console.WriteLine("Invoke " + method_info.Name + " self=" + self.GetType().Name + ":" + self.ToString()); * Console.WriteLine("mi_type=" + method_info.DeclaringType.Name); * foreach(ParameterInfo p in method_info.GetParameters()) { * Console.WriteLine("mparam: " + p.ParameterType.Name); * } * foreach(RBasic r in args) { * Console.WriteLine("realparam: " + r.GetType().Name); * } */ // return (RBasic)method_info.Invoke(null, new object[] { self, args }); ParameterInfo[] pi = method_info.GetParameters(); RBasic ret; if (pi.Length > 0 && pi[0].ParameterType == typeof(object[])) { ret = RClass.ConvertToRuby(ruby, method_info.Invoke(self, new object[] { args })); } else { object[] ca = new object[pi.Length]; for (int i = 0; i < pi.Length; i++) { if (pi[i].ParameterType == typeof(int)) { ca[i] = args[i].ToInteger(); } else { ca[i] = args[i]; } } ret = RClass.ConvertToRuby(ruby, method_info.Invoke(self, ca)); } th.PopLegacyBlock(); return(ret); }
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); }
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)); }
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); }
internal RClass(RClass o) : base(o) { }
/* private void CallEndProc(object o) { RThread th = GetCurrentContext(); th.PushIter(ITER.NOT); Frame frm = th.PushFrame(false); frm.self = frm.prev.self; frm.lastFunc = 0; frm.lastClass = null; try { ((RProc)o).Call(); } catch (Exception e) { th.errorHandle(e); } th.PopFrame(); th.PopIter(); } internal void End() { RThread th = GetCurrentContext(); Frame frm = th.PushFrame(false); frm.args = null; EndProcData.SetEndProc(this, new EndProcData.EndMethod(CallEndProc), Lambda(), th.wrapper != null); th.PopFrame(); } object ruby_at_exit(RBasic r, params object[] args) { NetRuby ruby = r.ruby; object o = ruby.Lambda(); EndProcData.SetEndProc(ruby, new EndProcData.EndMethod(ruby.CallEndProc), o, ruby.GetCurrentContext().wrapper != null); return o; } */ /* internal object ScopedFuncall(RMetaObject klass, object recver, uint id, object[] argv, RNScope n) { RThread th = GetCurrentContext(); #if LOCAL_TRACE System.Console.WriteLine("ScopedFuncall"); for (int h = 0; h < argv.Length; h++) { System.Console.WriteLine("arg = " + ((argv[h]==null)?"null":argv[h].ToString())); } #endif object result = null; object[] local_vars = null; RNCRef savedCRef = null; Scope.ScopeMode vm = th.PushScope(); if (n.rval != null) { savedCRef = th.cRef; th.cRef = (RNCRef)n.rval; th.frame.cBase = th.cRef; } if (n.tbl != null) { local_vars = new object[n.tbl.Length + 1]; local_vars[0] = n; th.scope.InitLocal(n.tbl, local_vars); } RNode body = n.next; RNode b2 = body; #if LOCAL_TRACE System.Console.WriteLine("local_vars = " + ((local_vars == null)?"null":local_vars.Length.ToString())); #endif RVarmap old = th.dyna_vars; th.dyna_vars = null; th.PushTag(Tag.TAG.PROT_FUNC); Tag.TAG state = Tag.TAG.EMPTY; try { RNode node = null; if (body is RNArgs) { node = body; body = null; } else if (body is RNBlock) { node = body.head; body = body.next; } int i = 0; if (node != null) { if (node is RNArgs == false) { bug("no argumenet-node"); } i = node.cnt; if (i > argv.Length) { throw new ArgumentException( String.Format("wrong # of arguments({0} for {1})", argv.Length, i)); } if (node.rest == -1) { int opt = i; RNode optnode = node.opt; while (optnode != null) { opt++; optnode = optnode.next; } if (opt < argv.Length) { throw new ArgumentException( String.Format("wrong # of arguments({0} for {1})", argv.Length, opt)); } // index offset is 2, for $_ and $~ th.frame.args = local_vars; } } if (local_vars != null) { if (i > 0) { // +2 for $_ and $~ Array.Copy(argv, 0, local_vars, 2, i); } #if LOCAL_TRACE for (int h = 0; h < i; h++) { System.Console.WriteLine("local = " + ((local_vars[2+h]==null)?"null":local_vars[2+h].ToString())); } #endif int argc = argv.Length - i; if (node.opt != null) { RNode opt = node.opt; while (opt != null && argc > 0) { Assign(recver, opt.head, argv[i], true); argc--; i++; opt = opt.next; } if (opt != null) { th.file = opt.file; th.line = opt.Line; Eval(recver, opt); } } if (node.rest >= 0) { ArrayList a = new ArrayList(); if (argc > 0) { for (int ix = argc; ix < argv.Length; ix++) a.Add(argv[ix]); } th.scope.local_vars[node.rest] = new RArray(this, a); } } if (TraceFunc != null) { } result = Eval(recver, body); } catch (eTagJump e) { Tag etag = th.CurrentTag; if (e.state == Tag.TAG.RETURN) { result = etag.Result; state = Tag.TAG.EMPTY; } } catch (Exception e) { th.errInfo = new RException(this, e); state = Tag.TAG.RAISE; } th.PopTag(true); th.dyna_vars = old; th.PopScope(vm); th.cRef = savedCRef; if (TraceFunc != null) { } switch (state) { case Tag.TAG.EMPTY: ; break; case Tag.TAG.RETRY: goto default; default: break; } return result; } internal void Assign(object self, RNode lhs, object val, bool check) { if (val is QUndef) { val = null; } if (val is string) { // create assignable object val = new RString(this, (string)val); } lhs.Assign(this, self, val, check); } public delegate object IterationProc(RBasic ob); public delegate object BlockProc(object it, object data, object self); public object Iterate(IterationProc itProc, RBasic dat1, BlockProc blProc, object data) { Tag.TAG state; object result = null; RThread th = GetCurrentContext(); RNode node = new RNIFunc(th, blProc, data); RObjectBase self = topSelf; iter_retry: th.PushIter(ITER.PRE); Block _block = new Block(th, null, node, self); th.block = _block; th.PushTag(Tag.TAG.PROT_NONE); state = Tag.TAG.EMPTY; try { result = itProc(dat1); } catch (eTagJump e) { state = e.state; if (_block.CheckTag(e.state)) { state &= Tag.TAG.MASK; if (state == Tag.TAG.RETURN) { Tag etag = th.CurrentTag; result = etag.Result; } } } catch (Exception e) { th.errInfo = new RException(this, e); state = Tag.TAG.RAISE; } th.PopTag(true); th.block = _block.prev; th.PopIter(); switch (state) { case Tag.TAG.EMPTY: break; case Tag.TAG.RETRY: goto iter_retry; case Tag.TAG.BREAK: result = null; break; case Tag.TAG.RETURN: Tag etag = (Tag)th.protTag.Peek(); etag.Result = result; goto default; default: th.TagJump(state); break; } return result; } internal object Iteration(RNode node, object self) { RThread th = GetCurrentContext(); object result = null; for (;;) { th.PushTag(Tag.TAG.PROT_FUNC); Block _block = new Block(th, node.var, node.body, self); th.block = _block; Tag.TAG state = Tag.TAG.EMPTY; try { th.PushIter(ITER.PRE); if (node is RNIter) { result = Eval(self, node.iter); } else { string file = th.file; int line = th.line; _block.DScope = false; object recv = CallIter(node, self); th.file = file; th.line = line; result = Call(ClassOf(recv), recv, "Each", null, 0); } th.PopIter(); } catch (eTagJump e) { state = e.state; if (_block.CheckTag(e.state)) { state &= Tag.TAG.MASK; if (state == Tag.TAG.RETURN) { Tag etag = th.CurrentTag; result = etag.Result; } } errorPrint(th); } catch (Exception ex) { state = Tag.TAG.RAISE; errorPrint(th, ex); } th.PopTag(false); if (_block.IsDynamic) { _block.Orphan = true; } th.block = _block.prev; switch (state) { case Tag.TAG.EMPTY: goto exit; case Tag.TAG.RETRY: continue; case Tag.TAG.BREAK: result = null; goto exit; case Tag.TAG.RETURN: { Tag etag = (Tag)th.protTag.Peek(); etag.Result = result; goto default; } default: th.TagJump(state); break; } } exit: return result; } internal void ReturnCheck() { RThread th = GetCurrentContext(); foreach (Tag tt in th.protTag) { #if EXCEP_TRACE System.Console.WriteLine("TAG:" + tt.tag.ToString()); #endif if (tt == null) break; if (tt.tag == Tag.TAG.PROT_FUNC) break; if (tt.tag == Tag.TAG.PROT_THREAD) { throw new eThreadError("return from within thread " + Thread.CurrentThread.ToString()); } } } internal void SetReturnValue(object o) { RThread th = GetCurrentContext(); th.CurrentTag.Result = o; } internal object ConditionalLoop(RNode node, object self, bool cond) { RThread th = GetCurrentContext(); Tag.TAG state = Tag.TAG.EMPTY; th.PushTag(Tag.TAG.PROT_NONE); bool redo = false; bool next = false; for (;;) { try { if (redo == false && next == false) { th.line = node.Line; if (node.state && RBasic.RTest(Eval(self, node.cond)) != cond) { goto loop_out; } } do { if (next == false) { Eval(self, node.body); } redo = next = false; } while (RBasic.RTest(Eval(self, node.cond)) == cond); break; } catch (eTagJump e) { state = e.state; } catch (Exception e) { th.errInfo = new RException(this, e); state = Tag.TAG.RAISE; } switch (state) { case Tag.TAG.REDO: state = Tag.TAG.EMPTY; next = false; redo = true; break; case Tag.TAG.NEXT: state = Tag.TAG.EMPTY; next = true; redo = false; break; case Tag.TAG.BREAK: state = Tag.TAG.EMPTY; goto loop_out; default: goto loop_out; } } loop_out: th.PopTag(true); if (state != Tag.TAG.EMPTY) { th.TagJump(state); } return null; } internal object ModuleSetup(RMetaObject module, RNode n) { RThread th = GetCurrentContext(); object result = null; string file = th.file; int line = th.line; Frame frm = th.DupFrame(); RMetaObject cls = th.rClass; th.rClass = module; Scope.ScopeMode oldvmode = th.PushScope(); RVarmap old = th.dyna_vars; th.dyna_vars = null; if (n.tbl != null) { object[] tbl = new object[n.tbl.Length + 1]; tbl[0] = n; th.scope.InitLocal(n.tbl, tbl); } else { th.scope.local_tbl = null; th.scope.local_vars = null; } th.cRef = new RNCRef(module, th.cRef); frm.cBase = th.cRef; th.PushTag(Tag.TAG.PROT_NONE); int state = 0; try { if (TraceFunc != null) { } result = Eval(th.rClass, n.next); } catch (eTagJump tj) { //errat = null; state = (int)tj.state; errorPrint(th); } catch (Exception ex) { state = (int)Tag.TAG.RAISE; errorPrint(th, ex); } th.PopTag(true); th.cRef = (RNCRef)th.cRef.next; th.dyna_vars = old; th.PopScope(oldvmode); th.rClass = cls; th.frame = frm.tmp; if (TraceFunc != null) { } return result; } */ public RClass DefineClass(string name, RMetaObject super) { uint id = intern(name); if (cObject.IsConstDefined(id)) { object o = cObject.ConstGet(id); if (o is RClass == false) { throw new eTypeError(name + " is not a class"); } RClass r = (RClass)o; if (r.super.ClassReal != super) { throw new eNameError(name + "# is already defined"); } return r; } if (super == null) super = cObject; RClass klass = new RClass(this, name, super); klass.klass = new RSingletonClass(super.klass); klass.klass.AttachSingleton(klass); Funcall(super, "inherited", klass); lock (class_tbl.SyncRoot) { class_tbl[id] = klass; } return klass; }
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; }
/* internal object[] CallArgs(RNode nd, object self) { RThread th = GetCurrentContext(); Block tempBlock = th.block; if ((ITER)th.iter.Peek() == ITER.PRE) { th.block = th.block.prev; } th.iter.Push(ITER.NOT); object[] ret = nd.SetupArgs(this, self, nd.args); th.block = tempBlock; th.iter.Pop(); return ret; } internal object[] CallArgs(RNCall nd, object self, out object receiver) { RThread th = GetCurrentContext(); Block tempBlock = th.block; if ((ITER)th.iter.Peek() == ITER.PRE) { th.block = th.block.prev; } th.iter.Push(ITER.NOT); object[] ret = nd.SetupArgs(this, self, out receiver); th.block = tempBlock; th.iter.Pop(); return ret; } internal object CallIter(RNode nd, object self) { RThread th = GetCurrentContext(); Block tempBlock = th.block; if ((ITER)th.iter.Peek() == ITER.PRE) { th.block = th.block.prev; } th.iter.Push(ITER.NOT); object ret = Eval(self, nd.iter); th.block = tempBlock; th.iter.Pop(); return ret; } */ // private void InitEnvironment(RThread th) { ////Scope.ScopeMode oldvmode = th.PushScope(); ////th.PushTag(Tag.TAG.PROT_NONE); /* try { */ missing = intern("method_missing"); idEq = intern("=="); idEql = intern("eql?"); cObject = new RClass(this, "Object", null); class_tbl[intern("Object")] = cObject; cModule = new RModule(this, "Module", cObject); cClass = new RClass(this, "Class", cModule); class_tbl[intern("Class")] = cClass; cObject.klass = new RSingletonClass(cClass); cObject.klass.AttachSingleton(cObject); cModule.klass = new RSingletonClass(cObject.klass); cModule.klass.AttachSingleton(cModule); cClass.klass = new RSingletonClass(cModule.klass); cClass.klass.AttachSingleton(cClass); mKernel = new RKernel(this, "Kernel"); RMetaObject.IncludeModule(cObject, mKernel); mKernel.Init(this); REnumerable.Init(this); evalInit(); RString.Init(this); RException.Init(this); RThreadClass.Init(this); RThreadGroupClass.Init(this); RNumeric.Init(this); RInteger.Init(this); RFixnum.Init(this); RFloat.Init(this); RBignum.Init(this); RArray.Init(this); RHashClass.Init(this); RRegexpClass.Init(this); RIOClass.Init(this); RProcClass.Init(this); RTimeClass.Init(this); loader = Loader.Init(this); ////RDotNetClass.Init(this); versionInit(); threadMain.Init(this); th.rClass = cObject; /* topCRef = new RNCRef(cObject); th.cRef = topCRef; th.frame.self = topSelf; th.frame.cBase = topCRef; */ progInit(); /* } catch (eTagJump) { errorPrint(th); } */ /* catch (Exception e) { errorPrint(th, e); } */ ////th.PopTag(true); ////th.PopScope(oldvmode); }
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); }