Module: Furnace::AVM2::ABC::RecordWithValue

Included in:
DefaultValue, TraitSlot
Defined in:
lib/furnace-avm2/abc/metadata/record_with_value.rb

Constant Summary collapse

XlatTable =
{
  :Int                => 0x03,
  :UInt               => 0x04,
  :Double             => 0x06,
  :Utf8               => 0x01,
  :True               => 0x0B,
  :False              => 0x0A,
  :Null               => 0x0C,
  :Undefined          => 0x00,
  :Namespace          => 0x08,
  :PackageNamespace   => 0x16,
  :PackageInternalNs  => 0x17,
  :ProtectedNamespace => 0x18,
  :ExplicitNamespace  => 0x19,
  :StaticProtectedNs  => 0x1A,
  :PrivateNs          => 0x05,
}

Instance Method Summary collapse

Instance Method Details

#printable_valueObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/furnace-avm2/abc/metadata/record_with_value.rb', line 75

def printable_value
  if value_idx > 0
    case value_kind
    when :Null
      "null"
    when :Undefined
      "undefined"
    when :Int, :UInt, :Double, :Utf8, :True, :False
      ruby_value.inspect
    end
  else
    nil
  end
end

#ruby_valueObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/furnace-avm2/abc/metadata/record_with_value.rb', line 48

def ruby_value
  if value_idx > 0
    case value_kind
    when :Int
      root.constant_pool.ints[value_idx - 1]
    when :UInt
      root.constant_pool.uints[value_idx - 1]
    when :Double
      root.constant_pool.doubles[value_idx - 1]
    when :Utf8
      root.constant_pool.strings[value_idx - 1]
    when :True
      true
    when :False
      false
    when :Null
      nil
    when :Namespace
      :"%%Namespace"
    else
      raise "unknown value kind #{value_kind}"
    end
  else
    nil
  end
end

#valueObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/furnace-avm2/abc/metadata/record_with_value.rb', line 21

def value
  if value_idx > 0
    case value_kind
    when :Int
      AST::Node.new(:integer, [ root.constant_pool.ints[value_idx - 1] ])
    when :UInt
      AST::Node.new(:integer, [ root.constant_pool.uints[value_idx - 1] ])
    when :Double
      AST::Node.new(:double, [ root.constant_pool.doubles[value_idx - 1] ])
    when :Utf8
      AST::Node.new(:string, [ root.constant_pool.strings[value_idx - 1] ])
    when :True
      AST::Node.new(:true)
    when :False
      AST::Node.new(:false)
    when :Null
      AST::Node.new(:null)
    when :Undefined
      AST::Node.new(:undefined)
    else
      raise "unknown value kind #{value_kind}"
    end
  else
    nil
  end
end