class BootstrapHelper::WithGrammar

Public Class Methods

new(body) click to toggle source
# File lib/atomy/bootstrap.rb, line 219
def initialize(body)
  @body = body
end

Public Instance Methods

bytecode(gen, mod) click to toggle source
# File lib/atomy/bootstrap.rb, line 223
def bytecode(gen, mod)
  gen.create_block(build_block(gen.state.scope, mod))
  gen.send(:call, 0)
end

Private Instance Methods

build_block(scope, mod) click to toggle source
# File lib/atomy/bootstrap.rb, line 230
def build_block(scope, mod)
  Atomy::Compiler.generate(mod.file) do |blk|
    # close over the outer scope
    blk.state.scope.parent = scope

    # capture original module
    blk.push_scope
    blk.send(:module, 0)

    # add Atomy::Grammar::AST to the lexical scope
    blk.push_cpath_top
    blk.find_const(:Atomy)
    blk.find_const(:Grammar)
    blk.find_const(:AST)
    blk.add_scope

    # restore original module for definition targets
    blk.push_scope
    blk.swap
    blk.send(:current_module=, 1)

    mod.compile(blk, @body)
  end
end