Class: Polycrystal::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/polycrystal/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build_path:, shardfile: nil, registry: Polycrystal::Registry.instance, precompile: LAZY_COMPILE) ⇒ Compiler

Returns a new instance of Compiler.



9
10
11
12
13
14
# File 'lib/polycrystal/compiler.rb', line 9

def initialize(build_path:, shardfile: nil, registry: Polycrystal::Registry.instance, precompile: LAZY_COMPILE)
  @build_path = build_path
  @registry = registry
  @shardfile = shardfile
  @precompile = precompile
end

Instance Attribute Details

#build_pathObject (readonly)

Returns the value of attribute build_path.



7
8
9
# File 'lib/polycrystal/compiler.rb', line 7

def build_path
  @build_path
end

#precompileObject (readonly)

Returns the value of attribute precompile.



7
8
9
# File 'lib/polycrystal/compiler.rb', line 7

def precompile
  @precompile
end

#registryObject (readonly)

Returns the value of attribute registry.



7
8
9
# File 'lib/polycrystal/compiler.rb', line 7

def registry
  @registry
end

#shardfileObject (readonly)

Returns the value of attribute shardfile.



7
8
9
# File 'lib/polycrystal/compiler.rb', line 7

def shardfile
  @shardfile
end

Instance Method Details

#executeObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/polycrystal/compiler.rb', line 26

def execute
  if precompile == NO_PRECOMPILE
    compile
  elsif precompile == REQUIRE_AOT
    raise 'Crystal module should be compiled before run' unless File.exist?(outfile)
  else
    compile unless File.exist?(outfile)
  end

  outfile
end

#prepareObject



16
17
18
19
20
21
22
23
24
# File 'lib/polycrystal/compiler.rb', line 16

def prepare
  # load anyolite
  add_anyolite
  # add lib with shards
  use_shards
  # write crystal entrypoint
  in_file.write(entrypoint)
  in_file.close
end