Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Created May 11, 2016 00:37
Show Gist options
  • Save joelibaceta/b7e10b78fb76b9f54bcf664f72868175 to your computer and use it in GitHub Desktop.
Save joelibaceta/b7e10b78fb76b9f54bcf664f72868175 to your computer and use it in GitHub Desktop.
codigo = " p 'hello world' "
pp Ripper.lex(codigo) # Paso 1, Tokenizacion
# [[[1, 0], :on_sp, " "],
# [[1, 1], :on_ident, "p"],
# [[1, 2], :on_sp, " "],
# [[1, 3], :on_tstring_beg, "'"],
# [[1, 4], :on_tstring_content, "hello world"],
# [[1, 15], :on_tstring_end, "'"],
# [[1, 16], :on_sp, " "]]
pp Ripper.sexp(codigo) # Paso 2, Parseo
# [:program,
# [[:command,
# [:@ident, "p", [1, 1]],
# [:args_add_block,
# [[:string_literal,
# [:string_content, [:@tstring_content, "hello world", [1, 4]]]]],
# false]]]]
puts RubyVM::InstructionSequence.compile(codigo).disasm # Compilacion y ejecucion a bajo nivel
# == disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
# 0000 trace 1 ( 1)
# 0002 putself
# 0003 putstring "hello world"
# 0005 opt_send_without_block <callinfo!mid:p, argc:1, FCALL|ARGS_SIMPLE>
#
# 0007 leave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment