haskell 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac0c087788b1e471523aed86d8dfd0c42be2503d
4
- data.tar.gz: 610eff264b8bdc1903ea519e857a5346f461aad6
3
+ metadata.gz: 106e2d1ecfffa78f4b146b64b741837d50810192
4
+ data.tar.gz: ea8a1d9025c75c76149a88d8af374df6d0d0f8d2
5
5
  SHA512:
6
- metadata.gz: 788e9b367f36ec0420f44fa89166768073332e8748aab5acd65f9c1796e1953367a2e9ed9bc5b738e0fdf53f6eb329237205e6a6dd819851f437b92264f7ccd5
7
- data.tar.gz: ae3aa09d9fd3af02d5361bccc45f33d27f6e153b5f9a2a2810693493bd18c5fc8a33f4d35ccd5e19f6be4ff179346376f9533753fad70665614055f42081f174
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
  ```
@@ -0,0 +1,7 @@
1
+ module Main where
2
+
3
+ add :: Integer -> Integer -> Integer
4
+ add x y = x + y
5
+ result = add 1 2
6
+
7
+ main = do putStrLn $ show result
@@ -3,45 +3,42 @@ module Haskell
3
3
  class HaskellCompileError < StandardError; end
4
4
 
5
5
  class << self
6
- def invoke_sandbox!
7
- file_path = File.expand_path('../', __FILE__)
8
- $sandbox_path = "#{file_path}/haskell_executing_sandbox"
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($sandbox_path)
12
+ FileUtils.rm_rf(@@sandbox_path)
14
13
  end
15
14
 
16
15
  def compile(hs_code)
17
- FileUtils.touch("#{$sandbox_path}/COMPILING")
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("#{$sandbox_path}/tmp.hs", executable_code)
25
- Kernel.system("ghc #{$sandbox_path}/tmp.hs")
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("#{$sandbox_path}/COMPILING")
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?("#{$sandbox_path}/COMPILING")
33
+ File.exist?("#{@@sandbox_path}/COMPILING")
37
34
  end
38
35
 
39
36
  def compiled?
40
- File.exist?("#{$sandbox_path}/tmp")
37
+ File.exist?("#{@@sandbox_path}/tmp")
41
38
  end
42
39
 
43
40
  def execute
44
- `#{$sandbox_path}/tmp`.gsub(/\n\z/, '')
41
+ `#{@@sandbox_path}/tmp`.gsub(/\n\z/, '')
45
42
  end
46
43
 
47
44
  private
@@ -1,3 +1,3 @@
1
1
  module Haskell
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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.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