Class: SyntaxTree::YARV::OptStrFreeze

Inherits:
Instruction 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

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?

Constructor Details

#initialize(object, calldata) ⇒ OptStrFreeze

Returns a new instance of OptStrFreeze.



4287
4288
4289
4290
# File 'lib/syntax_tree/yarv/instructions.rb', line 4287

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

Instance Attribute Details

#calldataObject (readonly)

Returns the value of attribute calldata.



4285
4286
4287
# File 'lib/syntax_tree/yarv/instructions.rb', line 4285

def calldata
  @calldata
end

#objectObject (readonly)

Returns the value of attribute object.



4285
4286
4287
# File 'lib/syntax_tree/yarv/instructions.rb', line 4285

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



4307
4308
4309
4310
# File 'lib/syntax_tree/yarv/instructions.rb', line 4307

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

#call(vm) ⇒ Object



4320
4321
4322
# File 'lib/syntax_tree/yarv/instructions.rb', line 4320

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

#deconstruct_keys(_keys) ⇒ Object



4303
4304
4305
# File 'lib/syntax_tree/yarv/instructions.rb', line 4303

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

#disasm(fmt) ⇒ Object



4292
4293
4294
4295
4296
4297
# File 'lib/syntax_tree/yarv/instructions.rb', line 4292

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

#lengthObject



4312
4313
4314
# File 'lib/syntax_tree/yarv/instructions.rb', line 4312

def length
  3
end

#pushesObject



4316
4317
4318
# File 'lib/syntax_tree/yarv/instructions.rb', line 4316

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4299
4300
4301
# File 'lib/syntax_tree/yarv/instructions.rb', line 4299

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