Created
August 17, 2014 22:13
-
-
Save jimsynz/8886a751456a1b4bd3a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bytecode g | |
pos g | |
g.push_rubinius | |
g.create_block block_from_children g | |
g.send_stack_with_block :lambda, 0 | |
g.ret | |
end | |
private | |
def block_from_children g | |
blk = g.class.new | |
blk.file = g.file | |
blk.for_block = true | |
blk.arity = arity | |
blk.definition_line line | |
pos blk | |
arguments.each do |argument| | |
argument.bytecode g | |
end | |
blk.push_modifiers | |
blk.break = nil | |
blk.next = nil | |
blk.redo = blk.new_label | |
blk.redo.set! | |
children.each do |child| | |
child.bytecode(blk) | |
end | |
blk.pop_modifiers | |
blk.ret | |
blk.close | |
# blk.pop_state | |
blk.local_count = local_count | |
blk.local_names = local_names | |
end | |
def local_count | |
@locals.size | |
end | |
def local_names | |
@locals.map { |v| v.name.to_sym } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment