Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finally, properly implement global variables.

  • Loading branch information...
commit 16e4f44a63e4e3defdecfc05166f896d896cee61 1 parent c4996b6
@whitequark authored
View
11 bin/furnace-avm2-decompiler
@@ -86,6 +86,17 @@ if opts[:grep]
exit
end
+global_slots = {}
+
+abc.scripts.each do |script|
+ (script.slot_traits + script.const_traits).each do |trait|
+ next if trait.idx == 0
+ global_slots[trait.idx] = trait
+ end
+end
+
+decompile_options[:global_slots] = global_slots
+
start_time = Time.now
mutex = Mutex.new
View
2  lib/furnace-avm2/source/declaration_tokens/script_token.rb
@@ -3,7 +3,7 @@ class ScriptToken < Furnace::Code::NonterminalToken
include TokenWithTraits
def initialize(origin, options={})
- options = options.merge(environment: :script, global_context: origin)
+ options = options.merge(environment: :script)
global_code = Furnace::AVM2::Decompiler.new(origin.initializer_body,
options.merge(global_code: true)).decompile
View
30 lib/furnace-avm2/source/decompiler.rb
@@ -60,12 +60,7 @@ def decompile
end
end
- if global = @options[:global_context]
- @global_slots = {}
- global.slot_traits.each do |trait|
- @global_slots[trait.idx] = trait
- end
- end
+ @global_slots = @options[:global_slots]
stmt_block @nf, function: !@options[:global_code]
@@ -327,10 +322,15 @@ def expr_get_slot(opcode)
# treat as a local variable
slot = @closure_slots[captures[:index]]
token(VariableNameToken)
- elsif @global_slots && captures = GlobalGetSlot.match(opcode)
+ elsif captures = GlobalGetSlot.match(opcode)
# treat as a global property
- slot = @global_slots[captures[:index]]
- get_name(nil, slot.name.to_astlet)
+ if @global_slots
+ slot = @global_slots[captures[:index]]
+ get_name(nil, slot.name.to_astlet)
+ else
+ token(PropertyNameToken,
+ "$__GLOBAL_#{captures[:index]}")
+ end
end
end
@@ -430,13 +430,19 @@ def expr_set_slot(opcode)
@locals.add index
expr
- elsif @global_slots && captures = GlobalSetSlot.match(opcode)
+ elsif captures = GlobalSetSlot.match(opcode)
# treat as a global property
index, value = captures.values_at(:index, :value)
- slot = @global_slots[index]
+
+ if @global_slots
+ slot = @global_slots[index]
+ name = get_name(nil, slot.name.to_astlet)
+ else
+ token(PropertyNameToken, "$__GLOBAL_#{index}")
+ end
token(AssignmentToken, [
- get_name(nil, slot.name.to_astlet),
+ name,
expr(value)
])
end
Please sign in to comment.
Something went wrong with that request. Please try again.