Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Flush stack upon encountering function return.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed May 7, 2012
1 parent cf5d43e commit e40eea6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/furnace-avm2/abc.rb
Expand Up @@ -16,6 +16,7 @@ module Furnace::AVM2::ABC
require_relative "abc/opcodes/push_literal_opcode" require_relative "abc/opcodes/push_literal_opcode"
require_relative "abc/opcodes/control_transfer_opcode" require_relative "abc/opcodes/control_transfer_opcode"
require_relative "abc/opcodes/function_invocation_opcode" require_relative "abc/opcodes/function_invocation_opcode"
require_relative "abc/opcodes/function_return_opcode"
require_relative "abc/opcodes/property_opcode" require_relative "abc/opcodes/property_opcode"


Dir[File.join(File.dirname(__FILE__), "abc", "opcodes", "*", "*.rb")].each do |file| Dir[File.join(File.dirname(__FILE__), "abc", "opcodes", "*", "*.rb")].each do |file|
Expand Down
@@ -1,5 +1,5 @@
module Furnace::AVM2::ABC module Furnace::AVM2::ABC
class AS3ReturnValue < Opcode class AS3ReturnValue < FunctionReturnOpcode
instruction 0x48 instruction 0x48


consume 1 consume 1
Expand Down
@@ -1,5 +1,5 @@
module Furnace::AVM2::ABC module Furnace::AVM2::ABC
class AS3ReturnVoid < Opcode class AS3ReturnVoid < FunctionReturnOpcode
instruction 0x47 instruction 0x47


consume 0 consume 0
Expand Down
4 changes: 4 additions & 0 deletions lib/furnace-avm2/abc/opcodes/function_return_opcode.rb
@@ -0,0 +1,4 @@
module Furnace::AVM2::ABC
class FunctionReturnOpcode < Opcode
end
end
8 changes: 8 additions & 0 deletions lib/furnace-avm2/transform/ast_build.rb
Expand Up @@ -195,6 +195,14 @@ def transform(code, body)
node.children.concat opcode.parameters node.children.concat opcode.parameters
node.children.concat 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-- # All opcodes which produce 2 results--that is, dup and swap--
# are already handled at the top. # are already handled at the top.
if opcode.produces == 0 if opcode.produces == 0
Expand Down

0 comments on commit e40eea6

Please sign in to comment.