From: Michael Neumann Date: 2004-12-26T21:30:45+09:00 Subject: Re: Revival of RubyInRuby? Ryan Davis wrote: > > On Dec 25, 2004, at 4:25 PM, Michael Neumann wrote: > >> Lately (as I was dissatified with Ruby's current continuation >> implementation), I remembered that we had a Ruby-In-Ruby project some >> years ago. Python has PyPy, which got even fund by EU. Squeak in >> mostly written in itself, too. >> >> So the question is, do we get enough interested people together that >> would work on such a project? > > > We've got a fairly good start w/ our ruby2c translator. The long term > goal is to reimplement ruby in ruby and translate it to C in much the > same way that Squeak smalltalk does. More info: That's great news. Very similar to what I thought. But I don't see a reason for implementing the parser in a subset of Ruby (except for performance). Once you've bootstrapped the parser to bytecode with real-Ruby, you can load it into the VM. How active is the project? Who else is working on it? Parser: I'm currently hacking a bit on my packrat project and try to get a TPDL (Top Down Parsing Language) generator working. It's pretty slow (~1000 lines per second), maybe if I implement memoizing it will become faster. Nevertheless, it would be fast enough if you precompile the whole libraries to .rbc, and use the parser only for "eval" at runtime. I don't think that this would be a big performance penalty. Garbage Collector? Any concrete plans, which strategy to use? Using a non conservating GC would break with existing C extensions. But if they'd be rewritten in Ruby2C language, the generator could automatically generate code for a conservating GC or a non conservating... I'm for a non-conservative due to the reasons I said in the last email. My idea for the Ruby2C translator is very similar, but more C oriented than yours (it's not only for extensions). Example: class MyStruct < CStruct def_type :initialize, {:a => 'int', :b => 'int', :return => 'void'} def initialize(a, b) @a = a @b = b end def_type :inspect, {:return => 'void'} def inspect printf("%d\n%d\n", @a, @b) end ... end which would then be translated into C: typedef struct MyStruct { int a; int b; }; void MyStruct_initialize(MyStruct* self, int a, int b) { self->a = a; self->b = b; } void MyStruct_inspect(MyStruct *self) { printf("%d\n%d\n", self->a, self->b); } The types of the instance variables are automatically infered. Types or local, argument and return values have to be specified via def_type. Special methods like deref(value) would map to *(value) in the C output. Constants map to MACROS, so they are simply replaced with their name in the C output: def a printf("%d\n", SQL_BIT) end becomes: printf("%d\n", SQL_BIT) And of course method calls map to function calls in C, with the difference that, if the method is defined in the class, then the self argument is passed, otherwise a real function call (as for printf) is performed. I think with this kind of translator, it's pretty simple to write C programs cleanly in Ruby. And it's still valid Ruby, unlike Pyrex for example (Pyrex is a Python-dialect for implementing extensions, but it's not valid Python, AFAIK). One could extend that a bit, and e.g. if your class inherits from T_DATA, then you are specifying a Ruby-extensions, which gets automatically wrapped and unwrapped, and provides the attached C struct to you without hassle. And of course class methods map to "self"-less functions: type_def :"MyStruct.new", {:i => int, :j => int, a => 'MyStruct*', :return => 'MyStruct*'} def MyStruct.new(i, j) obj = cast(malloc(sizeof(MyStruct)), 'MyStruct*') if obj == NULL # error else MyStruct_initialize(obj, i, j) # or obj.initialize(i,j) return obj end end Indeed, what I propose is some kind of C with classes ;-) Maybe I'm missing something important. > IRC: #ruby2c > rubyforge: http://rubyforge.org/projects/ruby2c/ > Propaganda: http://www.zenspider.com/~ryand/Ruby2C.pdf > >