Skip to content

Instantly share code, notes, and snippets.

@SpringMT
Created November 14, 2017 07:17
Show Gist options
  • Save SpringMT/24438590ca38bda0126099c200bbd828 to your computer and use it in GitHub Desktop.
Save SpringMT/24438590ca38bda0126099c200bbd828 to your computer and use it in GitHub Desktop.
% ruby ruby_compile.rb ~
compile file sample:
== disasm: #<ISeq:<main>@./sample_test.rb>==============================
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] hoe
0000 putspecialobject 3 ( 1)
0002 putnil
0003 defineclass :Hoe, <class:Hoe>, 0
0007 pop
0008 putnil ( 11)
0009 getconstant :Hoe
0011 send <callinfo!mid:new, argc:0, ARGS_SIMPLE>, <callcache>, nil
0015 setlocal hoe, 0
0018 getlocal hoe, 0 ( 12)
0021 putobject 1
0023 send <callinfo!mid:test_value=, argc:1, ARGS_SIMPLE>, <callcache>, nil
0027 pop
0028 getlocal hoe, 0 ( 13)
0031 send <callinfo!mid:func, argc:0, ARGS_SIMPLE>, <callcache>, nil
0035 leave
== disasm: #<ISeq:<class:Hoe>@./sample_test.rb>=========================
0000 putself ( 2)
0001 putobject :test_value
0003 send <callinfo!mid:attr_accessor, argc:1, FCALL|ARGS_SIMPLE>, <callcache>, nil
0007 pop
0008 putspecialobject 1 ( 3)
0010 putobject :func
0012 putiseq func
0014 send <callinfo!mid:core#define_method, argc:2, ARGS_SIMPLE>, <callcache>, nil
0018 pop
0019 putspecialobject 1 ( 6)
0021 putobject :as_is
0023 putiseq as_is
0025 send <callinfo!mid:core#define_method, argc:2, ARGS_SIMPLE>, <callcache>, nil
0029 leave
== disasm: #<ISeq:func@./sample_test.rb>================================
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] test_value
0000 putself ( 4)
0001 getlocal test_value, 0 <========= ここでtest_valueがローカル変数に変身
0004 send <callinfo!mid:as_is, argc:1, FCALL|ARGS_SIMPLE>, <callcache>, nil
0008 dup
0009 setlocal test_value, 0
0012 leave
== disasm: #<ISeq:as_is@./sample_test.rb>===============================
local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1])
[ 1] v<Arg>
0000 getlocal v, 0 ( 7)
0003 leave
@SpringMT
Copy link
Author

SpringMT commented Nov 14, 2017

class Hoe
  attr_accessor :test_value
  def func
    test_value = as_is(test_value)
  end
  def as_is(v)
    v
  end
end

hoe = Hoe.new
hoe.test_value = 1
hoe.func

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment