From: "Mauricio Fernández" Date: 2002-09-23T07:00:24+09:00 Subject: Re: [ANN] RubyInline 1.0.6 Released On Thu, Sep 19, 2002 at 03:16:41PM +0900, Ryan Davis wrote: > RubyInline 1.0.6 has been released! > > Ruby Inline is my quick attempt to create an analog to Perl's > Inline::C. It allows you to embed C external module code in your ruby > script directly. The code is compiled and run on the fly when needed. > The ruby version isn't near as feature-full as the perl version, but it > is neat! > > http://sourceforge.net/projects/rubyinline/ > > Changes: > > + Added a prelude argument for header and datatype declarations. > - Only output stuff if invoked verbose (ie 'ruby -v ./example.rb'). > - Added some compatibility code for windows. > - Declared requirement on POSIX system. Patch below for better error messages if the inline code fails to compile: Script started on Sun Sep 22 23:53:03 2002 batsman@kodos:/tmp/RubyInline-1.0.6$ diff -u inline.rb.old inline.rb --- inline.rb.old Sun Sep 22 23:50:46 2002 +++ inline.rb Sun Sep 22 23:50:41 2002 @@ -51,13 +51,15 @@ $stderr.puts "ERROR: Can't find header files for ruby. Exiting..." exit 1 end - + caller(1).first =~ /(.*):([0-9]+)[^0-9]*/ + lineinfo = "#line #{$2} \"#{$1}\"\n" # Generating code src = %Q{ #include "ruby.h" #{prelude} static VALUE t_#{mymethod}(int argc, VALUE *argv, VALUE self) { + #{lineinfo} #{src} } batsman@kodos:/tmp/RubyInline-1.0.6$ cat example.rb #!/usr/local/bin/ruby -w require "inline" class MyTest include Inline def factorial(n) f = 1 n.downto(1) { |x| f = f * x } f end def fastfact(*args) inline args, <<-END aint i, f=1; for (i = FIX2INT(argv[0]); i >= 1; i--) { f = f * i; } return INT2FIX(f); END end end t = MyTest.new() max = 1000000 puts "RubyInline #{Inline::VERSION}" if ARGV.length == 0 then type = "Inline" tstart = Time.now (1..max).each { |n| r = t.fastfact(5); if r != 120 then puts "ACK! - #{r}"; end } tend = Time.now else type = "Native" tstart = Time.now (1..max).each { |n| r = t.factorial(5); if r != 120 then puts "ACK! - #{r}"; end } tend = Time.now end total = tend - tstart avg = total / max printf "Type = #{type}, Iter = #{max}, time = %.8f sec, %.8f sec / iter\n", total, avg batsman@kodos:/tmp/RubyInline-1.0.6$ ruby example.rb RubyInline 1.0.6 example.rb: In function `t_fastfact': example.rb:17: `aint' undeclared (first use in this function) example.rb:17: (Each undeclared identifier is reported only once example.rb:17: for each function it appears in.) example.rb:17: parse error before `i' example.rb:18: `i' undeclared (first use in this function) example.rb:18: `f' undeclared (first use in this function) Type = Inline, Iter = 1000000, time = 2.44084700 sec, 0.00000244 sec / iter batsman@kodos:/tmp/RubyInline-1.0.6$ Script done on Sun Sep 22 23:53:48 2002 -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com MSDOS didn't get as bad as it is overnight -- it took over ten years of careful development. -- dmeggins@aix1.uottawa.ca