From: SASADA Koichi Date: 2008-06-05T19:29:00+09:00 Subject: [ruby-core:17121] Re: Bytecode handling (compilation) extensions to Ruby 1.9 Hi, Adam Strzelecki wrote: > Since there's no answer to my post :(, I just want to make sure that > emit/load of bytecode is possible with Ruby 1.9. I missed your post. > I know we can disasm any ruby program code with: > > $ ruby-1.9 --dump=insns hello.rb > > I'd like to try implementing VM seq serialization @ iseq.c > > VALUE ruby_iseq_serialize(VALUE self); /* VM seq -> bytecode */ > VALUE ruby_iseq_unserialize(VALUE self); /* bytecode -> VM seq */ > > Then use those new functions to implement compilation, loading of VM > bytecode. > > So if someone can tell me if it is waste of time because of something I > may now know about YARV, please do. In fact, there is: VALUE iseq_data_to_ary(rb_iseq_t *iseq) VALUE iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt) to_ary() convert ISeq object to Array and well known objects such as Numbers, Regexps, Strings, and so on. iseq_load() loads such data structure. Point of this feature is you can write down YARV assember with Ruby Script or YAML or something. YASM, the YARV bytecode assembler use this feature. ISeq#to_a is supported, but ISeq.load is not supported because of absence of bytecode verifyer. You can cause SEGV easily. This feature is convinient to use, but not optimal one. Now, we are developing following features (on a time of practical work in our university, 1 student is working on this topic): (1) ISeq -> external file that packed (2) ISeq -> external file -> .c file (1) is like Java class file approach. (2) make us happy with implanting Ruby codes to Ruby core or extension libraries written in C. -- // SASADA Koichi at atdot dot net