Serializing Ruby code

Discussion in 'Ruby' started by Victor \Zverok\ Shepelev, Dec 3, 2006.

  1. Hi all.

    A bit of philosophy.

    We have Marshal[1] to serializing Ruby's objects (and also YAML and so on).
    AFAIK, Rails community even uses objects serialization for program's state
    saving.
    But, existing marshalling/serialization can serialize only data, not plain
    code; this fact is restricting for their applications. For example,
    Smalltalk-style "image" (entire program state, which can be loaded and
    continued) is impossible.

    But! We have a method for translating code-to-data - ParseTree[2], and we
    even have method to translate back data-to-code (though a bit roundabout) -
    ruby2ruby[3].

    Had somebody thought about gathering all this to create full solution for
    entire running program "saving" and "loading"? (Or, may be, somebody already
    done this and I'm missing?)

    It can be really cool. And it seems completely possible.

    V.

    1. http://www.ruby-doc.org/core/classes/Marshal.html
    2. http://rubyforge.org/projects/parsetree
    3. http://seattlerb.rubyforge.org/ruby2ruby/
     
    Victor \Zverok\ Shepelev, Dec 3, 2006
    #1
    1. Advertising

  2. Victor \Zverok\ Shepelev

    Chris Pearl Guest

    If I understand your question correctly, what you're looking for is
    serializable continuations.

    I've checked this a while back, and the current stable Ruby branch
    (1.8.x) does not have those, though it supports continuations
    themselves. There are no plans to add serialization for continuations
    in this branch, afaik. Perhaps it would be added in the future Ruby
    implementations (at least in some of those ;-)) but here's where the
    implementation developers chime in...

    -Chris

    On 12/3/06, Victor Zverok Shepelev <> wrote:
    > Hi all.
    >
    > A bit of philosophy.
    >
    > We have Marshal[1] to serializing Ruby's objects (and also YAML and so on).
    > AFAIK, Rails community even uses objects serialization for program's state
    > saving.
    > But, existing marshalling/serialization can serialize only data, not plain
    > code; this fact is restricting for their applications. For example,
    > Smalltalk-style "image" (entire program state, which can be loaded and
    > continued) is impossible.
    >
    > But! We have a method for translating code-to-data - ParseTree[2], and we
    > even have method to translate back data-to-code (though a bit roundabout) -
    > ruby2ruby[3].
    >
    > Had somebody thought about gathering all this to create full solution for
    > entire running program "saving" and "loading"? (Or, may be, somebody already
    > done this and I'm missing?)
    >
    > It can be really cool. And it seems completely possible.
    >
    > V.
    >
    > 1. http://www.ruby-doc.org/core/classes/Marshal.html
    > 2. http://rubyforge.org/projects/parsetree
    > 3. http://seattlerb.rubyforge.org/ruby2ruby/
    >
    >
    >
     
    Chris Pearl, Dec 3, 2006
    #2
    1. Advertising

  3. Victor \Zverok\ Shepelev

    Eric Hodel Guest

    On Dec 2, 2006, at 19:06 , Victor Zverok Shepelev wrote:

    > A bit of philosophy.
    >
    > We have Marshal[1] to serializing Ruby's objects (and also YAML and
    > so on).
    > AFAIK, Rails community even uses objects serialization for
    > program's state
    > saving.
    > But, existing marshalling/serialization can serialize only data,
    > not plain
    > code; this fact is restricting for their applications. For example,
    > Smalltalk-style "image" (entire program state, which can be loaded and
    > continued) is impossible.
    >
    > But! We have a method for translating code-to-data - ParseTree[2],
    > and we
    > even have method to translate back data-to-code (though a bit
    > roundabout) -
    > ruby2ruby[3].
    >
    > Had somebody thought about gathering all this to create full
    > solution for
    > entire running program "saving" and "loading"? (Or, may be,
    > somebody already
    > done this and I'm missing?)


    You'd need more than that to get a full image to work (like recording
    the ObjectSpace, the symbol table, globals, ...)

    Also, ParseTree doesn't capture the closure so you can't copy the
    full state of the interpreter:

    $ cat closure.rb
    def make_proc
    x = 1
    proc do |y| y + x end
    end

    p = make_proc

    puts p.call(2)

    require 'rubygems'
    require 'ruby2ruby'

    ruby = p.to_ruby

    puts ruby

    q = eval ruby

    puts q.call(2)

    $ ruby closure.rb
    3
    proc { |y|
    (y + x)
    }
    (eval):2: undefined local variable or method `x' for main:Object
    (NameError)
    from closure.rb:19:in `call'
    from closure.rb:19

    --
    Eric Hodel - - http://blog.segment7.net

    I LIT YOUR GEM ON FIRE!
     
    Eric Hodel, Dec 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aidan Glendye

    Serializing classes derived from dataset

    Aidan Glendye, Jul 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    517
    Aidan Glendye
    Jul 28, 2003
  2. Jason Shohet
    Replies:
    4
    Views:
    371
    bruce barker
    Jul 29, 2003
  3. Andoni
    Replies:
    2
    Views:
    366
    Roedy Green
    Aug 19, 2005
  4. Replies:
    2
    Views:
    330
    Tim Roberts
    Dec 11, 2007
  5. Thomas Sondergaard
    Replies:
    5
    Views:
    154
    Simon Kitching
    Sep 24, 2003
Loading...

Share This Page