public override ExpressionCode GenerateCode()
        {
            var leftType  = LeftOperand.GenerateCode().Type;
            var rightType = RightOperand.GenerateCode().Type;

            if (leftType != null && rightType != null)
            {
                if (leftType == "float" || rightType == "float")
                {
                    var s = " ( getFloatSubValue( " + LeftOperand.GenerateCode().Code + " , " +
                            RightOperand.GenerateCode().Code + " ) )";

                    return(new ExpressionCode {
                        Code = s, Type = "float"
                    });
                }
                else if (leftType == "string" || rightType == "string")
                {
                    return(new ExpressionCode {
                        Code = "( " + LeftOperand.GenerateCode().Code + " + " + RightOperand.GenerateCode().Code + " )", Type = "string"
                    });
                }

                var stringCode = "( getIntSubValue( " + LeftOperand.GenerateCode().Code + " , " +
                                 RightOperand.GenerateCode().Code + " ) )";
                return(new ExpressionCode {
                    Code = stringCode, Type = "int"
                });
            }
            throw new GenerationException("Cannot generate code from null type operand");
        }
Exemplo n.º 2
0
        public override void GenerateCode(ILCodeGenerator cg)
        {
            Label trueLabel  = cg.ILGenerator.DefineLabel();
            Label falseLabel = cg.ILGenerator.DefineLabel();

            ///evalúo el operando izquierdo
            LeftOperand.GenerateCode(cg);

            ///si fue true salto para el final de la operación
            cg.ILGenerator.Emit(OpCodes.Brtrue, trueLabel);

            ///evalúo el operando derecho
            RightOperand.GenerateCode(cg);

            ///si fue true salto para el final de la operación
            cg.ILGenerator.Emit(OpCodes.Brtrue, trueLabel);

            ///el resultado del | fue false
            cg.ILGenerator.Emit(OpCodes.Ldc_I4_0);

            ///salto para el false
            cg.ILGenerator.Emit(OpCodes.Br, falseLabel);

            ///marcamos el fin de la operación
            cg.ILGenerator.MarkLabel(trueLabel);

            ///pongo true en la pila
            cg.ILGenerator.Emit(OpCodes.Ldc_I4_1);

            ///marcamos el false
            cg.ILGenerator.MarkLabel(falseLabel);
        }
Exemplo n.º 3
0
        public override void GenerateCode(ILGenerator gen, CodeFlow cf)
        {
            LeftOperand.GenerateCode(gen, cf);
            var leftDesc = LeftOperand.ExitDescriptor;
            var exitDesc = _exitTypeDescriptor;

            if (exitDesc == null)
            {
                throw new InvalidOperationException("No exit type descriptor");
            }

            CodeFlow.InsertNumericUnboxOrPrimitiveTypeCoercion(gen, leftDesc, exitDesc);
            if (_children.Length > 1)
            {
                cf.EnterCompilationScope();
                RightOperand.GenerateCode(gen, cf);
                var rightDesc = RightOperand.ExitDescriptor;
                cf.ExitCompilationScope();
                CodeFlow.InsertNumericUnboxOrPrimitiveTypeCoercion(gen, rightDesc, exitDesc);
                gen.Emit(OpCodes.Sub);
            }
            else
            {
                gen.Emit(OpCodes.Neg);
            }

            cf.PushDescriptor(_exitTypeDescriptor);
        }
Exemplo n.º 4
0
        public override void GenerateCode(ILGenerator gen, CodeFlow cf)
        {
            // pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; }
            var elseTarget  = gen.DefineLabel();
            var endIfTarget = gen.DefineLabel();
            var result      = gen.DeclareLocal(typeof(bool));

            cf.EnterCompilationScope();
            LeftOperand.GenerateCode(gen, cf);
            cf.UnboxBooleanIfNecessary(gen);
            cf.ExitCompilationScope();
            gen.Emit(OpCodes.Brfalse, elseTarget);
            gen.Emit(OpCodes.Ldc_I4_1);
            gen.Emit(OpCodes.Stloc, result);
            gen.Emit(OpCodes.Br, endIfTarget);
            gen.MarkLabel(elseTarget);
            cf.EnterCompilationScope();
            RightOperand.GenerateCode(gen, cf);
            cf.UnboxBooleanIfNecessary(gen);
            cf.ExitCompilationScope();
            gen.Emit(OpCodes.Stloc, result);
            gen.MarkLabel(endIfTarget);
            gen.Emit(OpCodes.Ldloc, result);
            cf.PushDescriptor(_exitTypeDescriptor);
        }
