class Dhallish::Ast::BinaryArithOpNode
Ast-Node for all operations that take two args of the same type and returns something of that type. `op` must be an ruby-Operator as String/Symbol
Attributes
lhs[RW]
rhs[RW]
Public Class Methods
new(types, lhs, rhs, op, &block)
click to toggle source
# File lib/ast.rb, line 16 def initialize(types, lhs, rhs, op, &block) @op = op @types = types @block = block @lhs = lhs @rhs = rhs end
Public Instance Methods
compute_type(ctx)
click to toggle source
# File lib/ast.rb, line 24 def compute_type(ctx) lhs_type = @lhs.compute_type(ctx) rhs_type = @rhs.compute_type(ctx) assert ("Wrong Operator types for #{@op}. left: #{lhs_type}, right: #{rhs_type}") { lhs_type == rhs_type and @types.include? lhs_type } lhs_type end
evaluate(ctx)
click to toggle source
# File lib/ast.rb, line 31 def evaluate(ctx) lhs = @lhs.evaluate ctx rhs = @rhs.evaluate ctx @block.call lhs, rhs end