Class: Dhallish::Ast::BinaryArithOpNode
- Inherits:
-
Object
- Object
- Dhallish::Ast::BinaryArithOpNode
- Defined in:
- lib/ast.rb
Overview
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
Instance Attribute Summary collapse
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(types, lhs, rhs, op, &block) ⇒ BinaryArithOpNode
constructor
A new instance of BinaryArithOpNode.
Constructor Details
#initialize(types, lhs, rhs, op, &block) ⇒ BinaryArithOpNode
Returns a new instance of BinaryArithOpNode.
16 17 18 19 20 21 22 |
# File 'lib/ast.rb', line 16 def initialize(types, lhs, rhs, op, &block) @op = op @types = types @block = block @lhs = lhs @rhs = rhs end |
Instance Attribute Details
#lhs ⇒ Object
Returns the value of attribute lhs.
13 14 15 |
# File 'lib/ast.rb', line 13 def lhs @lhs end |
#rhs ⇒ Object
Returns the value of attribute rhs.
14 15 16 |
# File 'lib/ast.rb', line 14 def rhs @rhs end |
Instance Method Details
#compute_type(ctx) ⇒ Object
24 25 26 27 28 29 |
# 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) ⇒ Object
31 32 33 34 35 |
# File 'lib/ast.rb', line 31 def evaluate(ctx) lhs = @lhs.evaluate ctx rhs = @rhs.evaluate ctx @block.call lhs, rhs end |