furnace-avm2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +17 -0
  4. data/abcdump.abc +0 -0
  5. data/bin/furnace-avm2 +175 -0
  6. data/bin/furnace-avm2-benchmark +38 -0
  7. data/darkorbit.abc +0 -0
  8. data/furnace-avm2.gemspec +22 -0
  9. data/lib/avm2.rb +13 -0
  10. data/lib/avm2/abc.rb +65 -0
  11. data/lib/avm2/abc/metadata/const_pool_info.rb +18 -0
  12. data/lib/avm2/abc/metadata/exception_info.rb +29 -0
  13. data/lib/avm2/abc/metadata/file.rb +27 -0
  14. data/lib/avm2/abc/metadata/instance_info.rb +53 -0
  15. data/lib/avm2/abc/metadata/klass_info.rb +7 -0
  16. data/lib/avm2/abc/metadata/metadata_info.rb +9 -0
  17. data/lib/avm2/abc/metadata/method_body_info.rb +31 -0
  18. data/lib/avm2/abc/metadata/method_info.rb +57 -0
  19. data/lib/avm2/abc/metadata/multiname_info.rb +42 -0
  20. data/lib/avm2/abc/metadata/multiname_kind_genericname.rb +16 -0
  21. data/lib/avm2/abc/metadata/multiname_kind_multiname.rb +18 -0
  22. data/lib/avm2/abc/metadata/multiname_kind_multinamel.rb +17 -0
  23. data/lib/avm2/abc/metadata/multiname_kind_qname.rb +44 -0
  24. data/lib/avm2/abc/metadata/multiname_kind_rtqname.rb +17 -0
  25. data/lib/avm2/abc/metadata/multiname_kind_rtqnamel.rb +11 -0
  26. data/lib/avm2/abc/metadata/namespace_info.rb +22 -0
  27. data/lib/avm2/abc/metadata/ns_set_info.rb +13 -0
  28. data/lib/avm2/abc/metadata/option_detail.rb +26 -0
  29. data/lib/avm2/abc/metadata/option_info.rb +5 -0
  30. data/lib/avm2/abc/metadata/script_info.rb +7 -0
  31. data/lib/avm2/abc/metadata/trait_class.rb +9 -0
  32. data/lib/avm2/abc/metadata/trait_function.rb +9 -0
  33. data/lib/avm2/abc/metadata/trait_info.rb +55 -0
  34. data/lib/avm2/abc/metadata/trait_method.rb +12 -0
  35. data/lib/avm2/abc/metadata/trait_slot.rb +11 -0
  36. data/lib/avm2/abc/opcodes/arithmetic/as3_add.rb +8 -0
  37. data/lib/avm2/abc/opcodes/arithmetic/as3_add_i.rb +10 -0
  38. data/lib/avm2/abc/opcodes/arithmetic/as3_declocal.rb +14 -0
  39. data/lib/avm2/abc/opcodes/arithmetic/as3_declocal_i.rb +14 -0
  40. data/lib/avm2/abc/opcodes/arithmetic/as3_decrement.rb +10 -0
  41. data/lib/avm2/abc/opcodes/arithmetic/as3_decrement_i.rb +10 -0
  42. data/lib/avm2/abc/opcodes/arithmetic/as3_divide.rb +10 -0
  43. data/lib/avm2/abc/opcodes/arithmetic/as3_equals.rb +8 -0
  44. data/lib/avm2/abc/opcodes/arithmetic/as3_greaterequals.rb +8 -0
  45. data/lib/avm2/abc/opcodes/arithmetic/as3_greaterthan.rb +8 -0
  46. data/lib/avm2/abc/opcodes/arithmetic/as3_inclocal.rb +14 -0
  47. data/lib/avm2/abc/opcodes/arithmetic/as3_inclocal_i.rb +18 -0
  48. data/lib/avm2/abc/opcodes/arithmetic/as3_increment.rb +10 -0
  49. data/lib/avm2/abc/opcodes/arithmetic/as3_increment_i.rb +10 -0
  50. data/lib/avm2/abc/opcodes/arithmetic/as3_lessequals.rb +8 -0
  51. data/lib/avm2/abc/opcodes/arithmetic/as3_lessthan.rb +8 -0
  52. data/lib/avm2/abc/opcodes/arithmetic/as3_modulo.rb +10 -0
  53. data/lib/avm2/abc/opcodes/arithmetic/as3_multiply.rb +10 -0
  54. data/lib/avm2/abc/opcodes/arithmetic/as3_multiply_i.rb +10 -0
  55. data/lib/avm2/abc/opcodes/arithmetic/as3_negate.rb +10 -0
  56. data/lib/avm2/abc/opcodes/arithmetic/as3_negate_i.rb +10 -0
  57. data/lib/avm2/abc/opcodes/arithmetic/as3_not.rb +8 -0
  58. data/lib/avm2/abc/opcodes/arithmetic/as3_strictequals.rb +8 -0
  59. data/lib/avm2/abc/opcodes/arithmetic/as3_subtract.rb +10 -0
  60. data/lib/avm2/abc/opcodes/arithmetic/as3_subtract_i.rb +10 -0
  61. data/lib/avm2/abc/opcodes/arithmetic_opcode.rb +4 -0
  62. data/lib/avm2/abc/opcodes/bitwise/as3_bitand.rb +8 -0
  63. data/lib/avm2/abc/opcodes/bitwise/as3_bitnot.rb +8 -0
  64. data/lib/avm2/abc/opcodes/bitwise/as3_bitor.rb +8 -0
  65. data/lib/avm2/abc/opcodes/bitwise/as3_bitxor.rb +8 -0
  66. data/lib/avm2/abc/opcodes/bitwise/as3_lshift.rb +8 -0
  67. data/lib/avm2/abc/opcodes/bitwise/as3_rshift.rb +8 -0
  68. data/lib/avm2/abc/opcodes/bitwise/as3_urshift.rb +8 -0
  69. data/lib/avm2/abc/opcodes/bitwise_opcode.rb +4 -0
  70. data/lib/avm2/abc/opcodes/contextual_opcode.rb +32 -0
  71. data/lib/avm2/abc/opcodes/control_transfer/as3_ifeq.rb +14 -0
  72. data/lib/avm2/abc/opcodes/control_transfer/as3_iffalse.rb +14 -0
  73. data/lib/avm2/abc/opcodes/control_transfer/as3_ifge.rb +14 -0
  74. data/lib/avm2/abc/opcodes/control_transfer/as3_ifgt.rb +14 -0
  75. data/lib/avm2/abc/opcodes/control_transfer/as3_ifle.rb +14 -0
  76. data/lib/avm2/abc/opcodes/control_transfer/as3_iflt.rb +14 -0
  77. data/lib/avm2/abc/opcodes/control_transfer/as3_ifne.rb +14 -0
  78. data/lib/avm2/abc/opcodes/control_transfer/as3_ifnge.rb +14 -0
  79. data/lib/avm2/abc/opcodes/control_transfer/as3_ifngt.rb +14 -0
  80. data/lib/avm2/abc/opcodes/control_transfer/as3_ifnle.rb +14 -0
  81. data/lib/avm2/abc/opcodes/control_transfer/as3_ifnlt.rb +14 -0
  82. data/lib/avm2/abc/opcodes/control_transfer/as3_ifstricteq.rb +14 -0
  83. data/lib/avm2/abc/opcodes/control_transfer/as3_ifstrictne.rb +14 -0
  84. data/lib/avm2/abc/opcodes/control_transfer/as3_iftrue.rb +14 -0
  85. data/lib/avm2/abc/opcodes/control_transfer/as3_jump.rb +22 -0
  86. data/lib/avm2/abc/opcodes/control_transfer/as3_lookupswitch.rb +34 -0
  87. data/lib/avm2/abc/opcodes/control_transfer_opcode.rb +37 -0
  88. data/lib/avm2/abc/opcodes/exception/as3_newcatch.rb +16 -0
  89. data/lib/avm2/abc/opcodes/exception_opcode.rb +4 -0
  90. data/lib/avm2/abc/opcodes/function_invocation/as3_call.rb +16 -0
  91. data/lib/avm2/abc/opcodes/function_invocation/as3_callproperty.rb +7 -0
  92. data/lib/avm2/abc/opcodes/function_invocation/as3_callpropvoid.rb +7 -0
  93. data/lib/avm2/abc/opcodes/function_invocation/as3_callsuper.rb +7 -0
  94. data/lib/avm2/abc/opcodes/function_invocation/as3_callsupervoid.rb +7 -0
  95. data/lib/avm2/abc/opcodes/function_invocation_opcode.rb +17 -0
  96. data/lib/avm2/abc/opcodes/function_return/as3_returnvalue.rb +8 -0
  97. data/lib/avm2/abc/opcodes/function_return/as3_returnvoid.rb +8 -0
  98. data/lib/avm2/abc/opcodes/function_return_opcode.rb +4 -0
  99. data/lib/avm2/abc/opcodes/generic/as3_astypelate.rb +8 -0
  100. data/lib/avm2/abc/opcodes/generic/as3_checkfilter.rb +8 -0
  101. data/lib/avm2/abc/opcodes/generic/as3_dup.rb +8 -0
  102. data/lib/avm2/abc/opcodes/generic/as3_dxnslate.rb +8 -0
  103. data/lib/avm2/abc/opcodes/generic/as3_escxattr.rb +8 -0
  104. data/lib/avm2/abc/opcodes/generic/as3_getglobalscope.rb +8 -0
  105. data/lib/avm2/abc/opcodes/generic/as3_getlex.rb +16 -0
  106. data/lib/avm2/abc/opcodes/generic/as3_getscopeobject.rb +16 -0
  107. data/lib/avm2/abc/opcodes/generic/as3_getslot.rb +16 -0
  108. data/lib/avm2/abc/opcodes/generic/as3_hasnext.rb +8 -0
  109. data/lib/avm2/abc/opcodes/generic/as3_hasnext2.rb +17 -0
  110. data/lib/avm2/abc/opcodes/generic/as3_in.rb +8 -0
  111. data/lib/avm2/abc/opcodes/generic/as3_instanceof.rb +8 -0
  112. data/lib/avm2/abc/opcodes/generic/as3_istypelate.rb +8 -0
  113. data/lib/avm2/abc/opcodes/generic/as3_kill.rb +16 -0
  114. data/lib/avm2/abc/opcodes/generic/as3_label.rb +8 -0
  115. data/lib/avm2/abc/opcodes/generic/as3_nextname.rb +8 -0
  116. data/lib/avm2/abc/opcodes/generic/as3_nextvalue.rb +8 -0
  117. data/lib/avm2/abc/opcodes/generic/as3_nop.rb +8 -0
  118. data/lib/avm2/abc/opcodes/generic/as3_pop.rb +8 -0
  119. data/lib/avm2/abc/opcodes/generic/as3_popscope.rb +8 -0
  120. data/lib/avm2/abc/opcodes/generic/as3_setslot.rb +16 -0
  121. data/lib/avm2/abc/opcodes/generic/as3_swap.rb +8 -0
  122. data/lib/avm2/abc/opcodes/generic/as3_throw.rb +8 -0
  123. data/lib/avm2/abc/opcodes/generic/as3_typeof.rb +8 -0
  124. data/lib/avm2/abc/opcodes/load_store/as3_getlocal.rb +15 -0
  125. data/lib/avm2/abc/opcodes/load_store/as3_getlocal_0.rb +11 -0
  126. data/lib/avm2/abc/opcodes/load_store/as3_getlocal_1.rb +11 -0
  127. data/lib/avm2/abc/opcodes/load_store/as3_getlocal_2.rb +11 -0
  128. data/lib/avm2/abc/opcodes/load_store/as3_getlocal_3.rb +11 -0
  129. data/lib/avm2/abc/opcodes/load_store/as3_setlocal.rb +15 -0
  130. data/lib/avm2/abc/opcodes/load_store/as3_setlocal_0.rb +11 -0
  131. data/lib/avm2/abc/opcodes/load_store/as3_setlocal_1.rb +11 -0
  132. data/lib/avm2/abc/opcodes/load_store/as3_setlocal_2.rb +11 -0
  133. data/lib/avm2/abc/opcodes/load_store/as3_setlocal_3.rb +11 -0
  134. data/lib/avm2/abc/opcodes/load_store_opcode.rb +18 -0
  135. data/lib/avm2/abc/opcodes/object_manipulation/as3_construct.rb +12 -0
  136. data/lib/avm2/abc/opcodes/object_manipulation/as3_constructsuper.rb +16 -0
  137. data/lib/avm2/abc/opcodes/object_manipulation/as3_newactivation.rb +8 -0
  138. data/lib/avm2/abc/opcodes/object_manipulation/as3_newarray.rb +12 -0
  139. data/lib/avm2/abc/opcodes/object_manipulation/as3_newclass.rb +12 -0
  140. data/lib/avm2/abc/opcodes/object_manipulation/as3_newfunction.rb +12 -0
  141. data/lib/avm2/abc/opcodes/object_manipulation/as3_newobject.rb +12 -0
  142. data/lib/avm2/abc/opcodes/object_manipulation_opcode.rb +4 -0
  143. data/lib/avm2/abc/opcodes/opcode.rb +127 -0
  144. data/lib/avm2/abc/opcodes/property/as3_constructprop.rb +20 -0
  145. data/lib/avm2/abc/opcodes/property/as3_deleteproperty.rb +9 -0
  146. data/lib/avm2/abc/opcodes/property/as3_findproperty.rb +9 -0
  147. data/lib/avm2/abc/opcodes/property/as3_findpropstrict.rb +9 -0
  148. data/lib/avm2/abc/opcodes/property/as3_getdescendants.rb +9 -0
  149. data/lib/avm2/abc/opcodes/property/as3_getproperty.rb +9 -0
  150. data/lib/avm2/abc/opcodes/property/as3_getsuper.rb +9 -0
  151. data/lib/avm2/abc/opcodes/property/as3_initproperty.rb +9 -0
  152. data/lib/avm2/abc/opcodes/property/as3_setproperty.rb +9 -0
  153. data/lib/avm2/abc/opcodes/property/as3_setsuper.rb +9 -0
  154. data/lib/avm2/abc/opcodes/property_opcode.rb +13 -0
  155. data/lib/avm2/abc/opcodes/push_literal/as3_pushbyte.rb +11 -0
  156. data/lib/avm2/abc/opcodes/push_literal/as3_pushdouble.rb +11 -0
  157. data/lib/avm2/abc/opcodes/push_literal/as3_pushfalse.rb +7 -0
  158. data/lib/avm2/abc/opcodes/push_literal/as3_pushint.rb +11 -0
  159. data/lib/avm2/abc/opcodes/push_literal/as3_pushnan.rb +7 -0
  160. data/lib/avm2/abc/opcodes/push_literal/as3_pushnull.rb +7 -0
  161. data/lib/avm2/abc/opcodes/push_literal/as3_pushscope.rb +8 -0
  162. data/lib/avm2/abc/opcodes/push_literal/as3_pushshort.rb +11 -0
  163. data/lib/avm2/abc/opcodes/push_literal/as3_pushstring.rb +11 -0
  164. data/lib/avm2/abc/opcodes/push_literal/as3_pushtrue.rb +7 -0
  165. data/lib/avm2/abc/opcodes/push_literal/as3_pushundefined.rb +7 -0
  166. data/lib/avm2/abc/opcodes/push_literal/as3_pushwith.rb +8 -0
  167. data/lib/avm2/abc/opcodes/push_literal_opcode.rb +18 -0
  168. data/lib/avm2/abc/opcodes/type_conversion/as3_applytype.rb +12 -0
  169. data/lib/avm2/abc/opcodes/type_conversion/as3_coerce.rb +16 -0
  170. data/lib/avm2/abc/opcodes/type_conversion/as3_coerce_a.rb +8 -0
  171. data/lib/avm2/abc/opcodes/type_conversion/as3_coerce_b.rb +10 -0
  172. data/lib/avm2/abc/opcodes/type_conversion/as3_coerce_s.rb +10 -0
  173. data/lib/avm2/abc/opcodes/type_conversion/as3_convert_d.rb +10 -0
  174. data/lib/avm2/abc/opcodes/type_conversion/as3_convert_i.rb +10 -0
  175. data/lib/avm2/abc/opcodes/type_conversion/as3_convert_o.rb +10 -0
  176. data/lib/avm2/abc/opcodes/type_conversion/as3_convert_s.rb +10 -0
  177. data/lib/avm2/abc/opcodes/type_conversion/as3_convert_u.rb +10 -0
  178. data/lib/avm2/abc/opcodes/type_conversion_opcode.rb +4 -0
  179. data/lib/avm2/abc/primitives/opcode_sequence.rb +195 -0
  180. data/lib/avm2/abc/primitives/record.rb +132 -0
  181. data/lib/avm2/binary/choice_definition.rb +21 -0
  182. data/lib/avm2/binary/record.rb +469 -0
  183. data/lib/avm2/transform.rb +6 -0
  184. data/lib/avm2/transform/ast_build.rb +206 -0
  185. data/lib/avm2/transform/ast_normalize.rb +0 -0
  186. data/lib/avm2/version.rb +3 -0
  187. data/test/exception.abc +0 -0
  188. data/test/exception.as +29 -0
  189. data/test/literal.abc +0 -0
  190. data/test/literal.as +5 -0
  191. data/test/logic.abc +0 -0
  192. data/test/logic.as +23 -0
  193. data/test/loops.abc +0 -0
  194. data/test/loops.as +30 -0
  195. data/test/number.abc +0 -0
  196. data/test/number.as +14 -0
  197. data/test/switch.abc +0 -0
  198. data/test/switch.as +38 -0
  199. data/test/ternary.abc +0 -0
  200. data/test/ternary.as +22 -0
  201. metadata +579 -0
