# Compiling to byte codes

**URL:** <https://www.ruby-forum.com/t/compiling-to-byte-codes/118472>\
**Category:** Ruby\
**Created:** [October 27, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472 "2007-10-27T14:11:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/u/JONNALAGADDA_Sriniv)\
**Post date:** [October 27, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472/1 "2007-10-27T14:11:47Z")

</div>

Dear all,  
I have just compiled and installed 1.9 from SVN trunk. I seem to miss  
the  
instructions for compiling my ruby script to byte codes. Is there some  
documentation available on using the YARV part of 1.9?

Greetings,  
JS

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/u/JONNALAGADDA_Sriniv)\
**Post date:** [October 27, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472/2 "2007-10-27T14:50:20Z")

</div>

Hi,

At Sat, 27 Oct 2007 21:10:53 +0900,  
JONNALAGADDA Srinivas wrote in [ruby-talk:276106]:

> I have just compiled and installed 1.9 from SVN trunk. I seem to miss the  
> instructions for compiling my ruby script to byte codes. Is there some  
> documentation available on using the YARV part of 1.9?

VM::InstructionSequence.new(source\_string)

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/u/JONNALAGADDA_Sriniv)\
**Post date:** [October 27, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472/3 "2007-10-27T15:22:31Z")

</div>

On 10/27/07, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> VM::InstructionSequence.new(source\_string)
> 
> Thank you very much, it worked. I have also been able to ‘VM::  
> InstructionSequence.compile\_file’ and subsequently ‘eval’ the same. Is  
> there a way I could dump this to a file, and re-load the same into  
> another  
> ruby session?  
> Greetings,  
> JS

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/u/JONNALAGADDA_Sriniv)\
**Post date:** [October 27, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472/4 "2007-10-27T15:42:58Z")

</div>

On Sat, 2007-10-27 at 22:21 +0900, JONNALAGADDA Srinivas wrote:

> On 10/27/07, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > VM::InstructionSequence.new(source\_string)
> > 
> > Thank you very much, it worked. I have also been able to ‘VM::  
> > InstructionSequence.compile\_file’ and subsequently ‘eval’ the same. Is  
> > there a way I could dump this to a file, and re-load the same into another  
> > ruby session?  
> > Greetings,  
> > JS

How about…

File.open(“something”, “w”) do |f|  
f.write vm\_compiled\_stuff  
end

# later

eval(File.read(“vm\_compiled”))

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/u/JONNALAGADDA_Sriniv)\
**Post date:** [October 27, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472/5 "2007-10-27T15:44:08Z")

</div>

Hi,

At Sat, 27 Oct 2007 22:21:47 +0900,  
JONNALAGADDA Srinivas wrote in [ruby-talk:276113]:

> Thank you very much, it worked. I have also been able to ‘VM::  
> InstructionSequence.compile\_file’ and subsequently ‘eval’ the same. Is  
> there a way I could dump this to a file, and re-load the same into another  
> ruby session?

There are InstructionSequence#to\_a and InstructionSequence.load  
now, but they will be changed or removed in the near future.

---

<div class="post-metadata">

**Author:** ![JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@JONNALAGADDA\_Sriniv](https://www.ruby-forum.com/u/JONNALAGADDA_Sriniv)\
**Post date:** [October 27, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/compiling-to-byte-codes/118472/6 "2007-10-27T16:45:02Z")

</div>

On 10/27/07, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There are InstructionSequence#to\_a and InstructionSequence.load  
> now, but they will be changed or removed in the near future.
> 
> Thank you, again.  
> Is there a way I can dump the byte codes, to subsequently run them with  
> something like ‘-y’ flag of jruby?

Or, simply, ship only the byte codes without the source code?

Greetings,  
JS
