Class: Dhallish::Ast::FunctionCallNode
- Inherits:
-
Object
- Object
- Dhallish::Ast::FunctionCallNode
- Defined in:
- lib/ast.rb
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#fn ⇒ Object
Returns the value of attribute fn.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(fn, arg) ⇒ FunctionCallNode
constructor
A new instance of FunctionCallNode.
Constructor Details
#initialize(fn, arg) ⇒ FunctionCallNode
Returns a new instance of FunctionCallNode.
231 232 233 234 |
# File 'lib/ast.rb', line 231 def initialize(fn, arg) @fn = fn @arg = arg end |
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg.
230 231 232 |
# File 'lib/ast.rb', line 230 def arg @arg end |
#fn ⇒ Object
Returns the value of attribute fn.
229 230 231 |
# File 'lib/ast.rb', line 229 def fn @fn end |
Instance Method Details
#compute_type(ctx) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ast.rb', line 236 def compute_type(ctx) arg_type = @arg.compute_type ctx fn_type = @fn.compute_type ctx assert("only functions can be called, not #{fn_type}") { fn_type.is_a? Types::Function } if arg_type.is_a? Types::Type and !fn_type.unres.nil? assert ("argument type mismatch: expected: #{fn_type.argtype}, got: #{arg_type}") { fn_type.argtype.is_a? Types::Type } Types::resolve(fn_type.restype, fn_type.unres, arg_type.) else unification = Types::unification(fn_type.argtype, arg_type) assert ("argument type mismatch: expected: #{fn_type.argtype}, got: #{arg_type}") { !unification.nil? } fn_type.restype end end |
#evaluate(ctx) ⇒ Object
252 253 254 255 256 |
# File 'lib/ast.rb', line 252 def evaluate(ctx) fn = @fn.evaluate ctx arg = @arg.evaluate ctx fn.call arg end |