Class: JavaClass::Code

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/javaclass/code.rb

Overview

コード

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, #===, #dump, #eql?, #hash, #to_byte

Constructor Details

#initialize(java_class, index, opcode, operands = [], wide = false) ⇒ Code

Returns a new instance of Code.



8
9
10
11
12
13
14
# File 'lib/javaclass/code.rb', line 8

def initialize( java_class, index, opcode, operands=[], wide=false )
  @java_class = java_class
  @index = index
  @opcode = opcode
  @operands = operands
  @wide = wide
end

Instance Attribute Details

#indexObject

インデックス



41
42
43
# File 'lib/javaclass/code.rb', line 41

def index
  @index
end

#java_classObject

JavaClass



39
40
41
# File 'lib/javaclass/code.rb', line 39

def java_class
  @java_class
end

#opcodeObject

opcode



43
44
45
# File 'lib/javaclass/code.rb', line 43

def opcode
  @opcode
end

#operandsObject

operands



45
46
47
# File 'lib/javaclass/code.rb', line 45

def operands
  @operands
end

#wideObject

wideかどうか



47
48
49
# File 'lib/javaclass/code.rb', line 47

def wide
  @wide
end

Instance Method Details

#to_bytesObject



29
30
31
32
33
34
35
36
37
# File 'lib/javaclass/code.rb', line 29

def to_bytes
  bytes = []
  bytes += to_byte( 0xC4, 1 ) if wide
  bytes += to_byte( opcode, 1 )
  operands.each {|o|
    bytes += o.to_bytes
  }
  return bytes
end

#to_sObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/javaclass/code.rb', line 15

def to_s
#      opts = values = operands.inject(""){|str,i|
#        if i.name == "index"
#          c = @java_class.get_constant(i.value)
#          str += c.kind_of?(MemberRefConstant) ? c.name_and_type.name : c.to_s 
#        end
#        str
#      }
  values = operands.map{|i|i.to_s}
  values.unshift( Converters.convert_code(opcode) )
  values.unshift( "#{@index} :" )
#      values.push( "#" + opts ) if !opts.empty?
  return values.join(" ") 
end