On Wed, Sep 10, 2008 at 03:21:20AM +0900, Roger Pack wrote: > > I much prefer 'location', because it is something that every Ruby > > implementation can provide. iseq is super super low-level, and we > > should think hard about the API before calling it public. > > True. I suppose my suggestion was a little bit MRI-centric after all :) > > Could I then also make a request for a few MRI specific functions, either > > >> p = proc { |n| n + 2 } > => #<Proc:...> > >> RubyVM::InstructionSequence.disassemble p # this doesn't currently work With ruby-internal (http://github.com/cout/ruby-internal) you can do this: irb(main):001:0> require 'internal/proc' => true irb(main):002:0> p = proc { |n| n + 2 } => #<Proc:0x40275ed0@(irb):2> irb(main):003:0> puts p.body.disasm == disasm: <ISeq:block (3 levels) in irb_binding@(irb)>================= == catch table | catch type: redo st: 0000 ed: 0006 sp: 0000 cont: 0000 | catch type: next st: 0000 ed: 0006 sp: 0000 cont: 0006 |------------------------------------------------------------------------ local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1] s3) [ 1] n<Arg> 0000 getdynamic n, 0 ( 2) 0003 putobject 2 0005 opt_plus 0006 leave => nil > > or the before mentioned > Proc#iseq > (Unbound)Method#iseq [see [1]] > > These would yield some very welcome functionality for projects like > [2,3,4] since it would allow users to potentially parse blocks [and > rewrite them] before executing them, which has some strong potential. > This is available in 1.8.x because the AST is made available to c > functions, but not (yet) for 1.9. AFAICT the AST is discarded once the method is compiled to bytecode. Paul