Class: JvmBytecode::Instructions::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/jvm_bytecode/instructions/instruction.rb

Direct Known Subclasses

IAdd, IReturn, InvokeSpecial, Return

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cp) ⇒ Instruction

Returns a new instance of Instruction.



30
31
32
33
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 30

def initialize(cp)
  @cp = cp
  @args = nil
end

Class Attribute Details

.mnemonicObject (readonly)

Returns the value of attribute mnemonic.



7
8
9
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 7

def mnemonic
  @mnemonic
end

.opcodeObject (readonly)

Returns the value of attribute opcode.



7
8
9
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 7

def opcode
  @opcode
end

.sizeObject (readonly)

Returns the value of attribute size.



7
8
9
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 7

def size
  @size
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



28
29
30
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 28

def args
  @args
end

#cpObject (readonly)

Returns the value of attribute cp.



27
28
29
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 27

def cp
  @cp
end

Class Method Details

.allObject



18
19
20
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 18

def all
  @@instructions.values
end

.fetch(opcode) ⇒ Object



22
23
24
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 22

def fetch(opcode)
  @@instructions[opcode] || raise(Errors::OpcodeError, "#{sprintf('0x%02X', opcode)} is not implemented")
end

.format(opcode:, size: 1, mnemonic: nil) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 9

def format(opcode:, size: 1, mnemonic: nil)
  @@instructions ||= {}
  @@instructions[opcode] = self

  @opcode = opcode
  @size = size
  @mnemonic = mnemonic || shortname.downcase
end

Instance Method Details

#additional_bytecodeObject



39
40
41
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 39

def additional_bytecode
  ''
end

#bytecodeObject



35
36
37
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 35

def bytecode
  [self.class.opcode].pack('C') + additional_bytecode
end

#decode(io) ⇒ Object



43
44
45
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 43

def decode(io)

end

#to_hashObject



47
48
49
50
51
52
# File 'lib/jvm_bytecode/instructions/instruction.rb', line 47

def to_hash
  {
    mnemonic: self.class.mnemonic,
    opcode: self.class.opcode
  }
end