Class: Rubex::CodeSupervisor

Inherits:
Object
  • Object
show all
Defined in:
lib/rubex/code_supervisor.rb

Overview

Class for storing Rubex files and their corresponding code writer objects.

Each file has two code writers - header_writer and code_writer. The
header_writer stores the file header of the outputted C code (the .h file)
and the code_writer stores the actual implementation (the .c file).

It is created only once in the execution of the compiler by the Compiler class.

Data is stored in the @data class in the form:
@data = {
  "file1.rubex" => {
    header: header_writer, # Rubex::CodeWriter instance.
    code:   code_writer, # Rubex:: CodeWriter instance.
  },
  "file2.rubex" => {
    header: header_writer, # Rubex::CodeWriter instance.
    code:   code_writer, # Rubex:: CodeWriter instance.
  }
}

Instance Method Summary collapse

Constructor Details

#initializeCodeSupervisor

Returns a new instance of CodeSupervisor.



20
21
22
# File 'lib/rubex/code_supervisor.rb', line 20

def initialize
  @data = {}
end

Instance Method Details

#code(file_name) ⇒ Object



41
42
43
# File 'lib/rubex/code_supervisor.rb', line 41

def code(file_name)
  @data[file_name][:code]
end

#filesObject



45
46
47
# File 'lib/rubex/code_supervisor.rb', line 45

def files
  @data.keys
end

#header(file_name) ⇒ Object



37
38
39
# File 'lib/rubex/code_supervisor.rb', line 37

def header(file_name)
  @data[file_name][:header]
end

#init_file(file_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubex/code_supervisor.rb', line 24

def init_file(file_name)
  header_writer = Rubex::CodeWriter.new(file_name, is_header: true)
  header_writer << "/*Header file for #{file_name}*/\n\n"

  code_writer = Rubex::CodeWriter.new(file_name)
  code_writer << "/*Code file for #{file_name}*/\n\n"
  
  @data[file_name] = {
    header: header_writer,
    code: code_writer
  }
end