예제 #1
0
        public int Load(IInstructionOperand operand)
        {
            if (operand is ConstantOperand <double> )
            {
                Emit(new Instruction(InstructionType.LdNum, operand));
                return(1);
            }

            if (operand is ConstantOperand <string> )
            {
                Emit(new Instruction(InstructionType.LdStr, operand));
                return(1);
            }

            if (operand is IdentifierOperand identifier)
            {
                if (identifier.FrameIndex == LocalIndex)
                {
                    Emit(new Instruction(InstructionType.LdLocF, new ImmediateOperand(identifier.Id)));
                }
                else if (identifier.FrameIndex < 0 && identifier.FrameIndex == -ArgIndex)
                {
                    Emit(new Instruction(InstructionType.LdArgF, new ImmediateOperand(identifier.Id)));
                }
                else
                {
                    Emit(new Instruction(InstructionType.LdLoc, operand));
                }

                return(1);
            }

            throw new NotSupportedException();
        }
예제 #2
0
        public int Load(IInstructionOperand operand)
        {
            if (operand is ConstantOperand <double> )
            {
                Emit(new Instruction(InstructionType.LdNum, operand));
                return(1);
            }

            if (operand is ConstantOperand <string> )
            {
                Emit(new Instruction(InstructionType.LdStr, operand));
                return(1);
            }

            if (operand is IdentifierOperand)
            {
                Emit(new Instruction(InstructionType.LdLoc, operand));
                return(1);
            }

            throw new NotSupportedException();
        }
예제 #3
0
        public void Load(IInstructionOperand operand)
        {
            InstructionType type;
            if (operand is ConstantOperand<double>)
                type = InstructionType.LdNum;
            else if (operand is ConstantOperand<string>)
                type = InstructionType.LdStr;
            else if (operand is IdentifierOperand)
                type = InstructionType.LdLoc;
            else
                throw new NotSupportedException();

            Emit(new Instruction(type, operand));
        }