haskell 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/haskell_executing_sandbox/tmp +0 -0
- data/haskell_executing_sandbox/tmp.hi +0 -0
- data/haskell_executing_sandbox/tmp.hs +7 -0
- data/lib/haskell.rb +11 -14
- data/lib/haskell/version.rb +1 -1
- data/test/test_haskell.rb +2 -2
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 106e2d1ecfffa78f4b146b64b741837d50810192
|
4
|
+
data.tar.gz: ea8a1d9025c75c76149a88d8af374df6d0d0f8d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b96e36faecf94815fe22aa9c48c1953f7f0035c5712d58acc57d13aea23a67c7fd694ee33d94ae0313c3d767f29e34259f37be17e8f5bb46663b6593bac2336d
|
7
|
+
data.tar.gz: cb6c972936b1d25eee624da68c200c22ae94033658c40cbc01df2c7ef99369ae34781902a90182b7804e0e425b46291aaf5867a105b184a9200f5e8479c41012
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
```rb
|
4
4
|
require 'haskell'
|
5
|
+
|
6
|
+
# Invoke sandbox for executing ghc
|
7
|
+
Haskell.invoke_sandbox!(File.expand_path('../', __FILE__))
|
8
|
+
|
5
9
|
Haskell.compile %{
|
6
10
|
add :: Integer -> Integer -> Integer
|
7
11
|
add x y = x + y
|
@@ -9,9 +13,12 @@ Haskell.compile %{
|
|
9
13
|
}
|
10
14
|
|
11
15
|
while Haskell.compiling?
|
12
|
-
|
16
|
+
# wait for....
|
13
17
|
end
|
14
18
|
|
15
19
|
p Haskell.execute
|
16
20
|
#=> 3
|
21
|
+
|
22
|
+
# Don't forget to revoke sandbox
|
23
|
+
Haskell.revoke_sandbox!
|
17
24
|
```
|
Binary file
|
Binary file
|
data/lib/haskell.rb
CHANGED
@@ -3,45 +3,42 @@ module Haskell
|
|
3
3
|
class HaskellCompileError < StandardError; end
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def invoke_sandbox!
|
7
|
-
|
8
|
-
|
9
|
-
FileUtils.mkdir($sandbox_path) unless Dir.exist?($sandbox_path)
|
6
|
+
def invoke_sandbox!(dir_path)
|
7
|
+
@@sandbox_path = "#{dir_path}/haskell_executing_sandbox"
|
8
|
+
FileUtils.mkdir(@@sandbox_path) unless Dir.exist?(@@sandbox_path)
|
10
9
|
end
|
11
10
|
|
12
11
|
def revoke_sandbox!
|
13
|
-
FileUtils.rm_rf(
|
12
|
+
FileUtils.rm_rf(@@sandbox_path)
|
14
13
|
end
|
15
14
|
|
16
15
|
def compile(hs_code)
|
17
|
-
FileUtils.touch("#{
|
16
|
+
FileUtils.touch("#{@@sandbox_path}/COMPILING")
|
18
17
|
#TODO: need inform user prefer message
|
19
18
|
Thread.abort_on_exception = true
|
20
19
|
Thread.new do
|
21
20
|
begin
|
22
21
|
executable_code = executable_code(hs_code)
|
23
22
|
puts_notation(executable_code)
|
24
|
-
File.write("#{
|
25
|
-
Kernel.system("ghc #{
|
23
|
+
File.write("#{@@sandbox_path}/tmp.hs", executable_code)
|
24
|
+
Kernel.system("ghc #{@@sandbox_path}/tmp.hs")
|
26
25
|
raise HaskellCompileError unless compiled?
|
27
26
|
ensure
|
28
|
-
FileUtils.rm("#{
|
27
|
+
FileUtils.rm("#{@@sandbox_path}/COMPILING")
|
29
28
|
end
|
30
29
|
end
|
31
|
-
rescue
|
32
|
-
raise "Something wrong...https://github.com/Azabuhs/Ruby/issues"
|
33
30
|
end
|
34
31
|
|
35
32
|
def compiling?
|
36
|
-
File.exist?("#{
|
33
|
+
File.exist?("#{@@sandbox_path}/COMPILING")
|
37
34
|
end
|
38
35
|
|
39
36
|
def compiled?
|
40
|
-
File.exist?("#{
|
37
|
+
File.exist?("#{@@sandbox_path}/tmp")
|
41
38
|
end
|
42
39
|
|
43
40
|
def execute
|
44
|
-
`#{
|
41
|
+
`#{@@sandbox_path}/tmp`.gsub(/\n\z/, '')
|
45
42
|
end
|
46
43
|
|
47
44
|
private
|
data/lib/haskell/version.rb
CHANGED
data/test/test_haskell.rb
CHANGED
@@ -27,7 +27,7 @@ class TestHaskell < MiniTest::Unit::TestCase
|
|
27
27
|
|
28
28
|
private
|
29
29
|
def assert_equal_execute(str, &block)
|
30
|
-
Haskell.invoke_sandbox!
|
30
|
+
Haskell.invoke_sandbox!(File.expand_path('../', __FILE__))
|
31
31
|
Haskell.compile(block.call)
|
32
32
|
nil while Haskell.compiling?
|
33
33
|
assert_equal str, Haskell.execute
|
@@ -35,7 +35,7 @@ class TestHaskell < MiniTest::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def assert_raise_compile_error(&block)
|
38
|
-
Haskell.invoke_sandbox!
|
38
|
+
Haskell.invoke_sandbox!(File.expand_path('../', __FILE__))
|
39
39
|
Haskell.compile(block.call)
|
40
40
|
nil while Haskell.compiling?
|
41
41
|
# TODO: more prefer test
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haskell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
@@ -81,6 +81,9 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- bin/rubype
|
84
|
+
- haskell_executing_sandbox/tmp
|
85
|
+
- haskell_executing_sandbox/tmp.hi
|
86
|
+
- haskell_executing_sandbox/tmp.hs
|
84
87
|
- lib/haskell.rb
|
85
88
|
- lib/haskell/version.rb
|
86
89
|
- rubype.gemspec
|