public Instruction GiveConcreteInstruction(Opcode instruction) { Instruction concreteInstruction = null; int opCode = instruction.GetOpCode(); switch (opCode) { case (int)Opcodes.Addition: concreteInstruction = new AdditionInstruction(instruction.GetFirstParameterMode(), instruction.GetSecondParameterMode()); break; case (int)Opcodes.Multiplication: concreteInstruction = new MultiplyInstruction(instruction.GetFirstParameterMode(), instruction.GetSecondParameterMode()); break; case (int)Opcodes.Input: concreteInstruction = new InputInstruction(program.Inputs[program.CurrentInputPointer++], instruction.GetFirstParameterMode()); break; case (int)Opcodes.Output: concreteInstruction = new OutputInstruction(instruction.GetFirstParameterMode()); break; case (int)Opcodes.JumpIfTrue: concreteInstruction = new JumpIfTrueInstruction(instruction.GetFirstParameterMode(), instruction.GetSecondParameterMode()); break; case (int)Opcodes.JumpIfFalse: concreteInstruction = new JumpIfFalseInstruction(instruction.GetFirstParameterMode(), instruction.GetSecondParameterMode()); break; case (int)Opcodes.LessThan: concreteInstruction = new LessThanInstruction(instruction.GetFirstParameterMode(), instruction.GetSecondParameterMode(), instruction.GetThirdParameterMode()); break; case (int)Opcodes.Equals: concreteInstruction = new EqualsInstruction(instruction.GetFirstParameterMode(), instruction.GetSecondParameterMode(), instruction.GetThirdParameterMode()); break; } return(concreteInstruction); }
protected override void SetMyBlockInternalArg() { switch (op) { case OPERATION.ADD: myBlockInternalArg = new AdditionInstruction(this); break; case OPERATION.DIV: myBlockInternalArg = new DivisionInstruction(this); break; case OPERATION.MUL: myBlockInternalArg = new MultiplicationInstruction(this); break; case OPERATION.SUB: myBlockInternalArg = new SubtractionInstruction(this); break; } }