Exemplo n.º 5
0
        public override void GenerateCode(ILGenerator gen, CodeFlow cf)
        {
            CodeFlow.LoadEvaluationContext(gen);
            var leftDesc  = LeftOperand.ExitDescriptor;
            var rightDesc = RightOperand.ExitDescriptor;
            var leftPrim  = CodeFlow.IsValueType(leftDesc);
            var rightPrim = CodeFlow.IsValueType(rightDesc);

            cf.EnterCompilationScope();
            LeftOperand.GenerateCode(gen, cf);
            cf.ExitCompilationScope();
            if (leftPrim)
            {
                CodeFlow.InsertBoxIfNecessary(gen, leftDesc);
            }

            cf.EnterCompilationScope();
            RightOperand.GenerateCode(gen, cf);
            cf.ExitCompilationScope();
            if (rightPrim)
            {
                CodeFlow.InsertBoxIfNecessary(gen, rightDesc);
            }

            gen.Emit(OpCodes.Call, _equalityCheck);
            cf.PushDescriptor(TypeDescriptor.Z);
        }
Exemplo n.º 6
0
 public override ExpressionCode GenerateCode()
 {
     return(new ExpressionCode
     {
         Code = "( typeof " + LeftOperand.GenerateCode().Code + " === \'" + RightOperand.GenerateCode().Code + "\' )",
         Type = "bool"
     });
 }
 public override ExpressionCode GenerateCode()
 {
     return(new ExpressionCode
     {
         Code = "( " + LeftOperand.GenerateCode().Code + " < " + RightOperand.GenerateCode().Code + " )",
         Type = "bool"
     });
 }
        public override void GenerateCode(ILCodeGenerator cg)
        {
            ///gen code al LeftOperand
            LeftOperand.GenerateCode(cg);

            ///gen code al RightOperand
            RightOperand.GenerateCode(cg);
        }
Exemplo n.º 9
0
        public override string GenerateCode()
        {
            var leftType  = LeftOperand.ValidateSemantic();
            var rightType = RightOperand.ValidateSemantic();

            if (leftType is StringType && rightType is StringType)
            {
                return($"!({LeftOperand.GenerateCode()}.equals({RightOperand.GenerateCode()}))");
            }

            return($"{LeftOperand.GenerateCode()} != {RightOperand.GenerateCode()}");
        }
        public override ExpressionCode GenerateCode()
        {
            var leftType  = LeftOperand.EvaluateSemantic();
            var rightType = RightOperand.EvaluateSemantic();

            if (leftType != null && rightType != null)
            {
                var stringCode = "( getIntLeftShiftValue( " + LeftOperand.GenerateCode().Code + " , " +
                                 RightOperand.GenerateCode().Code + " ) )";
                return(new ExpressionCode {
                    Code = stringCode, Type = "int"
                });
            }
            throw new GenerationException("Cannot generate code from null type operand");
        }
Exemplo n.º 11
0
        public override void GenerateCode(ILGenerator gen, CodeFlow cf)
        {
            LeftOperand.GenerateCode(gen, cf);
            CodeFlow.InsertBoxIfNecessary(gen, cf.LastDescriptor());
            if (_type == null)
            {
                throw new InvalidOperationException("No type available");
            }

            var convert = gen.DeclareLocal(typeof(bool));

            gen.Emit(OpCodes.Isinst, _type);
            gen.Emit(OpCodes.Ldnull);
            gen.Emit(OpCodes.Cgt_Un);
            gen.Emit(OpCodes.Stloc, convert);
            gen.Emit(OpCodes.Ldloc, convert);

            cf.PushDescriptor(_exitTypeDescriptor);
        }
