/// <inheritdoc /> public GraceObject FindReceiver(MethodRequest req, int skipRedirects) { ScopeLink sl = scope; GraceObject capture = null; while (sl != null && sl.scope != null) { if (skipRedirects > 0 && sl.scope.HasFlag(GraceObject.Flags.ObjectConstructor)) { sl = sl.next; skipRedirects--; continue; } if (sl.scope.RespondsTo(req)) { return(capture ?? sl.scope); } capture = null; var ls = sl.scope as LocalScope; if (ls != null) { if (ls.RedirectSurrounding != null) { capture = ls.RedirectSurrounding; } } sl = sl.next; } return(null); }
/// <param name="next">Next element in the list, or null</param> /// <param name="scope">Grace object to be used as a scope</param> /// <param name="minor">True if this link represents a "minor" /// scope that is used for internal names</param> public ScopeLink(ScopeLink next, GraceObject scope, bool minor) { this.next = next; this.scope = scope; this.minor = minor; }
/// <inheritdoc /> public void RestoreExactly(ScopeMemo sm) { scope = sm.Link; while (dynamics.Count > sm.dynamicsSize) { dynamics.Pop(); } restoreMajor(); }
/// <summary>Set the majorScope field to the closest non-minor /// scope</summary> private void restoreMajor() { ScopeLink s = scope; while (s.minor) { s = s.next; } majorScope = s.scope; }
/// <inheritdoc /> /// <seealso cref="ActivateDebuggingMessages" /> public void DebugScopes() { ScopeLink s = scope; while (s != null && s.scope != null) { Debug("Scope " + s.scope); foreach (string k in s.scope.MethodNames()) { Debug(" " + k); } s = s.next; } }
/// <inheritdoc /> public MethodScope FindNearestMethod() { ScopeLink sl = scope; while (sl != null && sl.scope != null) { var ms = sl.scope as MethodScope; if (ms != null) { return(ms); } sl = sl.next; } return(null); }
/// <inheritdoc /> public void InsertOuter(GraceObject obj) { var s = scope; while (s != null) { if (s.scope.HasFlag(GraceObject.Flags.ObjectConstructor)) { break; } s = s.next; } var newScope = new ScopeLink(s.next, obj); s.next = newScope; }
/// <inheritdoc /> public string ScopeStringList() { string ret = null; ScopeLink s = scope; while (s != null && s.scope != null) { if (ret != null) { ret += ", " + s.scope; } else { ret = "" + s.scope; } s = s.next; } return(ret); }
/// <inheritdoc /> public void Forget(ScopeMemo sm) { scope = dynamics.Pop(); restoreMajor(); }
/// <inheritdoc /> public void Remember(ScopeMemo sm) { dynamics.Push(scope); scope = sm.Link; restoreMajor(); }
/// <inheritdoc /> public void Unextend(GraceObject o) { scope = scope.next; restoreMajor(); }
/// <inheritdoc /> public void ExtendMinor(GraceObject o) { scope = new ScopeLink(scope, o, true); }
/// <inheritdoc /> public void Extend(GraceObject o) { scope = new ScopeLink(scope, o); majorScope = scope.scope; }
/// <param name="link">Top of the static scope stack</param> /// <param name="dynamics">Size of the dynamic stack</param> internal ScopeMemo(ScopeLink link, int dynamics) { this.link = link; this.dynamicsSize = dynamics; }
/// <param name="next">Next element in the list, or null</param> /// <param name="scope">Grace object to be used as a scope</param> public ScopeLink(ScopeLink next, GraceObject scope) { this.next = next; this.scope = scope; }