コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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));
        }
コード例 #3
0
 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);
     }
 }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
 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;
     }
 }
コード例 #7
0
 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;
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
0
 public override int Evaluate(IWarriorParser parser, int currentAddress)
 {
     return(value);
 }
コード例 #12
0
 public abstract void ExpandStatements(ExtendedWarrior warrior, IWarriorParser parser, ref int currentAddress,
                                       int coreSize, bool evaluate);
コード例 #13
0
        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();
            }
        }
コード例 #14
0
 public virtual string GetFullName(IWarriorParser parser, int currentAddress)
 {
     return(name);
 }
コード例 #15
0
        public int Evaluate(IWarriorParser parser, int currentAddress, int coreSize)
        {
            int raw = Evaluate(parser, currentAddress);

            return(Instruction.Wrap(raw, coreSize));
        }
コード例 #16
0
 public abstract Mode GetMode(IWarriorParser parser, int currentAddress);
コード例 #17
0
 public override Mode GetMode(IWarriorParser parser, int currentAddress)
 {
     return(Mode.NULL);
 }
コード例 #18
0
 public override int Evaluate(IWarriorParser parser, int currentAddress)
 {
     return(Original.Evaluate(parser, currentAddress));
 }
コード例 #19
0
 public override string GetFullName(IWarriorParser parser, int currentAddress)
 {
     return(name + parameter.Evaluate(parser, currentAddress).ToString("00"));
 }
コード例 #20
0
 public override Mode GetMode(IWarriorParser parser, int currentAddress)
 {
     return(sub.GetMode(parser, currentAddress));
 }
コード例 #21
0
        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);
        }
コード例 #22
0
 public abstract int Evaluate(IWarriorParser parser, int currentAddress);