Skip to content

Commit

Permalink
Import ensure bytecode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Aug 17, 2009
1 parent 912a4d1 commit 0836118
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
33 changes: 32 additions & 1 deletion lib/melbourne/nodes.rb
Expand Up @@ -1267,12 +1267,43 @@ def bytecode(g)
end

class Ensure < Node
def self.from(p, head, ensr)
def self.from(p, body, ensr)
node = Ensure.new p.compiler
node.body = body || Nil.from(p)
node.ensure = ensr
node
end

def children
[@body, @ensure]
end

def bytecode(g)
pos(g)

ok = g.new_label
g.exceptions :ensure do |ex|
@body.bytecode(g)
ex.escape ok

ex.handle!
g.push_exception

@ensure.bytecode(g)
g.pop

g.pop_exception

# Re-raise the exception
g.reraise
end

ok.set!

# Now, re-emit the code for the ensure which will run if there was no
# exception generated.
@ensure.bytecode(g)
g.pop
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/melbourne/processor.rb
Expand Up @@ -186,8 +186,8 @@ def process_dxstr(line, str, array)
AST::DynamicExecuteString.from self, str, array
end

def process_ensure(line, head, ensr)
AST::Ensure.from self, head, ensr
def process_ensure(line, body, ensr)
AST::Ensure.from self, body, ensr
end

def process_evstr(line, value)
Expand Down

0 comments on commit 0836118

Please sign in to comment.