Class: SyntaxTree::YARV::DefineMethod

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

Overview

### Summary

definemethod defines a method on the 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.

### Usage

~~~ruby def value = “value” ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, method_iseq) ⇒ DefineMethod



975
976
977
978
# File 'lib/syntax_tree/yarv/instructions.rb', line 975

def initialize(method_name, method_iseq)
  @method_name = method_name
  @method_iseq = method_iseq
end

Instance Attribute Details

#method_iseqObject (readonly)

Returns the value of attribute method_iseq.



973
974
975
# File 'lib/syntax_tree/yarv/instructions.rb', line 973

def method_iseq
  @method_iseq
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



973
974
975
# File 'lib/syntax_tree/yarv/instructions.rb', line 973

def method_name
  @method_name
end

Instance Method Details

#call(vm) ⇒ Object



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
# File 'lib/syntax_tree/yarv/instructions.rb', line 1008

def call(vm)
  name = method_name
  nesting = vm.frame.nesting
  iseq = method_iseq

  vm
    .frame
    ._self
    .__send__(:define_method, name) do |*args, **kwargs, &block|
      vm.run_method_frame(
        name,
        nesting,
        iseq,
        self,
        *args,
        **kwargs,
        &block
      )
    end
end

#canonicalObject



1004
1005
1006
# File 'lib/syntax_tree/yarv/instructions.rb', line 1004

def canonical
  self
end

#disasm(fmt) ⇒ Object



980
981
982
983
984
985
986
# File 'lib/syntax_tree/yarv/instructions.rb', line 980

def disasm(fmt)
  fmt.enqueue(method_iseq)
  fmt.instruction(
    "definemethod",
    [fmt.object(method_name), method_iseq.name]
  )
end

#lengthObject



992
993
994
# File 'lib/syntax_tree/yarv/instructions.rb', line 992

def length
  3
end

#popsObject



996
997
998
# File 'lib/syntax_tree/yarv/instructions.rb', line 996

def pops
  0
end

#pushesObject



1000
1001
1002
# File 'lib/syntax_tree/yarv/instructions.rb', line 1000

def pushes
  0
end

#to_a(_iseq) ⇒ Object



988
989
990
# File 'lib/syntax_tree/yarv/instructions.rb', line 988

def to_a(_iseq)
  [:definemethod, method_name, method_iseq.to_a]
end