Skip to content
Browse files

clean up extension loading

  • Loading branch information...
1 parent cab07f7 commit 1a924ff4ff9c91f71aa49b6e779c6392f90d101a @mwotton committed
Showing with 127 additions and 193 deletions.
  1. +8 −1 .gitignore
  2. +12 −0 Manifest.txt
  3. +0 −2 PostInstall.txt
  4. +16 −19 Rakefile
  5. +0 −21 doc/INSTALL
  6. +0 −74 doc/new_interface.rb
  7. +0 −5 ext/extconf.rb
  8. +5 −0 ext/stub/extconf.rb
  9. +1 −1 ext/{HubrisStubLoader.c → stub/stub.c}
  10. +42 −30 hubris.gemspec
  11. +6 −3 lib/hubris.rb
  12. +37 −37 spec/hubris_spec.rb
View
9 .gitignore
@@ -1,5 +1,4 @@
.jhci-hist
-stupid emacs lock files
.#*
jhc stuff
hs.out_code.c
@@ -24,3 +23,11 @@ lib/RubyMap.o
lib/rshim.o
sample/tmp
sample/tmp.old
+Makefile
+*.o
+*.bundle
+*.so
+*.dll
+pkg
+doc
+.DS_Store
View
12 Manifest.txt
@@ -1,10 +1,22 @@
+CommonErrors.txt
HISTORY.markdown
+History.txt
+HubrisStubLoader.so
Manifest.txt
PostInstall.txt
README.markdown
Rakefile
+examples/simple_inline/clean_and_run.sh
+examples/simple_inline/haskell_math.rb
+examples/simple_rack_app/Test.hs
+examples/simple_rack_app/config.ru
+examples/simple_rack_app/hsload.rb
+hubris.gemspec
+lib/Makefile
lib/hubris.rb
+rspec.rake
sample/Fibonacci.hs
sample/config.ru
+spec/hubris_spec.rb
spec/spec.opts
spec/spec_helper.rb
View
2 PostInstall.txt
@@ -1,3 +1 @@
For more information on Hubris, see http://github.com/mwotton/Hubris/tree/master
-
-You should now have a bin file named jhc_builder that you can use to compile Haskell files into .so files
View
35 Rakefile
@@ -1,26 +1,23 @@
require 'rubygems'
#gem 'hoe', '>= 2.1.0'
-#require 'hoe'
+require 'hoe'
require 'fileutils'
-require './lib/hubris'
-
-# Hoe.plugin :newgem
-# Hoe.plugin :website
-# Hoe.plugin :cucumberfeatures
-
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
-#$hoe = Hoe.spec 'hubris' do
-# self.developer 'Mark Wotton', 'mwotton@gmail.com'
-# self.rubyforge_name = "hubris"
-# self.summary = 'tool to help build .so files from haskell code for use in Ruby via dl'
-# self.post_install_message = 'PostInstall.txt'
-# self.readme_file = "README.markdown"
-# self.history_file = "HISTORY.markdown"
-#end
+# require './lib/hubris'
+
+Hoe.plugin :newgem
+
+
+$hoe = Hoe.spec 'hubris' do
+ self.developer 'Mark Wotton', 'mwotton@gmail.com'
+ self.rubyforge_name = "hubris"
+ self.summary = 'tool to help build .so files from haskell code for use in Ruby via dl'
+ self.post_install_message = 'PostInstall.txt'
+ self.readme_file = "README.markdown"
+ self.history_file = "HISTORY.markdown"
+end
-#require 'newgem/tasks'
-# Dir['tasks/**/*.rake'].each { |t| load t }
+require 'newgem/tasks'
+Dir['tasks/**/*.rake'].each { |t| load t }
#file "lib/RubyMap.hs" => ["lib/RubyMap.chs"] do
View
21 doc/INSTALL
@@ -1,21 +0,0 @@
-This is a bit involved at the moment, because you need to have a development version of GHC,
-as well as having a bootstrapping version of GHC to build it with.
-
-So, on Ubuntu,
-
-sudo apt-get install ruby ruby-dev ghc libopenssl-ruby
-sudo gem install rake open4 rspec hoe
-cabal install c2hs
-wget http://www.haskell.org/ghc/dist/current/dist/ghc-6.11.20090907-src.tar.bz2
-tar -jxvf ghc-6.11.20090907-src.tar.bz2
-cd ghc-6.11.20090907
-# adjust the argument to -j to your number of cores, and the prefix if you need to install somewhere else
-sh boot && ./configure --enable-shared --prefix=/usr/local && make -j 4 && sudo make install
-cd ..
-git clone git://github.com/mwotton/Hubris.git
-cd Hubris
-rake
-# here's where you'll see a whole lot of successes, if you're very lucky
-# There's a good chance you won't. Tell me what went wrong and i'll fix the docs.
-spec spec/*_spec.rb
-
View
74 doc/new_interface.rb
@@ -1,74 +0,0 @@
-# IDEAS for new interface
-
-# option 1 (implicit method name from haskell function)
-class MyClass
- include Hubris
- def_haskell(code)
-end
-
-# option 2 (explicit method name)
-class MyClass
- def_haskell(method_name,code)
-end
-
-# option 3 ()
-class Module
- include Hubris
-end
-
-class MyClass
- inline_haskell "haskell function"
-end
-
-# option 4 (more humourous)
-class Module
- include Hubris
-end
-
-class MyClass
- hubris "haskell function"
-end
-
-#-----------------------------------------
-# include at the module or package level
-#=========================================
-# does importing as_class make sense? no, just include the module
-# when interpreting Haskell module names replace . with ::
-
-# importing std module as a ruby module/class
-hubris :package => "containers", :module => "Data.Map", :as => "Data::Map"
-
-# importing your own module (defaults to module)
-hubris :package => "mypackage", :module => "MyModule" [, :as => "MyModule"]
-
-# implicit package handling (haskell file in my directory)
-hubris :module => "haskell/shit/MyModule"
-
-# simpler to implement option, allows more flexibility in Ruby land
-module MyRubyModule
- # :packages is optional, just brings in external packages.
- hubris :module => "Data.Map", :packages => ["containers","foo"]
- # or
- hubris :source => "MyHaskellCode.hs" # , :packages => [ ... ]
- # or
- hubris :inline => "foo x = x * 2"
-end
-
-
-# alternative
-
-Hubris.import :package => "containers", :module => "Data.Map"
-
-module MyRubyModule
- include Hubris::Data::Map
-end
-
-# alternative2
-
-module MyRubyModule
- hubris :package => "containers", :module => "Data.Map"
-end
-
-
-6:34:58 PM Josh Price: class Module; def hubris; self.class_eval { def self.h;"hubrified!";end };end;end
-6:35:10 PM Josh Price: class B;hubris;end
View
5 ext/extconf.rb
@@ -1,5 +0,0 @@
-require 'mkmf'
-
-# dir_config("HubrisStubLoader")
-have_header('ruby.h')
-create_makefile 'HubrisStubLoader'
View
5 ext/stub/extconf.rb
@@ -0,0 +1,5 @@
+require 'mkmf'
+
+dir_config("stub")
+have_header("ruby.h")
+create_makefile("stub")
View
2 ext/HubrisStubLoader.c → ext/stub/stub.c
@@ -17,7 +17,7 @@ void safe_hs_init() {
}
}
-void Init_HubrisStubLoader() {
+void Init_stub() {
// don't do anything, we just want to make
// sure that the other objects can see the
// safe_hs_init symbols at the C level
View
72 hubris.gemspec
@@ -1,35 +1,47 @@
+# -*- encoding: utf-8 -*-
+
Gem::Specification.new do |s|
- s.name = 'hubris'
- s.version = '0.0.3' # gets this from hubris.rb??
+ s.name = %q{hubris}
+ s.version = "0.0.3"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Mark Wotton"]
+ s.date = %q{2010-04-07}
+ s.description = %q{Hubris is a bridge between Ruby and Haskell, between love and bondage,
+between slothful indolence and raw, blazing speed. Hubris will wash
+your car, lie to your boss, and salvage your love life. If you are
+very, very lucky, it might also let you get some functional goodness
+into your ruby programs through the back door.
+
+I probably don't have to say this, but patches are very much
+welcome. If you have trouble installing it, tell me, and help me
+improve the docs.}
+ s.email = ["mwotton@gmail.com"]
+ s.extra_rdoc_files = ["Manifest.txt", "PostInstall.txt"]
+ s.files = ["HISTORY.markdown", "Manifest.txt", "PostInstall.txt", "README.markdown", "Rakefile", "lib/hubris.rb", "sample/Fibonacci.hs", "sample/config.ru", "spec/spec.opts", "spec/spec_helper.rb"]
+ s.post_install_message = %q{PostInstall.txt}
+ s.rdoc_options = ["--main", "README.markdown"]
+ s.require_paths = ["lib", "ext"]
+ s.rubyforge_project = %q{hubris}
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{tool to help build .so files from haskell code for use in Ruby via dl}
- # s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Mark Wotton", "James Britt", "Josh Price"]
- s.date = %q{2009-11-30}
- s.description = %q{A Ruby Haskell bridge}
- s.email = %q{mwotton@gmail.com}
- s.files = %w{HISTORY.markdown
- ext/extconf.rb
- ext/HubrisStubLoader.c
- lib/hubris.rb
- Rakefile
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
- sample/config.ru
- sample/Fibonacci.hs
- spec/hubris_spec.rb
- spec/spec.opts
- spec/spec_helper.rb}
- # s.extra_rdoc_files = ["README.markdown"]
-# README.markdown
- s.has_rdoc = false
- s.extensions = ["ext/extconf.rb"]
- s.homepage = 'http://github.com/mwotton/hubris'
- s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
- s.require_paths = %w{lib ext}
- s.rubyforge_project = 'hubris'
-
- s.summary = 'Hubris is a Ruby Haskell bridge allowing you to call Haskell functions from your Ruby code.'
- %w{rspec open4}.each do |gem|
- s.add_dependency(gem)
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
+ s.add_development_dependency(%q<gemcutter>, [">= 0.5.0"])
+ s.add_development_dependency(%q<hoe>, [">= 2.5.0"])
+ else
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
+ s.add_dependency(%q<gemcutter>, [">= 0.5.0"])
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
+ end
+ else
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
+ s.add_dependency(%q<gemcutter>, [">= 0.5.0"])
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
end
- puts s.extensions
end
View
9 lib/hubris.rb
@@ -3,7 +3,8 @@
require 'open4'
require 'digest/md5'
require 'rbconfig'
-
+$:.unshift File.dirname(__FILE__) + "/../ext/stub"
+require 'stub'
# require 'file/temp'
# require 'libHaskell'
# TODO delete old files
@@ -30,7 +31,7 @@ module Hubris
HUBRIS_DIR = ENV['HUBRIS_DIR'] || "/var/hubris"
SO_CACHE = File.expand_path(HUBRIS_DIR + "/cache")
HS_CACHE = File.expand_path(HUBRIS_DIR + "/source")
- require 'HubrisStubLoader'
+ # require 'stub'
[SO_CACHE,HS_CACHE].each {|dir| FileUtils.mkdir_p(dir)}
$:.push(SO_CACHE)
@always_rebuild=false
@@ -80,8 +81,10 @@ def zencode(name)
def hubrify(mod, args, src,packages=[])
libFile = "#{SO_CACHE}/#{zencode(mod)}.#{dylib_suffix}"
+ headers = ""
+ libraries = ""
if @always_rebuild or !File.exists?(libFile)
- status,msg = Hubris.noisy("Hubrify --module #{mod} --output #{libFile} #{args.join(' ')} " +
+ status,msg = Hubris.noisy("Hubrify #{headers} #{libraries} -v --module #{mod} --output #{libFile} #{args.join(' ')} " +
(packages+@@basepackages).collect{|x| "--package #{x}"}.join(' ') + ' ' + src)
# if Hubrify's not installed, we throw an exception. just as good as explicitly checking a flag.
raise HaskellError.new("Hubrify error:\n#{msg + status.exitstatus.to_s}") unless status.exitstatus == 0
View
74 spec/hubris_spec.rb
@@ -3,20 +3,6 @@
require "hubris"
Hubris.add_packages %w(base)
-# # just want to check it's actually possible to load a library dynamically
-# describe "dlload" do
-# it "actually builds and loads a C level dylib stupidly" do
-# system "cd sample; make"
-# `cd sample; ruby hsload.rb`.chomp.should eql("144")
-# end
-# end
-
-class Target
- def foo_local
- 14
- end
-end
-
Signal.trap("INT", 'EXIT');
describe "Target" do
@@ -41,16 +27,16 @@ class Foo; hubris :inline => "--blah blah blah
end
- # it "handles booleans" do
- # class Bar
- # hubris :inline => "my_negate True = False;my_negate False = True", :no_strict => true
- # end
- # t = Bar.new
- # # puts t.methods
- # t.my_negate(false).should eql(true)
- # t.my_negate(true).should eql(false)
- # lambda{ t.my_negate("Banana")}.should raise_error
- # end
+ it "handles booleans" do
+ class Bar
+ hubris :inline => "my_negate True = False;my_negate False = True", :no_strict => true
+ end
+ t = Bar.new
+ # puts t.methods
+ t.my_negate(false).should eql(true)
+ t.my_negate(true).should eql(false)
+ lambda{ t.my_negate("Banana")}.should raise_error
+ end
it "handles doubles" do
class Doubler
@@ -72,14 +58,31 @@ class Stringer
end
describe "BigInt" do
- it "handles BigInts" do
+ context "BigInts" do
class Bigint
hubris :inline => "big_inc :: Integer -> Integer; big_inc i = i + 1"
end
- b = Bigint.new
- b.big_inc(10000000000000000).should eql(10000000000000001)
- b.big_inc(1).should eql(2)
end
+ before(:each) do
+ @b = Bigint.new
+ end
+
+ it "handles smalls" do
+ @b.big_inc(1).should eql(2)
+ end
+
+ it "handles really big ints" do
+ @b.big_inc(1000000000000000000000000).should eql(1000000000000000000000001)
+ end
+
+ it "handles ints just before the border" do
+ @b.big_inc(2147483647).should == 2147483648
+ end
+
+ it "handles > int but < bigint" do
+ @b.big_inc(2147483648).should == 2147483649
+ end
+
end
describe 'Multiple' do
@@ -97,10 +100,7 @@ def foo_local
# and it doesn't wipe out other methods on the class
t.foo_local.should eql(14)
t.incr(3).should eql(4)
- # FIXME this one is waiting for support of Control.Exception in
- # JHC
- # lambda { t.mydouble(2.3)}.should raise_error(HaskellError)
- # Fooclever.mydouble(2.3).should raise_error(RuntimeError)
+ lambda { t.mydouble(2.3)}.should raise_error(HaskellError)
end
end
@@ -148,9 +148,9 @@ class MaybeLazy
hubris :inline => "foo:: Maybe Int -> Int; foo (Just _) = 1; foo Nothing = 0"
end
m=MaybeIn.new
-# m.foo(1).should == 1
-# m.foo(20).should == 1
-# m.foo(nil).should == 2
+ m.foo(1).should == 2
+ m.foo(20).should == 40
+ m.foo(nil).should == 0
lambda{ m.foo("blah") }.should raise_error(HaskellError)
# here's a tricky bit: in the previous example, we had to look at the value of the
# Maybe, so the exception got triggered.
@@ -158,8 +158,8 @@ class MaybeLazy
# deeply examine the something. Arguably, it would be less surprising if we always looked
# deeply into it, but it's up for debate. TODO
- lazy = MaybeLazy.new
- lazy.foo("blah").should == 1
+ #lazy = MaybeLazy.new
+ #lazy.foo("blah").should == 1
end
end

0 comments on commit 1a924ff

Please sign in to comment.
Something went wrong with that request. Please try again.