Created
July 9, 2019 19:13
-
-
Save brixen/618f948356000f3b165acf3f96908f02 to your computer and use it in GitHub Desktop.
Iterative fib() using Rubinius register bytecode
This file contains hidden or 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
$ bin/rbx | |
irb(main):001:0> load './fib_r.rb' | |
=> true | |
irb(main):002:0> cc = A.instance_method(:fibi).executable | |
=> #<Rubinius::CompiledCode:0x3680 name=fibi file=(dynamic) line=1> | |
irb(main):003:0> cc.iseq | |
=> #<Rubinius::InstructionSequence:0x3840> | |
irb(main):004:0> iseq = _ | |
=> #<Rubinius::InstructionSequence:0x3840> | |
irb(main):005:0> iseq.opcodes | |
=> #<Rubinius::Tuple: 184, 1, 127, 0, 0, 134, 2, 0, 148, 3, 2, 1, 126, 3, 49, 184, 0, 184, 3, 137, 4, 0, 0, 150, 5, 4, 2, 126, 5, 46, 136, 6, 0, 137, 0, 0, 3, 136, 3, 6, 137, 4, 4, 1, 181, 23, 135, 0, 0, 132, 0, 70, 0> | |
irb(main):006:0> puts cc.decode | |
0000: r_load_1 1 | |
0002: r_load_local 0, 0 | |
0005: r_load_int 2, 0 | |
0008: n_ile 3, 2, 1 | |
0012: b_if 3, 49 | |
0015: r_load_1 0 | |
0017: r_load_1 3 | |
0019: n_iadd 4, 0, 0 | |
0023: n_ige 5, 4, 2 | |
0027: b_if 5, 46 | |
0030: r_copy 6, 0 | |
0033: n_iadd 0, 0, 3 | |
0037: r_copy 3, 6 | |
0040: n_iadd 4, 4, 1 | |
0044: goto_past 0023: | |
0046: r_store_int 0, 0 | |
0049: r_store_stack 0 | |
0051: ret 0 | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment