Skip to content

Instantly share code, notes, and snippets.

@jimsynz
Created August 17, 2014 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimsynz/8886a751456a1b4bd3a1 to your computer and use it in GitHub Desktop.
Save jimsynz/8886a751456a1b4bd3a1 to your computer and use it in GitHub Desktop.
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