示例#1
0
        // public BinaryOperator Operator;
        // public Expression Expression1;
        // public Expression Expression2;

        public override void Compile(GeneratorState state, Trac42Program program)
        {
            Expression1.Compile(state, program);
            Expression2.Compile(state, program);

            switch (Operator)
            {
            case BinaryOperator.Add:
                program.Emit(new Instruction(Instruction.OPCODE.ADD));
                break;

            case BinaryOperator.Sub:
                program.Emit(new Instruction(Instruction.OPCODE.SUB));
                break;

            case BinaryOperator.Eq:
                switch (OperandType)
                {
                case Type.BoolType:
                    program.Emit(new Instruction(Instruction.OPCODE.EQBOOL));
                    break;

                case Type.NumType:
                    program.Emit(new Instruction(Instruction.OPCODE.EQINT));
                    break;
                }
                break;

            case BinaryOperator.Lt:
                program.Emit(new Instruction(Instruction.OPCODE.LTINT));
                break;
            }
        }
示例#2
0
        // public Expression Expression1;
        // public Expression Expression2;

        public override void Compile(GeneratorState state, Trac42Program program)
        {
            Expression1.Compile(state, program);
            program.Emit(new Instruction(Instruction.OPCODE.POP, 1));
            Expression2.Compile(state, program);
        }