Class: Kapusta::Compiler::Emitter

Constant Summary collapse

RUBY_KEYWORDS =
%w[
  BEGIN END alias and begin break case class def defined? do else elsif end ensure false for if in
  module next nil not or redo rescue retry return self super then true undef unless until when while yield
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Emitter

Returns a new instance of Emitter.



27
28
29
30
31
# File 'lib/kapusta/compiler/emitter.rb', line 27

def initialize(path:)
  @path = path
  @temp_index = 0
  @runtime_helpers = []
end

Instance Method Details

#emit_file(forms) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/kapusta/compiler/emitter.rb', line 33

def emit_file(forms)
  env = Env.new
  body = emit_forms_with_headers(forms, env, :toplevel)
  helpers = Runtime.helper_source(@runtime_helpers)
  [
    '# frozen_string_literal: true',
    helpers,
    body
  ].reject(&:empty?).join("\n\n") << "\n"
end