Class: SyntaxTree::YARV::DefinedIVar
Overview
Summary
definedivar checks if an instance variable is defined. It is a
specialization of the defined instruction. It accepts three arguments:
the name of the instance variable, an inline cache, and the string that
should be pushed onto the stack in the event that the instance variable
is defined.
Usage
defined?(@value)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(name, cache, message) ⇒ DefinedIVar
Returns a new instance of DefinedIVar.
1014
1015
1016
1017
1018
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1014
def initialize(name, cache, message)
@name = name
@cache = cache
@message = message
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
1012
1013
1014
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1012
def cache
@cache
end
|
#message ⇒ Object
Returns the value of attribute message.
1012
1013
1014
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1012
def message
@message
end
|
#name ⇒ Object
Returns the value of attribute name.
1012
1013
1014
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1012
def name
@name
end
|
Instance Method Details
#==(other) ⇒ Object
1035
1036
1037
1038
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1035
def ==(other)
other.is_a?(DefinedIVar) && other.name == name &&
other.cache == cache && other.message == message
end
|
#call(vm) ⇒ Object
1048
1049
1050
1051
1052
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1048
def call(vm)
result = (message if vm.frame._self.instance_variable_defined?(name))
vm.push(result)
end
|
#deconstruct_keys(_keys) ⇒ Object
1031
1032
1033
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1031
def deconstruct_keys(_keys)
{ name: name, cache: cache, message: message }
end
|
#disasm(fmt) ⇒ Object
1020
1021
1022
1023
1024
1025
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1020
def disasm(fmt)
fmt.instruction(
"definedivar",
[fmt.object(name), fmt.inline_storage(cache), fmt.object(message)]
)
end
|
#length ⇒ Object
1040
1041
1042
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1040
def length
4
end
|
#pushes ⇒ Object
1044
1045
1046
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1044
def pushes
1
end
|
#to_a(_iseq) ⇒ Object
1027
1028
1029
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1027
def to_a(_iseq)
[:definedivar, name, cache, message]
end
|