Method: Emfrp::Interpreter#compile_default

Defined in:
lib/emfrp/interpreter/interpreter.rb

#compile_default(gen_cpp = false, gen_main = true) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/emfrp/interpreter/interpreter.rb', line 41

def compile_default(gen_cpp = false, gen_main = true)
  filename = @top[:module_name][:desc]
  c_output_file = filename + (gen_cpp ? ".cpp" : ".c")
  h_output_file = filename + ".h"
  main_output_file = filename + "Main" + ".c"
  File.open(c_output_file, 'w') do |c_file|
    File.open(h_output_file, 'w') do |h_file|
      main_output_file += ".gen" if File.exist?(main_output_file)
      if gen_main
        File.open(main_output_file, 'w') do |main_file|
          compile(c_file, h_file, main_file, filename)
        end
      else
        require "stringio"
        compile(c_file, h_file, StringIO.new, filename)
      end
      return nil
    end
  end
rescue SystemCallError => err
  puts err.inspect
  return :file_write_error
end