-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/Neurogami/Hubris
- Loading branch information
Showing
14 changed files
with
340 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
.jhci-hist | ||
# stupid emacs lock files | ||
stupid emacs lock files | ||
.#* | ||
# jhc stuff | ||
jhc stuff | ||
hs.out_code.c | ||
hs.out | ||
examples/simple_inline/RubyMap.hs | ||
|
||
examples/simple_inline/rshim.h | ||
examples/simple_inline/stubs.c | ||
examples/simple_inline/stubs.o | ||
examples/simple_rack_app/stubs.c | ||
examples/simple_rack_app/tmp.old/ | ||
examples/simple_rack_app/tmp/ | ||
pkg/ | ||
RubyMap.hi | ||
RubyMap.hs | ||
RubyMap.o | ||
lib/RubyMap.chi | ||
lib/RubyMap.chs.h | ||
lib/RubyMap.hi | ||
lib/RubyMap.hs | ||
lib/RubyMap.o | ||
lib/rshim.o | ||
sample/tmp | ||
sample/tmp.old |
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,29 @@ | ||
|
||
|
||
warn "Have ARGV #{ARGV.inspect}" | ||
|
||
sh = %~ | ||
#!/bin/sh | ||
|
||
# $1 is our source haskell | ||
rm -rf tmp.old | ||
mv tmp tmp.old | ||
mkdir tmp | ||
tmp="tmp/$1" | ||
cat $1 >> $tmp | ||
echo "main :: IO ()" >> $tmp | ||
echo "main = return ()" >> $tmp | ||
|
||
cd tmp | ||
jhc -dc "$1" | ||
sed -i 's/^main(/disregard_main(/' hs.out_code.c | ||
|
||
# for linux | ||
gcc '-std=gnu99' -D_GNU_SOURCE '-falign-functions=4' -ffast-math\ | ||
-Wshadow -Wextra -Wall -Wno-unused-parameter -o libdynhs.so\ | ||
hs.out_code.c -DNDEBUG -O3 -fPIC -shared '-D_JHC_STANDALONE=0' | ||
# for mac | ||
#gcc '-std=gnu99' -D_GNU_SOURCE '-falign-functions=4' -ffast-math\ | ||
# -Wshadow -Wextra -Wall -Wno-unused-parameter -o libdynhs.so\ | ||
# hs.out_code.c -DNDEBUG -O3 -fPIC -shared '-D_JHC_STANDALONE=0' -dynamiclib | ||
#mv libdynhs.so .. |
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,24 @@ | ||
#!/bin/sh | ||
|
||
# $1 is our source haskell | ||
rm -rf tmp.old | ||
mv tmp tmp.old | ||
mkdir tmp | ||
tmp="tmp/$1" | ||
cat $1 >> $tmp | ||
echo "main :: IO ()" >> $tmp | ||
echo "main = return ()" >> $tmp | ||
|
||
cd tmp | ||
jhc -dc "$1" | ||
sed -i 's/^main(/disregard_main(/' hs.out_code.c | ||
|
||
# for linux | ||
gcc '-std=gnu99' -D_GNU_SOURCE '-falign-functions=4' -ffast-math\ | ||
-Wshadow -Wextra -Wall -Wno-unused-parameter -o libdynhs.so\ | ||
hs.out_code.c -DNDEBUG -O3 -fPIC -shared '-D_JHC_STANDALONE=0' | ||
for mac | ||
#gcc '-std=gnu99' -D_GNU_SOURCE '-falign-functions=4' -ffast-math\ | ||
# -Wshadow -Wextra -Wall -Wno-unused-parameter -o libdynhs.so\ | ||
# hs.out_code.c -DNDEBUG -O3 -fPIC -shared '-D_JHC_STANDALONE=0' -dynamiclib | ||
#mv libdynhs.so .. |
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,2 @@ | ||
here = File.expand_path(File.dirname(__FILE__)) | ||
exec "sh #{here}/../bin-scripts/ghc_builder #{ARGV[0]}" |
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 |
---|---|---|
@@ -1,24 +1,2 @@ | ||
#!/bin/sh | ||
|
||
# $1 is our source haskell | ||
rm -rf tmp.old | ||
mv tmp tmp.old | ||
mkdir tmp | ||
tmp="tmp/$1" | ||
cat $1 >> $tmp | ||
echo "main :: IO ()" >> $tmp | ||
echo "main = return ()" >> $tmp | ||
|
||
cd tmp | ||
jhc -dc "$1" | ||
sed -i 's/^main(/disregard_main(/' hs.out_code.c | ||
|
||
# for linux | ||
#gcc '-std=gnu99' -D_GNU_SOURCE '-falign-functions=4' -ffast-math\ | ||
# -Wshadow -Wextra -Wall -Wno-unused-parameter -o libdynhs.so\ | ||
# hs.out_code.c -DNDEBUG -O3 -fPIC -shared '-D_JHC_STANDALONE=0' | ||
# for mac | ||
gcc '-std=gnu99' -D_GNU_SOURCE '-falign-functions=4' -ffast-math\ | ||
-Wshadow -Wextra -Wall -Wno-unused-parameter -o libdynhs.so\ | ||
hs.out_code.c -DNDEBUG -O3 -fPIC -shared '-D_JHC_STANDALONE=0' -dynamiclib | ||
mv libdynhs.so .. | ||
here = File.expand_path(File.dirname(__FILE__)) | ||
exec "sh #{here}/../bin-scripts/jhc_builder #{ARGV[0]}" |
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,5 @@ | ||
#!/usr/bin/env sh | ||
# Delete existing binaries to see that the lib correctly recreates them | ||
clear; | ||
rm -rf ~/.hubris_cache/*; rm -rf *.o; rm -rf *.hi; rm -rf *.c; | ||
ruby haskell_math.rb |
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,29 @@ | ||
#!/usr/local/bin/ruby | ||
|
||
here = File.expand_path( File.dirname(__FILE__)) | ||
$:.unshift here + '/../../lib' | ||
require 'hubris' | ||
|
||
#Hubris.ruby_header = '/home/james/data/vendor/ruby-1.8.6-p383/' | ||
#Hubris.ghc_cmd = 'ghc' | ||
#Hubris.ghc_version = '6.11.20090913' | ||
|
||
class Target | ||
|
||
include Hubris | ||
|
||
def negate(i) | ||
return -i | ||
end | ||
end | ||
|
||
t = Target.new | ||
|
||
t.inline "mydouble (T_FIXNUM i) = T_FIXNUM (i + i) | ||
my_double _ = T_NIL", :no_strict => true | ||
|
||
#t.inline "mytriple (T_FIXNUM i) = T_FIXNUM (i * 3) | ||
# mytriple _ = T_NIL", :no_strict => true | ||
puts t.negate(3) | ||
puts t.mydouble(2) | ||
# puts t.mytriple(8) |
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,28 @@ | ||
{-# LANGUAGE ForeignFunctionInterface #-} | ||
|
||
-- module Test where | ||
|
||
import Foreign.C.Types | ||
-- import Data.Map | ||
import Maybe | ||
|
||
-- main = putStrLn "11" | ||
|
||
fibonacci :: Int -> Int | ||
fibonacci n = fibs !! n | ||
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs) | ||
|
||
-- local_map = Data.Map.fromList [(1,2), (3,4)] | ||
|
||
|
||
|
||
-- lookup_hs ::CInt -> CInt | ||
-- lookup_hs = fromIntegral . Maybe.fromJust . ((flip Data.Map.lookup) local_map) . fromIntegral | ||
-- foreign export ccall lookup_hs :: CInt -> CInt | ||
|
||
fibonacci_hs :: CInt -> CInt | ||
fibonacci_hs = fromIntegral . fibonacci . fromIntegral | ||
|
||
foreign export ccall fibonacci_hs :: CInt -> CInt | ||
|
||
-- main = putStrLn "foo" |
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,24 @@ | ||
#\ -w -p 8765 | ||
use Rack::Reloader, 0 | ||
use Rack::ContentLength | ||
|
||
require 'pp' | ||
require 'dl/import' | ||
|
||
module HaskyPants | ||
extend DL::Importable | ||
dlload "./libdynhs.so" | ||
extern "int fibonacci_hs(int)" | ||
end | ||
|
||
|
||
def arg_from env | ||
env['REQUEST_URI'] ? env['REQUEST_URI'].to_s.sub(/^\//, '').to_i : 0 | ||
end | ||
|
||
app = proc do |env| | ||
value = HaskyPants.fibonacci_hs( arg_from env ) | ||
[ 200, {'Content-Type' => 'text/plain'}, "The fib number is #{value }" ] | ||
end | ||
|
||
run app |
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,16 @@ | ||
require 'dl/import' | ||
|
||
module HaskyPants | ||
if /^1\.8/ =~ RUBY_VERSION | ||
extend DL::Importable | ||
else | ||
extend DL::Importer | ||
end | ||
|
||
dlload "./libdynhs.so" | ||
["int fibonacci_hs(int)"].each do |f| | ||
extern f | ||
end | ||
end | ||
|
||
puts HaskyPants.fibonacci_hs(12) |
Oops, something went wrong.