@@ -0,0 +1,7 @@
1
+ module AVM2::ABC
2
+ class KlassInfo < Record
3
+ root_ref :initializer, :method
4
+
5
+ abc_array_of :trait, :nested, :class => TraitInfo
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module AVM2::ABC
2
+ class MetadataInfo < Record
3
+ vuint30 :name
4
+
5
+ vuint30 :item_count, :value => lambda { item_keys.count }
6
+ array :item_keys, :type => :vuint30, :initial_length => :item_count
7
+ array :item_values, :type => :vuint30, :initial_length => :item_count
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ module AVM2::ABC
2
+ class MethodBodyInfo < Record
3
+ root_ref :method
4
+ vuint30 :max_stack
5
+ vuint30 :local_count
6
+ vuint30 :init_scope_depth
7
+ vuint30 :max_scope_depth
8
+
9
+ vuint30 :code_length, :value => lambda { code.byte_length }
10
+ nested :code, :class => OpcodeSequence
11
+
12
+ abc_array_of :exception, :nested, :class => ExceptionInfo
13
+
14
+ abc_array_of :trait, :nested, :class => TraitInfo
15
+
16
+ def after_read(io)
17
+ exceptions.each do |exception|
18
+ exception.resolve!
19
+ end
20
+ end
21
+
22
+ def build_ast
23
+ pipeline = Furnace::Transform::Pipeline.new([
24
+ AVM2::Transform::ASTBuild.new(validate: true),
25
+ #AVM2::Transform::ASTNormalize.new
26
+ ])
27
+
28
+ pipeline.run(code, self)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,57 @@
1
+ module AVM2::ABC
2
+ class MethodInfo < Record
3
+ NEED_ARGUMENTS = 0x01
4
+ NEED_ACTIVATION = 0x02
5
+ NEED_REST = 0x04
6
+ HAS_OPTIONAL = 0x08
7
+ SET_DXNS = 0x40
8
+ HAS_PARAM_NAMES = 0x80
9
+
10
+ vuint30 :param_count, :value => lambda { param_types.count }
11
+
12
+ const_ref :return_type, :multiname
13
+ const_array :param_types, :multiname, :initial_length => :param_count
14
+
15
+ const_ref :name, :string
16
+
17
+ uint8 :flags
18
+ flag :needs_arguments, :flags, NEED_ARGUMENTS
19
+ flag :needs_activation, :flags, NEED_ACTIVATION
20
+ flag :needs_rest, :flags, NEED_REST
21
+ flag :has_optional, :flags, HAS_OPTIONAL
22
+ flag :set_dxns, :flags, SET_DXNS
23
+ flag :has_param_names, :flags, HAS_PARAM_NAMES
24
+
25
+ nested :options, :class => OptionInfo, :if => lambda { flags & HAS_OPTIONAL != 0 }
26
+ const_array :param_names, :string, :initial_length => :param_count, :if => lambda { flags & HAS_PARAM_NAMES != 0 }
27
+
28
+ def to_astlet(name=nil)
29
+ root = AST::Node.new(:method)
30
+ root.metadata = { origin: self }
31
+
32
+ root.children << name || self.name
33
+
34
+ if return_type
35
+ root.children << return_type.to_astlet
36
+ else
37
+ root.children << nil
38
+ end
39
+
40
+ if has_param_names?
41
+ names = param_names
42
+ else
43
+ names = param_count.times.map { |n| "a#{n}" }
44
+ end
45
+
46
+ root.children << names.each_with_index.map do |name, index|
47
+ if param_types[index]
48
+ [ name, param_types[index].to_astlet ]
49
+ else
50
+ [ name, nil ]
51
+ end
52
+ end
53
+
54
+ root.normalize_hierarchy!
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,42 @@
1
+ module AVM2::ABC
2
+ class MultinameInfo < Record
3
+ XlatTable = {
4
+ :QName => 0x07,
5
+ :QNameA => 0x0D,
6
+ :RTQName => 0x0F,
7
+ :RTQNameA => 0x10,
8
+ :RTQNameL => 0x11,
9
+ :RTQNameLA => 0x12,
10
+ :Multiname => 0x09,
11
+ :MultinameA => 0x0E,
12
+ :MultinameL => 0x1B,
13
+ :MultinameLA => 0x1C,
14
+ :GenericName => 0x1D # Undocumented
15
+ }
16
+
17
+ uint8 :kind_raw
18
+ xlat_field :kind
19
+
20
+ choice :data, :selection => :kind do
21
+ variant :QName, :nested, :class => MultinameKindQName
22
+ variant :QNameA, :nested, :class => MultinameKindQName
23
+ variant :RTQName, :nested, :class => MultinameKindRTQName
24
+ variant :RTQNameA, :nested, :class => MultinameKindRTQName
25
+ variant :RTQNameL, :nested, :class => MultinameKindRTQNameL
26
+ variant :RTQNameLA, :nested, :class => MultinameKindRTQNameL
27
+ variant :Multiname, :nested, :class => MultinameKindMultiname
28
+ variant :MultinameA, :nested, :class => MultinameKindMultiname
29
+ variant :MultinameL, :nested, :class => MultinameKindMultinameL
30
+ variant :MultinameLA, :nested, :class => MultinameKindMultinameL
31
+ variant :GenericName, :nested, :class => MultinameKindGenericName
32
+ end
33
+
34
+ def method_missing(method, *args, &block)
35
+ data.send(method, *args, &block)
36
+ end
37
+
38
+ def to_s
39
+ data.to_s
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ module AVM2::ABC
2
+ # Undocumented
3
+ class MultinameKindGenericName < Record
4
+ vuint30 :name_type
5
+
6
+ abc_array_of :parameter, :vuint30
7
+
8
+ def to_s
9
+ "(genericname)"
10
+ end
11
+
12
+ def to_astlet
13
+ AST::Node.new(:generic, [ name_type, parameters ])
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module AVM2::ABC
2
+ class MultinameKindMultiname < Record
3
+ const_ref :name, :string
4
+ const_ref :ns_set, :ns_set
5
+
6
+ def to_s
7
+ "#{ns_set}::#{name || '*'}"
8
+ end
9
+
10
+ def to_astlet
11
+ AST::Node.new(:m, [ ns_set.to_astlet, name ])
12
+ end
13
+
14
+ def context_size
15
+ 0
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module AVM2::ABC
2
+ class MultinameKindMultinameL < Record
3
+ const_ref :ns_set, :ns_set
4
+
5
+ def to_s
6
+ "#{ns_set}::(rt)"
7
+ end
8
+
9
+ def to_astlet(name)
10
+ node = AST::Node.new(:m, [ ns_set.to_astlet, name ])
11
+ end
12
+
13
+ def context_size
14
+ 1
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module AVM2::ABC
2
+ class MultinameKindQName < Record
3
+ const_ref :ns, :namespace
4
+ const_ref :name, :string
5
+
6
+ def to_s
7
+ if ns
8
+ "#{ns}::#{name || '*'}"
9
+ else
10
+ name || '*'
11
+ end
12
+ end
13
+
14
+ def to_astlet
15
+ node = AST::Node.new(:q)
16
+
17
+ if ns && ns.name == ""
18
+ elsif ns
19
+ node.children << ns.name
20
+ else
21
+ node.children << "*"
22
+ end
23
+
24
+ node.children << name
25
+
26
+ node
27
+ end
28
+
29
+ def to_astpat(type=:qname)
30
+ case type
31
+ when :qname
32
+ [ :q, (ns.name if ns), name ].compact
33
+ when :multiname
34
+ [ :m, [ ns.name ], name ]
35
+ else
36
+ raise "unknown astpat type #{type}"
37
+ end
38
+ end
39
+
40
+ def context_size
41
+ 0
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ module AVM2::ABC
2
+ class MultinameKindRTQName < Record
3
+ const_ref :name, :string
4
+
5
+ def to_s
6
+ "(rt)::#{name || '*'}"
7
+ end
8
+
9
+ def to_astlet(ns)
10
+ node = AST::Node.new(:q, [ ns, name ])
11
+ end
12
+
13
+ def context_size
14
+ 1
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module AVM2::ABC
2
+ class MultinameKindRTQNameL < Record
3
+ def to_s
4
+ "(rt)::(rt)"
5
+ end
6
+
7
+ def context_size
8
+ 2
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module AVM2::ABC
2
+ class NamespaceInfo < Record
3
+ XlatTable = {
4
+ :Namespace => 0x08,
5
+ :PackageNamespace => 0x16,
6
+ :PackageInternalNs => 0x17,
7
+ :ProtectedNamespace => 0x18,
8
+ :ExplicitNamespace => 0x19,
9
+ :StaticProtectedNs => 0x1A,
10
+ :PrivateNs => 0x05,
11
+ }
12
+
13
+ uint8 :kind_raw
14
+ xlat_field :kind
15
+
16
+ const_ref :name, :string
17
+
18
+ def to_s
19
+ name.to_s
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module AVM2::ABC
2
+ class NsSetInfo < Record
3
+ const_array_of :ns, :namespace, :plural => :ns
4
+
5
+ def to_s
6
+ "{#{ns.map(&:to_s).join(",")}}"
7
+ end
8
+
9
+ def to_astlet
10
+ ns.map(&:name).uniq
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module AVM2::ABC
2
+ class OptionDetail < Record
3
+ XlatTable = {
4
+ :Int => 0x03,
5
+ :UInt => 0x04,
6
+ :Double => 0x06,
7
+ :Utf8 => 0x01,
8
+ :True => 0x0B,
9
+ :False => 0x0A,
10
+ :Null => 0x0C,
11
+ :Undefined => 0x00,
12
+ :Namespace => 0x08,
13
+ :PackageNamespace => 0x16,
14
+ :PackageInternalNs => 0x17,
15
+ :ProtectedNamespace => 0x18,
16
+ :ExplicitNamespace => 0x19,
17
+ :StaticProtectedNs => 0x1A,
18
+ :PrivateNs => 0x05,
19
+ }
20
+
21
+ vuint30 :val
22
+
23
+ uint8 :kind_raw
24
+ xlat_field :kind
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module AVM2::ABC
2
+ class OptionInfo < Record
3
+ abc_array_of :option, :nested, :class => OptionDetail
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module AVM2::ABC
2
+ class ScriptInfo < Record
3
+ vuint30 :init
4
+
5
+ abc_array_of :trait, :nested, :class => TraitInfo
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module AVM2::ABC
2
+ class TraitClass < Record
3
+ vuint30 :slot_id
4
+ vuint30 :classi
5
+
6
+ def to_astlet(trait)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module AVM2::ABC
2
+ class TraitFunction < Record
3
+ vuint30 :slot_id
4
+ root_ref :method
5
+
6
+ def to_astlet(trait)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ module AVM2::ABC
2
+ class TraitInfo < Record
3
+ XlatTable = {
4
+ :Slot => 0,
5
+ :Method => 1,
6
+ :Getter => 2,
7
+ :Setter => 3,
8
+ :Class => 4,
9
+ :Function => 5,
10
+ :Const => 6
11
+ }
12
+
13
+ FINAL = 0x01
14
+ OVERRIDE = 0x02
15
+ METADATA = 0x04
16
+
17
+ attr_accessor :kind_raw
18
+
19
+ def read_attributes(io, options)
20
+ byte = io.read(1).unpack("C").at(0)
21
+
22
+ value = byte >> 4
23
+ @kind_raw = byte & 0xF
24
+
25
+ value
26
+ end
27
+
28
+ def write_attributes(io, value, options)
29
+ byte = (value << 4) | (@kind_raw & 0xf)
30
+
31
+ io.write([ byte ].pack("C"))
32
+ end
33
+
34
+ const_ref :name, :multiname
35
+
36
+ attributes :attributes
37
+ xlat_field :kind
38
+
39
+ choice :data, :selection => :kind do
40
+ variant :Slot, :nested, :class => TraitSlot
41
+ variant :Method, :nested, :class => TraitMethod
42
+ variant :Getter, :nested, :class => TraitMethod
43
+ variant :Setter, :nested, :class => TraitMethod
44
+ variant :Class, :nested, :class => TraitClass
45
+ variant :Function, :nested, :class => TraitFunction
46
+ variant :Const, :nested, :class => TraitSlot
47
+ end
48
+
49
+ abc_array_of :metadata, :vuint30, :plural => :metadata, :if => lambda { attributes & METADATA != 0 }
50
+
51
+ def to_astlet
52
+ data.to_astlet(self)
53
+ end
54
+ end
55
+ end