# Running ruby1.9 bytecode

**URL:** <https://rubytalk.org/t/running-ruby1-9-bytecode/52703>\
**Category:** ruby-talk\
**Created:** [6 April 2009 12:48 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703 "2009-04-06T12:48:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Coglan2](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@James\_Coglan2](https://rubytalk.org/u/James_Coglan2)\
**Post date:** [6 April 2009 12:48 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703/1 "2009-04-06T12:48:17Z")

</div>

Hi all,

I just found out about the VM::InstructionSequence.compile method for  
turning Ruby code strings into ruby1.9 bytecode. Is there a standard method  
of de/serializing this bytecode to/from files, and is there a way of running  
bytecode directly? I'm looking at generating bytecode from another language  
to get it to run on Ruby.

> **···**
>
> --  
> James Coglan
> 
> > **[jcoglan (James Coglan)](https://github.com/jcoglan)**
> >
> > jcoglan has 126 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [6 April 2009 19:27 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703/2 "2009-04-06T19:27:50Z")

</div>

> Hi all,
> 
> I just found out about the VM::InstructionSequence.compile method for  
> turning Ruby code strings into ruby1.9 bytecode. Is there a standard method  
> of de/serializing this bytecode to/from files, and is there a way of running  
> bytecode directly? I'm looking at generating bytecode from another language  
> to get it to run on Ruby.

Quoting from the Pickaxe book  
no, because the bytecode verifier is not ready yet, that seems the  
only missing bit.  
HTH  
Robert

> **···**
>
> On Mon, Apr 6, 2009 at 2:48 PM, James Coglan \<jcoglan@googlemail.com\> wrote:
> 
> > --  
> > James Coglan  
> > [jcoglan (James Coglan) · GitHub](http://github.com/jcoglan)
> 
> --  
> There are some people who begin the Zoo at the beginning, called  
> WAYIN, and walk as quickly as they can past every cage until they get  
> to the one called WAYOUT, but the nicest people go straight to the  
> animal they love the most, and stay there. ~ A.A. Milne (from  
> Winnie-the-Pooh)

---

<div class="post-metadata">

**Author:** ![Rick\_DeNatale1](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@Rick\_DeNatale1](https://rubytalk.org/u/Rick_DeNatale1)\
**Post date:** [6 April 2009 20:35 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703/3 "2009-04-06T20:35:19Z")

</div>

Well that's part of it. But, if by "generating bytecode from another  
language" means, for instance, executing JVM bytecodes, I don't think it  
will fly. The term bytecode here is being used rather generically. The YARV  
"bytecodes" aren't the same as the JVM bytecodes, any more than Smalltalk-80  
bytecodes are the same as either.

It's like the difference between an Intel and Motorola processor, both have  
instruction sets with binary representations, but those instruction sets  
aren't necessarily interchangeable.

Getting another language to produce YARV bytecodes would be an exercise for  
the reader.

> **···**
>
> On Mon, Apr 6, 2009 at 3:27 PM, Robert Dober \<robert.dober@gmail.com\> wrote:
> 
> > On Mon, Apr 6, 2009 at 2:48 PM, James Coglan \<jcoglan@googlemail.com\> \> wrote:  
> > \> Hi all,  
> > \>  
> > \> I just found out about the VM::InstructionSequence.compile method for  
> > \> turning Ruby code strings into ruby1.9 bytecode. Is there a standard  
> > method  
> > \> of de/serializing this bytecode to/from files, and is there a way of  
> > running  
> > \> bytecode directly? I'm looking at generating bytecode from another  
> > language  
> > \> to get it to run on Ruby.  
> > Quoting from the Pickaxe book  
> > no, because the bytecode verifier is not ready yet, that seems the  
> > only missing bit.  
> > HTH  
> > Robert
> 
> --  
> Rick DeNatale
> 
> Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
> Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
> WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
> LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![James\_Coglan2](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@James\_Coglan2](https://rubytalk.org/u/James_Coglan2)\
**Post date:** [6 April 2009 21:03 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703/4 "2009-04-06T21:03:03Z")

</div>

> Well that's part of it. But, if by "generating bytecode from another  
> language" means, for instance, executing JVM bytecodes, I don't think it  
> will fly. The term bytecode here is being used rather generically. The YARV  
> "bytecodes" aren't the same as the JVM bytecodes, any more than  
> Smalltalk-80  
> bytecodes are the same as either..
> 
> Getting another language to produce YARV bytecodes would be an exercise for  
> the reader.

I meant that I'd like to try and generate YARV bytecode from non-Ruby  
source. Mostly a pie-in-the-sky idea, only just writing my first AST-walking  
interpreter, just wondering if it's possible.

---

<div class="post-metadata">

**Author:** ![Michael\_Malone](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@Michael\_Malone](https://rubytalk.org/u/Michael_Malone)\
**Post date:** [6 April 2009 21:46 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703/5 "2009-04-06T21:46:53Z")

</div>

James Coglan wrote:

> > Well that's part of it. But, if by "generating bytecode from another  
> > language" means, for instance, executing JVM bytecodes, I don't think it  
> > will fly. The term bytecode here is being used rather generically. The YARV  
> > "bytecodes" aren't the same as the JVM bytecodes, any more than  
> > Smalltalk-80  
> > bytecodes are the same as either..
> > 
> > Getting another language to produce YARV bytecodes would be an exercise for  
> > the reader.  
> > &nbsp;&nbsp;&nbsp;&nbsp;  
> > I meant that I'd like to try and generate YARV bytecode from non-Ruby  
> > source. Mostly a pie-in-the-sky idea, only just writing my first AST-walking  
> > interpreter, just wondering if it's possible.

It's definitely possible. I suggest you take a look at the parrot interpreter. It is a one-for-all interpreter (well, that's the aim, anyway), which began life as an April Fool's joke that someone took one step further. It officially hit version 1.0 the other day, so it should be a good example for you. By one-for-all I mean, it's a generic interpreter that can handle many languages, much like .NET and the clr, I guess.

> **···**
>
> # ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission.

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [7 April 2009 09:03 UTC](https://rubytalk.org/t/running-ruby1-9-bytecode/52703/6 "2009-04-07T09:03:40Z")

</div>

\<snip\>

> I meant that I'd like to try and generate YARV bytecode from non-Ruby  
> source. Mostly a pie-in-the-sky idea, only just writing my first AST-walking  
> interpreter, just wondering if it's possible.

Having YARV/Rubinius as a backend for other languages is certainly a  
very reasonable idea.  
And if I understood correctly it is planned to be possible in the  
(near?) future.

Cheers  
R.

> **···**
>
> On Mon, Apr 6, 2009 at 11:03 PM, James Coglan \<jcoglan@googlemail.com\> wrote:
> 
> --  
> There are some people who begin the Zoo at the beginning, called  
> WAYIN, and walk as quickly as they can past every cage until they get  
> to the one called WAYOUT, but the nicest people go straight to the  
> animal they love the most, and stay there. ~ A.A. Milne (from  
> Winnie-the-Pooh)
