public static object Cells(IokeObject context, IokeObject message, object on, bool includeMimics) { var cells = new SaneOrderedDictionary(); Runtime runtime = context.runtime; if (includeMimics) { var visited = IdentityHashTable.Create(); var undefined = new SaneHashSet <string>(); var toVisit = new SaneArrayList(); toVisit.Add(on); while (toVisit.Count > 0) { IokeObject current = IokeObject.As(toVisit[0], context); toVisit.RemoveAt(0); if (!visited.Contains(current)) { visited[current] = null; foreach (IokeObject o in current.GetMimics()) { toVisit.Add(o); } Cell c = current.body.firstAdded; while (c != null) { string s = c.name; if (!undefined.Contains(s)) { object val = c.value; if (val == runtime.nul) { undefined.Add(s); } else { object x = runtime.GetSymbol(s); if (!cells.Contains(x)) { cells[x] = val; } } } c = c.orderedNext; } } } } else { Cell c = IokeObject.As(on, context).body.firstAdded; while (c != null) { string s = c.name; if (c.value != runtime.nul) { cells[runtime.GetSymbol(s)] = c.value; } c = c.orderedNext; } } return(runtime.NewDict(cells)); }
public static object CellNames(IokeObject context, IokeObject message, object on, bool includeMimics, object cutoff) { if (includeMimics) { var visited = IdentityHashTable.Create(); var names = new SaneArrayList(); var visitedNames = new SaneHashSet <object>(); var undefined = new SaneHashSet <string>(); Runtime runtime = context.runtime; var toVisit = new SaneArrayList(); toVisit.Add(on); while (toVisit.Count > 0) { IokeObject current = IokeObject.As(toVisit[0], context); toVisit.RemoveAt(0); if (!visited.Contains(current)) { visited[current] = null; if (cutoff != current) { foreach (IokeObject o in current.GetMimics()) { toVisit.Add(o); } } Cell c = current.body.firstAdded; while (c != null) { string s = c.name; if (!undefined.Contains(s)) { if (c.value == runtime.nul) { undefined.Add(s); } else { object x = runtime.GetSymbol(s); if (!visitedNames.Contains(x)) { visitedNames.Add(x); names.Add(x); } } } c = c.orderedNext; } } } return(runtime.NewList(names)); } else { var names = new SaneArrayList(); Runtime runtime = context.runtime; Cell c = IokeObject.As(on, context).body.firstAdded; while (c != null) { string s = c.name; if (c.value != runtime.nul) { names.Add(runtime.GetSymbol(s)); } c = c.orderedNext; } return(runtime.NewList(names)); } }