Permalink
Browse files

Flush stack upon encountering function return.

  • Loading branch information...
1 parent cf5d43e commit e40eea68ef232961d4a82995376ba3140957e441 @whitequark committed May 7, 2012
View
@@ -16,6 +16,7 @@ module Furnace::AVM2::ABC
require_relative "abc/opcodes/push_literal_opcode"
require_relative "abc/opcodes/control_transfer_opcode"
require_relative "abc/opcodes/function_invocation_opcode"
+require_relative "abc/opcodes/function_return_opcode"
require_relative "abc/opcodes/property_opcode"
Dir[File.join(File.dirname(__FILE__), "abc", "opcodes", "*", "*.rb")].each do |file|
@@ -1,5 +1,5 @@
module Furnace::AVM2::ABC
- class AS3ReturnValue < Opcode
+ class AS3ReturnValue < FunctionReturnOpcode
instruction 0x48
consume 1
@@ -1,5 +1,5 @@
module Furnace::AVM2::ABC
- class AS3ReturnVoid < Opcode
+ class AS3ReturnVoid < FunctionReturnOpcode
instruction 0x47
consume 0
@@ -0,0 +1,4 @@
+module Furnace::AVM2::ABC
+ class FunctionReturnOpcode < Opcode
+ end
+ end
@@ -195,6 +195,14 @@ def transform(code, body)
node.children.concat opcode.parameters
node.children.concat parameters
+ # Spec does not require stack to be empty upon encountering return.
+ # If there's something left, it should have been here.
+ if opcode.is_a? ABC::FunctionReturnOpcode
+ while @stack.any?
+ emit(*consume(1))
+ end
+ end
+
# All opcodes which produce 2 results--that is, dup and swap--
# are already handled at the top.
if opcode.produces == 0

0 comments on commit e40eea6

Please sign in to comment.