Skip to content

Commit

Permalink
bigint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwotton committed Aug 20, 2010
1 parent cab07f7 commit a84dbcc
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 195 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.jhci-hist
stupid emacs lock files
.#*
jhc stuff
hs.out_code.c
Expand All @@ -24,3 +23,11 @@ lib/RubyMap.o
lib/rshim.o
sample/tmp
sample/tmp.old
Makefile
*.o
*.bundle
*.so
*.dll
pkg
doc
.DS_Store
12 changes: 12 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions PostInstall.txt
Original file line number Diff line number Diff line change
@@ -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
35 changes: 16 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 0 additions & 21 deletions doc/INSTALL

This file was deleted.

74 changes: 0 additions & 74 deletions doc/new_interface.rb

This file was deleted.

29 changes: 0 additions & 29 deletions ext/HubrisStubLoader.c

This file was deleted.

5 changes: 0 additions & 5 deletions ext/extconf.rb

This file was deleted.

72 changes: 42 additions & 30 deletions hubris.gemspec
Original file line number Diff line number Diff line change
@@ -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
18 changes: 8 additions & 10 deletions lib/hubris.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
22 changes: 18 additions & 4 deletions spec/hubris_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def foo_local
end
end

puts "hi!"

Signal.trap("INT", 'EXIT');

describe "Target" do
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a84dbcc

Please sign in to comment.