Exemplo n.º 12
0
        public override string GenerateCode()
        {
            var leftType  = LeftOperand.ValidateSemantic();
            var rightType = RightOperand.ValidateSemantic();

            if (leftType is IntType && rightType is StringType)
            {
                var count = (NumberNode)LeftOperand;
                var str   = (StringNode)RightOperand;
                return($"MultiplyString({count.Value},{str.Value})");
            }
            else if (leftType is StringType && rightType is IntType)
            {
                var str   = (StringNode)LeftOperand;
                var count = (NumberNode)RightOperand;
                return($"MultiplyString({count.Value},{str.Value})");
            }

            return($"({LeftOperand.GenerateCode()} * {RightOperand.GenerateCode()})");
        }
Exemplo n.º 13
0
        public override void GenerateCode(CodeGeneration.CodeGenerator cg)
        {
            Label rettrue = cg.IlGenerator.DefineLabel();
            Label end     = cg.IlGenerator.DefineLabel();

            LeftOperand.GenerateCode(cg);
            //if eval its 1 then ret 1
            cg.IlGenerator.Emit(OpCodes.Brtrue, rettrue);
            RightOperand.GenerateCode(cg);
            //if eval its 1 then ret 1
            cg.IlGenerator.Emit(OpCodes.Brtrue, rettrue);
            //ret 0 and jump to end
            cg.IlGenerator.Emit(OpCodes.Ldc_I4_0);
            cg.IlGenerator.Emit(OpCodes.Br, end);

            //ret 0
            cg.IlGenerator.MarkLabel(rettrue);
            cg.IlGenerator.Emit(OpCodes.Ldc_I4_1);

            cg.IlGenerator.MarkLabel(end);
        }
Exemplo n.º 14
0
        public override void GenerateCode(ILGenerator gen, CodeFlow cf)
        {
            CodeFlow.LoadEvaluationContext(gen);
            var leftDesc  = LeftOperand.ExitDescriptor;
            var rightDesc = RightOperand.ExitDescriptor;
            var leftPrim  = CodeFlow.IsValueType(leftDesc);
            var rightPrim = CodeFlow.IsValueType(rightDesc);

            cf.EnterCompilationScope();
            LeftOperand.GenerateCode(gen, cf);
            cf.ExitCompilationScope();
            if (leftPrim)
            {
                CodeFlow.InsertBoxIfNecessary(gen, leftDesc);
            }

            cf.EnterCompilationScope();
            RightOperand.GenerateCode(gen, cf);
            cf.ExitCompilationScope();
            if (rightPrim)
            {
                CodeFlow.InsertBoxIfNecessary(gen, rightDesc);
            }

            // returns bool
            gen.Emit(OpCodes.Call, _equalityCheck);

            // Invert the boolean
            var result = gen.DeclareLocal(typeof(bool));

            gen.Emit(OpCodes.Ldc_I4_0);
            gen.Emit(OpCodes.Ceq);
            gen.Emit(OpCodes.Stloc, result);
            gen.Emit(OpCodes.Ldloc, result);

            cf.PushDescriptor(TypeDescriptor.Z);
        }
Exemplo n.º 15
0
        public override ExpressionCode GenerateCode()
        {
            var leftType  = LeftOperand.GenerateCode().Type;
            var rightType = RightOperand.GenerateCode().Type;

            if (leftType != null && rightType != null)
            {
                if (leftType == "bool" && rightType == "bool")
                {
                    var s = " ( getBoolBitXorValue( " + LeftOperand.GenerateCode().Code + " , " +
                            RightOperand.GenerateCode().Code + " ) )";

                    return(new ExpressionCode {
                        Code = s, Type = "bool"
                    });
                }
                var stringCode = "( getIntBitXorValue( " + LeftOperand.GenerateCode().Code + " , " +
                                 RightOperand.GenerateCode().Code + " ) )";
                return(new ExpressionCode {
                    Code = stringCode, Type = "int"
                });
            }
            throw new GenerationException("Cannot generate code from null type operand");
        }
 public override ExpressionCode GenerateCode()
 {
     return(new ExpressionCode {
         Code = "(" + LeftOperand.GenerateCode().Code + ")", Type = LeftOperand.GenerateCode().Type
     });
 }
Exemplo n.º 17
0
 public override string GenerateCode()
 {
     return($"{LeftOperand.GenerateCode()} > {RightOperand.GenerateCode()}");
 }
Exemplo n.º 18
0
 public override string GenerateCode()
 {
     return($"({LeftOperand.GenerateCode()} / {RightOperand.GenerateCode()})");
 }