Permalink
Browse files

bigint changes

  • Loading branch information...
1 parent cab07f7 commit a84dbcc04ae8324597ed3cbba5cafff5aea6e6a0 @mwotton committed Aug 20, 2010
Showing with 104 additions and 195 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 −29 ext/HubrisStubLoader.c
  8. +0 −5 ext/extconf.rb
  9. +42 −30 hubris.gemspec
  10. +8 −10 lib/hubris.rb
  11. +18 −4 spec/hubris_spec.rb
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,29 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <ruby.h>
-
-int loaded = 0;
-VALUE Exports = Qnil;
-extern void hs_init(int * argc, char ** argv[]);
-void safe_hs_init() {
- char ** argv = malloc(sizeof(char**) * 1);
- int argc = 1;
-
- argv[0]="haskell_extension";
- if (! loaded) {
- loaded=1;
- // printf("really loading haskell runtime\n");
- hs_init(&argc, &argv);
- }
-}
-
-void Init_HubrisStubLoader() {
- // 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
-
- // so, ok. we do do some stuff here.:) but it's really two separate things.
- VALUE Hubris = rb_define_module("Hubris");
- Exports = rb_define_module_under(Hubris, "Exports");
-
-}
View
@@ -1,5 +0,0 @@
-require 'mkmf'
-
-# dir_config("HubrisStubLoader")
-have_header('ruby.h')
-create_makefile 'HubrisStubLoader'
View
@@ -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
@@ -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} --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
@@ -102,20 +105,15 @@ def dylib_suffix
def self.noisy(str)
pid, stdin, stdout, stderr = Open4.popen4 str
- # puts "running #{str}\n"
-
-
- # puts "Status: #{status.exitstatus}"
- # puts "#{pid} done"
-
-
+ puts "running #{str}\n"
msg =<<-"EOF"
ran |#{str}|
output|#{stdout.read}|
error |#{stderr.read}|
EOF
ignored, status = Process.waitpid2 pid
msg += "status |#{status}|"
+ puts msg
return status, msg
end
View
@@ -17,6 +17,8 @@ def foo_local
end
end
+puts "hi!"
+
Signal.trap("INT", 'EXIT');
describe "Target" do
@@ -72,13 +74,25 @@ 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 > int but < bigint" do
+ @b.big_inc(1000000000000000000).should eql(1000000000000000001)
end
end

0 comments on commit a84dbcc

Please sign in to comment.