public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { foreach (Statement statement in Statements) { statement.ExpandStatements(warrior, parser, ref currentAddress, coreSize, evaluate); } }
public override Mode GetMode(IWarriorParser parser, int currentAddress) { Mode l = left.GetMode(parser, currentAddress); if (l != Mode.NULL) { return(l); } return(right.GetMode(parser, currentAddress)); }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { if (!evaluate) { return; } if (expression.Evaluate(parser, currentAddress) == 0) { parser.WriteError("Assert failed : " + this + " at : " + Location, Location); } }
public override int Evaluate(IWarriorParser parser, int currentAddress) { switch (operation) { case UnaryOperation.Negate: return(0 - sub.Evaluate(parser, currentAddress)); case UnaryOperation.Brackets: return(sub.Evaluate(parser, currentAddress)); default: throw new InvalidOperationException(); } }
public override Mode GetMode(IWarriorParser parser, int currentAddress) { int l = left.Evaluate(parser, currentAddress); Mode m = middle.GetMode(parser, currentAddress); Mode r = right.GetMode(parser, currentAddress); switch (operation) { case TernaryOperation.If: return((l != 0) ? m : r); default: throw new InvalidOperationException(); } }
public override int Evaluate(IWarriorParser parser, int currentAddress) { if (inEval) { parser.WriteError("Cyclic definition of function : " + name + " at " + Location, Location); return(0); } try { return(EvaluateInternal(parser, currentAddress)); } finally { inEval = false; } }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { //set labels, except last which is EQU expression for (int l = 0; l < Labels.Count; l++) { LabelName label = Labels[l]; if (l == Labels.Count - 1) {//equ parser.Variables[label.GetFullName(parser, currentAddress)] = expression; } else {//labels parser.Variables[label.GetFullName(parser, currentAddress)] = new Address(currentAddress); } } return; }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { //set labels, except last which is FOR expression for (int l = 0; l < Labels.Count - 1; l++) { LabelName label = Labels[l]; parser.Variables[label.GetFullName(parser, currentAddress)] = new Address(currentAddress); } string cnt = Labels[Labels.Count - 1].Name; int count = parser.Variables[LimitName].Evaluate(parser, currentAddress); for (int i = 1; i <= count; i++) { parser.Variables[cnt] = new Value(i); base.ExpandStatements(warrior, parser, ref currentAddress, coreSize, evaluate); } }
public override Mode GetMode(IWarriorParser parser, int currentAddress) { string fullName = GetFullName(parser, currentAddress); if (parser.Variables.ContainsKey(fullName)) { Expression ex = parser.Variables[fullName]; if (ex == this) { parser.WriteError("Label not yet resolved: " + fullName + " at " + Location, Location); return(0); } return(ex.GetMode(parser, currentAddress)); } else { parser.WriteError("Label not defined: " + fullName + " at " + Location, Location); return(0); } }
protected virtual int EvaluateInternal(IWarriorParser parser, int currentAddress) { string fullName = GetFullName(parser, currentAddress); if (parser.Variables.ContainsKey(fullName)) { Expression ex = parser.Variables[fullName]; if (ex == this) { parser.WriteError("Label not yet resolved: " + fullName + " at " + Location, Location); return(0); } return(ex.Evaluate(parser, currentAddress)); } else { parser.WriteError("Label not defined: " + fullName + " at " + Location, Location); return(0); } }
public override int Evaluate(IWarriorParser parser, int currentAddress) { return(value); }
public abstract void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate);
public override int Evaluate(IWarriorParser parser, int currentAddress) { int l = left.Evaluate(parser, currentAddress); int r = right.Evaluate(parser, currentAddress); switch (operation) { case BinaryOperation.Plus: return(l + r); case BinaryOperation.Minus: return(l - r); case BinaryOperation.Multiply: return(l * r); case BinaryOperation.Divide: if (r == 0) { parser.WriteError("Divide by zero during evaluation of " + ToString() + " at " + Location, Location); return(0); } return(l / r); case BinaryOperation.Modulo: if (r == 0) { parser.WriteError("Divide by zero during evaluation of " + ToString() + " at " + Location, Location); return(0); } return(l % r); case BinaryOperation.BinOr: return(l | r); case BinaryOperation.BinXor: return(l ^ r); case BinaryOperation.BinAnd: return(l & r); case BinaryOperation.Shl: return(l << r); case BinaryOperation.Shr: return(l >> r); case BinaryOperation.Or: return(((l != 0) || (r != 0)) ? 1 : 0); case BinaryOperation.And: return(((l != 0) && (r != 0)) ? 1 : 0); case BinaryOperation.CompareGt: return((l > r) ? 1 : 0); case BinaryOperation.CompareGe: return((l >= r) ? 1 : 0); case BinaryOperation.CompareLe: return((l <= r) ? 1 : 0); case BinaryOperation.CompareLt: return((l < r) ? 1 : 0); case BinaryOperation.CompareEq: return((l == r) ? 1 : 0); case BinaryOperation.CompareNe: return((l != r) ? 1 : 0); default: throw new InvalidOperationException(); } }
public virtual string GetFullName(IWarriorParser parser, int currentAddress) { return(name); }
public int Evaluate(IWarriorParser parser, int currentAddress, int coreSize) { int raw = Evaluate(parser, currentAddress); return(Instruction.Wrap(raw, coreSize)); }
public abstract Mode GetMode(IWarriorParser parser, int currentAddress);
public override Mode GetMode(IWarriorParser parser, int currentAddress) { return(Mode.NULL); }
public override int Evaluate(IWarriorParser parser, int currentAddress) { return(Original.Evaluate(parser, currentAddress)); }
public override string GetFullName(IWarriorParser parser, int currentAddress) { return(name + parameter.Evaluate(parser, currentAddress).ToString("00")); }
public override Mode GetMode(IWarriorParser parser, int currentAddress) { return(sub.GetMode(parser, currentAddress)); }
public override void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress, int coreSize, bool evaluate) { //set all labels foreach (LabelName label in Labels) { parser.Variables[label.GetFullName(parser, currentAddress)] = new Address(currentAddress); } ExtendedInstruction instruction; if (!evaluate) { instruction = new ExtendedInstruction(Operation, Modifier, A.Mode, Int32.MinValue, B.Mode, Int32.MinValue); instruction.Address = currentAddress; warrior.Add(instruction); } else { instruction = (ExtendedInstruction)warrior.Instructions[currentAddress]; instruction.ValueA = Instruction.Mod(A.Expression.Evaluate(parser, currentAddress, coreSize), coreSize); instruction.ValueB = Instruction.Mod(B.Expression.Evaluate(parser, currentAddress, coreSize), coreSize); instruction.ExpressionA = A.Expression.ToString(); instruction.ExpressionB = B.Expression.ToString(); if (instruction.ModeA == Mode.NULL) { instruction.ModeA = A.Expression.GetMode(parser, currentAddress); } if (instruction.ModeA == Mode.NULL) { instruction.ModeA = Mode.Direct; } if (instruction.ModeB == Mode.NULL) { instruction.ModeB = B.Expression.GetMode(parser, currentAddress); } if (instruction.ModeB == Mode.NULL) { instruction.ModeB = Mode.Direct; } if (instruction.Modifier == Modifier.NULL) { instruction.Modifier = Instruction.DefaultModifier(instruction.Operation, instruction.ModeA, instruction.ModeB); } if (Comments != null) { instruction.Comment = Comments[Comments.Count - 1]; } else { instruction.Comment = ""; } instruction.OriginalInstruction = OriginalInstruction; if (Labels.Count > 0) { instruction.Label = Labels[Labels.Count - 1].GetFullName(parser, currentAddress); } else { instruction.Label = ""; } } currentAddress++; parser.Variables["CURLINE"] = new Value(currentAddress); }
public abstract int Evaluate(IWarriorParser parser, int currentAddress);