Skip to content

Instantly share code, notes, and snippets.

@hibariya
Created August 30, 2016 03:41
Show Gist options
  • Select an option

  • Save hibariya/eb0225db8de6ca06e0739f2ffb348af2 to your computer and use it in GitHub Desktop.

Select an option

Save hibariya/eb0225db8de6ca06e0739f2ffb348af2 to your computer and use it in GitHub Desktop.

Revisions

  1. hibariya created this gist Aug 30, 2016.
    22 changes: 22 additions & 0 deletions hi.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # 1 instruction
    puts RubyVM::InstructionSequence.compile(%('hi')).disasm
    # == disasm: #<ISeq:<compiled>@<compiled>>================================
    # 0000 trace 1 ( 1)
    # 0002 putstring "hi"
    # 0004 leave

    # 1 instruction
    puts RubyVM::InstructionSequence.compile(%('hi'.freeze)).disasm
    # == disasm: #<ISeq:<compiled>@<compiled>>================================
    # 0000 trace 1 ( 1)
    # 0002 opt_str_freeze "hi"
    # 0004 leave

    # 3 instructions
    puts RubyVM::InstructionSequence.compile(%('hi'.itself.freeze)).disasm
    # == disasm: #<ISeq:<compiled>@<compiled>>================================
    # 0000 trace 1 ( 1)
    # 0002 putstring "hi"
    # 0004 opt_send_without_block <callinfo!mid:itself, argc:0, ARGS_SIMPLE>, <callcache>
    # 0007 opt_send_without_block <callinfo!mid:freeze, argc:0, ARGS_SIMPLE>, <callcache>
    # 0010 leave