public virtual void Visit(AssignList s) { Expression[] targets = new Expression[s.Targets.Count]; for (int i = 0; i < s.Targets.Count; ++i) { targets[i] = Transform(s.Targets[i]); } Expression[] values = new Expression[s.Values.Count]; for (int i = 0; i < s.Values.Count; ++i) { values[i] = Transform(s.Values[i]); } Expression valueList = s.ValueList != null?Transform(s.ValueList) : null; result = new AssignList(s.SourceSpan, Array.AsReadOnly(targets), Array.AsReadOnly(values), valueList); }
public void Visit(AssignList s) { Indent(); bool bFirst = true; foreach (Expression target in s.Targets) { if (!bFirst) { o.Write(", "); } bFirst = false; target.Accept(this); } o.Write(" = "); bFirst = true; foreach (Expression value in s.Values) { if (!bFirst) { o.Write(", "); } bFirst = false; value.Accept(this); } if (s.ValueList != null) { if (!bFirst) { o.Write(", "); } o.Write("values "); s.ValueList.Accept(this); } o.WriteLine(); }
public void Visit(AssignList s) { // Evaluate subexpressions for index targets. Allocation allocTargets = function.Top(); Expression[] targets = new Expression[s.Targets.Count]; for (int target = 0; target < s.Targets.Count; ++target) { Expression e = s.Targets[target]; Index index = e as Index; if (index != null) { Allocation table = R(index.Table); Allocation key = RK(index.Key); targets[target] = new IndexRef(index.SourceSpan, table, key); key.Release(); table.Release(); allocTargets.Allocate(2); } else { targets[target] = e; } } // Evaluate all values. Allocation allocValues = function.Top(); for (int value = 0; value < s.Values.Count; ++value) { Allocation allocValue = Push(s.Values[value]); allocValue.Release(); allocValues.Allocate(); } if (s.ValueList != null) { if (s.Targets.Count <= s.Values.Count) { throw new ArgumentException(); } Allocation allocValueList = PushList(s.ValueList, s.Targets.Count - s.Values.Count); allocValueList.Release(); allocValues.Allocate(s.Targets.Count - s.Values.Count); } // Assign each value. for (int target = 0; target < targets.Length; ++target) { if (targets[target] is GlobalRef) { GlobalRef global = (GlobalRef)targets[target]; function.InstructionABx(s.SourceSpan, Opcode.SetGlobal, allocValues + target, function.Constant(global.Name)); } else if (targets[target] is IndexRef) { IndexRef index = (IndexRef)targets[target]; function.InstructionABC(s.SourceSpan, Opcode.SetTable, index.Table, index.Key, allocValues + target); } else if (targets[target] is LocalRef) { LocalRef local = (LocalRef)targets[target]; function.InstructionABC(s.SourceSpan, Opcode.Move, function.Local(local.Variable), allocValues + target, 0); } else if (targets[target] is UpValRef) { UpValRef upval = (UpValRef)targets[target]; function.InstructionABC(s.SourceSpan, Opcode.SetUpVal, allocValues + target, function.UpVal(upval.Variable), 0); } else { throw new InvalidOperationException(); } } // Release. allocValues.Release(); allocTargets.Release(); }