forked from seattlerb/rubyinline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Lots of minor cleanup. + Added add_to_init to extend init methods. Great hack! + Added 2 demo files used in the rubyconf 2005 presentation. [git-p4: depot-paths = "//src/RubyInline/dev/": change = 2198]
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
begin require 'rubygems' rescue LoadError end | ||
require 'inline' | ||
|
||
class FastMath | ||
def factorial(n) | ||
f = 1 | ||
n.downto(2) { |x| f *= x } | ||
return f | ||
end | ||
inline do |builder| | ||
builder.c " | ||
long factorial_c(int max) { | ||
int i=max, result=1; | ||
while (i >= 2) { result *= i--; } | ||
return result; | ||
}" | ||
end | ||
end | ||
|
||
math = FastMath.new | ||
|
||
if ARGV.empty? then | ||
30000.times do math.factorial(20); end | ||
else | ||
30000.times do math.factorial_c(20); end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/local/bin/ruby -w | ||
|
||
begin require 'rubygems' rescue LoadError end | ||
require 'inline' | ||
|
||
class Hello | ||
inline do |builder| | ||
builder.include "<stdio.h>" | ||
builder.c 'void hello() { puts("hello world"); }' | ||
end | ||
end | ||
|
||
Hello.new.hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters