Class: CodeTools::AST::SendFastCoerceTo
- Inherits:
-
SendWithArguments
- Object
- Node
- Send
- SendWithArguments
- CodeTools::AST::SendFastCoerceTo
- Defined in:
- lib/rubinius/code/ast/transforms.rb
Overview
Speeds up certain forms of Type.coerce_to
Instance Attribute Summary
Attributes inherited from SendWithArguments
Attributes inherited from Send
#block, #name, #privately, #receiver, #variable, #vcall_style
Attributes inherited from Node
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from SendWithArguments
Methods inherited from Send
#arguments_sexp, #check_local_reference, #defined, #initialize, #receiver_sexp, #sexp_name, #to_sexp, #value_defined
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, #initialize, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #to_sexp, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
This class inherits a constructor from CodeTools::AST::SendWithArguments
Class Method Details
.match?(line, receiver, name, arguments, privately) ⇒ Boolean
334 335 336 337 338 |
# File 'lib/rubinius/code/ast/transforms.rb', line 334 def self.match?(line, receiver, name, arguments, privately) methods = [:coerce_to, :check_convert_type, :try_convert] receiver.kind_of?(TypeConstant) && methods.include?(name) && arguments.body.size == 3 end |
Instance Method Details
#bytecode(g) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/rubinius/code/ast/transforms.rb', line 340 def bytecode(g) pos(g) var = @arguments.array[0] const = @arguments.array[1] if (var.kind_of?(LocalVariableAccess) || var.kind_of?(InstanceVariableAccess)) and (const.kind_of?(ConstantAccess) || const.kind_of?(ScopedConstant) || const.kind_of?(ToplevelConstant)) done = g.new_label var.bytecode(g) g.dup const.bytecode(g) g.swap g.kind_of g.goto_if_true done g.pop super(g) done.set! else super(g) end end |