From: Gyoung-Yoon Noh Date: 2005-05-04T05:32:11+09:00 Subject: Re: I rock. On 5/4/05, Eric Hodel wrote: > On 03 May 2005, at 11:09, Phil Tomson wrote: > > > In article , > > Eric Hodel wrote: > >> $ cat f.c > >> // BEGIN METARUBY PREAMBLE > >> #include > >> #define case_equal_long(x, y) (rb_funcall((x), rb_intern("==="), 1, > >> (y))) > >> // END METARUBY PREAMBLE > >> // class F < Object > >> > >> static VALUE > >> rrc_cF_factorial(VALUE __self, VALUE n) { > >> VALUE f; > >> VALUE x; > >> f = LONG2FIX(1); > >> x = n; > >> while (RTEST(rb_funcall(x, rb_intern(">="), 1, LONG2FIX(2)))) { > >> f = rb_funcall(f, rb_intern("*"), 1, x); > >> x = rb_funcall(x, rb_intern("-"), 1, LONG2FIX(1)); > >> }; > >> return f; > >> } > >> > >> static VALUE > >> rrc_cF_main(VALUE __self) { > >> return rb_funcall(__self, rb_intern("factorial"), 1, LONG2FIX(5)); > >> } > >> > >> void > >> Init_F() { > >> VALUE rrc_cF = rb_define_class("F", rb_path2class("Object")); > >> > >> rb_define_method(rrc_cF, "factorial", rrc_cF_factorial, 1); > >> rb_define_method(rrc_cF, "main", rrc_cF_main, 0); > >> > >> } > >> > > > > > > How does this differ from the current RubyToC stuff? > > This one (Ruby2RubyC) generates a C extension, where the other tail > generates raw, type inferenced C code. > > I think Ruby2RubyC can make optimizations for Fixnum math and other > boolean logic, but I haven't explored that yet. > > Ruby2RubyC is also dynamic code safe. It automatically converts from > Fixnum to Bignum, thanks to the Ruby C runtime. (I snipped the output > of factorial(9999), but it outputs a handful of lines of numbers.) > > For example, the other tail could not handle factorial(9999) because C > doesn't have Bignums. > > > Is this newer version available for download yet? > > No, not yet. Maybe after Thursday hacking. > > -- > Eric Hodel - drbrain@segment7.net - http://segment7.net > FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 > > Python has PyRex which enables writing CPython extensions with python-like syntax. I guess Ruby2RubyC can do a foundation role for future great works such as writing extensions with ruby syntax, enhancing performance easily with type conversion, or can be used as intermediate format for translating Ruby to C. Cheers, -- http://nohmad.sub-port.net