예제 #1
0
        public override HeronValue InvokeBinaryOperator(VM vm, OpCode opcode, HeronValue val)
        {
            int x = GetValue();
            int y = val.ToInt();

            switch (opcode)
            {
            case OpCode.opAdd: return(vm.MakeTemporary(x + y));

            case OpCode.opSub: return(vm.MakeTemporary(x - y));

            case OpCode.opMul: return(vm.MakeTemporary(x * y));

            case OpCode.opDiv: return(vm.MakeTemporary(x / y));

            case OpCode.opMod: return(vm.MakeTemporary(x % y));

            case OpCode.opShr: return(vm.MakeTemporary(x >> y));

            case OpCode.opShl: return(vm.MakeTemporary(x << y));

            case OpCode.opGtEq: return(vm.MakeTemporary(x >= y));

            case OpCode.opLtEq: return(vm.MakeTemporary(x <= y));

            case OpCode.opGt: return(vm.MakeTemporary(x > y));

            case OpCode.opLt: return(vm.MakeTemporary(x < y));

            case OpCode.opRange: return(new RangeEnumerator(this as IntValue, val as IntValue));

            default: return(base.InvokeBinaryOperator(vm, opcode, val));
            }
        }