Ejemplo n.º 1
0
        protected internal override void VisitAST(BinaryExprAST node)
        {
            // for convenience, convert both of the LHS and RHS type explicitly 
            var ty = (TypeKind) Math.Max((int) node.Lhs.RetType, (int) node.Rhs.RetType);
            
            this.Visit(node.Lhs);
            GenCode.Add(Ins.Conv(node.Lhs.RetType,ty));
            this.Visit(node.Rhs);
            GenCode.Add(Ins.Conv(node.Rhs.RetType, ty));

            var code = node.NodeType switch
            {
                ASTType.Add => Ins.Add(ty),
                ASTType.Subtract => Ins.Sub(ty),
                ASTType.Multiply => Ins.Mul(ty),
                ASTType.Divide => Ins.Div(ty),
                ASTType.Modulo => Ins.Mod(),
                ASTType.Equal => Ins.Equ(ty),
                ASTType.NotEqual => Ins.Neq(ty),
                ASTType.LessThan => Ins.Les(ty),
                ASTType.LessEqual => Ins.Leq(ty),
                ASTType.GreaterThan => Ins.Grt(ty),
                ASTType.GreaterEqual => Ins.Geq(ty),
                ASTType.And => Ins.And(),
                ASTType.Or => Ins.Or(),
                _ => throw new NotImplementedException()
            };
            GenCode.Add(code);
        }