Module: Haskell

Defined in:
lib/haskell.rb,
lib/haskell/version.rb

Defined Under Namespace

Classes: HaskellCompileError

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.compile(hs_code) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/haskell.rb', line 15

def compile(hs_code)
  FileUtils.touch("#{@@sandbox_path}/COMPILING")
  #TODO: need inform user prefer message
  Thread.abort_on_exception = true
  Thread.new do
    begin
      executable_code = executable_code(hs_code)
      puts_notation(executable_code)
      File.write("#{@@sandbox_path}/tmp.hs", executable_code)
      Kernel.system("ghc #{@@sandbox_path}/tmp.hs")
      raise HaskellCompileError unless compiled?
    ensure
      FileUtils.rm("#{@@sandbox_path}/COMPILING")
    end
  end
end

.compiled?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/haskell.rb', line 36

def compiled?
  File.exist?("#{@@sandbox_path}/tmp")
end

.compiling?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/haskell.rb', line 32

def compiling?
  File.exist?("#{@@sandbox_path}/COMPILING")
end

.executeObject



40
41
42
# File 'lib/haskell.rb', line 40

def execute
  `#{@@sandbox_path}/tmp`.gsub(/\n\z/, '')
end

.invoke_sandbox!(dir_path) ⇒ Object



6
7
8
9
# File 'lib/haskell.rb', line 6

def invoke_sandbox!(dir_path)
  @@sandbox_path = "#{dir_path}/haskell_executing_sandbox"
  FileUtils.mkdir(@@sandbox_path) unless Dir.exist?(@@sandbox_path)
end

.revoke_sandbox!Object



11
12
13
# File 'lib/haskell.rb', line 11

def revoke_sandbox!
  FileUtils.rm_rf(@@sandbox_path)
end