public static void EstablishSlot(P6any n, P6how.AttrInfo ai, Variable vx) { Variable obj; if ((ai.flags & P6how.A_TYPE) == P6how.A_SCALAR) { if (ai.type == null) obj = Kernel.NewMuScalar( vx != null ? vx.Fetch() : n.mo.setting.AnyMO.typeObj); else obj = Kernel.NewRWScalar(ai.type, vx != null ? vx.Fetch() : ai.type.initObj); } else { obj = (ai.flags & P6how.A_HASH) != 0 ? n.mo.setting.CreateHash() : n.mo.setting.CreateArray(); if (vx != null) { // https://github.com/sorear/niecza/issues/104 if (!vx.List) vx = Kernel.NewRWListVar(vx.Fetch()); Kernel.Assign(obj, vx); } } n.SetSlot(ai.owner, ai.name, obj); }
public void UnpackCaps(P6any into) { List<VarDeque> posr = new List<VarDeque>(); Dictionary<string,VarDeque> namr = new Dictionary<string,VarDeque>(); CapInfo it = captures; for (; it != null; it = it.prev) { if (it.names[0] == null) continue; // special node foreach (string name in it.names) { int nami; VarDeque t; if (int.TryParse(name, out nami) && nami >= 0) { while(posr.Count <= nami) posr.Add(new VarDeque()); t = posr[nami]; } else { if (!namr.TryGetValue(name, out t)) namr[name] = t = new VarDeque(); } t.Unshift(it.cap); } } VarHash nam = new VarHash(); Variable[] pos = new Variable[posr.Count]; foreach (KeyValuePair<string, VarDeque> kv in namr) nam[kv.Key] = FixupList(kv.Value); for (int i = 0; i < pos.Length; i++) pos[i] = FixupList(posr[i]); into.SetSlot(Kernel.CaptureMO, "$!positionals", pos); into.SetSlot(Kernel.CaptureMO, "$!named", nam); }
public static void EstablishSlot(P6any n, P6how.AttrInfo ai, Variable vx) { Variable obj; if ((ai.flags & P6how.A_TYPE) == P6how.A_SCALAR) { if (ai.type == null) obj = Kernel.NewMuScalar( vx != null ? vx.Fetch() : Kernel.AnyMO.typeObject); else obj = Kernel.NewRWScalar(ai.type, vx != null ? vx.Fetch() : ai.type.initObject); } else { obj = (ai.flags & P6how.A_HASH) != 0 ? Kernel.CreateHash() : Kernel.CreateArray(); if (vx != null) Kernel.Assign(obj, vx); } n.SetSlot(ai.owner, ai.name, obj); }