private void AssignArray(SpoolSpace Memory) { if (this._Parameters.Count < 2) { throw new Exception("Cannot assign an array without an index"); } Cell x = Memory[this._LibName][this._VarName]; if (!x.IsArray) { throw new Exception("Requires an array"); } // Find the array // CellArray z = x.valueARRAY; List <int> Indexes = new List <int>(); for (int i = 0; i < this._Parameters.Count - 1; i++) // the last parameter is the value to assign { Indexes.Add(this._Parameters[i].Evaluate(Memory).valueINT); } for (int i = 0; i < Indexes.Count - 1; i++) // the last parameter is the index we want to use to assign { z = z[Indexes[i]].valueARRAY; } int idx = Indexes.Last(); Cell q = this._Parameters.Last().Evaluate(Memory); switch (this._Affinity) { case AssignmentType.Equals: z[idx] = q; return; case AssignmentType.PlusEquals: z[idx] += q; return; case AssignmentType.MinusEquals: z[idx] -= q; return; case AssignmentType.MultEquals: z[idx] *= q; return; case AssignmentType.DivEquals: z[idx] /= q; return; case AssignmentType.Div2Equals: z[idx] = CellOperations.CheckDivide(z[idx], q); return; case AssignmentType.ModEquals: z[idx] %= q; return; case AssignmentType.Mod2Equals: z[idx] = CellOperations.CheckMod(z[idx], q); return; case AssignmentType.AndEquals: z[idx] &= q; return; case AssignmentType.OrEquals: z[idx] |= q; return; case AssignmentType.XorEquals: z[idx] ^= q; return; case AssignmentType.PlusPlus: z[idx]++; return; case AssignmentType.MinusMinus: z[idx]--; return; } throw new Exception("Operation is invalid"); }
public override Cell Evaluate(SpoolSpace Memory) { return(CellOperations.CheckDivide(this._Children[0].Evaluate(Memory), this._Children[1].Evaluate(Memory))); }
private void AssignVar(SpoolSpace Memory) { Cell x = (this._Parameters.Count == 0 ? CellValues.NullINT : this._Parameters[0].Evaluate(Memory)); switch (this._Affinity) { case AssignmentType.Equals: Memory[this._LibName][this._VarName] = x; break; case AssignmentType.PlusEquals: Memory[this._LibName][this._VarName] += x; break; case AssignmentType.MinusEquals: Memory[this._LibName][this._VarName] -= x; break; case AssignmentType.MultEquals: Memory[this._LibName][this._VarName] *= x; break; case AssignmentType.DivEquals: Memory[this._LibName][this._VarName] /= x; break; case AssignmentType.Div2Equals: Memory[this._LibName][this._VarName] = CellOperations.CheckDivide(Memory[this._LibName][this._VarName], x); break; case AssignmentType.ModEquals: Memory[this._LibName][this._VarName] %= x; break; case AssignmentType.Mod2Equals: Memory[this._LibName][this._VarName] = CellOperations.CheckMod(Memory[this._LibName][this._VarName], x); break; case AssignmentType.AndEquals: Memory[this._LibName][this._VarName] &= x; break; case AssignmentType.OrEquals: Memory[this._LibName][this._VarName] |= x; break; case AssignmentType.XorEquals: Memory[this._LibName][this._VarName] ^= x; break; case AssignmentType.PlusPlus: Memory[this._LibName][this._VarName]++; break; case AssignmentType.MinusMinus: Memory[this._LibName][this._VarName]--; break; default: throw new Exception("Operation is invalid"); } }