Class: Gloss::ProgLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/gloss/prog_loader.rb

Constant Summary collapse

STDLIB_TYPE_DEPENDENCIES =
{"yaml" => ["pstore", "dbm"],
"rbs" => ["logger", "set", "tsort"],
"logger" => ["monitor"]}

Instance Method Summary collapse

Constructor Details

#initializeProgLoader

Returns a new instance of ProgLoader.



10
11
12
13
14
15
16
17
18
# File 'lib/gloss/prog_loader.rb', line 10

def initialize()
  entrypoint = Config.entrypoint
  (if entrypoint.==(nil) || entrypoint.==("")
    throw(:"error", "Entrypoint is not yet set in .gloss.yml")
  end)
  @files_to_process = [Utils.absolute_path(Config.entrypoint), Utils.absolute_path(File.join(__dir__ || "", "..", "..", "sig", "core.rbs"))]
  @processed_files = Set.new
  @type_checker = TypeChecker.new
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gloss/prog_loader.rb', line 19

def run()
  @files_to_process.each() { |path_string|
    unless @processed_files.member?(path_string) || OUTPUT_BY_PATH.[](path_string)
      Gloss.logger
.debug("Loading #{path_string}")
      path = Utils.absolute_path(path_string)
      file_contents = File.open(path)
.read
      contents_tree = Parser.new(file_contents)
.run
      on_new_file_referenced = proc() { |pa, relative|
        (if relative
          handle_require_relative(pa)
        else
          handle_require(pa)
        end)
      }
      OUTPUT_BY_PATH.[]=(path_string, Visitor.new(contents_tree, @type_checker, on_new_file_referenced)
.run)
      @processed_files.add(path_string)
    end
  }
@type_checker
end