Class: SyntaxTree::YARV::OptStrFreeze

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

opt_str_freeze pushes a frozen known string value with no interpolation onto the stack using the #freeze method. If the method gets overridden, this will fall back to a send.

### Usage

~~~ruby “hello”.freeze ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, calldata) ⇒ OptStrFreeze



4557
4558
4559
4560
# File 'lib/syntax_tree/yarv/instructions.rb', line 4557

def initialize(object, calldata)
  @object = object
  @calldata = calldata
end

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4555
4556
4557
# File 'lib/syntax_tree/yarv/instructions.rb', line 4555

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



4555
4556
4557
# File 'lib/syntax_tree/yarv/instructions.rb', line 4555

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



4577
4578
4579
4580
# File 'lib/syntax_tree/yarv/instructions.rb', line 4577

def ==(other)
  other.is_a?(OptStrFreeze) && other.object == object &&
    other.calldata == calldata
end

#call(vm) ⇒ Object



4598
4599
4600
# File 'lib/syntax_tree/yarv/instructions.rb', line 4598

def call(vm)
  vm.push(object.freeze)
end

#canonicalObject



4594
4595
4596
# File 'lib/syntax_tree/yarv/instructions.rb', line 4594

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



4573
4574
4575
# File 'lib/syntax_tree/yarv/instructions.rb', line 4573

def deconstruct_keys(_keys)
  { object: object, calldata: calldata }
end

#disasm(fmt) ⇒ Object



4562
4563
4564
4565
4566
4567
# File 'lib/syntax_tree/yarv/instructions.rb', line 4562

def disasm(fmt)
  fmt.instruction(
    "opt_str_freeze",
    [fmt.object(object), fmt.calldata(calldata)]
  )
end

#lengthObject



4582
4583
4584
# File 'lib/syntax_tree/yarv/instructions.rb', line 4582

def length
  3
end

#popsObject



4586
4587
4588
# File 'lib/syntax_tree/yarv/instructions.rb', line 4586

def pops
  0
end

#pushesObject



4590
4591
4592
# File 'lib/syntax_tree/yarv/instructions.rb', line 4590

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4569
4570
4571
# File 'lib/syntax_tree/yarv/instructions.rb', line 4569

def to_a(_iseq)
  [:opt_str_freeze, object, calldata.to_h]
end