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



3980
3981
3982
3983
# File 'lib/syntax_tree/yarv/instructions.rb', line 3980

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



3978
3979
3980
# File 'lib/syntax_tree/yarv/instructions.rb', line 3978

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



3978
3979
3980
# File 'lib/syntax_tree/yarv/instructions.rb', line 3978

def object
  @object
end

Instance Method Details

#call(vm) ⇒ Object



4012
4013
4014
# File 'lib/syntax_tree/yarv/instructions.rb', line 4012

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

#canonicalObject



4008
4009
4010
# File 'lib/syntax_tree/yarv/instructions.rb', line 4008

def canonical
  self
end

#disasm(fmt) ⇒ Object



3985
3986
3987
3988
3989
3990
# File 'lib/syntax_tree/yarv/instructions.rb', line 3985

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

#lengthObject



3996
3997
3998
# File 'lib/syntax_tree/yarv/instructions.rb', line 3996

def length
  3
end

#popsObject



4000
4001
4002
# File 'lib/syntax_tree/yarv/instructions.rb', line 4000

def pops
  0
end

#pushesObject



4004
4005
4006
# File 'lib/syntax_tree/yarv/instructions.rb', line 4004

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3992
3993
3994
# File 'lib/syntax_tree/yarv/instructions.rb', line 3992

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