private static void FinishCustomDict(TypeGen tg, Namespace ns)
 {
     DictBuilder db = new DictBuilder(tg, ns);
     db.AddCustomDictMethods();
 }
        private void CreateClosureSlots(Slot staticLink, Namespace nspace)
        {
            foreach (KeyValuePair<SymbolId, Binding> kv in names) {
                if (!kv.Value.IsFree) continue;

                // Find the slot
                Slot instance = staticLink;
                ScopeStatement current = parent;

                for (; ; ) {
                    instance = new CastSlot(instance, current.environmentFactory.EnvironmentType);
                    Debug.Assert(current != null, "cannot resolve closure", kv.Key.GetString());
                    if (current.environment != null) {
                        EnvironmentReference er;

                        // Is the slot in this environment?
                        if (current.TryGetEnvironmentReference(kv.Key, out er)) {
                            nspace.SetSlot(kv.Key, er.CreateSlot(instance));
                            break;
                        }
                    }
                    instance = EnvironmentFactory.MakeParentSlot(instance);
                    current = current.parent;
                }
            }
        }
 public DictBuilder(TypeGen tg, Namespace names)
 {
     this.tg = tg;
     this.names = names;
 }