The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
A small FS in DATA and a pure Ruby compiler (in the classical sense)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
A small FS in DATA and a pure Ruby compiler (in the classical sense) Posted: Apr 8, 2006 11:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: A small FS in DATA and a pure Ruby compiler (in the classical sense)
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

DATA is one of those features one rarely sees in use, but it can be quite handy at times. I used it in rcov to include the xx markup generation library while ensuring the rcov executable remained self-contained (the extension is optional).

I've written a simple FS meant to be used with DATA, in order to structure it into individually accessible files. I then used it to implement a very simplistic pure Ruby compiler (in the sense of composing a .rb file out of many, i.e. a compiler as the very first ones, before the term started to be misused).

A small FS for the DATA section

I could have used minitar to create POSIX tar files in DATA, but I'd have had to implement random access on top of it, so I just defined a feeble YAML-based format:

 #!/usr/bin/env ruby
  
 # ...
 
 # this is the .rb file
 1 + 1
 __END__
 <length of the toc>
 <YAML-serialized toc (obvious from the code)>
 data for all the files in the DataFS
 just one after the other

Creating the FS

The utterly simplistic API for the Writer class is

datafs = DataFS::Writer.new
datafs.add("filename", "file contents")
datafs.add("whatever.rb", "puts 1")
datafs.dump(someIO) # dump to someIO
puts datafs.dump    # just return the serialized representation

The implementation is trivial; an array of FStat objects (holding name, content length and position in the DATA stream) for the embedded files is serialized with YAML and used as the TOC:


Read more...

Read: A small FS in DATA and a pure Ruby compiler (in the classical sense)

Topic: Build your own Ruby 2.0 (with VM) Previous Topic   Next Topic Topic: YARV and Rails

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use