Class: Furnace::AVM2::ABC::Opcode

Inherits:
Object
  • Object
show all
Defined in:
lib/furnace-avm2/abc/opcodes/opcode.rb

Constant Summary collapse

MAP =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence) ⇒ Opcode

Returns a new instance of Opcode.



63
64
65
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 63

def initialize(sequence)
  @sequence = sequence
end

Instance Attribute Details

#sequenceObject (readonly)

Returns the value of attribute sequence.



61
62
63
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 61

def sequence
  @sequence
end

Class Method Details

.body(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 29

def self.body(&block)
  @body_defined = true

  klass = Class.new(Record)
  klass.instance_exec &block

  const_set :Body, klass

  attr_accessor :body
end

.define_property(name, options = {}, &block) ⇒ Object

Metamethods



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 7

def self.define_property(name, options={}, &block)
  accessor_name = options[:accessor] || name

  define_singleton_method(name) do |value=nil, &value_block|
    if value_block
      define_method(accessor_name) do
        instance_exec &value_block
      end
    elsif !value.nil?
      define_method(accessor_name) do
        value
      end
    else
      define_method(accessor_name) do
        true
      end
    end

    instance_exec(value, &block) if block
  end
end

.mnemonicObject



40
41
42
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 40

def self.mnemonic
  @mnemonic ||= name.sub("Furnace::AVM2::ABC::AS3", "")
end

Instance Method Details

#ast_typeObject

Attributes



106
107
108
109
110
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 106

def ast_type
  self.class.mnemonic.
    gsub(/^[A-Z]/) { |m| m[0].downcase }.
    gsub(/([a-z])([A-Z])/) { |m| "#{m[0]}_#{m[1].downcase}" }
end

#byte_lengthObject



88
89
90
91
92
93
94
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 88

def byte_length
  if respond_to? :body
    @body.byte_length + 1
  else
    1
  end
end

#consumes_contextObject



112
113
114
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 112

def consumes_context
  false
end

#disassembleObject Also known as: inspect



126
127
128
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 126

def disassemble
  "   #{offset.to_s.rjust(4, "0")}  #{self.class.mnemonic.rjust(20, " ")} #{disassemble_parameters}"
end

#disassemble_parametersObject

Disassembling



122
123
124
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 122

def disassemble_parameters
  @body.to_hash if @body
end

#nextObject



100
101
102
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 100

def next
  @sequence.opcode_at(offset + byte_length)
end

#offsetObject



96
97
98
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 96

def offset
  @sequence.offset_of(self)
end

#parametersObject



116
117
118
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 116

def parameters
  []
end

#read(io) ⇒ Object

Stream manipulation



73
74
75
76
77
78
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 73

def read(io)
  if respond_to? :body
    @body = self.class.const_get(:Body).new(:parent => @sequence)
    @body.read(io)
  end
end

#rootObject



67
68
69
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 67

def root
  @sequence.root
end

#write(io) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/furnace-avm2/abc/opcodes/opcode.rb', line 80

def write(io)
  io.write([ instruction ].pack("C"))

  if respond_to? :body
    @body.write(io)
  end
end