public object Clone() { RThread tx = null; lock (this) { tx = (RThread)MemberwiseClone(); tx.errInfo = null; tx.lastCallStat = CALLSTAT.PUBLIC; tx.locals = null; ////tx.iter = (Stack)iter.Clone(); tx.scopes = (Stack)scopes.Clone(); ////tx.frame = frame.Dup(); ////if (block != null) ////{ //// tx.block.DupPrev(); ////} } ////tx.protTag = new Stack(); ////tx.protTag.Push(null); tx.inEval = 0; tx.threadId = 0; return(tx); }
static internal RThread Start(NetRuby ruby, object[] args) { RThread parent = ruby.GetCurrentContext(); RThread thrd = (RThread)parent.Clone(); return(thrd.Start(args)); }
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); * } */ }
public void Attribute(string name, bool read, bool write, bool ex) { NOEX noex = NOEX.PUBLIC; RThread th = ruby.GetCurrentContext(); if (ex) { if (th.ScopeTest(Scope.ScopeMode.Private)) { noex = NOEX.PRIVATE; ruby.warning((th.ScopeMode == Scope.ScopeMode.ModFunc) ? "attribute accessor as module_function" : "private attribute?"); } else if (th.ScopeTest(Scope.ScopeMode.Protected)) { noex = NOEX.PROTECTED; } } uint id = ruby.ToID(name); uint attriv = ruby.intern("@" + name); if (read) { ////addMethod(id, new RNIVar(th, attriv), noex); ruby.Funcall(this, "method_added", Symbol.ID2SYM(id)); } if (write) { id = ruby.intern(name + "="); ////addMethod(id, new RNAttrSet(th, attriv), noex); ruby.Funcall(this, "method_added", Symbol.ID2SYM(id)); } }
public Parser(NetRuby rb, RThread th, bool in_eval) { evalTree = null; ruby = rb; thread = th; compile_for_eval = in_eval; }
static private void matchSetter(object val, uint id, GlobalEntry gb, NetRuby rb) { rb.CheckType(val, typeof(RMatchData)); RThread th = rb.GetCurrentContext(); th.BackRef = val; }
public RString SubAt(params object[] args) { bool iter = false; RString repl = null; bool tainted = false; /* * if (args != null && args.Length == 1 && ruby.IsBlockGiven) * { * iter = true; * } * else */ if (args != null && args.Length == 2) { repl = StringToRString(ruby, args[1]); tainted = repl.IsTainted; } else { throw new eArgError(String.Format("wrong # of arguments({0} for 2)", (args == null) ? 0 : args.Length)); } RRegexp pat = GetPat(args[0]); if (pat.Search(ptr, 0, false, IsTainted) >= 0) { RThread th = ruby.GetCurrentContext(); RMatchData match = (RMatchData)th.BackRef; int beg = match.Begin(0); int len = match.End(0) - beg; if (iter) { /* * RRegexpClass.matchBusy(match); * repl = RString.AsRString(ruby, ruby.Yield(match[0])); * th.BackRef = match; // rescue from yield. */ } else { repl = new RString(ruby, match.Sub(repl.ToString(), ptr)); } if (repl.IsTainted) { tainted = true; } StringBuilder sb = new StringBuilder(ptr); sb.Remove(beg, len); sb.Insert(beg, repl.ptr, 1); ptr = sb.ToString(); if (tainted) { Taint(); } return(this); } return(null); }
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 private object matchGetter(uint id, GlobalEntry gb, NetRuby rb) { RThread th = rb.GetCurrentContext(); object o = th.BackRef; matchBusy(o); return(o); }
internal Tag(TAG t, RThread th) { retval = null; ////frame = th.frame; ////iter = th.iter.Peek(); scope = th.scope; tag = t; dst = 0; }
static internal object thread_stop(RBasic r, params object[] args) { RThread th = r.ruby.GetCurrentContext(); if (th.thread != null && th.thread.IsAlive) { th.thread.Suspend(); } return(null); }
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); }
public int Search(string s, int pos, bool rev, bool stringTainted) { if (pos > s.Length) { return(-1); } RThread th = ruby.GetCurrentContext(); Check(); if (ruby.cRegexp.IsRecompileNeed) { checkPreparation(); } Regex re = regex; if (rev) { re = new Regex(re.ToString(), re.Options | RegexOptions.RightToLeft); } Match m = re.Match(s, pos); if (m.Success == false) { th.BackRef = null; return(-1); } RMatchData mt = (RMatchData)th.BackRef; if (mt == null || mt.Test(RRegexpClass.MatchBusy)) { mt = new RMatchData(ruby, s, m); } else { /* * if (th.safeLevel >= 3) * mt.Taint(); * else * mt.Untaint(); */ mt.SetData(s, m); } th.BackRef = mt; mt.Infect(this); if (stringTainted) { mt.Taint(); } return(m.Index); }
static internal object match_m(RBasic r, params object[] args) { object o = match(r, args); if (o == null) { return(null); } RThread th = r.ruby.GetCurrentContext(); o = th.BackRef; matchBusy(o); return(o); }
public object Private(params object[] args) { ////ruby.SecureVisibility(this); RThread th = ruby.GetCurrentContext(); if (args == null || args.Length == 0) { th.ScopeSet(Scope.ScopeMode.Private); } else { SetMethodVisibility(args, NOEX.PRIVATE); } return(this); }
static internal object thread_status(RBasic r, params object[] args) { RThread th = (RThread)r; Thread thrd = th.thread; string s = th.ConvStat(); if (th.IsAlive == false) { if (th.HasError) { return(null); } return(false); } return(s); }
internal RNode(RThread th) { #if _SCANNER_DEBUG System.Console.WriteLine("Create Node:" + ToString()); #endif if (th != null) { File = th.file; Line = th.line; } else { File = "internal"; Line = 0; } }
public RThreadGroup Add(object o) { RThread th = ruby.GetCurrentContext(); ////th.Secure(4); if (o is RThread == false) { throw new eTypeError(String.Format("wrong argument type {0} (expected Thread)", ruby.ClassOf(o).Name)); } lock (o) { ((RThread)o).gid = gid; } return(this); }
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); }
static private object s_lastmatch(RBasic r, params object[] args) { RThread th = r.ruby.GetCurrentContext(); RMatchData m = (RMatchData)th.BackRef; if (m == null) { return(null); } string s = m[0]; if (m.IsTainted) { return(new RString(r.ruby, s, true)); } return(s); }
bool AddType(Type tp, RThread th) { BindingFlags bf = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod; MethodInfo mi = tp.GetMethod("Init", bf, null, new Type[] { typeof(NetRuby) }, null); #if REQUIRE_DEBUG System.Console.WriteLine("type:{0} has {1}", tp.ToString(), (mi == null) ? "null" : mi.ToString()); #endif /* * // NETRuby's extended libray * if (mi != null && mi.IsStatic) * { * Scope.ScopeMode vm = th.PushScope(); * th.PushTag(Tag.TAG.PROT_NONE); * Tag.TAG state = Tag.TAG.EMPTY; * try * { * mi.Invoke(null, new object[] {ruby}); * } * catch (eTagJump ej) * { * state = ej.state; * } * catch (Exception e) * { * th.errInfo = new RException(ruby, e); * state = Tag.TAG.RAISE; * } * th.PopTag(true); * th.PopScope(vm); * if (state != Tag.TAG.EMPTY) * { * th.TagJump(state); * } * } * else * { * ruby.cDotNet.AddFrameworkClass(tp); * } */ return(false); }
internal object SetTLS(object key, object val) { RThread th = ruby.GetCurrentContext(); /* * if (th.safeLevel >= 4 && th != this) * { * throw new SecurityException("Insecure: can't modify thread locals"); * } */ if (IsFrozen) { ruby.ErrorFrozen("thread locals"); } uint id = ruby.ToID(key); return(LocalASet(id, val)); }
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); }
internal RThread(NetRuby rb, RThread th) : base(rb, rb.cThread) { result = null; ////safeLevel = th.safeLevel; gid = th.gid; abortOnException = rb.cThread.abortOnException; threadId = AppDomain.GetCurrentThreadId(); thread = Thread.CurrentThread; vMode = Scope.ScopeMode.Private; ////frame = (Frame)rb.topFrame.Dup(); ////frame.self = rb.topSelf; ////frame.cBase = rb.topCRef; scopes = new Stack(); scope = new Scope(rb); dyna_vars = null; ////iter = new Stack(); ////iter.Push(ITER.NOT); ////protTag = new Stack(); //// protTag.Push(null); ////block = null; lvtbl = null; rClass = rb.cObject; wrapper = null; ////cRef = rb.topCRef; file = "ruby"; line = 0; inEval = 0; tracing = false; errInfo = null; lastCallStat = CALLSTAT.PUBLIC; locals = null; }
public void RemoveMethod(uint id) { RThread th = ruby.GetCurrentContext(); /* * if (this == ruby.cObject) th.Secure(4); * if (th.safeLevel >= 4 && IsTainted == false) * throw new SecurityException("Insecure: can't remove method"); */ if (IsFrozen) { ruby.ErrorFrozen("class/module"); } lock (m_tbl.SyncRoot) { if (m_tbl.ContainsKey(id) == false) { throw new eNameError(String.Format("method `{0}' not defined in {1}", ruby.id2name(id), Name)); } m_tbl.Remove(id); } ///ruby.ClearCache(id); }
internal RNMatch(RThread p, RNode n) : base(p) { hd = n; }
internal RNYield(RThread p) : base(p) { st = null; }
internal RNNewLine(RThread p, RNode n) : base(p) { FixPos(n); nt = n.Line; nd = n; }
internal RNEVStr(RThread p, NetRuby rb, string s) : base(p, rb, s) { }
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; }
internal RNMatch2(RThread p, RNode n, RNode gv) : base(p) { rv = n; vl = gv; }
internal RNNthRef(RThread p, int n) : base(p, n) { }
internal RNBackRef(RThread p, int n) : base(p, n) { }
internal RNReturn(RThread p) : base(p) { }
// list internal static RNode list_append(RThread th, RNode head, RNode tail) { if (head == null) return new RNArray(th, tail); RNode last = head; while (last.next != null) { last = last.next; } last.next = new RNArray(th, tail); head.alen += 1; return head; }
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); }
internal static RNode block_append(RThread p, RNode head, RNode tail) { RNode end = null; if (tail == null) return head; if (head == null) return tail; if (head is RNBlock) { end = head.end; } else { end = new RNBlock(p, head); head = end; } if (p.ruby.verbose) { for (RNode nd = end.head;;) { if (nd is RNNewLine) { nd = nd.next; } else if (nd is RNReturn || nd is RNBreak || nd is RNNext || nd is RNRedo || nd is RNRetry) { p.ruby.warn("statement not reached"); break; } else { break; } } } if (tail is RNBlock == false) { tail = new RNBlock(p, tail); } end.next = tail; head.end = tail.end; return head; }
internal RNBlock(RThread th, RNode n) : base(th) { FixPos(n); bg = n; ed = this; nxt = null; }
static internal object thread_alive(RBasic r, params object[] args) { RThread th = (RThread)r; return(th.thread.IsAlive); }
internal RNMatch(RThread p, object n) : base(p) { hd = new RNLit(p, n); }
protected RNRef(RThread p, int n) : base(p) { argcnt = n; ct = p.LocalCnt('~'); }
internal RNMatch3(RThread p, RNode r, RNode n2) : base(p, r, n2) { }
internal RNReturn(RThread p, RNode n) : base(p, n) { }
public RString GsubAt(params object[] args) { bool iter = false; RString repl = null; bool tainted = false; /* * if (args != null && args.Length == 1 && ruby.IsBlockGiven) * { * iter = true; * } * else */ if (args != null && args.Length == 2) { repl = StringToRString(ruby, args[1]); tainted = repl.IsTainted; } else { throw new eArgError(String.Format("wrong # of arguments({0} for 2)", (args == null) ? 0 : args.Length)); } RRegexp pat = GetPat(args[0]); int beg = pat.Search(ptr, 0, false, IsTainted); if (beg < 0) { return(null); } StringBuilder sb = new StringBuilder(); RThread th = ruby.GetCurrentContext(); int offset = 0; RMatchData match = null; while (beg >= 0) { string val; match = (RMatchData)th.BackRef; beg = match.Begin(0); int len = match.End(0) - beg; /* * if (iter) * { * * RRegexpClass.matchBusy(match); * repl = RString.AsRString(ruby, ruby.Yield(match[0])); * th.BackRef = match; // rescue from yield. * if (repl.IsTainted) tainted = true; * val = repl.ToString(); * * } * else */ { val = match.Sub(repl.ToString(), ptr); } if (beg > offset) { sb.Append(ptr, offset, beg - offset); } sb.Append(val); if (len == 0) { if (ptr.Length > match.End(0)) { sb.Append(ptr, match.End(0), 1); } offset = beg + 1; } else { offset = beg + len; } if (offset > ptr.Length) { break; } beg = pat.Search(ptr, offset, false, IsTainted); } if (ptr.Length > offset) { sb.Append(ptr, offset, ptr.Length - offset); } th.BackRef = match; // rescue from yield. ptr = sb.ToString(); if (tainted) { Taint(); } return(this); }
internal RNDStr(RThread p, NetRuby rb, string s) : base(p, rb, s) { nxt = null; argcnt = 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; }
internal RNNot(RThread p, RNode a) : base(p, a) { }
internal RNBreak(RThread p) : base(p) { }
internal RNDStr(RThread p, NetRuby rb, object o) : base(p, rb, o) { nxt = null; argcnt = 0; }
internal RNOr(RThread p, RNode l, RNode r) : base(p, l, r) { }
internal RNZArray(RThread p) : base(p, null) { }
internal RNLogic(RThread p, RNode l, RNode r) : base(p) { nd1st = l; nd2nd = r; }
static internal object thread_exit(RBasic r, params object[] args) { RThread th = r.ruby.GetCurrentContext(); return(th.exit()); }
internal RNYield(RThread p, RNode a) : base(p) { st = a; }
// A block argument to blocks is allowed in newer versions of Ruby public abstract RBasic Call(RThread thread, RBasic[] args, RCBlock block);