public override void Compile(CompilationEnvironment compilationEnvironment, Generator generator)
        {
            _e1.Compile(compilationEnvironment, generator);
            compilationEnvironment.PushTemporary();
            _e2.Compile(compilationEnvironment, generator);

            switch (_op)
            {
                case Operator.Add:
                    generator.Emit(Instruction.Add);
                    break;
                case Operator.Div:
                    generator.Emit(Instruction.Div);
                    break;
                case Operator.Mul:
                    generator.Emit(Instruction.Mul);
                    break;
                case Operator.Sub:
                    generator.Emit(Instruction.Sub);
                    break;
                case Operator.Eq:
                    generator.Emit(Instruction.Eq);
                    break;
                case Operator.Ne:
                    generator.Emit(Instruction.Eq);
                    generator.Emit(Instruction.Not);
                    break;
                case Operator.Ge:
                    generator.Emit(Instruction.LT);
                    generator.Emit(Instruction.Not);
                    break;
                case Operator.Gt:
                    generator.Emit(Instruction.Swap);
                    generator.Emit(Instruction.LT);
                    break;
                case Operator.Le:
                    generator.Emit(Instruction.Swap);
                    generator.Emit(Instruction.LT);
                    generator.Emit(Instruction.Not);
                    break;
                case Operator.Lt:
                    generator.Emit(Instruction.LT);
                    break;
                case Operator.And:
                    generator.Emit(Instruction.Mul);
                    break;
                case Operator.Or:
                    generator.Emit(Instruction.Add);
                    generator.Emit(new CstI(0));
                    generator.Emit(Instruction.Eq);
                    generator.Emit(Instruction.Not);
                    break;
                default:
                    throw new InvalidOperationException(string.Format("Unknown binary operator: {0}", _op));
            }
            compilationEnvironment.PopTemporary();
        }
Exemple #2
0
        public override void Compile(CompilationEnvironment env, Generator gen)
        {
            foreach (Expression arg in _args)
            {
                arg.Compile(env, gen);
                env.PushTemporary();
            }

            String fLabel = env.GetFunctionLabel(fName);

            gen.Emit(new Call(_args.Count, fLabel));

            foreach (var arg in _args)
            {
                env.PopTemporary();
            }

            /*
             * arg.Compile(env, gen);
             * String fLabel = env.getFunctionLabel(fName);
             * gen.Emit(new CALL(1, fLabel));
             */
        }
        public override void Compile(CompilationEnvironment compilationEnvironment, Generator generator)
        {
            _e1.Compile(compilationEnvironment, generator);
            compilationEnvironment.PushTemporary();
            _e2.Compile(compilationEnvironment, generator);

            switch (_op)
            {
            case Operator.Mod:
                generator.Emit(Instruction.Mod);
                break;

            case Operator.Add:
                generator.Emit(Instruction.Add);
                break;

            case Operator.Div:
                generator.Emit(Instruction.Div);
                break;

            case Operator.Mul:
                generator.Emit(Instruction.Mul);
                break;

            case Operator.Sub:
                generator.Emit(Instruction.Sub);
                break;

            case Operator.Eq:
                generator.Emit(Instruction.Eq);
                break;

            case Operator.Ne:
                generator.Emit(Instruction.Eq);
                generator.Emit(Instruction.Not);
                break;

            case Operator.Ge:
                generator.Emit(Instruction.LT);
                generator.Emit(Instruction.Not);
                break;

            case Operator.Gt:
                generator.Emit(Instruction.Swap);
                generator.Emit(Instruction.LT);
                break;

            case Operator.Le:
                generator.Emit(Instruction.Swap);
                generator.Emit(Instruction.LT);
                generator.Emit(Instruction.Not);
                break;

            case Operator.Lt:
                generator.Emit(Instruction.LT);
                break;

            case Operator.And:
                generator.Emit(Instruction.Mul);
                break;

            case Operator.Or:
                generator.Emit(Instruction.Add);
                generator.Emit(new CstI(0));
                generator.Emit(Instruction.Eq);
                generator.Emit(Instruction.Not);
                break;

            default:
                throw new InvalidOperationException(string.Format("Unknown binary operator: {0}", _op));
            }
            compilationEnvironment.PopTemporary();
        }