[#14206] undef_method :method_missing — Kenichi Komiya <kom@...1.accsnet.ne.jp>

154 messages 2001/08/04
[#14207] Re: undef_method :method_missing — nobu.nakada@... 2001/08/04

なかだです。

[#14208] Re: undef_method :method_missing — nobu.nakada@... 2001/08/05

なかだです。

[#14209] Virtual Machine — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14210] Re: Virtual Machine — Kenta MURATA <muraken2@...> 2001/08/05

むらけんです.

[#14212] Re: Virtual Machine — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14214] Re: Virtual Machine — SHIROYAMA Takayuki <psi@...> 2001/08/05

[#14220] Re: Virtual Machine — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14211] Common GUI framework(Re: Virtual Machine) — nobu.nakada@... 2001/08/05

なかだです。

[#14213] RE: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。どもっ。

[#14215] Re: Common GUI framework(Re: Virtual Machine) — akira yamada / やまだあきら <akira@...> 2001/08/05

[#14221] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14235] Re: Common GUI framework(Re: Virtual Machine) — IWATSUKI Hiroyuki <don@...> 2001/08/05

岩月と申します。

[#14237] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。どもっ。

[#14239] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/05

有馬です。

[#14241] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14244] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/05

有馬です。

[#14247] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。どもっ。

[#14263] Re: Common GUI framework(Re: Virtual Machine) — とみたまさひろ <tommy@...> 2001/08/05

とみたです。

[#14266] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14269] Re: Common GUI framework(Re: Virtual Machine) — とみたまさひろ <tommy@...> 2001/08/05

とみたです。

[#14275] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/05

有馬です。

[#14294] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。

[#14317] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/06

有馬です。

[#14321] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/06

金光です。どもっ。

[#14332] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/06

有馬です。

[#14335] Re: Common GUI framework(Re: Virtual Machine) — Kenta MURATA <muraken2@...> 2001/08/06

むらけんです.

[#14346] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/06

金光です。どもっ。

[#14356] Re: Common GUI framework(Re: Virtual Machine) — ARIMA Yasuhiro <fit0298@...> 2001/08/06

有馬です。

[#14357] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/06

金光です。どもどもっ。

[#14243] Re: Common GUI framework(Re: Virtual Machine) — IWATSUKI Hiroyuki <don@...> 2001/08/05

岩月と申します。

[#14258] Re: Common GUI framework(Re: Virtual Machine) — akira yamada / やまだあきら <akira@...> 2001/08/05

[#14260] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。FOXとかもあるのかぁ。すげぇなぁ。

[#14277] Re: Common GUI framework(Re: Virtual Machine) — matz@... (Yukihiro Matsumoto) 2001/08/05

まつもと ゆきひろです

[#14295] Re: Common GUI framework(Re: Virtual Machine) — "KANEMITSU Masao" <masao-k@...> 2001/08/05

金光です。御大、待ってましたっ。

[#14390] [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...>

なひです。

113 messages 2001/08/09
[#14391] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/09

なひです。書き忘れ。

[#14392] Re: [Patch] pp.rb and debug.rb — nobu.nakada@... 2001/08/09

なかだです。

[#14435] Re: [Patch] pp.rb and debug.rb — "K.Kosako" <kosako@...> 2001/08/13

nobu.nakada@nifty.ne.jpさんの

[#14437] Re: [Patch] pp.rb and debug.rb — nobu.nakada@... 2001/08/13

なかだです。

[#14449] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/14

In article <DJEGJLCFNEIMKDNMLFPHMEAHCBAA.nakahiro@sarion.co.jp>,

[#14450] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/14

なひです。

[#14452] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/14

In article <DJEGJLCFNEIMKDNMLFPHEEAICBAA.nakahiro@sarion.co.jp>,

[#14453] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/14

なひです。

[#14454] Re: [Patch] pp.rb and debug.rb — matz@... (Yukihiro Matsumoto) 2001/08/14

まつもと ゆきひろです

[#14455] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/14

In article <997774251.527258.14423.nullmailer@ev.netlab.jp>,

[#14474] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/15

なひです。

[#14498] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/16

In article <DJEGJLCFNEIMKDNMLFPHEEALCBAA.nakahiro@sarion.co.jp>,

[#14499] Re: [Patch] pp.rb and debug.rb — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/16

なひです。

[#14504] Re: [Patch] pp.rb and debug.rb — Tanaka Akira <akr@...17n.org> 2001/08/16

In article <DJEGJLCFNEIMKDNMLFPHEEAPCBAA.nakahiro@sarion.co.jp>,

[#14507] marshal API (was Re: [Patch] pp.rb and debug.rb) — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/16

なひです。

[#14510] Re: marshal API (was Re: [Patch] pp.rb and debug.rb) — Tanaka Akira <akr@...17n.org> 2001/08/16

In article <DJEGJLCFNEIMKDNMLFPHMEBACBAA.nakahiro@sarion.co.jp>,

[#14511] Re: marshal API (was Re: [Patch] pp.rb and debug.rb) — "NAKAMURA, Hiroshi" <nakahiro@...> 2001/08/16

なひです。

[#14519] custom marshal (Re: Re: marshal API (was Re: [Patch] pp.rb and debug.rb)) — Tanaka Akira <akr@...17n.org> 2001/08/17

In article <DJEGJLCFNEIMKDNMLFPHIEBBCBAA.nakahiro@sarion.co.jp>,

[#14520] Re: marshal API (was Re: [Patch] pp.rb and debug.rb) — Tanaka Akira <akr@...17n.org> 2001/08/17

うぅむ。ぼーっとしてたら意味もなく Subject を変えてしまった。

[#14549] Re: custom marshal (Re: Re: marshal API (was Re: [Patch] pp.rb and debug.rb)) — Tanaka Akira <akr@...17n.org> 2001/08/22

In article <hvo66bnxe4b.fsf_-_@flux.etl.go.jp>,

[#14832] Re: custom marshal — GOTO Kentaro <gotoken@...> 2001/09/29

古い話題で恐縮ですが…

[#14833] Re: custom marshal — nobu.nakada@... 2001/09/29

なかだです。

[#14834] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/01

In article <200109290948.f8T9mbh12942@sharui.nakada.kanuma.tochigi.jp>,

[#14835] Re: custom marshal — nobu.nakada@... 2001/10/01

なかだです。

[#14836] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/01

まつもと ゆきひろです

[#14837] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/02

In article <1001945748.240863.24023.nullmailer@ev.netlab.jp>,

[#14838] Re: custom marshal — nobu.nakada@... 2001/10/02

なかだです。

[#14839] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/02

In article <200110020334.f923YLb08299@sharui.nakada.kanuma.tochigi.jp>,

[#14842] Re: custom marshal — nobu.nakada@... 2001/10/02

なかだです。

[#14843] Re: custom marshal — Tanaka Akira <akr@...17n.org> 2001/10/02

In article <200110021010.f92AAIb13474@sharui.nakada.kanuma.tochigi.jp>,

[#14844] Re: custom marshal — nobu.nakada@... 2001/10/02

なかだです。

[#14845] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/02

まつもと ゆきひろです

[#14847] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/02

まつもと ゆきひろです

[#14848] Re: custom marshal — nobu.nakada@... 2001/10/03

なかだです。

[#14852] Re: custom marshal — matz@... (Yukihiro Matsumoto) 2001/10/03

まつもと ゆきひろです

[#14465] Ruby/Bsearch — akira yamada / やまだあきら <akira@...>

16 messages 2001/08/14
[#14472] Re: Ruby/Bsearch — matz@... (Yukihiro Matsumoto) 2001/08/15

まつもと ゆきひろです

[#14595] SEGV at `$0 = "long long string"' — nobu.nakada@...

なかだです。

14 messages 2001/08/28

[ruby-dev:14582] Re: marshal API (was Re: [Patch] pp.rb and debug.rb)

From: Masatoshi SEKI <m_seki@...>
Date: 2001-08-26 20:26:34 UTC
List: ruby-dev #14582
咳といいます。

投稿しないとサボってすすまないので、やりかけのものをポストします。

> > なひは、marshalおよびunmarshalの実装は、一行も書きたくないです。
> > traverseしてdumpする/loadしてネットワークを構築するという機能は
> > Ruby本体が既に持っており、また今後も提供していくだろう機能なので、
> > そのカスタマイズ用界面(API)をうまく定義することによって、
> > custom marshal/unmarshalで流用したい。
> > custom marshal/unmarshalをする人たちで共有したい(10個あったら3000行)。
> 
> すばらしいです。オブジェクト群からの情報抽出・再構成と外部フォーマット
> の定義を完全に分離しようという決意のあらわれですね。うむうむ。まったく
> もってそういうふうにモジュール化されるべきですね。

* トラバーズする層
* その結果を外部フォーマットの出力層

にわかれるんでしょうね。

機能で層がわかれるというか、情報の層がちがうのかな。

[Rubyオブジェクトのネットワーク]
               |
           traverser
               |
    [抽象化したネットワーク]  → オブジェクトを再構成する情報の 列 ができる。
               |
           formatter
               |
      [任意のフォーマット]


んで、いまそういうのを書きはじめてみました。

気持ちとしては、marshal.cのw_objectがバッファを出力する代わりに、
オブジェクトを再構成する情報(BMarshal::Ref)を出力します。

フォーマッタはそれを任意の形、順序で外部フォーマットに出力できます。

とりあえず、うそSOAPっぽい出力をさせてみました。
marshal.cの出力と同じものを出すのも簡単だと思います。


---------
class BTraverser
  I32 = (-2147483647-1)..2147483647

  class Ref
    def initialize
      @klass = nil
      @primary = nil
      @ivars = {}
      @custom_loader = false
    end
    attr_accessor :klass, :custom_loader
    attr_reader :ivars, :primary

    # primaryってヘンだな。bodyのがいいかも
    def push_primary(it)
      @primary = [] unless @primary
      @primary.push(it)
    end
  end

  def initialize
    @map = {}
    @limit = nil
    @stream = []
    @cur = nil
  end
  attr_accessor :map, :limit, :stream

  # w_objectというメソッド、呼ばれてないっす。@limitも見てない
  def w_object(obj)
    raise(ArgError, 'exeed depth limit') if @limit == 0
    case obj
    when nil, true, false
      @stream.push(obj)
    when Fixnum
      if I32 === obj
	@stream.push(obj)
      else
	make_ref(obj)
      end
    else
      make_ref(obj)
    end
  end

  def make_ref(obj)
    ref = @map[obj.__id__]
    if ref
      @stream.push ref
      return ref
    end

    ref = Ref.new
    @map[obj.__id__] = ref
    @stream.push ref
    begin
      stack = @cur
      @cur = ref

      ref.klass = obj.class

      if obj.respond_to? (:__load)
	ref.custom_loader = true
      end
      obj.__dump(self)

    ensure
      @cur = stack
    end
    
    return ref
  end

  def put_class(klass)
    @cur.klass = klass
  end

  def put_primary(v)
    @cur.push_primary(v)
  end

  def put_ivar(n, v)
    @cur.ivars[n] = v
  end

  def put_all_ivars(obj)
    obj.instance_variables.each do |var|
      value = obj.instance_eval var
      @cur.ivars[var] = self.put(value)
    end
  end

  def put(obj)
    #    w_object(obj)
    make_ref(obj)
  end
end

class Fixnum
  def __dump(dumper)
    dumper.put_primary(to_i)
  end
end

class Object
  def __dump(dumper)
    dumper.put_all_ivars(self)
  end
end

class Symbol
  def __dump(dumper)
    dumper.put_primary(self.id2name)
  end
end

class Module
  def __dump(dumper)
    dumper.put_primary(name)
  end
end

class Float
  def __dump(dumper)
    dumper.put_primary(to_f)
  end
end

class Bignum
  def __dump(dumper)
    dumper.put_primary(to_i)
  end
end

class String
  def __dump(dumper)
    dumper.put_primary(to_s)
  end
end

class Regexp
  def __dump(dumper)
    dumper.put_primary(source)
    dumper.put_primary(options)
  end
end

class Array
  def __dump(dumper)
    self.each do |v|
      dumper.put_primary(dumper.put(v))
    end
  end
end

class Hash
  def __dump(dumper)
    dumper.put_primary(dumper.put(self.default))
    self.each do |k, v|
      dumper.put_primary(dumper.put(k))
      dumper.put_primary(dumper.put(v))
    end
  end
end

class Struct
  def __dump(dumper)
    dumper.members.each do |m|
      dumper.put_primary(dumper.put(m))
      dumper.put_primary(dumper.put(self[m]))
    end
  end
end


class Foo
  def initialize(it)
    @foo = self
    @bar = it
  end
end

class BXmlDumper
  def initialize(output=[])
    @cur = 1
    @map = {}
    @child = []
    @output = output
  end
  attr_reader :output

  def feed(obj)
    return if @map[obj.id]
    @map[obj.id] = @cur
    @cur += 1
    @child.push(obj)
  end

  def finish
    @child.each do |r|
      begin_obj(r)
      primary_value(r)
      ivars(r)
      end_obj(r)
    end
  end

  def dump(stream)
    stream.each do |obj|
      feed(obj)
    end
    finish
  end

  def put(s)
    @output.push s
  end

  def begin_obj(r)
    put %Q!<obj xsi:type="myns:#{r.klass}" id="id#{@map[r.id]}">! 
  end

  def ivars(r)
    r.ivars.each do |k, v|
      name = k.sub(/^@/, '')
      put %Q!  <#{name} href="#id#{@map[v.id]}">!
    end
  end

  def primary_value(r)
    case r.klass.name
    when 'Fixnum', 'Bignum'
      put r.primary[0]
    when 'Symbol'
      put r.primary[0].dump
    when 'String'
      put r.primary[0].dump
    when 'Array'
      r.primary.each do |e|
	put %Q!  <item href="#id#{@map[e.id]}">!
      end
    when 'Hash'
      it = r.primary[0]
      put %Q!  <default href="#id#{@map[it.id]}">!
      ary = r.primary[1..-1]
      while (ary.size > 0) do
	put '  <pair>'
	put %Q!    <key href="#id#{@map[ary.shift.id]}">!
	put %Q!    <value href="#id#{@map[ary.shift.id]}">!
	put '  </pair>'
      end
    end
  end
  
  def end_obj(r)
    put '</obj>'
  end
end

def test_dump(obj)
  puts
  p obj
  puts
  p Marshal.dump(obj)
  puts

  t = BTraverser.new
  t.put(obj)

  xml = BXmlDumper.new
  xml.dump(t.stream)
  xml.output.each do |line|
    puts line
  end
end

hello = Foo.new("Hello")

complex = Foo.new([:string, 2, 3, hello, :string, {hello=>:string}])
test_dump(complex)
test_dump(hello)

In This Thread