public static void AssignV(Variable lhs, IP6 rhs) { if (!lhs.islist) { lhs.Store(rhs); } else { Frame n = lhs.Fetch().InvokeMethod(Kernel.GetInferiorRoot(), "LISTSTORE", new Variable[2] { lhs, Kernel.NewROScalar(rhs) }, null); Kernel.RunInferior(n); } }
// Assign a value to a variable, while handling list variables sensibly public static void AssignV(Variable lhs, P6any rhs) { if (!lhs.islist) { lhs.Store(rhs); } else { lhs.Fetch().mo.mro_LISTSTORE.Get(lhs, Kernel.NewROScalar(rhs)); } }
public static Variable mixin(Constants c, P6any obj, Variable role_list, Variable init, Variable newtype) { VarDeque iter = start_iter(role_list); List<STable> roles = new List<STable>(); while (Kernel.IterHasFlat(iter, true)) roles.Add(iter.Shift().Fetch().mo); STable n = new STable(c.setting, obj.mo.name + "+" + Kernel.JoinS(",", roles)); n.how = Kernel.BoxAny<STable>(n, obj.mo.how).Fetch(); n.typeObj = n.initObj = new P6opaque(n); ((P6opaque)n.typeObj).slots = null; n.mo.superclasses.Add(obj.mo); n.mo.local_roles = roles; n.mo.Compose(); newtype.Store(n.typeObj); string aname = null; if (init != c.setting.AnyP) { if (!obj.IsDefined()) throw new NieczaException("Cannot initialize a slot when mixing into a type object"); if (n.mo.local_attr.Count != 1 || (n.mo.local_attr[0].flags & P6how.A_PUBLIC) == 0) throw new NieczaException("Role(s) being mixed in do not define precisely one, public attribute"); aname = n.mo.local_attr[0].name; } if (obj.IsDefined()) { obj.ChangeType(n); BuildMostDerived(obj); if (aname != null) Kernel.Assign((Variable)obj.GetSlot(n, aname), init); return obj; } else { return n.typeObj; } }