Class: SyntaxTree::YARV::DefineSMethod
- Inherits:
-
Instruction
- Object
- Instruction
- SyntaxTree::YARV::DefineSMethod
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
‘definesmethod` defines a method on the singleton class of the current value of `self`. It accepts two arguments. The first is the name of the method being defined. The second is the instruction sequence representing the body of the method. It pops the object off the stack that the method should be defined on.
### Usage
~~~ruby def self.value = “value” ~~~
Instance Attribute Summary collapse
-
#method_iseq ⇒ Object
readonly
Returns the value of attribute method_iseq.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(method_name, method_iseq) ⇒ DefineSMethod
constructor
A new instance of DefineSMethod.
- #length ⇒ Object
- #pops ⇒ Object
- #to_a(_iseq) ⇒ Object
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(method_name, method_iseq) ⇒ DefineSMethod
Returns a new instance of DefineSMethod.
1082 1083 1084 1085 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1082 def initialize(method_name, method_iseq) @method_name = method_name @method_iseq = method_iseq end |
Instance Attribute Details
#method_iseq ⇒ Object (readonly)
Returns the value of attribute method_iseq.
1080 1081 1082 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1080 def method_iseq @method_iseq end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
1080 1081 1082 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1080 def method_name @method_name end |
Instance Method Details
#==(other) ⇒ Object
1103 1104 1105 1106 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1103 def ==(other) other.is_a?(DefineSMethod) && other.method_name == method_name && other.method_iseq == method_iseq end |
#call(vm) ⇒ Object
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1116 def call(vm) name = method_name nesting = vm.frame.nesting iseq = method_iseq vm .frame ._self .__send__(:define_singleton_method, name) do |*args, **kwargs, &block| vm.run_method_frame( name, nesting, iseq, self, *args, **kwargs, &block ) end end |
#deconstruct_keys(_keys) ⇒ Object
1099 1100 1101 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1099 def deconstruct_keys(_keys) { method_name: method_name, method_iseq: method_iseq } end |
#disasm(fmt) ⇒ Object
1087 1088 1089 1090 1091 1092 1093 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1087 def disasm(fmt) fmt.enqueue(method_iseq) fmt.instruction( "definesmethod", [fmt.object(method_name), method_iseq.name] ) end |
#length ⇒ Object
1108 1109 1110 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1108 def length 3 end |
#pops ⇒ Object
1112 1113 1114 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1112 def pops 1 end |
#to_a(_iseq) ⇒ Object
1095 1096 1097 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1095 def to_a(_iseq) [:definesmethod, method_name, method_iseq.to_a] end |